Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Custom File Tasks

Table of Contents

Gregory Beaver

$Date: 2008-10-09 15:16:18 $

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.

package.xml 1.0 provides a single undocumented system of customizing file contents through the <replace> tag, like so:

<file name="blah.php" role="php">
 <replace from="@token@" to="version" type="package-info"/>
 <replace from="@anothertoken@" to="php_dir" type="pear-config"/>

This example above would scan the blah.php file at installation, and then use » str_replace() to replace all occurrences of the string @token@ with the package's version number. Then, it would replace all occurrences of the string @anothertoken@ with the value of the user's php_dir configuration variable.

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 » Phing became the inspiration for an expanded kind customization called a "task".

Tasks are defined by xml children of a <file> tag. Tasks are implemented by extending the PEAR_Task_Common task.

PEAR Manual