cvs: peardoc /en/guide/developers recommendations.xml /en/guide/developers/recommendations colorrepresentation.xml drivercheck.xml unittestconfig.xml
| From: | Christian Weiske | Date: | Tue, 29 Apr 2008 20:49:43 +0000 |
| Subject: | cvs: peardoc /en/guide/developers recommendations.xml /en/guide/developers/recommendations colorrepresentation.xml drivercheck.xml unittestconfig.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-10747@lists.php.net to get a copy of this message | ||
cweiske Tue Apr 29 20:49:43 2008 UTC
Added files:
/peardoc/en/guide/developers/recommendations
colorrepresentation.xml
drivercheck.xml
unittestconfig.xml
Modified files:
/peardoc/en/guide/developers recommendations.xml
Log:
we already have a "best practices" section.
It got two new sections.
http://cvs.php.net/viewvc.cgi/peardoc/en/guide/developers/recommendations.xml?r1=1.9&r2=1.10&diff_format=u Index: peardoc/en/guide/developers/recommendations.xml diff -u peardoc/en/guide/developers/recommendations.xml:1.9 peardoc/en/guide/developers/recommendations.xml:1.10 --- peardoc/en/guide/developers/recommendations.xml:1.9 Wed Jan 9 22:11:57 2008 +++ peardoc/en/guide/developers/recommendations.xml Tue Apr 29 20:49:43 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.9 $ --> +<!-- $Revision: 1.10 $ --> <chapter id="developers.recommendations"> <chapterinfo> <author> @@ -15,10 +15,10 @@ Why recommendations? </title> <para> - The following recommendations describe topics which were discussed + The following best practises describe topics which were discussed and agreed upon by the PEAR developers on the <ulink - url="mailto:&email.pear.dev;">developers mailinglist</ulink>. - They aren't strict rules, which you need to follow + url="mailto:&email.pear.dev;">developers mailinglist</ulink>. + They aren't strict rules, which you need to follow (like <link linkend="standards">Coding Standards</link>), but are intended as guidelines for a common API scheme and easier package interoperability. Please consider following them in your packages @@ -26,128 +26,10 @@ </para> </sect1> - <sect1 id="developers.faq.colorrepresentation"> - <title> - Color Representation inside PEAR Packages - </title> - <titleabbrev> - Color Representation - </titleabbrev> - - <para> - In case a package has to deal with colors, it is recommended that - developers store and use an array representation of the color values - in their PEAR packages. All values are in the range of 0..255. - </para> - - <sect2> - <title>RGB representation</title> - <para> - The following snippet defines an array that holds the RGB - definition of the green coloring that is used in the official PEAR - logo. - - <programlisting role="php"> -<![CDATA[ -$color = array(0x33, 0x99, 0x00); -]]> - </programlisting> + &guide.developers.recommendations.colorrepresentation; + &guide.developers.recommendations.drivercheck; + &guide.developers.recommendations.unittestconfig; - or - - <programlisting role="php"> -<![CDATA[ -$color = array(51, 153, 0); -]]> - </programlisting> - - Please note that the internal, numerical representation of both forms - of the example are equal. The values represent the RGB (red, green, - blue) values. It was decided not to use "r", "g" and "b" as indices - for the array, because numerical indices allow easier creation of - color arrays in the sourcecode, make handling less complicated and - are an already commonly used array representation for colors. - </para> - </sect2> - - <sect2> - <title>RGB representation with alpha-values</title> - <para> - Since this an extension of the RGB representation above, it is - recommended to use a fourth value for alpha-channel-presentation. - An example of the <quote>PEAR-green</quote> with approximately 80% - intensity would be: - - <programlisting role="php"> -<![CDATA[ -$color = array(0x33, 0x99, 0x00, 0xCC); -]]> - </programlisting> - - For consistency the alpha-value is also from the range 0..255. A - value of 255 means fully opaque (full color-intensity, same as in RGB- - notation), 0 means fully transparent. - </para> - <para> - Please note this is in contrast to the alpha-value used by - imagecolorallocate(). The alpha-representation used in PEAR was - chosen for consistency with the other RGB values and because it is - commonly accepted practice in many other applications - (image-processing tools, etc.). - </para> - </sect2> - - <sect2> - <title>Other color representations than RGB(A)</title> - <para> - Since RGB/RGBA will used for graphic generation on a computer we - decided to leave out an optional type-identifier classifying colors - as RGB/RGBA. However for different color-representations an - identifier is needed. The optional identifier "type" can be added to - the color array. - - <programlisting role="php"> -<![CDATA[ -$color = array(0x33, 0x99, 0x00, 0xCC, "type" => "RGB"); -]]> - </programlisting> - - Currently the following types are defined, with array-indices from - 0..n following the color names listed beside them: - </para> - - <itemizedlist> - <listitem> - <simpara>RGB - red, green, blue</simpara> - </listitem> - <listitem> - <simpara>CYMK - cyan, yellow, magenta, black (key)</simpara> - </listitem> - </itemizedlist> - - <para> - Please note that also the RGBA representation has the type "RGB" - since it's closely related. - </para> - </sect2> - - <sect2> - <title>Conversion to/between the color-representations</title> - <para> - The PEAR-package <ulink url="&url.pear.package;Image_Color">Image_Color</ulink> - will (hopefully soon) contain all needed functions to convert arbitrary - color formats to the internal RGBA representation and convert different - color representations. - </para> - <para> - Status: Currently Image_Color already offers functions to convert - color-names (e.g. "green") and hex-representations-strings (e.g. - "#339900") to the PEAR-RGBA-format. We are working to get alpha- - channel support added hopefully soon and will later add functions for - CYMK-conversion as well. - </para> - </sect2> - </sect1> </chapter> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/peardoc/en/guide/developers/recommendations/colorrepresentation.xml?view=markup&rev=1.1 Index: peardoc/en/guide/developers/recommendations/colorrepresentation.xml +++ peardoc/en/guide/developers/recommendations/colorrepresentation.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <sect1 id="developers.recommendations.colorrepresentation"> <title> Color Representation inside PEAR Packages </title> <titleabbrev> Color Representation </titleabbrev> <para> In case a package has to deal with colors, it is recommended that developers store and use an array representation of the color values in their PEAR packages. All values are in the range of 0..255. </para> <sect2> <title>RGB representation</title> <para> The following snippet defines an array that holds the RGB definition of the green coloring that is used in the official PEAR logo. <programlisting role="php"> <![CDATA[ $color = array(0x33, 0x99, 0x00); ]]> </programlisting> or <programlisting role="php"> <![CDATA[ $color = array(51, 153, 0); ]]> </programlisting> Please note that the internal, numerical representation of both forms of the example are equal. The values represent the RGB (red, green, blue) values. It was decided not to use "r", "g" and "b" as indices for the array, because numerical indices allow easier creation of color arrays in the sourcecode, make handling less complicated and are an already commonly used array representation for colors. </para> </sect2> <sect2> <title>RGB representation with alpha-values</title> <para> Since this an extension of the RGB representation above, it is recommended to use a fourth value for alpha-channel-presentation. An example of the <quote>PEAR-green</quote> with approximately 80% intensity would be: <programlisting role="php"> <![CDATA[ $color = array(0x33, 0x99, 0x00, 0xCC); ]]> </programlisting> For consistency the alpha-value is also from the range 0..255. A value of 255 means fully opaque (full color-intensity, same as in RGB- notation), 0 means fully transparent. </para> <para> Please note this is in contrast to the alpha-value used by imagecolorallocate(). The alpha-representation used in PEAR was chosen for consistency with the other RGB values and because it is commonly accepted practice in many other applications (image-processing tools, etc.). </para> </sect2> <sect2> <title>Other color representations than RGB(A)</title> <para> Since RGB/RGBA will used for graphic generation on a computer we decided to leave out an optional type-identifier classifying colors as RGB/RGBA. However for different color-representations an identifier is needed. The optional identifier "type" can be added to the color array. <programlisting role="php"> <![CDATA[ $color = array(0x33, 0x99, 0x00, 0xCC, "type" => "RGB"); ]]> </programlisting> Currently the following types are defined, with array-indices from 0..n following the color names listed beside them: </para> <itemizedlist> <listitem> <simpara>RGB - red, green, blue</simpara> </listitem> <listitem> <simpara>CYMK - cyan, yellow, magenta, black (key)</simpara> </listitem> </itemizedlist> <para> Please note that also the RGBA representation has the type "RGB" since it's closely related. </para> </sect2> <sect2> <title>Conversion to/between the color-representations</title> <para> The PEAR-package <ulink url="&url.pear.package;Image_Color">Image_Color</ulink> will (hopefully soon) contain all needed functions to convert arbitrary color formats to the internal RGBA representation and convert different color representations. </para> <para> Status: Currently Image_Color already offers functions to convert color-names (e.g. "green") and hex-representations-strings (e.g. "#339900") to the PEAR-RGBA-format. We are working to get alpha- channel support added hopefully soon and will later add functions for CYMK-conversion as well. </para> </sect2> </sect1> http://cvs.php.net/viewvc.cgi/peardoc/en/guide/developers/recommendations/drivercheck.xml?view=markup&rev=1.1 Index: peardoc/en/guide/developers/recommendations/drivercheck.xml +++ peardoc/en/guide/developers/recommendations/drivercheck.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <sect1 id="developers.recommendations.drivercheck"> <title>Checking if a driver can be loaded</title> <para> In driver-based packages you should check if the driver exists before loading it. A simple <function>file_exists</function> does not work since it does not check the include path. <function>fopen</function>'s third parameter does that, so we use it. </para> <example> <title></title> <programlisting role="php"><![CDATA[ <?php $driver = 'SomeDriver'; $class = 'My_Package_Driver_' . $driver; $file = str_replace('_', '/', $class) . '.php'; //check if it exists and can be loaded if (!@fclose(@fopen($file, 'r', true))) { throw new My_Package_Driver_Exception( 'Driver ' . $driver . ' cannot be loaded.' ); } //continue with including the driver require_once $file; //... ?> ]]></programlisting> </example> </sect1> http://cvs.php.net/viewvc.cgi/peardoc/en/guide/developers/recommendations/unittestconfig.xml?view=markup&rev=1.1 Index: peardoc/en/guide/developers/recommendations/unittestconfig.xml +++ peardoc/en/guide/developers/recommendations/unittestconfig.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <sect1 id="developers.recommendations.unittestconfig"> <title>Unit test configuration</title> <para> Every now and then your unit tests depend on external services - be it a database or LDAP server or a company's web service. Access to those services and servers require creditentials, be it username and password combinations or API keys. </para> <para> Such confidential information may often not be distributed, and your unit tests should not have them coded into. Instead a separate config file template, <filename>config.php.dist</filename>, should be shipped. To run the tests, the user creates a copy of that configuration template, saves it as <filename>config.php</filename> and adjusts it. </para> <example> <title>Exemplary directory layout</title> <screen><![CDATA[ tests/ config.php.dist config.php ]]></screen> </example> <example> <title>Exemplary configuration template</title> <programlisting role="php"><![CDATA[ $GLOBALS['My_Package_UnittestConfig'] = array( 'host' => 'FIXME', 'username' => 'FIXME', 'password' => 'FIXME', 'host' => 'FIXME', ); ]]></programlisting> </example> </sect1>
http://cvs.php.net/viewvc.cgi/peardoc/en/guide/developers/recommendations.xml?r1=1.9&r2=1.10&diff_format=u Index: peardoc/en/guide/developers/recommendations.xml diff -u peardoc/en/guide/developers/recommendations.xml:1.9 peardoc/en/guide/developers/recommendations.xml:1.10 --- peardoc/en/guide/developers/recommendations.xml:1.9 Wed Jan 9 22:11:57 2008 +++ peardoc/en/guide/developers/recommendations.xml Tue Apr 29 20:49:43 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.9 $ --> +<!-- $Revision: 1.10 $ --> <chapter id="developers.recommendations"> <chapterinfo> <author> @@ -15,10 +15,10 @@ Why recommendations? </title> <para> - The following recommendations describe topics which were discussed + The following best practises describe topics which were discussed and agreed upon by the PEAR developers on the <ulink - url="mailto:&email.pear.dev;">developers mailinglist</ulink>. - They aren't strict rules, which you need to follow + url="mailto:&email.pear.dev;">developers mailinglist</ulink>. + They aren't strict rules, which you need to follow (like <link linkend="standards">Coding Standards</link>), but are intended as guidelines for a common API scheme and easier package interoperability. Please consider following them in your packages @@ -26,128 +26,10 @@ </para> </sect1> - <sect1 id="developers.faq.colorrepresentation"> - <title> - Color Representation inside PEAR Packages - </title> - <titleabbrev> - Color Representation - </titleabbrev> - - <para> - In case a package has to deal with colors, it is recommended that - developers store and use an array representation of the color values - in their PEAR packages. All values are in the range of 0..255. - </para> - - <sect2> - <title>RGB representation</title> - <para> - The following snippet defines an array that holds the RGB - definition of the green coloring that is used in the official PEAR - logo. - - <programlisting role="php"> -<![CDATA[ -$color = array(0x33, 0x99, 0x00); -]]> - </programlisting> + &guide.developers.recommendations.colorrepresentation; + &guide.developers.recommendations.drivercheck; + &guide.developers.recommendations.unittestconfig; - or - - <programlisting role="php"> -<![CDATA[ -$color = array(51, 153, 0); -]]> - </programlisting> - - Please note that the internal, numerical representation of both forms - of the example are equal. The values represent the RGB (red, green, - blue) values. It was decided not to use "r", "g" and "b" as indices - for the array, because numerical indices allow easier creation of - color arrays in the sourcecode, make handling less complicated and - are an already commonly used array representation for colors. - </para> - </sect2> - - <sect2> - <title>RGB representation with alpha-values</title> - <para> - Since this an extension of the RGB representation above, it is - recommended to use a fourth value for alpha-channel-presentation. - An example of the <quote>PEAR-green</quote> with approximately 80% - intensity would be: - - <programlisting role="php"> -<![CDATA[ -$color = array(0x33, 0x99, 0x00, 0xCC); -]]> - </programlisting> - - For consistency the alpha-value is also from the range 0..255. A - value of 255 means fully opaque (full color-intensity, same as in RGB- - notation), 0 means fully transparent. - </para> - <para> - Please note this is in contrast to the alpha-value used by - imagecolorallocate(). The alpha-representation used in PEAR was - chosen for consistency with the other RGB values and because it is - commonly accepted practice in many other applications - (image-processing tools, etc.). - </para> - </sect2> - - <sect2> - <title>Other color representations than RGB(A)</title> - <para> - Since RGB/RGBA will used for graphic generation on a computer we - decided to leave out an optional type-identifier classifying colors - as RGB/RGBA. However for different color-representations an - identifier is needed. The optional identifier "type" can be added to - the color array. - - <programlisting role="php"> -<![CDATA[ -$color = array(0x33, 0x99, 0x00, 0xCC, "type" => "RGB"); -]]> - </programlisting> - - Currently the following types are defined, with array-indices from - 0..n following the color names listed beside them: - </para> - - <itemizedlist> - <listitem> - <simpara>RGB - red, green, blue</simpara> - </listitem> - <listitem> - <simpara>CYMK - cyan, yellow, magenta, black (key)</simpara> - </listitem> - </itemizedlist> - - <para> - Please note that also the RGBA representation has the type "RGB" - since it's closely related. - </para> - </sect2> - - <sect2> - <title>Conversion to/between the color-representations</title> - <para> - The PEAR-package <ulink url="&url.pear.package;Image_Color">Image_Color</ulink> - will (hopefully soon) contain all needed functions to convert arbitrary - color formats to the internal RGBA representation and convert different - color representations. - </para> - <para> - Status: Currently Image_Color already offers functions to convert - color-names (e.g. "green") and hex-representations-strings (e.g. - "#339900") to the PEAR-RGBA-format. We are working to get alpha- - channel support added hopefully soon and will later add functions for - CYMK-conversion as well. - </para> - </sect2> - </sect1> </chapter> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/peardoc/en/guide/developers/recommendations/colorrepresentation.xml?view=markup&rev=1.1 Index: peardoc/en/guide/developers/recommendations/colorrepresentation.xml +++ peardoc/en/guide/developers/recommendations/colorrepresentation.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <sect1 id="developers.recommendations.colorrepresentation"> <title> Color Representation inside PEAR Packages </title> <titleabbrev> Color Representation </titleabbrev> <para> In case a package has to deal with colors, it is recommended that developers store and use an array representation of the color values in their PEAR packages. All values are in the range of 0..255. </para> <sect2> <title>RGB representation</title> <para> The following snippet defines an array that holds the RGB definition of the green coloring that is used in the official PEAR logo. <programlisting role="php"> <![CDATA[ $color = array(0x33, 0x99, 0x00); ]]> </programlisting> or <programlisting role="php"> <![CDATA[ $color = array(51, 153, 0); ]]> </programlisting> Please note that the internal, numerical representation of both forms of the example are equal. The values represent the RGB (red, green, blue) values. It was decided not to use "r", "g" and "b" as indices for the array, because numerical indices allow easier creation of color arrays in the sourcecode, make handling less complicated and are an already commonly used array representation for colors. </para> </sect2> <sect2> <title>RGB representation with alpha-values</title> <para> Since this an extension of the RGB representation above, it is recommended to use a fourth value for alpha-channel-presentation. An example of the <quote>PEAR-green</quote> with approximately 80% intensity would be: <programlisting role="php"> <![CDATA[ $color = array(0x33, 0x99, 0x00, 0xCC); ]]> </programlisting> For consistency the alpha-value is also from the range 0..255. A value of 255 means fully opaque (full color-intensity, same as in RGB- notation), 0 means fully transparent. </para> <para> Please note this is in contrast to the alpha-value used by imagecolorallocate(). The alpha-representation used in PEAR was chosen for consistency with the other RGB values and because it is commonly accepted practice in many other applications (image-processing tools, etc.). </para> </sect2> <sect2> <title>Other color representations than RGB(A)</title> <para> Since RGB/RGBA will used for graphic generation on a computer we decided to leave out an optional type-identifier classifying colors as RGB/RGBA. However for different color-representations an identifier is needed. The optional identifier "type" can be added to the color array. <programlisting role="php"> <![CDATA[ $color = array(0x33, 0x99, 0x00, 0xCC, "type" => "RGB"); ]]> </programlisting> Currently the following types are defined, with array-indices from 0..n following the color names listed beside them: </para> <itemizedlist> <listitem> <simpara>RGB - red, green, blue</simpara> </listitem> <listitem> <simpara>CYMK - cyan, yellow, magenta, black (key)</simpara> </listitem> </itemizedlist> <para> Please note that also the RGBA representation has the type "RGB" since it's closely related. </para> </sect2> <sect2> <title>Conversion to/between the color-representations</title> <para> The PEAR-package <ulink url="&url.pear.package;Image_Color">Image_Color</ulink> will (hopefully soon) contain all needed functions to convert arbitrary color formats to the internal RGBA representation and convert different color representations. </para> <para> Status: Currently Image_Color already offers functions to convert color-names (e.g. "green") and hex-representations-strings (e.g. "#339900") to the PEAR-RGBA-format. We are working to get alpha- channel support added hopefully soon and will later add functions for CYMK-conversion as well. </para> </sect2> </sect1> http://cvs.php.net/viewvc.cgi/peardoc/en/guide/developers/recommendations/drivercheck.xml?view=markup&rev=1.1 Index: peardoc/en/guide/developers/recommendations/drivercheck.xml +++ peardoc/en/guide/developers/recommendations/drivercheck.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <sect1 id="developers.recommendations.drivercheck"> <title>Checking if a driver can be loaded</title> <para> In driver-based packages you should check if the driver exists before loading it. A simple <function>file_exists</function> does not work since it does not check the include path. <function>fopen</function>'s third parameter does that, so we use it. </para> <example> <title></title> <programlisting role="php"><![CDATA[ <?php $driver = 'SomeDriver'; $class = 'My_Package_Driver_' . $driver; $file = str_replace('_', '/', $class) . '.php'; //check if it exists and can be loaded if (!@fclose(@fopen($file, 'r', true))) { throw new My_Package_Driver_Exception( 'Driver ' . $driver . ' cannot be loaded.' ); } //continue with including the driver require_once $file; //... ?> ]]></programlisting> </example> </sect1> http://cvs.php.net/viewvc.cgi/peardoc/en/guide/developers/recommendations/unittestconfig.xml?view=markup&rev=1.1 Index: peardoc/en/guide/developers/recommendations/unittestconfig.xml +++ peardoc/en/guide/developers/recommendations/unittestconfig.xml <?xml version="1.0" encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <sect1 id="developers.recommendations.unittestconfig"> <title>Unit test configuration</title> <para> Every now and then your unit tests depend on external services - be it a database or LDAP server or a company's web service. Access to those services and servers require creditentials, be it username and password combinations or API keys. </para> <para> Such confidential information may often not be distributed, and your unit tests should not have them coded into. Instead a separate config file template, <filename>config.php.dist</filename>, should be shipped. To run the tests, the user creates a copy of that configuration template, saves it as <filename>config.php</filename> and adjusts it. </para> <example> <title>Exemplary directory layout</title> <screen><![CDATA[ tests/ config.php.dist config.php ]]></screen> </example> <example> <title>Exemplary configuration template</title> <programlisting role="php"><![CDATA[ $GLOBALS['My_Package_UnittestConfig'] = array( 'host' => 'FIXME', 'username' => 'FIXME', 'password' => 'FIXME', 'host' => 'FIXME', ); ]]></programlisting> </example> </sect1>