cvs: peardoc /en/guide/migrating customtasks.xml

From: Date: Thu, 07 Apr 2005 04:02:24 +0000
Subject: cvs: peardoc /en/guide/migrating customtasks.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-5881@lists.php.net to get a copy of this message
cellog Thu Apr 7 00:02:24 2005 EDT Modified files: /peardoc/en/guide/migrating customtasks.xml Log: begin custom tasks documentation http://cvs.php.net/diff.php/peardoc/en/guide/migrating/customtasks.xml?r1=1.1&r2=1.2&ty=u Index: peardoc/en/guide/migrating/customtasks.xml diff -u peardoc/en/guide/migrating/customtasks.xml:1.1 peardoc/en/guide/migrating/customtasks.xml:1.2 --- peardoc/en/guide/migrating/customtasks.xml:1.1 Sat Mar 26 00:58:19 2005 +++ peardoc/en/guide/migrating/customtasks.xml Thu Apr 7 00:02:23 2005 @@ -1,21 +1,171 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.1 $ --> - <chapter id="guide.migrating.customtasks"> - <chapterinfo> - <author> - <firstname>Gregory</firstname> - <surname>Beaver</surname> - </author> - <date>$Date: 2005/03/26 05:58:19 $</date> - </chapterinfo> - <title>Custom File Tasks</title> - - <warning> - <title>Incomplete documentation</title> - <para>Documentation is not yet complete</para> - </warning> +<!-- $Revision: 1.2 $ --> +<chapter id="guide.migrating.customtasks"> + <chapterinfo> + <author> + <firstname>Gregory</firstname> + <surname>Beaver</surname> + </author> + <date>$Date: 2005/04/07 04:02:23 $</date> + </chapterinfo> + <title>Custom File Tasks</title> - </chapter> + <warning> + <title>Incomplete documentation</title> + <para>Documentation is not yet complete</para> + </warning> + + <simpara> + For many small library packages, very little customization is needed. Just install + and go. package.xml 1.0 is very good at this task. As packages grow in size and + complexity, it is often necessary to make slight changes to the contents of files, + and occasionally to external components such as databases. + </simpara> + + <simpara> + package.xml 1.0 provides a single undocumented system of customizing file contents through + the &lt;replace&gt; tag, like so: + </simpara> + + <para> + <programlisting role="xml"> + <![CDATA[ +<file name="blah.php" role="php"> + <replace from="@token@" to="version" type="package-info"/> + <replace from="@anothertoken@" to="php_dir" type="pear-config"/> +</file> + ]]> + </programlisting> + </para> + + <simpara> + This example above would scan the blah.php file at installation, and then use + <ulink url="&url.php.manual;str_replace"><function>str_replace</function></ulink> + to replace all occurences of the string <literal>@token@</literal> with the package's + version number. Then, it would replace all occurences of the string + <literal>@anothertoken@</literal> with the value of the user's php_dir configuration + variable. + </simpara> + + <simpara> + Although powerful, the replace tag is the only customization tag available in package.xml + version 1.0. When developing package.xml version 2.0, the replace tag and innovative work + of other projects such as <ulink url="&url.phing;">Phing</ulink> became the inspiration + for an expanded kind customization called a &quot;task&quot;. + </simpara> + + <simpara> + Tasks are defined by xml children of a + <link linkend="guide.developers.package2.file">&lt;file&gt;</link> tag. Tasks are + implemented by extending the <classname>PEAR_Task_Common</classname> task. + </simpara> + <sect1 id="guide.migrating.customtasks.xml"> + <title>Using a customized task in a package.xml</title> + <titleabbrev>custom tasks in package.xml</titleabbrev> + <para> + Tasks are defined in package.xml through the tasks namespace, which is currently + <uri type="namespace">http://pear.php.net/dtd/tasks-1.0</uri>. The current tasks + namespace is defined by <ulink url="&url.pear.tasks.xsd;">&url.pear.tasks.xsd;</ulink>. + Custom tasks bundled with PEAR include: + </para> + <para> + <itemizedlist> + <listitem> + <para> + <link linkend="guide.developers.package2.tasks.replace">&lt;tasks:replace&gt;</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.developers.package2.tasks.unixeol">&lt;tasks:unixeol&gt;</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.developers.package2.tasks.windowseol">&lt;tasks:windowseol&gt;</link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.developers.package2.tasks.postinstallscript">&lt;tasks:postinstallscript&gt;</link> + </para> + </listitem> + </itemizedlist> + </para> + <para> + The xml for each of these tasks is documented + <link linkend="guide.developers.package2.tasks">here</link>. + </para> + </sect1> + + <sect1 id="guide.migrating.customtasks.php"> + <title>Creating customized tasks in PHP</title> + <titleabbrev>coding custom tasks</titleabbrev> + + <para> + Creating a custom task involves creating a class that validates xml, and performs the + task when called upon. Tasks can be invoked in two situations: at package-time and + at install-time. Each task can control whether it should be called at package-time, + install-time, or at both times. + </para> + <para> + There are two kinds of tasks: simple and multiple. Most tasks are simple tasks. Simple + tasks are self-contained: all customization is limited to that file. Multiple tasks + are collected during installation and processed fully as a unit after files have been + committed to disk, allowing more complex processing. + </para> + <para> + All simple tasks must define 3 methods, all multiple task must define 4 methods. + These are: + </para> + <para> + <itemizedlist> + <listitem> + <para> + <link linkend="guide.migrating.customtasks.php.validxml"><function>validXml</function></link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customtasks.php.init"><function>init</function></link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customtasks.php.startsession"><function>startSession</function></link> + </para> + </listitem> + <listitem> + <para> + <link linkend="guide.migrating.customtasks.php.run"><function>run</function></link> + (multiple tasks only) + </para> + </listitem> + </itemizedlist> + </para> + <sect2 id="guide.migrating.customtasks.php.validxml"> + <title><function>validXml</function></title> + <para> + </para> + </sect2> + <sect2 id="guide.migrating.customtasks.php.init"> + <title><function>init</function></title> + <para> + </para> + </sect2> + <sect2 id="guide.migrating.customtasks.php.startsession"> + <title><function>startSession</function></title> + <para> + </para> + </sect2> + <sect2 id="guide.migrating.customtasks.php.run"> + <title><function>run</function></title> + <para> + </para> + </sect2> + </sect1> + +</chapter> <!-- Keep this comment at the end of the file Local variables:

« previous php.pear.doc (#5881) next »