/** * Add a replacement option for a file * * This sets an install-time complex search-and-replace function * allowing the setting of platform-specific variables in an * installed file. * * if $type is php-const, then $to must be the name of a PHP Constant. * If $type is pear-config, then $to must be the name of a PEAR config * variable accessible through a {@link PEAR_Config::get()} method. If * type is package-info, then $to must be the name of a section from * the package.xml file used to install this file. * * @param string $path relative path of file (relative to packagedirectory option) * @param string $type variable type, either php-const, pear-config or package-info * @param string $from text to replace in the source file * @param string $to variable name to use for replacement * * @return void|PEAR_Error * @throws PEAR_PACKAGEFILEMANAGER2_INVALID_REPLACETYPE * @access public * @since 1.6.0a1 */ function addReplacement($path, $type, $from, $to) { if (!isset($this->_options['replacements'])) { $this->_options['replacements'] = array(); } include_once 'PEAR/Task/Replace/rw.php'; $l = null; $task = new PEAR_Task_Replace_rw($this, $this->_config, $l, ''); $task->setInfo($from, $to, $type); if (is_array($res = $task->validate())) { return $this->raiseError(PEAR_PACKAGEFILEMANAGER2_INVALID_REPLACETYPE, implode(', ', $res[3]), $res[1] . ': ' . $res[2]); } $this->_options['replacements'][$path][] = $task; }
/** * Add a replacement option for a file, or files matching the glob pattern * * This sets an install-time complex search-and-replace function * allowing the setting of platform-specific variables in an * installed file. * * if $type is php-const, then $to must be the name of a PHP Constant. * If $type is pear-config, then $to must be the name of a PEAR config * variable accessible through a {@link PEAR_Config::get()} method. If * type is package-info, then $to must be the name of a section from * the package.xml file used to install this file. * * @param string $path relative path of file (relative to packagedirectory option) * glob patterns are allowed (eg. {Dir1,Dir2}/*.php) * @param string $type variable type, either php-const, pear-config or package-info * @param string $from text to replace in the source file * @param string $to variable name to use for replacement * * @return void|PEAR_Error * @throws PEAR_PACKAGEFILEMANAGER2_INVALID_REPLACETYPE * @access public * @since 1.0.0a1 */ function addReplacement($path, $type, $from, $to) { if (!isset($this->_options['replacements'])) { $this->_options['replacements'] = array(); } include_once 'PEAR/Task/Replace/rw.php'; $l = null; $task = new PEAR_Task_Replace_rw($this, $this->_config, $l, ''); $task->setInfo($from, $to, $type); if (is_array($res = $task->validate())) { return $this->raiseError(PEAR_PACKAGEFILEMANAGER2_INVALID_REPLACETYPE, implode(', ', $res[3]), $res[1] . ': ' . $res[2]); } $current_dir = getcwd(); chdir($this->_options['packagedirectory']); $glob = defined('GLOB_BRACE') ? glob($path, GLOB_BRACE) : glob($path); chdir($current_dir); if (false !== $glob) { foreach ($glob as $pathItem) { $this->_options['replacements'][$pathItem][] = $task; } } }