ArininAV

Defining a customized role for use in a package.xml

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:

<?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>

The script itself in Chiarafoo.php should be similar to this script:

<?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.3 2005/04/07 02:21:50 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,
            'unusualbaseinstall' => false, // required as of PEAR 1.4.0a11
            'phpfile' => true,
            'executable' => false,
            'phpextension' => false,
        );
    function getInfo()
    {
        return array(
            'releasetypes' => array('php'),
            'installable' => true,
            'locationconfig' => 'foo_dir',
            'honorsbaseinstall' => true,
            'unusualbaseinstall' => false, // required as of PEAR 1.4.0a11
            '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',
            ),
        );
    }
}
?>

Both $_setup and getInfo() are required for all roles. getSupportingConfigVars() is only required if the custom role needs to process differing configuration roles to do a successful installation.

The contents of the $_setup and the array returned from getInfo() must contain all of these indices:

The 'releasetypes' index

This index must be one of:

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:

array('releasetypes' => array('php', 'extsrc', 'extbin'), // etc.);

The 'installable' index

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

The 'locationconfig' index

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".

Our example role, chiarafoo, uses the "foo_dir" configuration variable, and then through the definition of getSupportingConfigVars(), 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!

getSupportingConfigVars() 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.

The 'honorsbaseinstall' index

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:

Packagename/full/path/from/contents/file.ext

The 'unusualbaseinstall' index

This index controls whether a role that would normally ignore the "baseinstalldir" attribute of a <file> or <dir> tag would honor it, but still use the Packagename/baseinstalldir/full/path/from/contents/file.ext instead of baseinstalldir/full/path/from/contents/file.ext. Any role that supports the unusual baseinstalldir type cannot conflict with other files because the package name is always the parent directory.

The 'phpfile' index

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.

The 'executable' index

This index should be used for roles like the "script" role that should have their executable attribute set via chmod() on install.

The 'phpextension' index

This index should be used for roles like the "ext" role that provide a binary PHP extension.