PEAR logo

PEAR_PackageFileManager : The Definitive Guide



Chapter 9. Using tasks to customize file installation

Table of Contents

Search and Replace file contents
Converting file line endings
Advanced installation with post install script
Giving parameters for PEAR installer
Scripting actions proceed after files copy

This lesson :

Search and Replace file contents

The replace task is nearly identical to the old <replace> tag from package.xml 1.0, and does a text search-and-replace of a file's contents.

In this example we will specialize file pear-phpdoc contents on installation, with the most common and used basic task : <tasks:replace>.

Search all @PHP-BIN@ occurences in source file pear-phpdoc, and replace them by value of option php_bin (PHP CLI/CGI binary location).

To produce a package.xml version 1.0

  1. <?php
  2. require_once 'PEAR/PackageFileManager.php';
  3.  
  4. PEAR::setErrorHandling(PEAR_ERROR_DIE);
  5.  
  6. $p1 = new PEAR_PackageFileManager();
  7. //...
  8. $p1->addReplacement('pear-phpdoc', 'pear-config', '@PHP-BIN@', 'php_bin');
  9. ?>

To produce a package.xml version 2.0

  1. <?php
  2. require_once 'PEAR/PackageFileManager2.php';
  3.  
  4. PEAR::setErrorHandling(PEAR_ERROR_DIE);
  5.  
  6. $p2 = new PEAR_PackageFileManager2();
  7. //...
  8. $p2->addReplacement('pear-phpdoc', 'pear-config', '@PHP-BIN@', 'php_bin');
  9. ?>
[Tip] Tip
If all your files, or almost all of them as the same task replacement to do, you can use the addGlobalReplacement() function that accept same $type, $from, $to parameters (#2, #3, #4) of addReplacement().
  1. <?php
  2. require_once 'PEAR/PackageFileManager2.php';
  3.  
  4. PEAR::setErrorHandling(PEAR_ERROR_DIE);
  5.  
  6. $p2 = new PEAR_PackageFileManager2();
  7. //...
  8. $p2->addGlobalReplacement('pear-config', '@PHP-BIN@', 'php_bin');
  9. ?>
PEAR_PackageFileManager : The Definitive Guide v 1.6.0 : November 17, 2006