/trunk/bibliotheque/pear/PEAR/Task/Common.php |
---|
New file |
0,0 → 1,208 |
<?php |
/** |
* PEAR_Task_Common, base class for installer tasks |
* |
* 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 PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: Common.php,v 1.16 2006/11/12 05:02:41 cellog Exp $ |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 1.4.0a1 |
*/ |
/**#@+ |
* Error codes for task validation routines |
*/ |
define('PEAR_TASK_ERROR_NOATTRIBS', 1); |
define('PEAR_TASK_ERROR_MISSING_ATTRIB', 2); |
define('PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE', 3); |
define('PEAR_TASK_ERROR_INVALID', 4); |
/**#@-*/ |
define('PEAR_TASK_PACKAGE', 1); |
define('PEAR_TASK_INSTALL', 2); |
define('PEAR_TASK_PACKAGEANDINSTALL', 3); |
/** |
* A task is an operation that manipulates the contents of a file. |
* |
* Simple tasks operate on 1 file. Multiple tasks are executed after all files have been |
* processed and installed, and are designed to operate on all files containing the task. |
* The Post-install script task simply takes advantage of the fact that it will be run |
* after installation, replace is a simple task. |
* |
* Combining tasks is possible, but ordering is significant. |
* |
* <file name="test.php" role="php"> |
* <tasks:replace from="@data-dir@" to="data_dir" type="pear-config"/> |
* <tasks:postinstallscript/> |
* </file> |
* |
* This will first replace any instance of @data-dir@ in the test.php file |
* with the path to the current data directory. Then, it will include the |
* test.php file and run the script it contains to configure the package post-installation. |
* @category pear |
* @package PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 1.4.0a1 |
* @abstract |
*/ |
class PEAR_Task_Common |
{ |
/** |
* Valid types for this version are 'simple' and 'multiple' |
* |
* - simple tasks operate on the contents of a file and write out changes to disk |
* - multiple tasks operate on the contents of many files and write out the |
* changes directly to disk |
* |
* Child task classes must override this property. |
* @access protected |
*/ |
var $type = 'simple'; |
/** |
* Determines which install phase this task is executed under |
*/ |
var $phase = PEAR_TASK_INSTALL; |
/** |
* @access protected |
*/ |
var $config; |
/** |
* @access protected |
*/ |
var $registry; |
/** |
* @access protected |
*/ |
var $logger; |
/** |
* @access protected |
*/ |
var $installphase; |
/** |
* @param PEAR_Config |
* @param PEAR_Common |
*/ |
function PEAR_Task_Common(&$config, &$logger, $phase) |
{ |
$this->config = &$config; |
$this->registry = &$config->getRegistry(); |
$this->logger = &$logger; |
$this->installphase = $phase; |
if ($this->type == 'multiple') { |
$GLOBALS['_PEAR_TASK_POSTINSTANCES'][get_class($this)][] = &$this; |
} |
} |
/** |
* Validate the basic contents of a task tag. |
* @param PEAR_PackageFile_v2 |
* @param array |
* @param PEAR_Config |
* @param array the entire parsed <file> tag |
* @return true|array On error, return an array in format: |
* array(PEAR_TASK_ERROR_???[, param1][, param2][, ...]) |
* |
* For PEAR_TASK_ERROR_MISSING_ATTRIB, pass the attribute name in |
* For PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, pass the attribute name and an array |
* of legal values in |
* @static |
* @abstract |
*/ |
function validateXml($pkg, $xml, &$config, $fileXml) |
{ |
} |
/** |
* Initialize a task instance with the parameters |
* @param array raw, parsed xml |
* @param array attributes from the <file> tag containing this task |
* @param string|null last installed version of this package |
* @abstract |
*/ |
function init($xml, $fileAttributes, $lastVersion) |
{ |
} |
/** |
* Begin a task processing session. All multiple tasks will be processed after each file |
* has been successfully installed, all simple tasks should perform their task here and |
* return any errors using the custom throwError() method to allow forward compatibility |
* |
* This method MUST NOT write out any changes to disk |
* @param PEAR_PackageFile_v2 |
* @param string file contents |
* @param string the eventual final file location (informational only) |
* @return string|false|PEAR_Error false to skip this file, PEAR_Error to fail |
* (use $this->throwError), otherwise return the new contents |
* @abstract |
*/ |
function startSession($pkg, $contents, $dest) |
{ |
} |
/** |
* This method is used to process each of the tasks for a particular multiple class |
* type. Simple tasks need not implement this method. |
* @param array an array of tasks |
* @access protected |
* @static |
* @abstract |
*/ |
function run($tasks) |
{ |
} |
/** |
* @static |
* @final |
*/ |
function hasPostinstallTasks() |
{ |
return isset($GLOBALS['_PEAR_TASK_POSTINSTANCES']); |
} |
/** |
* @static |
* @final |
*/ |
function runPostinstallTasks() |
{ |
foreach ($GLOBALS['_PEAR_TASK_POSTINSTANCES'] as $class => $tasks) { |
$err = call_user_func(array($class, 'run'), |
$GLOBALS['_PEAR_TASK_POSTINSTANCES'][$class]); |
if ($err) { |
return PEAR_Task_Common::throwError($err); |
} |
} |
unset($GLOBALS['_PEAR_TASK_POSTINSTANCES']); |
} |
/** |
* Determines whether a role is a script |
* @return bool |
*/ |
function isScript() |
{ |
return $this->type == 'script'; |
} |
function throwError($msg, $code = -1) |
{ |
include_once 'PEAR.php'; |
return PEAR::raiseError($msg, $code); |
} |
} |
?> |
/trunk/bibliotheque/pear/PEAR/Task/Windowseol.php |
---|
New file |
0,0 → 1,83 |
<?php |
/** |
* <tasks:windowseol> |
* |
* 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 PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: Windowseol.php,v 1.7 2006/01/06 04:47:37 cellog Exp $ |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 1.4.0a1 |
*/ |
/** |
* Base class |
*/ |
require_once 'PEAR/Task/Common.php'; |
/** |
* Implements the windows line endsings file task. |
* @category pear |
* @package PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 1.4.0a1 |
*/ |
class PEAR_Task_Windowseol extends PEAR_Task_Common |
{ |
var $type = 'simple'; |
var $phase = PEAR_TASK_PACKAGE; |
var $_replacements; |
/** |
* Validate the raw xml at parsing-time. |
* @param PEAR_PackageFile_v2 |
* @param array raw, parsed xml |
* @param PEAR_Config |
* @static |
*/ |
function validateXml($pkg, $xml, &$config, $fileXml) |
{ |
if ($xml != '') { |
return array(PEAR_TASK_ERROR_INVALID, 'no attributes allowed'); |
} |
return true; |
} |
/** |
* Initialize a task instance with the parameters |
* @param array raw, parsed xml |
* @param unused |
*/ |
function init($xml, $attribs) |
{ |
} |
/** |
* Replace all line endings with windows line endings |
* |
* 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_Error false to skip this file, PEAR_Error to fail |
* (use $this->throwError), otherwise return the new contents |
*/ |
function startSession($pkg, $contents, $dest) |
{ |
$this->logger->log(3, "replacing all line endings with \\r\\n in $dest"); |
return preg_replace("/\r\n|\n\r|\r|\n/", "\r\n", $contents); |
} |
} |
?> |
/trunk/bibliotheque/pear/PEAR/Task/Postinstallscript/rw.php |
---|
New file |
0,0 → 1,176 |
<?php |
/** |
* <tasks:postinstallscript> - read/write version |
* |
* 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 PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: rw.php,v 1.11 2006/01/06 04:47:37 cellog Exp $ |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 1.4.0a10 |
*/ |
/** |
* Base class |
*/ |
require_once 'PEAR/Task/Postinstallscript.php'; |
/** |
* Abstracts the postinstallscript file task xml. |
* @category pear |
* @package PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 1.4.0a10 |
*/ |
class PEAR_Task_Postinstallscript_rw extends PEAR_Task_Postinstallscript |
{ |
/** |
* parent package file object |
* |
* @var PEAR_PackageFile_v2_rw |
*/ |
var $_pkg; |
/** |
* Enter description here... |
* |
* @param PEAR_PackageFile_v2_rw $pkg |
* @param PEAR_Config $config |
* @param PEAR_Frontend $logger |
* @param array $fileXml |
* @return PEAR_Task_Postinstallscript_rw |
*/ |
function PEAR_Task_Postinstallscript_rw(&$pkg, &$config, &$logger, $fileXml) |
{ |
parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE); |
$this->_contents = $fileXml; |
$this->_pkg = &$pkg; |
$this->_params = array(); |
} |
function validate() |
{ |
return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents); |
} |
function getName() |
{ |
return 'postinstallscript'; |
} |
/** |
* add a simple <paramgroup> to the post-install script |
* |
* Order is significant, so call this method in the same |
* sequence the users should see the paramgroups. The $params |
* parameter should either be the result of a call to {@link getParam()} |
* or an array of calls to getParam(). |
* |
* Use {@link addConditionTypeGroup()} to add a <paramgroup> containing |
* a <conditiontype> tag |
* @param string $id <paramgroup> id as seen by the script |
* @param array|false $params array of getParam() calls, or false for no params |
* @param string|false $instructions |
*/ |
function addParamGroup($id, $params = false, $instructions = false) |
{ |
if ($params && isset($params[0]) && !isset($params[1])) { |
$params = $params[0]; |
} |
$stuff = |
array( |
$this->_pkg->getTasksNs() . ':id' => $id, |
); |
if ($instructions) { |
$stuff[$this->_pkg->getTasksNs() . ':instructions'] = $instructions; |
} |
if ($params) { |
$stuff[$this->_pkg->getTasksNs() . ':param'] = $params; |
} |
$this->_params[$this->_pkg->getTasksNs() . ':paramgroup'][] = $stuff; |
} |
/** |
* add a complex <paramgroup> to the post-install script with conditions |
* |
* This inserts a <paramgroup> with |
* |
* Order is significant, so call this method in the same |
* sequence the users should see the paramgroups. The $params |
* parameter should either be the result of a call to {@link getParam()} |
* or an array of calls to getParam(). |
* |
* Use {@link addParamGroup()} to add a simple <paramgroup> |
* |
* @param string $id <paramgroup> id as seen by the script |
* @param string $oldgroup <paramgroup> id of the section referenced by |
* <conditiontype> |
* @param string $param name of the <param> from the older section referenced |
* by <contitiontype> |
* @param string $value value to match of the parameter |
* @param string $conditiontype one of '=', '!=', 'preg_match' |
* @param array|false $params array of getParam() calls, or false for no params |
* @param string|false $instructions |
*/ |
function addConditionTypeGroup($id, $oldgroup, $param, $value, $conditiontype = '=', |
$params = false, $instructions = false) |
{ |
if ($params && isset($params[0]) && !isset($params[1])) { |
$params = $params[0]; |
} |
$stuff = |
array( |
$this->_pkg->getTasksNs() . ':id' => $id, |
); |
if ($instructions) { |
$stuff[$this->_pkg->getTasksNs() . ':instructions'] = $instructions; |
} |
$stuff[$this->_pkg->getTasksNs() . ':name'] = $oldgroup . '::' . $param; |
$stuff[$this->_pkg->getTasksNs() . ':conditiontype'] = $conditiontype; |
$stuff[$this->_pkg->getTasksNs() . ':value'] = $value; |
if ($params) { |
$stuff[$this->_pkg->getTasksNs() . ':param'] = $params; |
} |
$this->_params[$this->_pkg->getTasksNs() . ':paramgroup'][] = $stuff; |
} |
function getXml() |
{ |
return $this->_params; |
} |
/** |
* Use to set up a param tag for use in creating a paramgroup |
* @static |
*/ |
function getParam($name, $prompt, $type = 'string', $default = null) |
{ |
if ($default !== null) { |
return |
array( |
$this->_pkg->getTasksNs() . ':name' => $name, |
$this->_pkg->getTasksNs() . ':prompt' => $prompt, |
$this->_pkg->getTasksNs() . ':type' => $type, |
$this->_pkg->getTasksNs() . ':default' => $default |
); |
} |
return |
array( |
$this->_pkg->getTasksNs() . ':name' => $name, |
$this->_pkg->getTasksNs() . ':prompt' => $prompt, |
$this->_pkg->getTasksNs() . ':type' => $type, |
); |
} |
} |
?> |
/trunk/bibliotheque/pear/PEAR/Task/Replace.php |
---|
New file |
0,0 → 1,182 |
<?php |
/** |
* <tasks:replace> |
* |
* 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 PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: Replace.php,v 1.15 2006/03/02 18:14:13 cellog Exp $ |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 1.4.0a1 |
*/ |
/** |
* Base class |
*/ |
require_once 'PEAR/Task/Common.php'; |
/** |
* Implements the replace file task. |
* @category pear |
* @package PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 1.4.0a1 |
*/ |
class PEAR_Task_Replace extends PEAR_Task_Common |
{ |
var $type = 'simple'; |
var $phase = PEAR_TASK_PACKAGEANDINSTALL; |
var $_replacements; |
/** |
* Validate the raw xml at parsing-time. |
* @param PEAR_PackageFile_v2 |
* @param array raw, parsed xml |
* @param PEAR_Config |
* @static |
*/ |
function validateXml($pkg, $xml, &$config, $fileXml) |
{ |
if (!isset($xml['attribs'])) { |
return array(PEAR_TASK_ERROR_NOATTRIBS); |
} |
if (!isset($xml['attribs']['type'])) { |
return array(PEAR_TASK_ERROR_MISSING_ATTRIB, 'type'); |
} |
if (!isset($xml['attribs']['to'])) { |
return array(PEAR_TASK_ERROR_MISSING_ATTRIB, 'to'); |
} |
if (!isset($xml['attribs']['from'])) { |
return array(PEAR_TASK_ERROR_MISSING_ATTRIB, 'from'); |
} |
if ($xml['attribs']['type'] == 'pear-config') { |
if (!in_array($xml['attribs']['to'], $config->getKeys())) { |
return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'], |
$config->getKeys()); |
} |
} elseif ($xml['attribs']['type'] == 'php-const') { |
if (defined($xml['attribs']['to'])) { |
return true; |
} else { |
return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'], |
array('valid PHP constant')); |
} |
} elseif ($xml['attribs']['type'] == 'package-info') { |
if (in_array($xml['attribs']['to'], |
array('name', 'summary', 'channel', 'notes', 'extends', 'description', |
'release_notes', 'license', 'release-license', 'license-uri', |
'version', 'api-version', 'state', 'api-state', 'release_date', |
'date', 'time'))) { |
return true; |
} else { |
return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'], |
array('name', 'summary', 'channel', 'notes', 'extends', 'description', |
'release_notes', 'license', 'release-license', 'license-uri', |
'version', 'api-version', 'state', 'api-state', 'release_date', |
'date', 'time')); |
} |
} else { |
return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'type', $xml['attribs']['type'], |
array('pear-config', 'package-info', 'php-const')); |
} |
return true; |
} |
/** |
* Initialize a task instance with the parameters |
* @param array raw, parsed xml |
* @param unused |
*/ |
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_Error false to skip this file, PEAR_Error to fail |
* (use $this->throwError), otherwise return the new contents |
*/ |
function startSession($pkg, $contents, $dest) |
{ |
$subst_from = $subst_to = array(); |
foreach ($this->_replacements as $a) { |
$a = $a['attribs']; |
$to = ''; |
if ($a['type'] == 'pear-config') { |
if ($this->installphase == PEAR_TASK_PACKAGE) { |
return false; |
} |
if ($a['to'] == 'master_server') { |
$chan = $this->registry->getChannel($pkg->getChannel()); |
if (!PEAR::isError($chan)) { |
$to = $chan->getServer(); |
} else { |
$this->logger->log(0, "$dest: invalid pear-config replacement: $a[to]"); |
return false; |
} |
} else { |
if ($this->config->isDefinedLayer('ftp')) { |
// try the remote config file first |
$to = $this->config->get($a['to'], 'ftp', $pkg->getChannel()); |
if (is_null($to)) { |
// then default to local |
$to = $this->config->get($a['to'], null, $pkg->getChannel()); |
} |
} else { |
$to = $this->config->get($a['to'], null, $pkg->getChannel()); |
} |
} |
if (is_null($to)) { |
$this->logger->log(0, "$dest: invalid pear-config replacement: $a[to]"); |
return false; |
} |
} elseif ($a['type'] == 'php-const') { |
if ($this->installphase == PEAR_TASK_PACKAGE) { |
return false; |
} |
if (defined($a['to'])) { |
$to = constant($a['to']); |
} else { |
$this->logger->log(0, "$dest: invalid php-const replacement: $a[to]"); |
return false; |
} |
} else { |
if ($t = $pkg->packageInfo($a['to'])) { |
$to = $t; |
} else { |
$this->logger->log(0, "$dest: invalid package-info replacement: $a[to]"); |
return false; |
} |
} |
if (!is_null($to)) { |
$subst_from[] = $a['from']; |
$subst_to[] = $to; |
} |
} |
$this->logger->log(3, "doing " . sizeof($subst_from) . |
" substitution(s) for $dest"); |
if (sizeof($subst_from)) { |
$contents = str_replace($subst_from, $subst_to, $contents); |
} |
return $contents; |
} |
} |
?> |
/trunk/bibliotheque/pear/PEAR/Task/Unixeol/rw.php |
---|
New file |
0,0 → 1,62 |
<?php |
/** |
* <tasks:unixeol> - read/write version |
* |
* 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 PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: rw.php,v 1.4 2006/01/06 04:47:37 cellog Exp $ |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 1.4.0a10 |
*/ |
/** |
* Base class |
*/ |
require_once 'PEAR/Task/Unixeol.php'; |
/** |
* Abstracts the unixeol task xml. |
* @category pear |
* @package PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 1.4.0a10 |
*/ |
class PEAR_Task_Unixeol_rw extends PEAR_Task_Unixeol |
{ |
function PEAR_Task_Unixeol_rw(&$pkg, &$config, &$logger, $fileXml) |
{ |
parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE); |
$this->_contents = $fileXml; |
$this->_pkg = &$pkg; |
$this->_params = array(); |
} |
function validate() |
{ |
return true; |
} |
function getName() |
{ |
return 'unixeol'; |
} |
function getXml() |
{ |
return ''; |
} |
} |
?> |
/trunk/bibliotheque/pear/PEAR/Task/Postinstallscript.php |
---|
New file |
0,0 → 1,329 |
<?php |
/** |
* <tasks:postinstallscript> |
* |
* 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 PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: Postinstallscript.php,v 1.18 2006/02/08 01:21:47 cellog Exp $ |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 1.4.0a1 |
*/ |
/** |
* Base class |
*/ |
require_once 'PEAR/Task/Common.php'; |
/** |
* Implements the postinstallscript file task. |
* |
* Note that post-install scripts are handled separately from installation, by the |
* "pear run-scripts" command |
* @category pear |
* @package PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 1.4.0a1 |
*/ |
class PEAR_Task_Postinstallscript extends PEAR_Task_Common |
{ |
var $type = 'script'; |
var $_class; |
var $_params; |
var $_obj; |
/** |
* |
* @var PEAR_PackageFile_v2 |
*/ |
var $_pkg; |
var $_contents; |
var $phase = PEAR_TASK_INSTALL; |
/** |
* Validate the raw xml at parsing-time. |
* |
* This also attempts to validate the script to make sure it meets the criteria |
* for a post-install script |
* @param PEAR_PackageFile_v2 |
* @param array The XML contents of the <postinstallscript> tag |
* @param PEAR_Config |
* @param array the entire parsed <file> tag |
* @static |
*/ |
function validateXml($pkg, $xml, &$config, $fileXml) |
{ |
if ($fileXml['role'] != 'php') { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" must be role="php"'); |
} |
PEAR::pushErrorHandling(PEAR_ERROR_RETURN); |
$file = $pkg->getFileContents($fileXml['name']); |
if (PEAR::isError($file)) { |
PEAR::popErrorHandling(); |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" is not valid: ' . |
$file->getMessage()); |
} elseif ($file === null) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" could not be retrieved for processing!'); |
} else { |
$analysis = $pkg->analyzeSourceCode($file, true); |
if (!$analysis) { |
PEAR::popErrorHandling(); |
$warnings = ''; |
foreach ($pkg->getValidationWarnings() as $warn) { |
$warnings .= $warn['message'] . "\n"; |
} |
return array(PEAR_TASK_ERROR_INVALID, 'Analysis of post-install script "' . |
$fileXml['name'] . '" failed: ' . $warnings); |
} |
if (count($analysis['declared_classes']) != 1) { |
PEAR::popErrorHandling(); |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" must declare exactly 1 class'); |
} |
$class = $analysis['declared_classes'][0]; |
if ($class != str_replace(array('/', '.php'), array('_', ''), |
$fileXml['name']) . '_postinstall') { |
PEAR::popErrorHandling(); |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" class "' . $class . '" must be named "' . |
str_replace(array('/', '.php'), array('_', ''), |
$fileXml['name']) . '_postinstall"'); |
} |
if (!isset($analysis['declared_methods'][$class])) { |
PEAR::popErrorHandling(); |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" must declare methods init() and run()'); |
} |
$methods = array('init' => 0, 'run' => 1); |
foreach ($analysis['declared_methods'][$class] as $method) { |
if (isset($methods[$method])) { |
unset($methods[$method]); |
} |
} |
if (count($methods)) { |
PEAR::popErrorHandling(); |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" must declare methods init() and run()'); |
} |
} |
PEAR::popErrorHandling(); |
$definedparams = array(); |
$tasksNamespace = $pkg->getTasksNs() . ':'; |
if (!isset($xml[$tasksNamespace . 'paramgroup']) && isset($xml['paramgroup'])) { |
// in order to support the older betas, which did not expect internal tags |
// to also use the namespace |
$tasksNamespace = ''; |
} |
if (isset($xml[$tasksNamespace . 'paramgroup'])) { |
$params = $xml[$tasksNamespace . 'paramgroup']; |
if (!is_array($params) || !isset($params[0])) { |
$params = array($params); |
} |
foreach ($params as $param) { |
if (!isset($param[$tasksNamespace . 'id'])) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" <paramgroup> must have ' . |
'an ' . $tasksNamespace . 'id> tag'); |
} |
if (isset($param[$tasksNamespace . 'name'])) { |
if (!in_array($param[$tasksNamespace . 'name'], $definedparams)) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" ' . $tasksNamespace . |
'paramgroup> id "' . $param[$tasksNamespace . 'id'] . |
'" parameter "' . $param[$tasksNamespace . 'name'] . |
'" has not been previously defined'); |
} |
if (!isset($param[$tasksNamespace . 'conditiontype'])) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" ' . $tasksNamespace . |
'paramgroup> id "' . $param[$tasksNamespace . 'id'] . |
'" must have a ' . $tasksNamespace . |
'conditiontype> tag containing either "=", ' . |
'"!=", or "preg_match"'); |
} |
if (!in_array($param[$tasksNamespace . 'conditiontype'], |
array('=', '!=', 'preg_match'))) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" ' . $tasksNamespace . |
'paramgroup> id "' . $param[$tasksNamespace . 'id'] . |
'" must have a ' . $tasksNamespace . |
'conditiontype> tag containing either "=", ' . |
'"!=", or "preg_match"'); |
} |
if (!isset($param[$tasksNamespace . 'value'])) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" ' . $tasksNamespace . |
'paramgroup> id "' . $param[$tasksNamespace . 'id'] . |
'" must have a ' . $tasksNamespace . |
'value> tag containing expected parameter value'); |
} |
} |
if (isset($param[$tasksNamespace . 'instructions'])) { |
if (!is_string($param[$tasksNamespace . 'instructions'])) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" ' . $tasksNamespace . |
'paramgroup> id "' . $param[$tasksNamespace . 'id'] . |
'" ' . $tasksNamespace . 'instructions> must be simple text'); |
} |
} |
if (!isset($param[$tasksNamespace . 'param'])) { |
continue; // <param> is no longer required |
} |
$subparams = $param[$tasksNamespace . 'param']; |
if (!is_array($subparams) || !isset($subparams[0])) { |
$subparams = array($subparams); |
} |
foreach ($subparams as $subparam) { |
if (!isset($subparam[$tasksNamespace . 'name'])) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" parameter for ' . |
$tasksNamespace . 'paramgroup> id "' . |
$param[$tasksNamespace . 'id'] . '" must have ' . |
'a ' . $tasksNamespace . 'name> tag'); |
} |
if (!preg_match('/[a-zA-Z0-9]+/', |
$subparam[$tasksNamespace . 'name'])) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" parameter "' . |
$subparam[$tasksNamespace . 'name'] . |
'" for ' . $tasksNamespace . 'paramgroup> id "' . |
$param[$tasksNamespace . 'id'] . |
'" is not a valid name. Must contain only alphanumeric characters'); |
} |
if (!isset($subparam[$tasksNamespace . 'prompt'])) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" parameter "' . |
$subparam[$tasksNamespace . 'name'] . |
'" for ' . $tasksNamespace . 'paramgroup> id "' . |
$param[$tasksNamespace . 'id'] . |
'" must have a ' . $tasksNamespace . 'prompt> tag'); |
} |
if (!isset($subparam[$tasksNamespace . 'type'])) { |
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' . |
$fileXml['name'] . '" parameter "' . |
$subparam[$tasksNamespace . 'name'] . |
'" for ' . $tasksNamespace . 'paramgroup> id "' . |
$param[$tasksNamespace . 'id'] . |
'" must have a ' . $tasksNamespace . 'type> tag'); |
} |
$definedparams[] = $param[$tasksNamespace . 'id'] . '::' . |
$subparam[$tasksNamespace . 'name']; |
} |
} |
} |
return true; |
} |
/** |
* Initialize a task instance with the parameters |
* @param array raw, parsed xml |
* @param array attributes from the <file> tag containing this task |
* @param string|null last installed version of this package, if any (useful for upgrades) |
*/ |
function init($xml, $fileattribs, $lastversion) |
{ |
$this->_class = str_replace('/', '_', $fileattribs['name']); |
$this->_filename = $fileattribs['name']; |
$this->_class = str_replace ('.php', '', $this->_class) . '_postinstall'; |
$this->_params = $xml; |
$this->_lastversion = $lastversion; |
} |
/** |
* Strip the tasks: namespace from internal params |
* |
* @access private |
*/ |
function _stripNamespace($params = null) |
{ |
if ($params === null) { |
$params = array(); |
if (!is_array($this->_params)) { |
return; |
} |
foreach ($this->_params as $i => $param) { |
if (is_array($param)) { |
$param = $this->_stripNamespace($param); |
} |
$params[str_replace($this->_pkg->getTasksNs() . ':', '', $i)] = $param; |
} |
$this->_params = $params; |
} else { |
$newparams = array(); |
foreach ($params as $i => $param) { |
if (is_array($param)) { |
$param = $this->_stripNamespace($param); |
} |
$newparams[str_replace($this->_pkg->getTasksNs() . ':', '', $i)] = $param; |
} |
return $newparams; |
} |
} |
/** |
* Unlike other tasks, the installed file name is passed in instead of the file contents, |
* because this task is handled post-installation |
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2 |
* @param string file name |
* @return bool|PEAR_Error false to skip this file, PEAR_Error to fail |
* (use $this->throwError) |
*/ |
function startSession($pkg, $contents) |
{ |
if ($this->installphase != PEAR_TASK_INSTALL) { |
return false; |
} |
// remove the tasks: namespace if present |
$this->_pkg = $pkg; |
$this->_stripNamespace(); |
$this->logger->log(0, 'Including external post-installation script "' . |
$contents . '" - any errors are in this script'); |
include_once $contents; |
if (class_exists($this->_class)) { |
$this->logger->log(0, 'Inclusion succeeded'); |
} else { |
return $this->throwError('init of post-install script class "' . $this->_class |
. '" failed'); |
} |
$this->_obj = new $this->_class; |
$this->logger->log(1, 'running post-install script "' . $this->_class . '->init()"'); |
PEAR::pushErrorHandling(PEAR_ERROR_RETURN); |
$res = $this->_obj->init($this->config, $pkg, $this->_lastversion); |
PEAR::popErrorHandling(); |
if ($res) { |
$this->logger->log(0, 'init succeeded'); |
} else { |
return $this->throwError('init of post-install script "' . $this->_class . |
'->init()" failed'); |
} |
$this->_contents = $contents; |
return true; |
} |
/** |
* No longer used |
* @see PEAR_PackageFile_v2::runPostinstallScripts() |
* @param array an array of tasks |
* @param string install or upgrade |
* @access protected |
* @static |
*/ |
function run() |
{ |
} |
} |
?> |
/trunk/bibliotheque/pear/PEAR/Task/Unixeol.php |
---|
New file |
0,0 → 1,83 |
<?php |
/** |
* <tasks:unixeol> |
* |
* 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 PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: Unixeol.php,v 1.8 2006/01/06 04:47:37 cellog Exp $ |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 1.4.0a1 |
*/ |
/** |
* Base class |
*/ |
require_once 'PEAR/Task/Common.php'; |
/** |
* Implements the unix line endings file task. |
* @category pear |
* @package PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 1.4.0a1 |
*/ |
class PEAR_Task_Unixeol extends PEAR_Task_Common |
{ |
var $type = 'simple'; |
var $phase = PEAR_TASK_PACKAGE; |
var $_replacements; |
/** |
* Validate the raw xml at parsing-time. |
* @param PEAR_PackageFile_v2 |
* @param array raw, parsed xml |
* @param PEAR_Config |
* @static |
*/ |
function validateXml($pkg, $xml, &$config, $fileXml) |
{ |
if ($xml != '') { |
return array(PEAR_TASK_ERROR_INVALID, 'no attributes allowed'); |
} |
return true; |
} |
/** |
* Initialize a task instance with the parameters |
* @param array raw, parsed xml |
* @param unused |
*/ |
function init($xml, $attribs) |
{ |
} |
/** |
* Replace all line endings with line endings customized for the current OS |
* |
* 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_Error false to skip this file, PEAR_Error to fail |
* (use $this->throwError), otherwise return the new contents |
*/ |
function startSession($pkg, $contents, $dest) |
{ |
$this->logger->log(3, "replacing all line endings with \\n in $dest"); |
return preg_replace("/\r\n|\n\r|\r|\n/", "\n", $contents); |
} |
} |
?> |
/trunk/bibliotheque/pear/PEAR/Task/Windowseol/rw.php |
---|
New file |
0,0 → 1,62 |
<?php |
/** |
* <tasks:windowseol> - read/write version |
* |
* 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 PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: rw.php,v 1.4 2006/01/06 04:47:37 cellog Exp $ |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 1.4.0a10 |
*/ |
/** |
* Base class |
*/ |
require_once 'PEAR/Task/Windowseol.php'; |
/** |
* Abstracts the windowseol task xml. |
* @category pear |
* @package PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 1.4.0a10 |
*/ |
class PEAR_Task_Windowseol_rw extends PEAR_Task_Windowseol |
{ |
function PEAR_Task_Windowseol_rw(&$pkg, &$config, &$logger, $fileXml) |
{ |
parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE); |
$this->_contents = $fileXml; |
$this->_pkg = &$pkg; |
$this->_params = array(); |
} |
function validate() |
{ |
return true; |
} |
function getName() |
{ |
return 'windowseol'; |
} |
function getXml() |
{ |
return ''; |
} |
} |
?> |
/trunk/bibliotheque/pear/PEAR/Task/Replace/rw.php |
---|
New file |
0,0 → 1,67 |
<?php |
/** |
* <tasks:replace> - read/write version |
* |
* 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 PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: rw.php,v 1.3 2006/01/06 04:47:37 cellog Exp $ |
* @link http://pear.php.net/package/PEAR |
* @since File available since Release 1.4.0a10 |
*/ |
/** |
* Base class |
*/ |
require_once 'PEAR/Task/Replace.php'; |
/** |
* Abstracts the replace task xml. |
* @category pear |
* @package PEAR |
* @author Greg Beaver <cellog@php.net> |
* @copyright 1997-2006 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.5.1 |
* @link http://pear.php.net/package/PEAR |
* @since Class available since Release 1.4.0a10 |
*/ |
class PEAR_Task_Replace_rw extends PEAR_Task_Replace |
{ |
function PEAR_Task_Replace_rw(&$pkg, &$config, &$logger, $fileXml) |
{ |
parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE); |
$this->_contents = $fileXml; |
$this->_pkg = &$pkg; |
$this->_params = array(); |
} |
function validate() |
{ |
return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents); |
} |
function setInfo($from, $to, $type) |
{ |
$this->_params = array('attribs' => array('from' => $from, 'to' => $to, 'type' => $type)); |
} |
function getName() |
{ |
return 'replace'; |
} |
function getXml() |
{ |
return $this->_params; |
} |
} |
?> |