Source for file Replace.php
Documentation is available at Replace.php
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: Replace.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
require_once 'PEAR/Task/Common.php';
* Implements the replace file task.
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
var $phase = PEAR_TASK_PACKAGEANDINSTALL;
* Validate the raw xml at parsing-time.
* @param PEAR_PackageFile_v2
* @param array raw, parsed xml
if (!isset ($xml['attribs'])) {
if (!isset ($xml['attribs']['type'])) {
if (!isset ($xml['attribs']['to'])) {
if (!isset ($xml['attribs']['from'])) {
if ($xml['attribs']['type'] == 'pear-config') {
if (!in_array($xml['attribs']['to'], $config->getKeys ())) {
} elseif ($xml['attribs']['type'] == 'php-const') {
if (defined($xml['attribs']['to'])) {
array ('valid PHP constant'));
} elseif ($xml['attribs']['type'] == 'package-info') {
array ('name', 'summary', 'channel', 'notes', 'extends', 'description',
'release_notes', 'license', 'release-license', 'license-uri',
'version', 'api-version', 'state', 'api-state', 'release_date',
array ('name', 'summary', 'channel', 'notes', 'extends', 'description',
'release_notes', 'license', 'release-license', 'license-uri',
'version', 'api-version', 'state', 'api-state', 'release_date',
array ('pear-config', 'package-info', 'php-const'));
* Initialize a task instance with the parameters
* @param array raw, parsed xml
function init($xml, $attribs)
$this->_replacements = isset ($xml['attribs']) ? array ($xml) : $xml;
* Do a package.xml 1.0 replacement, with additional package-info fields available
* See validateXml() source for the complete list of allowed fields
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @param string file contents
* @param string the eventual final file location (informational only)
* @return string|false|PEAR_Errorfalse to skip this file, PEAR_Error to fail
* (use $this->throwError), otherwise return the new contents
$subst_from = $subst_to = array ();
foreach ($this->_replacements as $a) {
if ($a['type'] == 'pear-config') {
if ($a['to'] == 'master_server') {
$chan = $this->registry->getChannel ($pkg->getChannel ());
$to = $chan->getServer ();
$this->logger->log (0 , " $dest: invalid pear-config replacement: $a[to]" );
if ($this->config->isDefinedLayer ('ftp')) {
// try the remote config file first
$to = $this->config->get ($a['to'], 'ftp', $pkg->getChannel ());
$to = $this->config->get ($a['to'], null , $pkg->getChannel ());
$to = $this->config->get ($a['to'], null , $pkg->getChannel ());
$this->logger->log (0 , " $dest: invalid pear-config replacement: $a[to]" );
} elseif ($a['type'] == 'php-const') {
$this->logger->log (0 , " $dest: invalid php-const replacement: $a[to]" );
if ($t = $pkg->packageInfo ($a['to'])) {
$this->logger->log (0 , " $dest: invalid package-info replacement: $a[to]" );
$subst_from[] = $a['from'];
" substitution(s) for $dest" );
$contents = str_replace($subst_from, $subst_to, $contents);
Documentation generated on Wed, 06 Jul 2011 23:31:16 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|