Section 12.9. String Substitutions


12.9. String Substitutions

It is possible to set up replacements, or substitutions, that are performed on files when installed. This is useful to keep default path names and other configuration data in sync with the user's PEAR configuration, to invoke PHP with the right PATH, and more.

12.9.1. Element: <replace>

Element name:

replace

Attributes:

from (required)

to (required)

type (required)

May occur in:

file (optional)


The replace element specifies a substitution that is performed for the containing file during installation. All occurrences of the from attribute in the file are replaced with a string represented by the to and type attributes. The type attribute may have one of these values:

  • php-const. from is replaced by the value of the PHP constant named by to.

  • pear-config. from is replaced by the PEAR configuration parameter named by to.

  • package-info. from is replaced by the to field from the package's configuration.

Usually, the from pattern is of the form @foo@, but in theory, you can replace anything because what is being done by the installer is a straightforward str_replace().

12.9.2. Examples

A typical use for string substitutions is setting up the PEAR install directory and PHP executable path in command-line PHP scripts. Consider this script:

 #!@php_bin@ <?php print "Hello!\n"; ?> 

Because the PHP executable may be installed in different locations on different machines, the PEAR installer has a configuration parameter for which PHP executable should be used (php_bin). By setting up a pear-config substitution in the package.xml file, we can insert the right path to the PHP executable during installation:

 <file role="script" name="myscript">   <replace type="pear-config" from="@php_bin@" to="php_bin"/> </file> 



    PHP 5 Power Programming
    PHP 5 Power Programming
    ISBN: 013147149X
    EAN: 2147483647
    Year: 2003
    Pages: 240

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net