cvs: peardoc /en/chapters standards.xml

From: Date: Thu, 17 Feb 2005 18:31:38 +0000
Subject: cvs: peardoc /en/chapters standards.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-5540@lists.php.net to get a copy of this message
danielc Thu Feb 17 13:31:38 2005 EDT Modified files: /peardoc/en/chapters standards.xml Log: * Implement Header Comment Blocks RFC (PEPr #128). * Add explanation of why formatting is important. * Add docblock example for $GLOBALS. * Add docblock example for sample code.

http://cvs.php.net/diff.php/peardoc/en/chapters/standards.xml?r1=1.28&r2=1.29&ty=u Index: peardoc/en/chapters/standards.xml diff -u peardoc/en/chapters/standards.xml:1.28 peardoc/en/chapters/standards.xml:1.29 --- peardoc/en/chapters/standards.xml:1.28 Mon Dec 20 15:13:26 2004 +++ peardoc/en/chapters/standards.xml Thu Feb 17 13:31:37 2005 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.28 $ --> +<!-- $Revision: 1.29 $ --> <chapter id="standards"> <title>Coding Standards</title> @@ -222,47 +222,336 @@ <sect1 id="standards.header"> <title>Header Comment Blocks</title> <para> - All source code files in the core PEAR distribution should contain - the following comment block as the header: + All source code files in the PEAR repository shall contain a + <quote>page-level</quote> docblock at the top of each file + and a <quote>class-level</quote> docblock immediately above + each class. Below are examples of such docblocks. + </para> + + <para> <programlisting role="php"> + <![CDATA[ +<?php + /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ -// +----------------------------------------------------------------------+ -// | PHP version 4 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2004 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available through the world-wide-web at the following url: | -// | http://www.php.net/license/3_0.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Original Author &lt;author@example.com&gt; | -// | Your Name &lt;you@example.com&gt; | -// +----------------------------------------------------------------------+ -// -// &dollar;Id:&dollar; -</programlisting> - </para> - <para> - There's no hard rule to determine when a new code contributor - should be added to the list of authors for a given source file. - In general, their changes should fall into the <quote>substantial</quote> - category (meaning somewhere around 10% to 20% of code changes). - Exceptions could be made for rewriting functions or contributing - new logic. - </para> - <para> - Simple code reorganization or bug fixes would not justify the - addition of a new individual to the list of authors. - </para> - <para> - Files not in the core PEAR repository should have a similar block - stating the copyright, the license, and the authors. All files - should include the modeline comments to encourage consistency. + +/** + * Short description for file + * + * Long description for file (if any)... + * + * PHP versions 4 and 5 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_0.txt. If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category CategoryName + * @package PackageName + * @author Original Author <author@example.com> + * @author Another Author <another@example.com> + * @copyright 1997-2005 The PHP Group + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: &#x24;Id:&#x24; + * @link http://pear.php.net/package/PackageName + * @see NetOther, Net_Sample::Net_Sample() + * @since File available since Release 1.2.0 + * @deprecated File deprecated in Release 2.0.0 + */ + +/* + * Place includes, constant defines and $_GLOBAL settings here. + * Make sure they have appropriate docblocks to avoid phpDocumentor + * construing they are documented by the page-level docblock. + */ + +/** + * Short description for class + * + * Long description for class (if any)... + * + * @category CategoryName + * @package PackageName + * @author Original Author <author@example.com> + * @author Another Author <another@example.com> + * @copyright 1997-2005 The PHP Group + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.php.net/package/PackageName + * @see NetOther, Net_Sample::Net_Sample() + * @since Class available since Release 1.2.0 + * @deprecated Class deprecated in Release 2.0.0 + */ +class foo +{ +} + +?> + ]]> + </programlisting> </para> + + <sect2 id="standards.header.variable"> + <title>Required Tags That Have Variable Content</title> + <variablelist> + <varlistentry> + <term>Short Descriptions</term> + <listitem> + <para> + Short descriptions must be provided for all docblocks. + They should be a quick sentence, not the name of the item. + Please read the Coding Standard's + <link linkend="standards.sample"> + Sample File</link> about how to write good descriptions. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>PHP Versions</term> + <listitem> + <para> + One of the following must go in the page-level docblock: + </para> + <informalexample> + <programlisting role="docblock"> + * PHP version 4 + * PHP version 5 + * PHP versions 4 and 5 + </programlisting> + </informalexample> + </listitem> + </varlistentry> + + <varlistentry> + <term>@license</term> + <listitem> + <para> + There are several possible licenses. One of the + following must be picked and placed in the page-level + and class-level docblocks: + </para> + <informalexample> + <programlisting role="docblock"> + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 + * @license http://www.freebsd.org/copyright/freebsd-license.html BSD License (2 Clause) + * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) + * @license http://www.freebsd.org/copyright/license.html BSD License (4 Clause) + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + </programlisting> + </informalexample> + <para> + For more information, see the PEAR Group's + <ulink url="&url.pear.group.licenses;"> + Licensing Announcement</ulink>. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>@link</term> + <listitem> + <para> + The following must be used in both the page-level and + class-level docblocks. Of course, change + <quote>PackageName</quote> to the name of your package. + This ensures the generated documentation links back your package. + </para> + <informalexample> + <programlisting role="docblock"> + * @link http://pear.php.net/package/PackageName + </programlisting> + </informalexample> + </listitem> + </varlistentry> + + <varlistentry> + <term>@author</term> + <listitem> + <para> + There's no hard rule to determine when a new code + contributor should be added to the list of authors + for a given source file. In general, their changes + should fall into the "substantial" category (meaning + somewhere around 10% to 20% of code changes). + Exceptions could be made for rewriting functions or + contributing new logic. + </para> + <para> + Simple code reorganization or bug fixes would not + justify the addition of a new individual to the + list of authors. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>@since</term> + <listitem> + <para> + This tag is required when a file or class is added + after the package's initial release. Do not use it + in an initial release. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>@deprecated</term> + <listitem> + <para> + This tag is required when a file or class is no + longer used but has been left in place for + backwards compatibility. + </para> + </listitem> + </varlistentry> + + </variablelist> + </sect2> + + <sect2 id="standards.header.optional"> + <title>Optional Tags</title> + <variablelist> + <varlistentry> + <term>@copyright</term> + <listitem> + <para> + Feel free to apply whatever copyrights you desire. + When formatting this tag, the year should be in + four digit format and if a span of years is involved, + use a hyphen between the earliest and latest year. + The copyright holder can be you, a list of people, a + company, the PHP Group, etc. Examples: + </para> + <informalexample> + <programlisting role="docblock"> + * @copyright 2003 John Doe and Jennifer Buck + * @copyright 2001-2004 John Doe + * @copyright 1997-2004 The PHP Group + * @copyright 2001-2004 XYZ Corporation + </programlisting> + </informalexample> + </listitem> + </varlistentry> + + <varlistentry> + <term>License Summary</term> + <listitem> + <para> + If you are using the PHP License, use the summary text + provided above. If another license is being used, + please remove the PHP License summary. Feel free to + substitute it with text appropriate to your license, + though to keep things easy to locate, please preface + the text with <literal>LICENSE: </literal>. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>@see</term> + <listitem> + <para> + Add a @see tag when you want to refer users to other + sections of the package's documentation. If you have + multiple items, separate them with commas rather than + adding multiple @see tags. + </para> + </listitem> + </varlistentry> + + </variablelist> + </sect2> + + <sect2 id="standards.header.order"> + <title>Order and Spacing</title> + <para> + To ease long term readability of PEAR source code, the + text and tags must conform to the order and spacing + provided in the example above. This standard is + adopted from the JavaDoc standard. + </para> + </sect2> + + <sect2 id="standards.header.version"> + <title>@package_version@ Usage</title> + <para> + There are two ways to implement the + @package_version@ replacements. The procedure depends on + whether you write your own package.xml files or if you + use the PackageFileManager. + </para> + <para> + For those authoring package.xml files directly, add a + &lt;replace&gt; element for each file. The XML for + such would look something like this: + </para> + <informalexample> + <programlisting role="xml"> + <![CDATA[ +<file name="Class.php"> + <replace from="@package_version@" to="version" type="package-info" /> +</file> + ]]> + </programlisting> + </informalexample> + <para> + Maintainers using the PackageFileManager need to + call <function>addReplacement</function> for each file: + </para> + <informalexample> + <programlisting role="php"> + <![CDATA[ +$pkg->addReplacement('filename.php', 'package-info', + '@package_version@', 'version'); + ]]> + </programlisting> + </informalexample> + </sect2> + + <sect2 id="standards.header.transition"> + <title>Transition Policy</title> + <variablelist> + <varlistentry> + <term>Existing Small Packages</term> + <listitem> + <para> + Existing packages that have only a few files are required + to adopt these docblocks before the next release. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>Existing Large Packages</term> + <listitem> + <para> + Existing packages with many files are encouraged to + adopt the new headers as soon as possible. When such + packages come out with a new major version upgrade, + these docblocks must be implemented therein. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term>New and Unreleased Packages</term> + <listitem> + <para> + New packages and existing packages which have no + releases yet must include these docblocks before + their first release. + </para> + </listitem> + </varlistentry> + + </variablelist> + </sect2> + </sect1> <sect1 id="standards.cvs"> @@ -517,11 +806,14 @@ <sect1 id="standards.sample"> <title>Sample File</title> <para> - The <command>Id</command> CVS keyword you see in the - example below contains the data for the file used to - create the document you are reading now. When creating - your own PEAR scripts, replace the data there with a - blank keyword: <literal>&dollar;Id:&dollar;</literal> + The source code of PEAR packages are read by thousands + of people. Also, it is likely other people will become + developers on your package at some point in the future. + Therefore, it is important to make life easier for + everyone by formatting the code and docblocks in + standardized ways. People can then quickly find the + information they are looking for because it is in the + expected location. Your cooperation is appreciated. </para> <para> Please take note of the vertical and horizontal spacing. @@ -548,37 +840,58 @@ <programlisting role="php"> <![CDATA[ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ -// +----------------------------------------------------------------------+ -// | PHP version 4 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2004 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available through the world-wide-web at the following url: | -// | http://www.php.net/license/3_0.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Original Author <author@example.com> | -// | Your Name <you@example.com> | -// +----------------------------------------------------------------------+ -// -// $Id: standards.xml,v 1.28 2004/12/20 20:13:26 sean Exp $ -require_once 'PEAR.php'; +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ -// {{{ constants +/** + * Short description for file + * + * Long description for file (if any)... + * + * PHP versions 4 and 5 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_0.txt. If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category CategoryName + * @package PackageName + * @author Original Author <author@example.com> + * @author Another Author <another@example.com> + * @copyright 1997-2005 The PHP Group + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: &#x24;Id:&#x24; + * @link http://pear.php.net/package/PackageName + * @see NetOther, Net_Sample::Net_Sample() + * @since File available since Release 1.2.0 + * @deprecated File deprecated in Release 2.0.0 + */ /** * This is a "Docblock Comment," also known as a "docblock." The class' * docblock, below, contains a complete description of how to write these. */ +require_once 'PEAR.php'; + +// {{{ constants + +/** + * Methods return this if they succeed + */ define('NET_SAMPLE_OK', 1); // }}} +// {{{ GLOBALS + +/** + * The number of objects created + * @global int $GLOBALS['NET_SAMPLE_Count'] + */ +$GLOBALS['NET_SAMPLE_Count'] = 0; + +// }}} // {{{ Net_Sample /** @@ -615,13 +928,16 @@ * Please use them in the order they appear here. phpDocumentor has * several other tags available, feel free to use them. * - * @category categoryname - * @package packagename - * @author Original Author <author@example.com> - * @version $Id: standards.xml,v 1.28 2004/12/20 20:13:26 sean Exp $ - * @access public - * @see NetOther, Net_Sample::Net_Sample() - * @since Class available since Release 1.2.0 + * @category CategoryName + * @package PackageName + * @author Original Author <author@example.com> + * @author Another Author <another@example.com> + * @copyright 1997-2005 The PHP Group + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.php.net/package/PackageName + * @see NetOther, Net_Sample::Net_Sample() + * @since Class available since Release 1.2.0 * @deprecated Class deprecated in Release 2.0.0 */ class Net_Sample @@ -702,13 +1018,23 @@ * when an error happens, say 'object' rather than 'mixed.' Use * 'void' if nothing is returned. * + * Here's an example of how to format examples: + * <sample> + * require_once 'Net/Sample.php'; + * + * $s = new Net_Sample(); + * if (PEAR::isError($s)) { + * echo $s->getMessage() . "\n"; + * } + * </sample> + * * @param string $arg1 the string to quote * @param int $arg2 an integer of how many problems happened. - * Indent to the description's starting point - * for long ones. + * Indent to the description's starting point + * for long ones. * * @return int the integer of the set mode used. FALSE if foo - * foo could not be set. + * foo could not be set. * @throws exceptionclass [description] * * @access public
« previous php.pear.doc (#5540) next »