cvs: peardoc /en/guide/migrating customroles.xml
| From: | Greg Beaver | Date: | Wed, 30 Mar 2005 20:23:00 +0000 |
| Subject: | cvs: peardoc /en/guide/migrating customroles.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-5826@lists.php.net to get a copy of this message | ||
cellog Wed Mar 30 15:23:00 2005 EDT
Modified files:
/peardoc/en/guide/migrating customroles.xml
Log:
complete documention of custom file roles
http://cvs.php.net/diff.php/peardoc/en/guide/migrating/customroles.xml?r1=1.1&r2=1.2&ty=u Index: peardoc/en/guide/migrating/customroles.xml diff -u peardoc/en/guide/migrating/customroles.xml:1.1 peardoc/en/guide/migrating/customroles.xml:1.2 --- peardoc/en/guide/migrating/customroles.xml:1.1 Sat Mar 26 00:58:19 2005 +++ peardoc/en/guide/migrating/customroles.xml Wed Mar 30 15:23:00 2005 @@ -1,21 +1,352 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.1 $ --> - <chapter id="guide.migrating.customroles"> - <chapterinfo> - <author> - <firstname>Gregory</firstname> - <surname>Beaver</surname> - </author> - <date>$Date: 2005/03/26 05:58:19 $</date> - </chapterinfo> - <title>Custom File Roles</title> - - <warning> - <title>Incomplete documentation</title> - <para>Documentation is not yet complete</para> - </warning> +<!-- $Revision: 1.2 $ --> +<chapter id="guide.migrating.customroles"> + <chapterinfo> + <author> + <firstname>Gregory</firstname> + <surname>Beaver</surname> + </author> + <date>$Date: 2005/03/30 20:23:00 $</date> + </chapterinfo> + <title>Custom File Roles</title> - </chapter> + <simpara> + One of the programming features that the PEAR installer enforces is the separation + of files into separate categories, and the important idea that files of a similar + category are always installed into the same location, or at least handled the + same way, as in the case of role="src" for PECL packages. + </simpara> + + <simpara> + This has been quite successful for smaller library-style packages, but complete + applications cannot function without customized installation locations. For instance, + some files may be intended for use in a public web frontend, others for library location. + PEAR 1.4 introduces the possibility of defining custom installation roles to fill this + void. + </simpara> + + <sect1 id="guide.migrating.customroles.xml"> + <title>Using a customized role in a package.xml</title> + <titleabbrev>custom roles in package.xml</titleabbrev> + <para> + To use a custom installation role that another programmer has written, there are three + steps that are necessary. First, the + <link linkend="guide.developers.package2.usesrole"><usesrole></link> tag should + be used to define each custom role that is used in the package.xml. Next, the role should + simply be used for the files it pertains to. Finally, a dependency on the package that + provides the custom role should be added to the package.xml, just for completeness. + </para> + <para> + Pretty simple! + </para> + </sect1> + + <sect1 id="guide.migrating.customroles.defining"> + <title>Defining a customized role for use in a package.xml</title> + <titleabbrev>creating custom roles</titleabbrev> + <para> + To define a custom role, you need to create a package containing a single file. Here is + a sample package.xml that could be a custom role: + </para> + <para> + <programlisting role="xml"> + <![CDATA[ +<?xml version="1.0"?> +<package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" + xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 +http://pear.php.net/dtd/tasks-1.0.xsd +http://pear.php.net/dtd/package-2.0 +http://pear.php.net/dtd/package-2.0.xsd"> + <name>Chiarafoo</name> + <channel>pear.chiaraquartet.net</channel> + <summary>Chiarafoo role</summary> + <description> + The chiarafoo role installs files into your customized Foo directory + </description> + <lead> + <name>Greg Beaver</name> + <user>cellog</user> + <email>cellog@php.net</email> + <active>yes</active> + </lead> + <date>2005-03-21</date> + <version> + <release>1.0.0</release> + <api>1.0.0</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.php.net/license">PHP License</license> + <notes> + Provides the chiarafoo file role + </notes> + <contents> + <dir name="/" baseinstalldir="PEAR/Installer/Role"> + <file name="Chiarafoo.php" role="php"> + <tasks:replace from="@package_version@" to="version" type="package-info"/> + </file> + </dir> <!-- / --> + </contents> + <dependencies> + <required> + <php> + <min>4.2</min> + <max>6.0.0</max> + </php> + <pearinstaller> + <min>1.4.0a9</min> + </pearinstaller> + </required> + </dependencies> + <phprelease/> +</package> + ]]> + </programlisting> + </para> + <para> + The script itself in Chiarafoo.php should be similar to this script: + </para> + <para> + <programlisting role="php"> + <![CDATA[ +<?php +/** + * PEAR_Installer_Role_Chiarafoo + * + * 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 pear + * @package Chiarafoo + * @author Greg Beaver <cellog@php.net> + * @copyright 2005 Greg Beaver + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: $Id: customroles.xml,v 1.2 2005/03/30 20:23:00 cellog Exp $ + * @link http://pear.chiaraquartet.net/index.php?package=Chiarafoo + * @since File available since Release 0.1.0 + */ + +/** + * @category pear + * @package Chiarafoo + * @author Greg Beaver <cellog@php.net> + * @copyright 2005 Greg Beaver + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.chiaraquartet.net/index.php?package=Chiarafoo + * @since Class available since Release 0.1.0 + */ +class PEAR_Installer_Role_Chiarafoo extends PEAR_Installer_Role_Common +{ + var $_setup = + array( + 'releasetypes' => array('php'), + 'installable' => true, + 'locationconfig' => 'foo_dir', + 'honorsbaseinstall' => true, + 'phpfile' => true, + 'executable' => false, + 'phpextension' => false, + ); + function getInfo() + { + return array( + 'releasetypes' => array('php'), + 'installable' => true, + 'locationconfig' => 'foo_dir', + 'honorsbaseinstall' => true, + 'phpfile' => true, + 'executable' => false, + 'phpextension' => false, + ); + } + + function setup(&$installer, $pkg, $atts, $file) + { + } + + /** + * This method is called upon instantiating a PEAR_Config object. + * + * This method MUST an array of information for all new configuration + * variables required by the file role. addConfigVar() expects an array of + * configuration information that is identical to what is used internally in PEAR_Config + * @access protected + * @param PEAR_Config + */ + function getSupportingConfigVars() + { + return array( + 'foo_dir' => array( + 'type' => 'directory', + 'default' => PEAR_CONFIG_DEFAULT_PHP_DIR . DIRECTORY_SEPARATOR . 'Foo', + 'doc' => 'directory where foo files are installed', + 'prompt' => 'PHP foo directory', + 'group' => 'File Locations', + ), + ); + } +} +?> + ]]> + </programlisting> + </para> + <para> + Both <varname>$_setup</varname> and <function>getInfo</function> are required for all + roles. <function>getSupportingConfigVars</function> is only required if the custom role + needs to process differing configuration roles to do a successful installation. + </para> + <para> + The contents of the <varname>$_setup</varname> and the array returned from + <function>getInfo</function> must contain all of these indices: + <itemizedlist> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.releasetypes">releasetypes</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.installable">installable</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.locationconfig">locationconfig</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.honorsbaseinstall">honorsbaseinstall</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.phpfile">phpfile</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.executable">executable</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.phpextension">phpextension</link> + </para> + </listitem> + </itemizedlist> + </para> + <sect2 id="guide.migrating.customroles.defining.releasetypes"> + <title>The 'releasetypes' index</title> + <para> + This index must be one of: + </para> + <para> + <itemizedlist> + <listitem> + <para> + php + </para> + </listitem> + <listitem> + <para> + extsrc + </para> + </listitem> + <listitem> + <para> + extbin + </para> + </listitem> + </itemizedlist> + </para> + <para> + releasetypes defines the kind of releases that this role can be used in. For instance, + the "src" role is reserved for extsrc packages, and cannot be used in regular + PEAR-style php releases. The "data" role can be used in any release, and would + define releasetypes as: + </para> + <para> + <programlisting role="php"> + <![CDATA[ +array('releasetypes' => array('php', 'extsrc', 'extbin'), // etc.); + ]]> + </programlisting> + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.installable"> + <title>The 'installable' index</title> + <para> + This index must be either &true; or &false; and determines whether files utilizing + this custom role can be installed. Any file that should be installed must set this to + true. Only roles such as the "src" role that is processed and used to create + the files that are eventually installed should set this to &false; + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.locationconfig"> + <title>The 'locationconfig' index</title> + <para> + This index is used for all installable files to determine which configuration variable + contains the directory in which the file should be installed. For instance, the php role + uses the "php_dir" locationconfig, the data role uses "data_dir". + </para> + <para> + Our example role, chiarafoo, uses the "foo_dir" configuration variable, and then + through the definition of <function>getSupportingConfigVars</function>, tells the installer + what foo_dir means. Note that once a custom role is installed, the user can config-set/ + config-get/config-show the variable just like any other configuration variable! + </para> + <para> + <function>getSupportingConfigVars</function> can define more than one configuration + variable, but note that more than 3 variables will trigger an error, disallowing any + of them, as a security precaution. + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.honorsbaseinstall"> + <title>The 'honorsbaseinstall' index</title> + <para> + This index controls whether a role reacts to the "baseinstalldir" attribute + of a <file> or <dir> tag. Any role that honors baseinstalldir can potentially + allow conflicting files from different packages, and so a check has to be made. A file + role that does not honor baseinstalldir is always installed into: + </para> + <para> + <filename>Packagename/full/path/from/contents/file.ext</filename> + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.phpfile"> + <title>The 'phpfile' index</title> + <para> + This index should be used for any roles that contain php script files. These files + are analyzed at package time, possibly catching errors before release. + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.executable"> + <title>The 'executable' index</title> + <para> + This index should be used for roles like the "script" role that should have + their executable attribute set via <function>chmod</function> on install. + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.phpextension"> + <title>The 'phpextension' index</title> + <para> + This index should be used for roles like the "ext" role that provide a + binary PHP extension. + </para> + </sect2> + </sect1> +</chapter> <!-- Keep this comment at the end of the file Local variables:
http://cvs.php.net/diff.php/peardoc/en/guide/migrating/customroles.xml?r1=1.1&r2=1.2&ty=u Index: peardoc/en/guide/migrating/customroles.xml diff -u peardoc/en/guide/migrating/customroles.xml:1.1 peardoc/en/guide/migrating/customroles.xml:1.2 --- peardoc/en/guide/migrating/customroles.xml:1.1 Sat Mar 26 00:58:19 2005 +++ peardoc/en/guide/migrating/customroles.xml Wed Mar 30 15:23:00 2005 @@ -1,21 +1,352 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.1 $ --> - <chapter id="guide.migrating.customroles"> - <chapterinfo> - <author> - <firstname>Gregory</firstname> - <surname>Beaver</surname> - </author> - <date>$Date: 2005/03/26 05:58:19 $</date> - </chapterinfo> - <title>Custom File Roles</title> - - <warning> - <title>Incomplete documentation</title> - <para>Documentation is not yet complete</para> - </warning> +<!-- $Revision: 1.2 $ --> +<chapter id="guide.migrating.customroles"> + <chapterinfo> + <author> + <firstname>Gregory</firstname> + <surname>Beaver</surname> + </author> + <date>$Date: 2005/03/30 20:23:00 $</date> + </chapterinfo> + <title>Custom File Roles</title> - </chapter> + <simpara> + One of the programming features that the PEAR installer enforces is the separation + of files into separate categories, and the important idea that files of a similar + category are always installed into the same location, or at least handled the + same way, as in the case of role="src" for PECL packages. + </simpara> + + <simpara> + This has been quite successful for smaller library-style packages, but complete + applications cannot function without customized installation locations. For instance, + some files may be intended for use in a public web frontend, others for library location. + PEAR 1.4 introduces the possibility of defining custom installation roles to fill this + void. + </simpara> + + <sect1 id="guide.migrating.customroles.xml"> + <title>Using a customized role in a package.xml</title> + <titleabbrev>custom roles in package.xml</titleabbrev> + <para> + To use a custom installation role that another programmer has written, there are three + steps that are necessary. First, the + <link linkend="guide.developers.package2.usesrole"><usesrole></link> tag should + be used to define each custom role that is used in the package.xml. Next, the role should + simply be used for the files it pertains to. Finally, a dependency on the package that + provides the custom role should be added to the package.xml, just for completeness. + </para> + <para> + Pretty simple! + </para> + </sect1> + + <sect1 id="guide.migrating.customroles.defining"> + <title>Defining a customized role for use in a package.xml</title> + <titleabbrev>creating custom roles</titleabbrev> + <para> + To define a custom role, you need to create a package containing a single file. Here is + a sample package.xml that could be a custom role: + </para> + <para> + <programlisting role="xml"> + <![CDATA[ +<?xml version="1.0"?> +<package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" + xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 +http://pear.php.net/dtd/tasks-1.0.xsd +http://pear.php.net/dtd/package-2.0 +http://pear.php.net/dtd/package-2.0.xsd"> + <name>Chiarafoo</name> + <channel>pear.chiaraquartet.net</channel> + <summary>Chiarafoo role</summary> + <description> + The chiarafoo role installs files into your customized Foo directory + </description> + <lead> + <name>Greg Beaver</name> + <user>cellog</user> + <email>cellog@php.net</email> + <active>yes</active> + </lead> + <date>2005-03-21</date> + <version> + <release>1.0.0</release> + <api>1.0.0</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.php.net/license">PHP License</license> + <notes> + Provides the chiarafoo file role + </notes> + <contents> + <dir name="/" baseinstalldir="PEAR/Installer/Role"> + <file name="Chiarafoo.php" role="php"> + <tasks:replace from="@package_version@" to="version" type="package-info"/> + </file> + </dir> <!-- / --> + </contents> + <dependencies> + <required> + <php> + <min>4.2</min> + <max>6.0.0</max> + </php> + <pearinstaller> + <min>1.4.0a9</min> + </pearinstaller> + </required> + </dependencies> + <phprelease/> +</package> + ]]> + </programlisting> + </para> + <para> + The script itself in Chiarafoo.php should be similar to this script: + </para> + <para> + <programlisting role="php"> + <![CDATA[ +<?php +/** + * PEAR_Installer_Role_Chiarafoo + * + * 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 pear + * @package Chiarafoo + * @author Greg Beaver <cellog@php.net> + * @copyright 2005 Greg Beaver + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: $Id: customroles.xml,v 1.2 2005/03/30 20:23:00 cellog Exp $ + * @link http://pear.chiaraquartet.net/index.php?package=Chiarafoo + * @since File available since Release 0.1.0 + */ + +/** + * @category pear + * @package Chiarafoo + * @author Greg Beaver <cellog@php.net> + * @copyright 2005 Greg Beaver + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.chiaraquartet.net/index.php?package=Chiarafoo + * @since Class available since Release 0.1.0 + */ +class PEAR_Installer_Role_Chiarafoo extends PEAR_Installer_Role_Common +{ + var $_setup = + array( + 'releasetypes' => array('php'), + 'installable' => true, + 'locationconfig' => 'foo_dir', + 'honorsbaseinstall' => true, + 'phpfile' => true, + 'executable' => false, + 'phpextension' => false, + ); + function getInfo() + { + return array( + 'releasetypes' => array('php'), + 'installable' => true, + 'locationconfig' => 'foo_dir', + 'honorsbaseinstall' => true, + 'phpfile' => true, + 'executable' => false, + 'phpextension' => false, + ); + } + + function setup(&$installer, $pkg, $atts, $file) + { + } + + /** + * This method is called upon instantiating a PEAR_Config object. + * + * This method MUST an array of information for all new configuration + * variables required by the file role. addConfigVar() expects an array of + * configuration information that is identical to what is used internally in PEAR_Config + * @access protected + * @param PEAR_Config + */ + function getSupportingConfigVars() + { + return array( + 'foo_dir' => array( + 'type' => 'directory', + 'default' => PEAR_CONFIG_DEFAULT_PHP_DIR . DIRECTORY_SEPARATOR . 'Foo', + 'doc' => 'directory where foo files are installed', + 'prompt' => 'PHP foo directory', + 'group' => 'File Locations', + ), + ); + } +} +?> + ]]> + </programlisting> + </para> + <para> + Both <varname>$_setup</varname> and <function>getInfo</function> are required for all + roles. <function>getSupportingConfigVars</function> is only required if the custom role + needs to process differing configuration roles to do a successful installation. + </para> + <para> + The contents of the <varname>$_setup</varname> and the array returned from + <function>getInfo</function> must contain all of these indices: + <itemizedlist> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.releasetypes">releasetypes</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.installable">installable</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.locationconfig">locationconfig</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.honorsbaseinstall">honorsbaseinstall</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.phpfile">phpfile</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.executable">executable</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customroles.defining.phpextension">phpextension</link> + </para> + </listitem> + </itemizedlist> + </para> + <sect2 id="guide.migrating.customroles.defining.releasetypes"> + <title>The 'releasetypes' index</title> + <para> + This index must be one of: + </para> + <para> + <itemizedlist> + <listitem> + <para> + php + </para> + </listitem> + <listitem> + <para> + extsrc + </para> + </listitem> + <listitem> + <para> + extbin + </para> + </listitem> + </itemizedlist> + </para> + <para> + releasetypes defines the kind of releases that this role can be used in. For instance, + the "src" role is reserved for extsrc packages, and cannot be used in regular + PEAR-style php releases. The "data" role can be used in any release, and would + define releasetypes as: + </para> + <para> + <programlisting role="php"> + <![CDATA[ +array('releasetypes' => array('php', 'extsrc', 'extbin'), // etc.); + ]]> + </programlisting> + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.installable"> + <title>The 'installable' index</title> + <para> + This index must be either &true; or &false; and determines whether files utilizing + this custom role can be installed. Any file that should be installed must set this to + true. Only roles such as the "src" role that is processed and used to create + the files that are eventually installed should set this to &false; + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.locationconfig"> + <title>The 'locationconfig' index</title> + <para> + This index is used for all installable files to determine which configuration variable + contains the directory in which the file should be installed. For instance, the php role + uses the "php_dir" locationconfig, the data role uses "data_dir". + </para> + <para> + Our example role, chiarafoo, uses the "foo_dir" configuration variable, and then + through the definition of <function>getSupportingConfigVars</function>, tells the installer + what foo_dir means. Note that once a custom role is installed, the user can config-set/ + config-get/config-show the variable just like any other configuration variable! + </para> + <para> + <function>getSupportingConfigVars</function> can define more than one configuration + variable, but note that more than 3 variables will trigger an error, disallowing any + of them, as a security precaution. + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.honorsbaseinstall"> + <title>The 'honorsbaseinstall' index</title> + <para> + This index controls whether a role reacts to the "baseinstalldir" attribute + of a <file> or <dir> tag. Any role that honors baseinstalldir can potentially + allow conflicting files from different packages, and so a check has to be made. A file + role that does not honor baseinstalldir is always installed into: + </para> + <para> + <filename>Packagename/full/path/from/contents/file.ext</filename> + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.phpfile"> + <title>The 'phpfile' index</title> + <para> + This index should be used for any roles that contain php script files. These files + are analyzed at package time, possibly catching errors before release. + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.executable"> + <title>The 'executable' index</title> + <para> + This index should be used for roles like the "script" role that should have + their executable attribute set via <function>chmod</function> on install. + </para> + </sect2> + <sect2 id="guide.migrating.customroles.defining.phpextension"> + <title>The 'phpextension' index</title> + <para> + This index should be used for roles like the "ext" role that provide a + binary PHP extension. + </para> + </sect2> + </sect1> +</chapter> <!-- Keep this comment at the end of the file Local variables: