Subversion Repositories Applications.gtt

Compare Revisions

No changes between revisions

Ignore whitespace Rev 186 → Rev 187

/trunk/scripts/clonegtt.sh
67,7 → 67,7
// cree par clonegtt le $DATE
define('GTT_AUTH_SESSION_NOM', 'gtt_auth_$PREFIXE');
define('GTT_BDD_NOM', '$BDD_BASE');
define('GTT_BDD_DSN', 'mysql://$BDD_LOGIN:$BDD_MDP@$BDD_HOTE/'.GTT_BDD_NOM);
define('GTT_BDD_DSN', 'mysqli://$BDD_LOGIN:$BDD_MDP@$BDD_HOTE/'.GTT_BDD_NOM);
define('GTT_BDD_PREFIXE', '$PREFIXE');
define('GTT_DEBOGAGE', false);
define('GTT_DEBOGAGE_SQL', false);
/trunk/scripts/installgtt.sh
47,7 → 47,7
// cree par installgtt le $DATE
define('GTT_AUTH_SESSION_NOM', 'gtt_auth_$PREFIXE');
define('GTT_BDD_NOM', '$BDD_BASE');
define('GTT_BDD_DSN', 'mysql://$BDD_LOGIN:$BDD_MDP@$BDD_HOTE/'.GTT_BDD_NOM);
define('GTT_BDD_DSN', 'mysqli://$BDD_LOGIN:$BDD_MDP@$BDD_HOTE/'.GTT_BDD_NOM);
define('GTT_BDD_PREFIXE', '$PREFIXE');
define('GTT_DEBOGAGE', false);
define('GTT_DEBOGAGE_SQL', false);
/trunk/config.inc.defaut.php
3,7 → 3,7
define('GTT_AUTH_SESSION_NOM', 'gtt_auth_v4');
// Base de données
define('GTT_BDD_NOM', 'gtt_v4');
define('GTT_BDD_DSN', 'mysql://utilsiateur:mot_de_passe@localhost/'.GTT_BDD_NOM);
define('GTT_BDD_DSN', 'mysqli://utilsiateur:mot_de_passe@localhost/'.GTT_BDD_NOM);
define('GTT_BDD_PREFIXE', '');
// Débogage
/** Constante stockant si oui ou non on veut afficher le débogage.*/
/trunk/bibliotheque/pear/PEAR.php
6,12 → 6,6
*
* 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 Sterling Hughes <sterling@php.net>
18,9 → 12,8
* @author Stig Bakken <ssb@php.net>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @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: PEAR.php,v 1.101 2006/04/25 02:41:03 cellog Exp $
* @copyright 1997-2010 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
39,8 → 32,6
*/
define('PEAR_ERROR_EXCEPTION', 32);
/**#@-*/
define('PEAR_ZE2', (function_exists('version_compare') &&
version_compare(zend_version(), "2-dev", "ge")));
 
if (substr(PHP_OS, 0, 3) == 'WIN') {
define('OS_WINDOWS', true);
52,15 → 43,6
define('PEAR_OS', 'Unix'); // blatant assumption
}
 
// instant backwards compatibility
if (!defined('PATH_SEPARATOR')) {
if (OS_WINDOWS) {
define('PATH_SEPARATOR', ';');
} else {
define('PATH_SEPARATOR', ':');
}
}
 
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
$GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE;
$GLOBALS['_PEAR_destructor_object_list'] = array();
92,8 → 74,8
* @author Tomas V.V. Cox <cox@idecnet.com>
* @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
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @see PEAR_Error
* @since Class available since PHP 4.0.2
101,8 → 83,6
*/
class PEAR
{
// {{{ properties
 
/**
* Whether to enable internal debug messages.
*
153,10 → 133,18
*/
var $_expected_errors = array();
 
// }}}
/**
* List of methods that can be called both statically and non-statically.
* @var array
*/
protected static $bivalentMethods = array(
'setErrorHandling' => true,
'raiseError' => true,
'throwError' => true,
'pushErrorHandling' => true,
'popErrorHandling' => true,
);
 
// {{{ constructor
 
/**
* Constructor. Registers this object in
* $_PEAR_destructor_object_list for destructor emulation if a
167,15 → 155,17
* @access public
* @return void
*/
function PEAR($error_class = null)
function __construct($error_class = null)
{
$classname = strtolower(get_class($this));
if ($this->_debug) {
print "PEAR constructor called, class=$classname\n";
}
 
if ($error_class !== null) {
$this->_error_class = $error_class;
}
 
while ($classname && strcasecmp($classname, "pear")) {
$destructor = "_$classname";
if (method_exists($this, $destructor)) {
192,8 → 182,17
}
}
 
// }}}
// {{{ destructor
/**
* Only here for backwards compatibility.
* E.g. Archive_Tar calls $this->PEAR() in its constructor.
*
* @param string $error_class Which class to use for error objects,
* defaults to PEAR_Error.
*/
public function PEAR($error_class = null)
{
self::__construct($error_class);
}
 
/**
* Destructor (the emulated type of...). Does nothing right now,
212,9 → 211,32
}
}
 
// }}}
// {{{ getStaticProperty()
public function __call($method, $arguments)
{
if (!isset(self::$bivalentMethods[$method])) {
trigger_error(
'Call to undefined method PEAR::' . $method . '()', E_USER_ERROR
);
}
return call_user_func_array(
array(get_class(), '_' . $method),
array_merge(array($this), $arguments)
);
}
 
public static function __callStatic($method, $arguments)
{
if (!isset(self::$bivalentMethods[$method])) {
trigger_error(
'Call to undefined method PEAR::' . $method . '()', E_USER_ERROR
);
}
return call_user_func_array(
array(get_class(), '_' . $method),
array_merge(array(null), $arguments)
);
}
 
/**
* If you have a class that's mostly/entirely static, and you need static
* properties, you can use this method to simulate them. Eg. in your method(s)
221,37 → 243,35
* do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
* You MUST use a reference, or they will not persist!
*
* @access public
* @param string $class The calling classname, to prevent clashes
* @param string $var The variable to retrieve.
* @return mixed A reference to the variable. If not set it will be
* auto initialised to NULL.
*/
function &getStaticProperty($class, $var)
public static function &getStaticProperty($class, $var)
{
static $properties;
if (!isset($properties[$class])) {
$properties[$class] = array();
}
 
if (!array_key_exists($var, $properties[$class])) {
$properties[$class][$var] = null;
}
 
return $properties[$class][$var];
}
 
// }}}
// {{{ registerShutdownFunc()
 
/**
* Use this function to register a shutdown method for static
* classes.
*
* @access public
* @param mixed $func The function name (or array of class/method) to call
* @param mixed $args The arguments to pass to the function
*
* @return void
*/
function registerShutdownFunc($func, $args = array())
public static function registerShutdownFunc($func, $args = array())
{
// if we are called statically, there is a potential
// that no shutdown func is registered. Bug #6445
262,9 → 282,6
$GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
}
 
// }}}
// {{{ isError()
 
/**
* Tell whether a value is a PEAR error.
*
273,26 → 290,24
* only if $code is a string and
* $obj->getMessage() == $code or
* $code is an integer and $obj->getCode() == $code
* @access public
*
* @return bool true if parameter is an error
*/
function isError($data, $code = null)
public static function isError($data, $code = null)
{
if (is_a($data, 'PEAR_Error')) {
if (is_null($code)) {
return true;
} elseif (is_string($code)) {
return $data->getMessage() == $code;
} else {
return $data->getCode() == $code;
}
if (!is_a($data, 'PEAR_Error')) {
return false;
}
return false;
 
if (is_null($code)) {
return true;
} elseif (is_string($code)) {
return $data->getMessage() == $code;
}
 
return $data->getCode() == $code;
}
 
// }}}
// {{{ setErrorHandling()
 
/**
* Sets how errors generated by this object should be handled.
* Can be invoked both in objects and statically. If called
300,6 → 315,9
* PEAR objects. If called in an object, setErrorHandling sets
* the default behaviour for that object.
*
* @param object $object
* Object the method was called on (non-static mode)
*
* @param int $mode
* One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
* PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
331,12 → 349,12
*
* @since PHP 4.0.5
*/
 
function setErrorHandling($mode = null, $options = null)
{
if (isset($this) && is_a($this, 'PEAR')) {
$setmode = &$this->_default_error_mode;
$setoptions = &$this->_default_error_options;
protected static function _setErrorHandling(
$object, $mode = null, $options = null
) {
if ($object !== null) {
$setmode = &$object->_default_error_mode;
$setoptions = &$object->_default_error_options;
} else {
$setmode = &$GLOBALS['_PEAR_default_error_mode'];
$setoptions = &$GLOBALS['_PEAR_default_error_options'];
369,9 → 387,6
}
}
 
// }}}
// {{{ expectError()
 
/**
* This method is used to tell which errors you expect to get.
* Expected errors are always returned with error mode
394,12 → 409,9
} else {
array_push($this->_expected_errors, array($code));
}
return sizeof($this->_expected_errors);
return count($this->_expected_errors);
}
 
// }}}
// {{{ popExpect()
 
/**
* This method pops one element off the expected error codes
* stack.
411,9 → 423,6
return array_pop($this->_expected_errors);
}
 
// }}}
// {{{ _checkDelExpect()
 
/**
* This method checks unsets an error code if available
*
425,8 → 434,7
function _checkDelExpect($error_code)
{
$deleted = false;
 
foreach ($this->_expected_errors AS $key => $error_array) {
foreach ($this->_expected_errors as $key => $error_array) {
if (in_array($error_code, $error_array)) {
unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
$deleted = true;
437,12 → 445,10
unset($this->_expected_errors[$key]);
}
}
 
return $deleted;
}
 
// }}}
// {{{ delExpect()
 
/**
* This method deletes all occurences of the specified element from
* the expected error codes stack.
455,35 → 461,27
function delExpect($error_code)
{
$deleted = false;
 
if ((is_array($error_code) && (0 != count($error_code)))) {
// $error_code is a non-empty array here;
// we walk through it trying to unset all
// values
foreach($error_code as $key => $error) {
if ($this->_checkDelExpect($error)) {
$deleted = true;
} else {
$deleted = false;
}
// $error_code is a non-empty array here; we walk through it trying
// to unset all values
foreach ($error_code as $key => $error) {
$deleted = $this->_checkDelExpect($error) ? true : false;
}
 
return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
} elseif (!empty($error_code)) {
// $error_code comes alone, trying to unset it
if ($this->_checkDelExpect($error_code)) {
return true;
} else {
return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
}
} else {
// $error_code is empty
return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
 
return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
}
 
// $error_code is empty
return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
}
 
// }}}
// {{{ raiseError()
 
/**
* This method is a wrapper that returns an instance of the
* configured error class with this object's default error
516,12 → 514,12
* @param bool $skipmsg If true, raiseError will only pass error codes,
* the error message parameter will be dropped.
*
* @access public
* @return object a PEAR error object
* @see PEAR::setErrorHandling
* @since PHP 4.0.5
*/
function &raiseError($message = null,
protected static function _raiseError($object,
$message = null,
$code = null,
$mode = null,
$options = null,
538,19 → 536,26
$message = $message->getMessage();
}
 
if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
if (
$object !== null &&
isset($object->_expected_errors) &&
count($object->_expected_errors) > 0 &&
count($exp = end($object->_expected_errors))
) {
if ($exp[0] == "*" ||
(is_int(reset($exp)) && in_array($code, $exp)) ||
(is_string(reset($exp)) && in_array($message, $exp))) {
(is_string(reset($exp)) && in_array($message, $exp))
) {
$mode = PEAR_ERROR_RETURN;
}
}
 
// No mode given, try global ones
if ($mode === null) {
// Class error handler
if (isset($this) && isset($this->_default_error_mode)) {
$mode = $this->_default_error_mode;
$options = $this->_default_error_options;
if ($object !== null && isset($object->_default_error_mode)) {
$mode = $object->_default_error_mode;
$options = $object->_default_error_options;
// Global error handler
} elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
$mode = $GLOBALS['_PEAR_default_error_mode'];
560,47 → 565,50
 
if ($error_class !== null) {
$ec = $error_class;
} elseif (isset($this) && isset($this->_error_class)) {
$ec = $this->_error_class;
} elseif ($object !== null && isset($object->_error_class)) {
$ec = $object->_error_class;
} else {
$ec = 'PEAR_Error';
}
 
if ($skipmsg) {
$a = &new $ec($code, $mode, $options, $userinfo);
return $a;
$a = new $ec($code, $mode, $options, $userinfo);
} else {
$a = &new $ec($message, $code, $mode, $options, $userinfo);
return $a;
$a = new $ec($message, $code, $mode, $options, $userinfo);
}
 
return $a;
}
 
// }}}
// {{{ throwError()
 
/**
* Simpler form of raiseError with fewer options. In most cases
* message, code and userinfo are enough.
*
* @param string $message
* @param mixed $message a text error message or a PEAR error object
*
* @param int $code a numeric error code (it is up to your class
* to define these if you want to use codes)
*
* @param string $userinfo If you need to pass along for example debug
* information, this parameter is meant for that.
*
* @return object a PEAR error object
* @see PEAR::raiseError
*/
function &throwError($message = null,
$code = null,
$userinfo = null)
protected static function _throwError($object, $message = null, $code = null, $userinfo = null)
{
if (isset($this) && is_a($this, 'PEAR')) {
$a = &$this->raiseError($message, $code, null, null, $userinfo);
if ($object !== null) {
$a = &$object->raiseError($message, $code, null, null, $userinfo);
return $a;
} else {
$a = &PEAR::raiseError($message, $code, null, null, $userinfo);
return $a;
}
 
$a = &PEAR::raiseError($message, $code, null, null, $userinfo);
return $a;
}
 
// }}}
function staticPushErrorHandling($mode, $options = null)
public static function staticPushErrorHandling($mode, $options = null)
{
$stack = &$GLOBALS['_PEAR_error_handler_stack'];
$stack = &$GLOBALS['_PEAR_error_handler_stack'];
$def_mode = &$GLOBALS['_PEAR_default_error_mode'];
$def_options = &$GLOBALS['_PEAR_default_error_options'];
$stack[] = array($def_mode, $def_options);
633,7 → 641,7
return true;
}
 
function staticPopErrorHandling()
public static function staticPopErrorHandling()
{
$stack = &$GLOBALS['_PEAR_error_handler_stack'];
$setmode = &$GLOBALS['_PEAR_default_error_mode'];
669,8 → 677,6
return true;
}
 
// {{{ pushErrorHandling()
 
/**
* Push a new error handler on top of the error handler options stack. With this
* you can easily override the actual error handler for some code and restore
683,12 → 689,12
*
* @see PEAR::setErrorHandling
*/
function pushErrorHandling($mode, $options = null)
protected static function _pushErrorHandling($object, $mode, $options = null)
{
$stack = &$GLOBALS['_PEAR_error_handler_stack'];
if (isset($this) && is_a($this, 'PEAR')) {
$def_mode = &$this->_default_error_mode;
$def_options = &$this->_default_error_options;
if ($object !== null) {
$def_mode = &$object->_default_error_mode;
$def_options = &$object->_default_error_options;
} else {
$def_mode = &$GLOBALS['_PEAR_default_error_mode'];
$def_options = &$GLOBALS['_PEAR_default_error_options'];
695,8 → 701,8
}
$stack[] = array($def_mode, $def_options);
 
if (isset($this) && is_a($this, 'PEAR')) {
$this->setErrorHandling($mode, $options);
if ($object !== null) {
$object->setErrorHandling($mode, $options);
} else {
PEAR::setErrorHandling($mode, $options);
}
704,9 → 710,6
return true;
}
 
// }}}
// {{{ popErrorHandling()
 
/**
* Pop the last error handler used
*
714,14 → 717,14
*
* @see PEAR::pushErrorHandling
*/
function popErrorHandling()
protected static function _popErrorHandling($object)
{
$stack = &$GLOBALS['_PEAR_error_handler_stack'];
array_pop($stack);
list($mode, $options) = $stack[sizeof($stack) - 1];
array_pop($stack);
if (isset($this) && is_a($this, 'PEAR')) {
$this->setErrorHandling($mode, $options);
if ($object !== null) {
$object->setErrorHandling($mode, $options);
} else {
PEAR::setErrorHandling($mode, $options);
}
728,44 → 731,43
return true;
}
 
// }}}
// {{{ loadExtension()
 
/**
* OS independant PHP extension load. Remember to take care
* OS independent PHP extension load. Remember to take care
* on the correct extension name for case sensitive OSes.
*
* @param string $ext The extension name
* @return bool Success or not on the dl() call
*/
function loadExtension($ext)
public static function loadExtension($ext)
{
if (!extension_loaded($ext)) {
// if either returns true dl() will produce a FATAL error, stop that
if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
return false;
}
if (OS_WINDOWS) {
$suffix = '.dll';
} elseif (PHP_OS == 'HP-UX') {
$suffix = '.sl';
} elseif (PHP_OS == 'AIX') {
$suffix = '.a';
} elseif (PHP_OS == 'OSX') {
$suffix = '.bundle';
} else {
$suffix = '.so';
}
return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
if (extension_loaded($ext)) {
return true;
}
return true;
 
// if either returns true dl() will produce a FATAL error, stop that
if (
function_exists('dl') === false ||
ini_get('enable_dl') != 1
) {
return false;
}
 
if (OS_WINDOWS) {
$suffix = '.dll';
} elseif (PHP_OS == 'HP-UX') {
$suffix = '.sl';
} elseif (PHP_OS == 'AIX') {
$suffix = '.a';
} elseif (PHP_OS == 'OSX') {
$suffix = '.bundle';
} else {
$suffix = '.so';
}
 
return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
}
 
// }}}
}
 
// {{{ _PEAR_call_destructors()
 
function _PEAR_call_destructors()
{
global $_PEAR_destructor_object_list;
773,9 → 775,13
sizeof($_PEAR_destructor_object_list))
{
reset($_PEAR_destructor_object_list);
if (PEAR::getStaticProperty('PEAR', 'destructlifo')) {
 
$destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo');
 
if ($destructLifoExists) {
$_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
}
 
while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
$classname = get_class($objref);
while ($classname) {
794,7 → 800,11
}
 
// Now call the shutdown functions
if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
if (
isset($GLOBALS['_PEAR_shutdown_funcs']) &&
is_array($GLOBALS['_PEAR_shutdown_funcs']) &&
!empty($GLOBALS['_PEAR_shutdown_funcs'])
) {
foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
call_user_func_array($value[0], $value[1]);
}
801,7 → 811,6
}
}
 
// }}}
/**
* Standard PEAR error class for PHP 4
*
813,8 → 822,8
* @author Tomas V.V. Cox <cox@idecnet.com>
* @author Gregory 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
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/manual/en/core.pear.pear-error.php
* @see PEAR::raiseError(), PEAR::throwError()
* @since Class available since PHP 4.0.2
821,8 → 830,6
*/
class PEAR_Error
{
// {{{ properties
 
var $error_message_prefix = '';
var $mode = PEAR_ERROR_RETURN;
var $level = E_USER_NOTICE;
831,9 → 838,6
var $userinfo = '';
var $backtrace = null;
 
// }}}
// {{{ constructor
 
/**
* PEAR_Error constructor
*
854,7 → 858,7
* @access public
*
*/
function PEAR_Error($message = 'unknown error', $code = null,
function __construct($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
{
if ($mode === null) {
864,12 → 868,16
$this->code = $code;
$this->mode = $mode;
$this->userinfo = $userinfo;
if (!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) {
 
$skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
 
if (!$skiptrace) {
$this->backtrace = debug_backtrace();
if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
unset($this->backtrace[0]['object']);
}
}
 
if ($mode & PEAR_ERROR_CALLBACK) {
$this->level = E_USER_NOTICE;
$this->callback = $options;
877,9 → 885,11
if ($options === null) {
$options = E_USER_NOTICE;
}
 
$this->level = $options;
$this->callback = null;
}
 
if ($this->mode & PEAR_ERROR_PRINT) {
if (is_null($options) || is_int($options)) {
$format = "%s";
886,11 → 896,14
} else {
$format = $options;
}
 
printf($format, $this->getMessage());
}
 
if ($this->mode & PEAR_ERROR_TRIGGER) {
trigger_error($this->getMessage(), $this->level);
}
 
if ($this->mode & PEAR_ERROR_DIE) {
$msg = $this->getMessage();
if (is_null($options) || is_int($options)) {
903,11 → 916,11
}
die(sprintf($format, $msg));
}
if ($this->mode & PEAR_ERROR_CALLBACK) {
if (is_callable($this->callback)) {
call_user_func($this->callback, $this);
}
 
if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) {
call_user_func($this->callback, $this);
}
 
if ($this->mode & PEAR_ERROR_EXCEPTION) {
trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
eval('$e = new Exception($this->message, $this->code);throw($e);');
914,8 → 927,23
}
}
 
// }}}
// {{{ getMode()
/**
* Only here for backwards compatibility.
*
* Class "Cache_Error" still uses it, among others.
*
* @param string $message Message
* @param int $code Error code
* @param int $mode Error mode
* @param mixed $options See __construct()
* @param string $userinfo Additional user/debug info
*/
public function PEAR_Error(
$message = 'unknown error', $code = null, $mode = null,
$options = null, $userinfo = null
) {
self::__construct($message, $code, $mode, $options, $userinfo);
}
 
/**
* Get the error mode from an error object.
923,13 → 951,11
* @return int error mode
* @access public
*/
function getMode() {
function getMode()
{
return $this->mode;
}
 
// }}}
// {{{ getCallback()
 
/**
* Get the callback function/method from an error object.
*
936,14 → 962,11
* @return mixed callback function or object/method array
* @access public
*/
function getCallback() {
function getCallback()
{
return $this->callback;
}
 
// }}}
// {{{ getMessage()
 
 
/**
* Get the error message from an error object.
*
955,10 → 978,6
return ($this->error_message_prefix . $this->message);
}
 
 
// }}}
// {{{ getCode()
 
/**
* Get error code from an error object
*
970,9 → 989,6
return $this->code;
}
 
// }}}
// {{{ getType()
 
/**
* Get the name of this error/exception.
*
984,9 → 1000,6
return get_class($this);
}
 
// }}}
// {{{ getUserInfo()
 
/**
* Get additional user-supplied information.
*
998,9 → 1011,6
return $this->userinfo;
}
 
// }}}
// {{{ getDebugInfo()
 
/**
* Get additional debug information supplied by the application.
*
1012,9 → 1022,6
return $this->getUserInfo();
}
 
// }}}
// {{{ getBacktrace()
 
/**
* Get the call backtrace from where the error was generated.
* Supported with PHP 4.3.0 or newer.
1034,9 → 1041,6
return $this->backtrace[$frame];
}
 
// }}}
// {{{ addUserInfo()
 
function addUserInfo($info)
{
if (empty($this->userinfo)) {
1046,8 → 1050,10
}
}
 
// }}}
// {{{ toString()
function __toString()
{
return $this->getMessage();
}
 
/**
* Make a string representation of this object.
1055,7 → 1061,8
* @return string a string with an object summary
* @access public
*/
function toString() {
function toString()
{
$modes = array();
$levels = array(E_USER_NOTICE => 'notice',
E_USER_WARNING => 'warning',
1094,8 → 1101,6
$this->error_message_prefix,
$this->userinfo);
}
 
// }}}
}
 
/*
1105,4 → 1110,3
* c-basic-offset: 4
* End:
*/
?>
/trunk/bibliotheque/pear/OS/Guess.php
New file
0,0 → 1,337
<?php
/**
* The OS_Guess class
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @author Gregory Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since PEAR 0.1
*/
 
// {{{ uname examples
 
// php_uname() without args returns the same as 'uname -a', or a PHP-custom
// string for Windows.
// PHP versions prior to 4.3 return the uname of the host where PHP was built,
// as of 4.3 it returns the uname of the host running the PHP code.
//
// PC RedHat Linux 7.1:
// Linux host.example.com 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
//
// PC Debian Potato:
// Linux host 2.4.17 #2 SMP Tue Feb 12 15:10:04 CET 2002 i686 unknown
//
// PC FreeBSD 3.3:
// FreeBSD host.example.com 3.3-STABLE FreeBSD 3.3-STABLE #0: Mon Feb 21 00:42:31 CET 2000 root@example.com:/usr/src/sys/compile/CONFIG i386
//
// PC FreeBSD 4.3:
// FreeBSD host.example.com 4.3-RELEASE FreeBSD 4.3-RELEASE #1: Mon Jun 25 11:19:43 EDT 2001 root@example.com:/usr/src/sys/compile/CONFIG i386
//
// PC FreeBSD 4.5:
// FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb 6 23:59:23 CET 2002 root@example.com:/usr/src/sys/compile/CONFIG i386
//
// PC FreeBSD 4.5 w/uname from GNU shellutils:
// FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb i386 unknown
//
// HP 9000/712 HP-UX 10:
// HP-UX iq B.10.10 A 9000/712 2008429113 two-user license
//
// HP 9000/712 HP-UX 10 w/uname from GNU shellutils:
// HP-UX host B.10.10 A 9000/712 unknown
//
// IBM RS6000/550 AIX 4.3:
// AIX host 3 4 000003531C00
//
// AIX 4.3 w/uname from GNU shellutils:
// AIX host 3 4 000003531C00 unknown
//
// SGI Onyx IRIX 6.5 w/uname from GNU shellutils:
// IRIX64 host 6.5 01091820 IP19 mips
//
// SGI Onyx IRIX 6.5:
// IRIX64 host 6.5 01091820 IP19
//
// SparcStation 20 Solaris 8 w/uname from GNU shellutils:
// SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc
//
// SparcStation 20 Solaris 8:
// SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc SUNW,SPARCstation-20
//
// Mac OS X (Darwin)
// Darwin home-eden.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug 5 19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC Power Macintosh
//
// Mac OS X early versions
//
 
// }}}
 
/* TODO:
* - define endianness, to allow matchSignature("bigend") etc.
*/
 
/**
* Retrieves information about the current operating system
*
* This class uses php_uname() to grok information about the current OS
*
* @category pear
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @author Gregory Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class OS_Guess
{
var $sysname;
var $nodename;
var $cpu;
var $release;
var $extra;
 
function __construct($uname = null)
{
list($this->sysname,
$this->release,
$this->cpu,
$this->extra,
$this->nodename) = $this->parseSignature($uname);
}
 
function parseSignature($uname = null)
{
static $sysmap = array(
'HP-UX' => 'hpux',
'IRIX64' => 'irix',
);
static $cpumap = array(
'i586' => 'i386',
'i686' => 'i386',
'ppc' => 'powerpc',
);
if ($uname === null) {
$uname = php_uname();
}
$parts = preg_split('/\s+/', trim($uname));
$n = count($parts);
 
$release = $machine = $cpu = '';
$sysname = $parts[0];
$nodename = $parts[1];
$cpu = $parts[$n-1];
$extra = '';
if ($cpu == 'unknown') {
$cpu = $parts[$n - 2];
}
 
switch ($sysname) {
case 'AIX' :
$release = "$parts[3].$parts[2]";
break;
case 'Windows' :
switch ($parts[1]) {
case '95/98':
$release = '9x';
break;
default:
$release = $parts[1];
break;
}
$cpu = 'i386';
break;
case 'Linux' :
$extra = $this->_detectGlibcVersion();
// use only the first two digits from the kernel version
$release = preg_replace('/^([0-9]+\.[0-9]+).*/', '\1', $parts[2]);
break;
case 'Mac' :
$sysname = 'darwin';
$nodename = $parts[2];
$release = $parts[3];
if ($cpu == 'Macintosh') {
if ($parts[$n - 2] == 'Power') {
$cpu = 'powerpc';
}
}
break;
case 'Darwin' :
if ($cpu == 'Macintosh') {
if ($parts[$n - 2] == 'Power') {
$cpu = 'powerpc';
}
}
$release = preg_replace('/^([0-9]+\.[0-9]+).*/', '\1', $parts[2]);
break;
default:
$release = preg_replace('/-.*/', '', $parts[2]);
break;
}
 
if (isset($sysmap[$sysname])) {
$sysname = $sysmap[$sysname];
} else {
$sysname = strtolower($sysname);
}
if (isset($cpumap[$cpu])) {
$cpu = $cpumap[$cpu];
}
return array($sysname, $release, $cpu, $extra, $nodename);
}
 
function _detectGlibcVersion()
{
static $glibc = false;
if ($glibc !== false) {
return $glibc; // no need to run this multiple times
}
$major = $minor = 0;
include_once "System.php";
// Use glibc's <features.h> header file to
// get major and minor version number:
if (@file_exists('/usr/include/features.h') &&
@is_readable('/usr/include/features.h')) {
if (!@file_exists('/usr/bin/cpp') || !@is_executable('/usr/bin/cpp')) {
$features_file = fopen('/usr/include/features.h', 'rb');
while (!feof($features_file)) {
$line = fgets($features_file, 8192);
if (!$line || (strpos($line, '#define') === false)) {
continue;
}
if (strpos($line, '__GLIBC__')) {
// major version number #define __GLIBC__ version
$line = preg_split('/\s+/', $line);
$glibc_major = trim($line[2]);
if (isset($glibc_minor)) {
break;
}
continue;
}
 
if (strpos($line, '__GLIBC_MINOR__')) {
// got the minor version number
// #define __GLIBC_MINOR__ version
$line = preg_split('/\s+/', $line);
$glibc_minor = trim($line[2]);
if (isset($glibc_major)) {
break;
}
continue;
}
}
fclose($features_file);
if (!isset($glibc_major) || !isset($glibc_minor)) {
return $glibc = '';
}
return $glibc = 'glibc' . trim($glibc_major) . "." . trim($glibc_minor) ;
} // no cpp
 
$tmpfile = System::mktemp("glibctest");
$fp = fopen($tmpfile, "w");
fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n");
fclose($fp);
$cpp = popen("/usr/bin/cpp $tmpfile", "r");
while ($line = fgets($cpp, 1024)) {
if ($line{0} == '#' || trim($line) == '') {
continue;
}
 
if (list($major, $minor) = explode(' ', trim($line))) {
break;
}
}
pclose($cpp);
unlink($tmpfile);
} // features.h
 
if (!($major && $minor) && @is_link('/lib/libc.so.6')) {
// Let's try reading the libc.so.6 symlink
if (preg_match('/^libc-(.*)\.so$/', basename(readlink('/lib/libc.so.6')), $matches)) {
list($major, $minor) = explode('.', $matches[1]);
}
}
 
if (!($major && $minor)) {
return $glibc = '';
}
 
return $glibc = "glibc{$major}.{$minor}";
}
 
function getSignature()
{
if (empty($this->extra)) {
return "{$this->sysname}-{$this->release}-{$this->cpu}";
}
return "{$this->sysname}-{$this->release}-{$this->cpu}-{$this->extra}";
}
 
function getSysname()
{
return $this->sysname;
}
 
function getNodename()
{
return $this->nodename;
}
 
function getCpu()
{
return $this->cpu;
}
 
function getRelease()
{
return $this->release;
}
 
function getExtra()
{
return $this->extra;
}
 
function matchSignature($match)
{
$fragments = is_array($match) ? $match : explode('-', $match);
$n = count($fragments);
$matches = 0;
if ($n > 0) {
$matches += $this->_matchFragment($fragments[0], $this->sysname);
}
if ($n > 1) {
$matches += $this->_matchFragment($fragments[1], $this->release);
}
if ($n > 2) {
$matches += $this->_matchFragment($fragments[2], $this->cpu);
}
if ($n > 3) {
$matches += $this->_matchFragment($fragments[3], $this->extra);
}
return ($matches == $n);
}
 
function _matchFragment($fragment, $value)
{
if (strcspn($fragment, '*?') < strlen($fragment)) {
$reg = '/^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '\\z/';
return preg_match($reg, $value);
}
return ($fragment == '*' || !strcasecmp($fragment, $value));
}
 
}
/*
* Local Variables:
* indent-tabs-mode: nil
* c-basic-offset: 4
* End:
*/
/trunk/bibliotheque/pear/DB/ldap.php
File deleted
/trunk/bibliotheque/pear/DB/NestedSet.php
File deleted
\ No newline at end of file
/trunk/bibliotheque/pear/DB/Pager.php
File deleted
/trunk/bibliotheque/pear/DB/DataObject.php
File deleted
/trunk/bibliotheque/pear/DB/QueryTool.php
File deleted
\ No newline at end of file
/trunk/bibliotheque/pear/DB/ifx.php
6,7 → 6,7
* The PEAR DB driver for PHP's ifx extension
* for interacting with Informix databases
*
* PHP versions 4 and 5
* PHP version 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:
18,9 → 18,9
* @package DB
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: ifx.php,v 1.70 2005/02/20 00:44:48 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
46,9 → 46,9
* @package DB
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_ifx extends DB_common
101,6 → 101,7
'-236' => DB_ERROR_VALUE_COUNT_ON_ROW,
'-239' => DB_ERROR_CONSTRAINT,
'-253' => DB_ERROR_SYNTAX,
'-268' => DB_ERROR_CONSTRAINT,
'-292' => DB_ERROR_CONSTRAINT_NOT_NULL,
'-310' => DB_ERROR_ALREADY_EXISTS,
'-316' => DB_ERROR_ALREADY_EXISTS,
113,6 → 114,7
'-691' => DB_ERROR_CONSTRAINT,
'-692' => DB_ERROR_CONSTRAINT,
'-703' => DB_ERROR_CONSTRAINT_NOT_NULL,
'-1202' => DB_ERROR_DIVZERO,
'-1204' => DB_ERROR_INVALID_DATE,
'-1205' => DB_ERROR_INVALID_DATE,
'-1206' => DB_ERROR_INVALID_DATE,
165,13 → 167,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_ifx()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
243,10 → 245,10
*/
function simpleQuery($query)
{
$ismanip = DB::isManip($query);
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
$this->affected = null;
if (preg_match('/(SELECT)/i', $query)) { //TESTME: Use !DB::isManip()?
if (preg_match('/(SELECT|EXECUTE)/i', $query)) { //TESTME: Use !DB::isManip()?
// the scroll is needed for fetching absolute row numbers
// in a select query result
$result = @ifx_query($query, $this->connection, IFX_SCROLL);
268,7 → 270,7
$this->affected = @ifx_affected_rows($result);
// Determine which queries should return data, and which
// should return an error code only.
if (preg_match('/(SELECT)/i', $query)) {
if (preg_match('/(SELECT|EXECUTE)/i', $query)) {
return $result;
}
// XXX Testme: free results inside a transaction
309,7 → 311,7
*/
function affectedRows()
{
if (DB::isManip($this->last_query)) {
if ($this->_last_query_manip) {
return $this->affected;
} else {
return 0;
420,7 → 422,7
*/
function freeResult($result)
{
return @ifx_free_result($result);
return is_resource($result) ? ifx_free_result($result) : false;
}
 
// }}}
534,7 → 536,7
*/
function errorCode($nativecode)
{
if (ereg('SQLCODE=(.*)]', $nativecode, $match)) {
if (preg_match('/SQLCODE=(.*)]/', $nativecode, $match)) {
$code = $match[1];
if (isset($this->errorcode_map[$code])) {
return $this->errorcode_map[$code];
/trunk/bibliotheque/pear/DB/pgsql.php
6,7 → 6,7
* The PEAR DB driver for PHP's pgsql extension
* for interacting with PostgreSQL databases
*
* PHP versions 4 and 5
* PHP version 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:
19,9 → 19,9
* @author Rui Hirokawa <hirokawa@php.net>
* @author Stig Bakken <ssb@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: pgsql.php,v 1.126 2005/03/04 23:12:36 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
41,9 → 41,9
* @author Rui Hirokawa <hirokawa@php.net>
* @author Stig Bakken <ssb@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_pgsql extends DB_common
148,13 → 148,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_pgsql()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
193,7 → 193,7
* 'portability' => DB_PORTABILITY_ALL,
* );
*
* $db =& DB::connect($dsn, $options);
* $db = DB::connect($dsn, $options);
* if (PEAR::isError($db)) {
* die($db->getMessage());
* }
277,10 → 277,10
$this->connection = @call_user_func_array($connect_function,
$params);
} else {
ini_set('track_errors', 1);
@ini_set('track_errors', 1);
$this->connection = @call_user_func_array($connect_function,
$params);
ini_set('track_errors', $ini);
@ini_set('track_errors', $ini);
}
 
if (!$this->connection) {
320,7 → 320,7
*/
function simpleQuery($query)
{
$ismanip = DB::isManip($query);
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
$query = $this->modifyQuery($query);
if (!$this->autocommit && $ismanip) {
336,19 → 336,26
if (!$result) {
return $this->pgsqlRaiseError();
}
// Determine which queries that should return data, and which
// should return an error code only.
 
/*
* Determine whether queries produce affected rows, result or nothing.
*
* This logic was introduced in version 1.1 of the file by ssb,
* though the regex has been modified slightly since then.
*
* PostgreSQL commands:
* ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY,
* CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH,
* GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET,
* REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW,
* UNLISTEN, UPDATE, VACUUM, WITH
*/
if ($ismanip) {
$this->affected = @pg_affected_rows($result);
return DB_OK;
} elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|SHOW)\s/si', $query)) {
/* PostgreSQL commands:
ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY,
CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH,
GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET,
REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW,
UNLISTEN, UPDATE, VACUUM
*/
} elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW|WITH)\s/si',
$query))
{
$this->row[(int)$result] = 0; // reset the row counter.
$numrows = $this->numRows($result);
if (is_object($numrows)) {
459,50 → 466,21
}
 
// }}}
// {{{ quote()
// {{{ quoteBoolean()
 
/**
* @deprecated Deprecated in release 1.6.0
* @internal
*/
function quote($str)
{
return $this->quoteSmart($str);
}
 
// }}}
// {{{ quoteSmart()
 
/**
* Formats input so it can be safely used in a query
* Formats a boolean value for use within a query in a locale-independent
* manner.
*
* @param mixed $in the data to be formatted
*
* @return mixed the formatted data. The format depends on the input's
* PHP type:
* + null = the string <samp>NULL</samp>
* + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp>
* + integer or double = the unquoted number
* + other (including strings and numeric strings) =
* the data escaped according to MySQL's settings
* then encapsulated between single quotes
*
* @param boolean the boolean value to be quoted.
* @return string the quoted string.
* @see DB_common::quoteSmart()
* @since Method available since Release 1.6.0
* @since Method available since release 1.7.8.
*/
function quoteSmart($in)
{
if (is_int($in) || is_double($in)) {
return $in;
} elseif (is_bool($in)) {
return $in ? 'TRUE' : 'FALSE';
} elseif (is_null($in)) {
return 'NULL';
} else {
return "'" . $this->escapeSimple($in) . "'";
}
function quoteBoolean($boolean) {
return $boolean ? 'TRUE' : 'FALSE';
}
 
// }}}
// {{{ escapeSimple()
 
512,9 → 490,6
* {@internal PostgreSQL treats a backslash as an escape character,
* so they are escaped as well.
*
* Not using pg_escape_string() yet because it requires PostgreSQL
* to be at version 7.2 or greater.}}
*
* @param string $str the string to be escaped
*
* @return string the escaped string
524,7 → 499,21
*/
function escapeSimple($str)
{
return str_replace("'", "''", str_replace('\\', '\\\\', $str));
if (function_exists('pg_escape_string')) {
/* This fixes an undocumented BC break in PHP 5.2.0 which changed
* the prototype of pg_escape_string. I'm not thrilled about having
* to sniff the PHP version, quite frankly, but it's the only way
* to deal with the problem. Revision 1.331.2.13.2.10 on
* php-src/ext/pgsql/pgsql.c (PHP_5_2 branch) is to blame, for the
* record. */
if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
return pg_escape_string($this->connection, $str);
} else {
return pg_escape_string($str);
}
} else {
return str_replace("'", "''", str_replace('\\', '\\\\', $str));
}
}
 
// }}}
675,7 → 664,7
$repeat = false;
do {
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$result =& $this->query("SELECT NEXTVAL('${seqname}')");
$result = $this->query("SELECT NEXTVAL('${seqname}')");
$this->popErrorHandling();
if ($ondemand && DB::isError($result) &&
$result->getCode() == DB_ERROR_NOSUCHTABLE) {
779,6 → 768,10
function pgsqlRaiseError($errno = null)
{
$native = $this->errorNative();
if (!$native) {
$native = 'Database connection has been lost.';
$errno = DB_ERROR_CONNECT_FAILED;
}
if ($errno === null) {
$errno = $this->errorCode($native);
}
815,12 → 808,12
static $error_regexps;
if (!isset($error_regexps)) {
$error_regexps = array(
'/column .* (of relation .*)?does not exist/i'
=> DB_ERROR_NOSUCHFIELD,
'/(relation|sequence|table).*does not exist|class .* not found/i'
=> DB_ERROR_NOSUCHTABLE,
'/index .* does not exist/'
=> DB_ERROR_NOT_FOUND,
'/column .* does not exist/i'
=> DB_ERROR_NOSUCHFIELD,
'/relation .* already exists/i'
=> DB_ERROR_ALREADY_EXISTS,
'/(divide|division) by zero$/i'
976,12 → 969,23
{
$field_name = @pg_fieldname($resource, $num_field);
 
// Check if there's a schema in $table_name and update things
// accordingly.
$from = 'pg_attribute f, pg_class tab, pg_type typ';
if (strpos($table_name, '.') !== false) {
$from .= ', pg_namespace nsp';
list($schema, $table) = explode('.', $table_name);
$tableWhere = "tab.relname = '$table' AND tab.relnamespace = nsp.oid AND nsp.nspname = '$schema'";
} else {
$tableWhere = "tab.relname = '$table_name'";
}
 
$result = @pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef
FROM pg_attribute f, pg_class tab, pg_type typ
FROM $from
WHERE tab.relname = typ.typname
AND typ.typrelid = f.attrelid
AND f.attname = '$field_name'
AND tab.relname = '$table_name'");
AND $tableWhere");
if (@pg_numrows($result) > 0) {
$row = @pg_fetch_row($result, 0);
$flags = ($row[0] == 't') ? 'not_null ' : '';
988,10 → 992,10
 
if ($row[1] == 't') {
$result = @pg_exec($this->connection, "SELECT a.adsrc
FROM pg_attribute f, pg_class tab, pg_type typ, pg_attrdef a
FROM $from, pg_attrdef a
WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid
AND f.attrelid = a.adrelid AND f.attname = '$field_name'
AND tab.relname = '$table_name' AND f.attnum = a.adnum");
AND $tableWhere AND f.attnum = a.adnum");
$row = @pg_fetch_row($result, 0);
$num = preg_replace("/'(.*)'::\w+/", "\\1", $row[0]);
$flags .= 'default_' . rawurlencode($num) . ' ';
1000,12 → 1004,12
$flags = '';
}
$result = @pg_exec($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey
FROM pg_attribute f, pg_class tab, pg_type typ, pg_index i
FROM $from, pg_index i
WHERE tab.relname = typ.typname
AND typ.typrelid = f.attrelid
AND f.attrelid = i.indrelid
AND f.attname = '$field_name'
AND tab.relname = '$table_name'");
AND $tableWhere");
$count = @pg_numrows($result);
 
for ($i = 0; $i < $count ; $i++) {
1066,6 → 1070,9
. ' FROM pg_catalog.pg_tables'
. ' WHERE schemaname NOT IN'
. " ('pg_catalog', 'information_schema', 'pg_toast')";
case 'schema.views':
return "SELECT schemaname || '.' || viewname from pg_views WHERE schemaname"
. " NOT IN ('information_schema', 'pg_catalog')";
case 'views':
// Table cols: viewname | viewowner | definition
return 'SELECT viewname from pg_views WHERE schemaname'
1084,7 → 1091,26
}
 
// }}}
// {{{ _checkManip()
 
/**
* Checks if the given query is a manipulation query. This also takes into
* account the _next_query_manip flag and sets the _last_query_manip flag
* (and resets _next_query_manip) according to the result.
*
* @param string The query to check.
*
* @return boolean true if the query is a manipulation query, false
* otherwise
*
* @access protected
*/
function _checkManip($query)
{
return (preg_match('/^\s*(SAVEPOINT|RELEASE)\s+/i', $query)
|| parent::_checkManip($query));
}
 
}
 
/*
/trunk/bibliotheque/pear/DB/sybase.php
6,7 → 6,7
* The PEAR DB driver for PHP's sybase extension
* for interacting with Sybase databases
*
* PHP versions 4 and 5
* PHP version 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:
19,9 → 19,9
* @author Sterling Hughes <sterling@php.net>
* @author Antônio Carlos Venâncio Júnior <floripa@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: sybase.php,v 1.78 2005/02/20 00:44:48 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
44,9 → 44,9
* @author Sterling Hughes <sterling@php.net>
* @author Antônio Carlos Venâncio Júnior <floripa@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_sybase extends DB_common
141,13 → 141,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_sybase()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
248,9 → 248,9
*/
function simpleQuery($query)
{
$ismanip = DB::isManip($query);
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
if (!@sybase_select_db($this->_db, $this->connection)) {
if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
}
$query = $this->modifyQuery($query);
370,7 → 370,7
*/
function freeResult($result)
{
return @sybase_free_result($result);
return is_resource($result) ? sybase_free_result($result) : false;
}
 
// }}}
435,7 → 435,7
*/
function affectedRows()
{
if (DB::isManip($this->last_query)) {
if ($this->_last_query_manip) {
$result = @sybase_affected_rows($this->connection);
} else {
$result = 0;
462,7 → 462,7
function nextId($seq_name, $ondemand = true)
{
$seqname = $this->getSequenceName($seq_name);
if (!@sybase_select_db($this->_db, $this->connection)) {
if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
}
$repeat = 0;
479,7 → 479,7
return $this->raiseError($result);
}
} elseif (!DB::isError($result)) {
$result =& $this->query("SELECT @@IDENTITY FROM $seqname");
$result = $this->query("SELECT @@IDENTITY FROM $seqname");
$repeat = 0;
} else {
$repeat = false;
529,6 → 529,22
}
 
// }}}
// {{{ quoteFloat()
 
/**
* Formats a float value for use within a query in a locale-independent
* manner.
*
* @param float the float value to be quoted.
* @return string the quoted string.
* @see DB_common::quoteSmart()
* @since Method available since release 1.7.8.
*/
function quoteFloat($float) {
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
}
// }}}
// {{{ autoCommit()
 
/**
558,7 → 574,7
function commit()
{
if ($this->transaction_opcount > 0) {
if (!@sybase_select_db($this->_db, $this->connection)) {
if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
}
$result = @sybase_query('COMMIT', $this->connection);
581,7 → 597,7
function rollback()
{
if ($this->transaction_opcount > 0) {
if (!@sybase_select_db($this->_db, $this->connection)) {
if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
}
$result = @sybase_query('ROLLBACK', $this->connection);
642,6 → 658,11
function errorCode($errormsg)
{
static $error_regexps;
// PHP 5.2+ prepends the function name to $php_errormsg, so we need
// this hack to work around it, per bug #9599.
$errormsg = preg_replace('/^sybase[a-z_]+\(\): /', '', $errormsg);
if (!isset($error_regexps)) {
$error_regexps = array(
'/Incorrect syntax near/'
674,6 → 695,8
=> DB_ERROR_ALREADY_EXISTS,
'/^There are fewer columns in the INSERT statement than values specified/i'
=> DB_ERROR_VALUE_COUNT_ON_ROW,
'/Divide by zero/i'
=> DB_ERROR_DIVZERO,
);
}
 
714,7 → 737,7
* Probably received a table name.
* Create a result resource identifier.
*/
if (!@sybase_select_db($this->_db, $this->connection)) {
if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
}
$id = @sybase_query("SELECT * FROM $result WHERE 1=0",
811,14 → 834,24
$flags = array();
$tableName = $table;
 
// get unique/primary keys
$res = $this->getAll("sp_helpindex $table", DB_FETCHMODE_ASSOC);
/* We're running sp_helpindex directly because it doesn't exist in
* older versions of ASE -- unfortunately, we can't just use
* DB::isError() because the user may be using callback error
* handling. */
$res = @sybase_query("sp_helpindex $table", $this->connection);
 
if (!isset($res[0]['index_description'])) {
if ($res === false || $res === true) {
// Fake a valid response for BC reasons.
return '';
}
 
foreach ($res as $val) {
while (($val = sybase_fetch_assoc($res)) !== false) {
if (!isset($val['index_keys'])) {
/* No useful information returned. Break and be done with
* it, which preserves the pre-1.7.9 behaviour. */
break;
}
 
$keys = explode(', ', trim($val['index_keys']));
 
if (sizeof($keys) > 1) {
834,6 → 867,8
}
}
 
sybase_free_result($res);
 
}
 
if (array_key_exists($column, $flags)) {
/trunk/bibliotheque/pear/DB/fbsql.php
6,7 → 6,7
* The PEAR DB driver for PHP's fbsql extension
* for interacting with FrontBase databases
*
* PHP versions 4 and 5
* PHP version 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:
18,9 → 18,9
* @package DB
* @author Frank M. Kromann <frank@frontbase.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: fbsql.php,v 1.82 2005/03/04 23:12:36 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
39,9 → 39,9
* @package DB
* @author Frank M. Kromann <frank@frontbase.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
* @since Class functional since Release 1.7.0
*/
124,13 → 124,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_fbsql()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
171,10 → 171,10
$this->connection = @call_user_func_array($connect_function,
$params);
} else {
ini_set('track_errors', 1);
@ini_set('track_errors', 1);
$this->connection = @call_user_func_array($connect_function,
$params);
ini_set('track_errors', $ini);
@ini_set('track_errors', $ini);
}
 
if (!$this->connection) {
229,7 → 229,7
}
// Determine which queries that should return data, and which
// should return an error code only.
if (DB::isManip($query)) {
if ($this->_checkManip($query)) {
return DB_OK;
}
return $result;
320,7 → 320,7
*/
function freeResult($result)
{
return @fbsql_free_result($result);
return is_resource($result) ? fbsql_free_result($result) : false;
}
 
// }}}
353,7 → 353,7
*/
function commit()
{
@fbsql_commit();
@fbsql_commit($this->connection);
}
 
// }}}
366,7 → 366,7
*/
function rollback()
{
@fbsql_rollback();
@fbsql_rollback($this->connection);
}
 
// }}}
431,7 → 431,7
*/
function affectedRows()
{
if (DB::isManip($this->last_query)) {
if ($this->_last_query_manip) {
$result = @fbsql_affected_rows($this->connection);
} else {
$result = 0;
543,7 → 543,7
*/
function modifyLimitQuery($query, $from, $count, $params = array())
{
if (DB::isManip($query)) {
if (DB::isManip($query) || $this->_next_query_manip) {
return preg_replace('/^([\s(])*SELECT/i',
"\\1SELECT TOP($count)", $query);
} else {
553,38 → 553,37
}
 
// }}}
// {{{ quoteSmart()
// {{{ quoteBoolean()
 
/**
* Formats input so it can be safely used in a query
* Formats a boolean value for use within a query in a locale-independent
* manner.
*
* @param mixed $in the data to be formatted
* @param boolean the boolean value to be quoted.
* @return string the quoted string.
* @see DB_common::quoteSmart()
* @since Method available since release 1.7.8.
*/
function quoteBoolean($boolean) {
return $boolean ? 'TRUE' : 'FALSE';
}
// }}}
// {{{ quoteFloat()
 
/**
* Formats a float value for use within a query in a locale-independent
* manner.
*
* @return mixed the formatted data. The format depends on the input's
* PHP type:
* + null = the string <samp>NULL</samp>
* + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp>
* + integer or double = the unquoted number
* + other (including strings and numeric strings) =
* the data escaped according to FrontBase's settings
* then encapsulated between single quotes
*
* @param float the float value to be quoted.
* @return string the quoted string.
* @see DB_common::quoteSmart()
* @since Method available since Release 1.6.0
* @since Method available since release 1.7.8.
*/
function quoteSmart($in)
{
if (is_int($in) || is_double($in)) {
return $in;
} elseif (is_bool($in)) {
return $in ? 'TRUE' : 'FALSE';
} elseif (is_null($in)) {
return 'NULL';
} else {
return "'" . $this->escapeSimple($in) . "'";
}
function quoteFloat($float) {
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
}
 
// }}}
// {{{ fbsqlRaiseError()
 
/trunk/bibliotheque/pear/DB/odbc.php
6,7 → 6,7
* The PEAR DB driver for PHP's odbc extension
* for interacting with databases via ODBC connections
*
* PHP versions 4 and 5
* PHP version 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:
18,9 → 18,9
* @package DB
* @author Stig Bakken <ssb@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: odbc.php,v 1.78 2005/02/28 01:42:17 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
42,9 → 42,9
* @package DB
* @author Stig Bakken <ssb@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_odbc extends DB_common
153,13 → 153,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_odbc()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
266,7 → 266,7
}
// Determine which queries that should return data, and which
// should return an error code only.
if (DB::isManip($query)) {
if ($this->_checkManip($query)) {
$this->affected = $result; // For affectedRows()
return DB_OK;
}
367,7 → 367,7
*/
function freeResult($result)
{
return @odbc_free_result($result);
return is_resource($result) ? odbc_free_result($result) : false;
}
 
// }}}
481,18 → 481,6
}
 
// }}}
// {{{ quote()
 
/**
* @deprecated Deprecated in release 1.6.0
* @internal
*/
function quote($str)
{
return $this->quoteSmart($str);
}
 
// }}}
// {{{ nextId()
 
/**
/trunk/bibliotheque/pear/DB/common.php
5,7 → 5,7
/**
* Contains the DB_common base class
*
* PHP versions 4 and 5
* PHP version 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:
18,9 → 18,9
* @author Stig Bakken <ssb@php.net>
* @author Tomas V.V. Cox <cox@idecnet.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: common.php,v 1.137 2005/04/07 14:27:35 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
40,9 → 40,9
* @author Stig Bakken <ssb@php.net>
* @author Tomas V.V. Cox <cox@idecnet.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_common extends PEAR
121,7 → 121,22
*/
var $prepared_queries = array();
 
/**
* Flag indicating that the last query was a manipulation query.
* @access protected
* @var boolean
*/
var $_last_query_manip = false;
 
/**
* Flag indicating that the next query <em>must</em> be a manipulation
* query.
* @access protected
* @var boolean
*/
var $_next_query_manip = false;
 
 
// }}}
// {{{ DB_common
 
130,7 → 145,7
*
* @return void
*/
function DB_common()
function __construct()
{
$this->PEAR('DB_Error');
}
189,7 → 204,7
function __wakeup()
{
if ($this->was_connected) {
$this->connect($this->dsn, $this->options);
$this->connect($this->dsn, $this->options['persistent']);
}
}
 
246,7 → 261,7
*/
function quoteString($string)
{
$string = $this->quote($string);
$string = $this->quoteSmart($string);
if ($string{0} == "'") {
return substr($string, 1, -1);
}
269,8 → 284,7
*/
function quote($string = null)
{
return ($string === null) ? 'NULL'
: "'" . str_replace("'", "''", $string) . "'";
return $this->quoteSmart($string);
}
 
// }}}
424,18 → 438,57
*/
function quoteSmart($in)
{
if (is_int($in) || is_double($in)) {
if (is_int($in)) {
return $in;
} elseif (is_float($in)) {
return $this->quoteFloat($in);
} elseif (is_bool($in)) {
return $in ? 1 : 0;
return $this->quoteBoolean($in);
} elseif (is_null($in)) {
return 'NULL';
} else {
if ($this->dbsyntax == 'access'
&& preg_match('/^#.+#$/', $in))
{
return $this->escapeSimple($in);
}
return "'" . $this->escapeSimple($in) . "'";
}
}
 
// }}}
// {{{ quoteBoolean()
 
/**
* Formats a boolean value for use within a query in a locale-independent
* manner.
*
* @param boolean the boolean value to be quoted.
* @return string the quoted string.
* @see DB_common::quoteSmart()
* @since Method available since release 1.7.8.
*/
function quoteBoolean($boolean) {
return $boolean ? '1' : '0';
}
// }}}
// {{{ quoteFloat()
 
/**
* Formats a float value for use within a query in a locale-independent
* manner.
*
* @param float the float value to be quoted.
* @return string the quoted string.
* @see DB_common::quoteSmart()
* @since Method available since release 1.7.8.
*/
function quoteFloat($float) {
return "'".$this->escapeSimple(str_replace(',', '.', strval(floatval($float))))."'";
}
// }}}
// {{{ escapeSimple()
 
/**
837,7 → 890,7
if (DB::isError($sth)) {
return $sth;
}
$ret =& $this->execute($sth, array_values($fields_values));
$ret = $this->execute($sth, array_values($fields_values));
$this->freePrepared($sth);
return $ret;
 
931,7 → 984,7
* "'it''s good'",
* 'filename.txt'
* );
* $res =& $db->execute($sth, $data);
* $res = $db->execute($sth, $data);
* </code>
*
* @param resource $stmt a DB statement resource returned from prepare()
960,7 → 1013,7
if ($result === DB_OK || DB::isError($result)) {
return $result;
} else {
$tmp =& new DB_result($this, $result);
$tmp = new DB_result($this, $result);
return $tmp;
}
}
1041,7 → 1094,7
function executeMultiple($stmt, $data)
{
foreach ($data as $value) {
$res =& $this->execute($stmt, $value);
$res = $this->execute($stmt, $value);
if (DB::isError($res)) {
return $res;
}
1154,7 → 1207,7
if (DB::isError($sth)) {
return $sth;
}
$ret =& $this->execute($sth, $params);
$ret = $this->execute($sth, $params);
$this->freePrepared($sth, false);
return $ret;
} else {
1163,7 → 1216,7
if ($result === DB_OK || DB::isError($result)) {
return $result;
} else {
$tmp =& new DB_result($this, $result);
$tmp = new DB_result($this, $result);
return $tmp;
}
}
1194,8 → 1247,8
if (DB::isError($query)){
return $query;
}
$result =& $this->query($query, $params);
if (is_a($result, 'DB_result')) {
$result = $this->query($query, $params);
if (is_object($result) && is_a($result, 'DB_result')) {
$result->setOption('limit_from', $from);
$result->setOption('limit_count', $count);
}
1229,10 → 1282,10
if (DB::isError($sth)) {
return $sth;
}
$res =& $this->execute($sth, $params);
$res = $this->execute($sth, $params);
$this->freePrepared($sth);
} else {
$res =& $this->query($query);
$res = $this->query($query);
}
 
if (DB::isError($res)) {
1293,10 → 1346,10
if (DB::isError($sth)) {
return $sth;
}
$res =& $this->execute($sth, $params);
$res = $this->execute($sth, $params);
$this->freePrepared($sth);
} else {
$res =& $this->query($query);
$res = $this->query($query);
}
 
if (DB::isError($res)) {
1344,10 → 1397,10
return $sth;
}
 
$res =& $this->execute($sth, $params);
$res = $this->execute($sth, $params);
$this->freePrepared($sth);
} else {
$res =& $this->query($query);
$res = $this->query($query);
}
 
if (DB::isError($res)) {
1360,7 → 1413,7
$ret = array();
} else {
if (!array_key_exists($col, $row)) {
$ret =& $this->raiseError(DB_ERROR_NOSUCHFIELD);
$ret = $this->raiseError(DB_ERROR_NOSUCHFIELD);
} else {
$ret = array($row[$col]);
while (is_array($row = $res->fetchRow($fetchmode))) {
1476,10 → 1529,10
return $sth;
}
 
$res =& $this->execute($sth, $params);
$res = $this->execute($sth, $params);
$this->freePrepared($sth);
} else {
$res =& $this->query($query);
$res = $this->query($query);
}
 
if (DB::isError($res)) {
1491,7 → 1544,7
$cols = $res->numCols();
 
if ($cols < 2) {
$tmp =& $this->raiseError(DB_ERROR_TRUNCATED);
$tmp = $this->raiseError(DB_ERROR_TRUNCATED);
return $tmp;
}
 
1603,10 → 1656,10
return $sth;
}
 
$res =& $this->execute($sth, $params);
$res = $this->execute($sth, $params);
$this->freePrepared($sth);
} else {
$res =& $this->query($query);
$res = $this->query($query);
}
 
if ($res === DB_OK || DB::isError($res)) {
1627,7 → 1680,7
$res->free();
 
if (DB::isError($row)) {
$tmp =& $this->raiseError($row);
$tmp = $this->raiseError($row);
return $tmp;
}
return $results;
1814,6 → 1867,10
* query and native error code.
* @param mixed native error code, integer or string depending the
* backend
* @param mixed dummy parameter for E_STRICT compatibility with
* PEAR::raiseError
* @param mixed dummy parameter for E_STRICT compatibility with
* PEAR::raiseError
*
* @return object the PEAR_Error object
*
1820,7 → 1877,8
* @see PEAR_Error
*/
function &raiseError($code = DB_ERROR, $mode = null, $options = null,
$userinfo = null, $nativecode = null)
$userinfo = null, $nativecode = null, $dummy1 = null,
$dummy2 = null)
{
// The error is yet a DB error object
if (is_object($code)) {
2103,6 → 2161,52
}
 
// }}}
// {{{ nextQueryIsManip()
 
/**
* Sets (or unsets) a flag indicating that the next query will be a
* manipulation query, regardless of the usual DB::isManip() heuristics.
*
* @param boolean true to set the flag overriding the isManip() behaviour,
* false to clear it and fall back onto isManip()
*
* @return void
*
* @access public
*/
function nextQueryIsManip($manip)
{
$this->_next_query_manip = $manip;
}
 
// }}}
// {{{ _checkManip()
 
/**
* Checks if the given query is a manipulation query. This also takes into
* account the _next_query_manip flag and sets the _last_query_manip flag
* (and resets _next_query_manip) according to the result.
*
* @param string The query to check.
*
* @return boolean true if the query is a manipulation query, false
* otherwise
*
* @access protected
*/
function _checkManip($query)
{
if ($this->_next_query_manip || DB::isManip($query)) {
$this->_last_query_manip = true;
} else {
$this->_last_query_manip = false;
}
$this->_next_query_manip = false;
return $this->_last_query_manip;
$manip = $this->_next_query_manip;
}
 
// }}}
// {{{ _rtrimArrayValues()
 
/**
/trunk/bibliotheque/pear/DB/msql.php
10,7 → 10,7
* 4.3.11 and 5.0.4. Make sure your version of PHP meets or exceeds
* those versions.
*
* PHP versions 4 and 5
* PHP version 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:
21,9 → 21,9
* @category Database
* @package DB
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: msql.php,v 1.57 2005/02/22 07:26:46 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
45,9 → 45,9
* @category Database
* @package DB
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
* @since Class not functional until Release 1.7.0
*/
126,13 → 126,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_msql()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
153,7 → 153,7
* 'portability' => DB_PORTABILITY_ALL,
* );
*
* $db =& DB::connect($dsn, $options);
* $db = DB::connect($dsn, $options);
* if (PEAR::isError($db)) {
* die($db->getMessage());
* }
190,10 → 190,10
$this->connection = @call_user_func_array($connect_function,
$params);
} else {
ini_set('track_errors', 1);
@ini_set('track_errors', 1);
$this->connection = @call_user_func_array($connect_function,
$params);
ini_set('track_errors', $ini);
@ini_set('track_errors', $ini);
}
 
if (!$this->connection) {
251,7 → 251,7
}
// Determine which queries that should return data, and which
// should return an error code only.
if (DB::isManip($query)) {
if ($this->_checkManip($query)) {
$this->_result = $result;
return DB_OK;
} else {
350,7 → 350,7
*/
function freeResult($result)
{
return @msql_free_result($result);
return is_resource($result) ? msql_free_result($result) : false;
}
 
// }}}
443,7 → 443,7
$repeat = false;
do {
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$result =& $this->query("SELECT _seq FROM ${seqname}");
$result = $this->query("SELECT _seq FROM ${seqname}");
$this->popErrorHandling();
if ($ondemand && DB::isError($result) &&
$result->getCode() == DB_ERROR_NOSUCHTABLE) {
531,6 → 531,22
}
 
// }}}
// {{{ quoteFloat()
 
/**
* Formats a float value for use within a query in a locale-independent
* manner.
*
* @param float the float value to be quoted.
* @return string the quoted string.
* @see DB_common::quoteSmart()
* @since Method available since release 1.7.8.
*/
function quoteFloat($float) {
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
}
// }}}
// {{{ escapeSimple()
 
/**
598,6 → 614,11
function errorCode($errormsg)
{
static $error_regexps;
// PHP 5.2+ prepends the function name to $php_errormsg, so we need
// this hack to work around it, per bug #9599.
$errormsg = preg_replace('/^msql[a-z_]+\(\): /', '', $errormsg);
 
if (!isset($error_regexps)) {
$error_regexps = array(
'/^Access to database denied/i'
/trunk/bibliotheque/pear/DB/dbase.php
6,7 → 6,7
* The PEAR DB driver for PHP's dbase extension
* for interacting with dBase databases
*
* PHP versions 4 and 5
* PHP version 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:
18,9 → 18,9
* @package DB
* @author Tomas V.V. Cox <cox@idecnet.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: dbase.php,v 1.39 2005/02/19 23:25:25 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
39,9 → 39,9
* @package DB
* @author Tomas V.V. Cox <cox@idecnet.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_dbase extends DB_common
140,13 → 140,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_dbase()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
188,7 → 188,7
* 'portability' => DB_PORTABILITY_ALL,
* );
*
* $db =& DB::connect($dsn, $options);
* $db = DB::connect($dsn, $options);
* if (PEAR::isError($db)) {
* die($db->getMessage());
* }
214,7 → 214,7
* Turn track_errors on for entire script since $php_errormsg
* is the only way to find errors from the dbase extension.
*/
ini_set('track_errors', 1);
@ini_set('track_errors', 1);
$php_errormsg = '';
 
if (!file_exists($dsn['database'])) {
273,7 → 273,7
{
// emulate result resources
$this->res_row[(int)$this->result] = 0;
$tmp =& new DB_result($this, $this->result++);
$tmp = new DB_result($this, $this->result++);
return $tmp;
}
 
326,6 → 326,26
}
 
// }}}
// {{{ freeResult()
 
/**
* Deletes the result set and frees the memory occupied by the result set.
*
* This method is a no-op for dbase, as there aren't result resources in
* the same sense as most other database backends.
*
* @param resource $result PHP's query result resource
*
* @return bool TRUE on success, FALSE if $result is invalid
*
* @see DB_result::free()
*/
function freeResult($result)
{
return true;
}
 
// }}}
// {{{ numCols()
 
/**
368,41 → 388,21
}
 
// }}}
// {{{ quoteSmart()
// {{{ quoteBoolean()
 
/**
* Formats input so it can be safely used in a query
* Formats a boolean value for use within a query in a locale-independent
* manner.
*
* @param mixed $in the data to be formatted
*
* @return mixed the formatted data. The format depends on the input's
* PHP type:
* + null = the string <samp>NULL</samp>
* + boolean = <samp>T</samp> if true or
* <samp>F</samp> if false. Use the <kbd>Logical</kbd>
* data type.
* + integer or double = the unquoted number
* + other (including strings and numeric strings) =
* the data with single quotes escaped by preceeding
* single quotes then the whole string is encapsulated
* between single quotes
*
* @param boolean the boolean value to be quoted.
* @return string the quoted string.
* @see DB_common::quoteSmart()
* @since Method available since Release 1.6.0
* @since Method available since release 1.7.8.
*/
function quoteSmart($in)
{
if (is_int($in) || is_double($in)) {
return $in;
} elseif (is_bool($in)) {
return $in ? 'T' : 'F';
} elseif (is_null($in)) {
return 'NULL';
} else {
return "'" . $this->escapeSimple($in) . "'";
}
function quoteBoolean($boolean) {
return $boolean ? 'T' : 'F';
}
 
// }}}
// {{{ tableInfo()
 
/trunk/bibliotheque/pear/DB/mysqli.php
6,7 → 6,7
* The PEAR DB driver for PHP's mysqli extension
* for interacting with MySQL databases
*
* PHP versions 4 and 5
* PHP version 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:
17,9 → 17,9
* @category Database
* @package DB
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: mysqli.php,v 1.69 2005/03/04 23:12:36 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
41,9 → 41,9
* @category Database
* @package DB
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
* @since Class functional since Release 1.6.3
*/
114,6 → 114,9
1146 => DB_ERROR_NOSUCHTABLE,
1216 => DB_ERROR_CONSTRAINT,
1217 => DB_ERROR_CONSTRAINT,
1356 => DB_ERROR_DIVZERO,
1451 => DB_ERROR_CONSTRAINT,
1452 => DB_ERROR_CONSTRAINT,
);
 
/**
210,6 → 213,10
MYSQLI_TYPE_VAR_STRING => 'varchar',
MYSQLI_TYPE_STRING => 'char',
MYSQLI_TYPE_GEOMETRY => 'geometry',
/* These constants are conditionally compiled in ext/mysqli, so we'll
* define them by number rather than constant. */
16 => 'bit',
246 => 'decimal',
);
 
 
217,13 → 224,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_mysqli()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
264,7 → 271,7
* 'ssl' => true,
* );
*
* $db =& DB::connect($dsn, $options);
* $db = DB::connect($dsn, $options);
* if (PEAR::isError($db)) {
* die($db->getMessage());
* }
287,10 → 294,10
}
 
$ini = ini_get('track_errors');
ini_set('track_errors', 1);
@ini_set('track_errors', 1);
$php_errormsg = '';
 
if ($this->getOption('ssl') === true) {
if (((int) $this->getOption('ssl')) === 1) {
$init = mysqli_init();
mysqli_ssl_set(
$init,
322,7 → 329,7
);
}
 
ini_set('track_errors', $ini);
@ini_set('track_errors', $ini);
 
if (!$this->connection) {
if (($err = @mysqli_connect_error()) != '') {
372,7 → 379,7
*/
function simpleQuery($query)
{
$ismanip = DB::isManip($query);
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
$query = $this->modifyQuery($query);
if ($this->_db) {
490,7 → 497,11
*/
function freeResult($result)
{
return @mysqli_free_result($result);
if (! $result instanceof mysqli_result) {
return false;
}
mysqli_free_result($result);
return true;
}
 
// }}}
626,7 → 637,7
*/
function affectedRows()
{
if (DB::isManip($this->last_query)) {
if ($this->_last_query_manip) {
return @mysqli_affected_rows($this->connection);
} else {
return 0;
823,9 → 834,10
 
/**
* Quotes a string so it can be safely used as a table or column name
* (WARNING: using names that require this is a REALLY BAD IDEA)
*
* MySQL can't handle the backtick character (<kbd>`</kbd>) in
* table or column names.
* WARNING: Older versions of MySQL can't handle the backtick
* character (<kbd>`</kbd>) in table or column names.
*
* @param string $str identifier name to be quoted
*
836,7 → 848,7
*/
function quoteIdentifier($str)
{
return '`' . $str . '`';
return '`' . str_replace('`', '``', $str) . '`';
}
 
// }}}
878,7 → 890,7
*/
function modifyLimitQuery($query, $from, $count, $params = array())
{
if (DB::isManip($query)) {
if (DB::isManip($query) || $this->_next_query_manip) {
return $query . " LIMIT $count";
} else {
return $query . " LIMIT $from, $count";
954,6 → 966,13
function tableInfo($result, $mode = null)
{
if (is_string($result)) {
// Fix for bug #11580.
if ($this->_db) {
if (!@mysqli_select_db($this->connection, $this->_db)) {
return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED);
}
}
 
/*
* Probably received a table name.
* Create a result resource identifier.
978,7 → 997,7
$got_string = false;
}
 
if (!is_a($id, 'mysqli_result')) {
if (!is_object($id) || !is_a($id, 'mysqli_result')) {
return $this->mysqliRaiseError(DB_ERROR_NEED_MORE_DATA);
}
 
1015,7 → 1034,12
'type' => isset($this->mysqli_types[$tmp->type])
? $this->mysqli_types[$tmp->type]
: 'unknown',
'len' => $tmp->max_length,
// http://bugs.php.net/?id=36579
// Doc Bug #36579: mysqli_fetch_field length handling
// https://bugs.php.net/bug.php?id=62426
// Bug #62426: mysqli_fetch_field_direct returns incorrect
// length on UTF8 fields
'len' => $tmp->length,
'flags' => $flags,
);
 
/trunk/bibliotheque/pear/DB/mssql.php
6,7 → 6,7
* The PEAR DB driver for PHP's mssql extension
* for interacting with Microsoft SQL Server databases
*
* PHP versions 4 and 5
* PHP version 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:
18,9 → 18,9
* @package DB
* @author Sterling Hughes <sterling@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: mssql.php,v 1.83 2005/03/07 18:24:51 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
35,13 → 35,21
*
* These methods overload the ones declared in DB_common.
*
* DB's mssql driver is only for Microsfoft SQL Server databases.
*
* If you're connecting to a Sybase database, you MUST specify "sybase"
* as the "phptype" in the DSN.
*
* This class only works correctly if you have compiled PHP using
* --with-mssql=[dir_to_FreeTDS].
*
* @category Database
* @package DB
* @author Sterling Hughes <sterling@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_mssql extends DB_common
89,19 → 97,40
*/
// XXX Add here error codes ie: 'S100E' => DB_ERROR_SYNTAX
var $errorcode_map = array(
102 => DB_ERROR_SYNTAX,
110 => DB_ERROR_VALUE_COUNT_ON_ROW,
155 => DB_ERROR_NOSUCHFIELD,
156 => DB_ERROR_SYNTAX,
170 => DB_ERROR_SYNTAX,
207 => DB_ERROR_NOSUCHFIELD,
208 => DB_ERROR_NOSUCHTABLE,
245 => DB_ERROR_INVALID_NUMBER,
319 => DB_ERROR_SYNTAX,
321 => DB_ERROR_NOSUCHFIELD,
325 => DB_ERROR_SYNTAX,
336 => DB_ERROR_SYNTAX,
515 => DB_ERROR_CONSTRAINT_NOT_NULL,
547 => DB_ERROR_CONSTRAINT,
1018 => DB_ERROR_SYNTAX,
1035 => DB_ERROR_SYNTAX,
1913 => DB_ERROR_ALREADY_EXISTS,
2209 => DB_ERROR_SYNTAX,
2223 => DB_ERROR_SYNTAX,
2248 => DB_ERROR_SYNTAX,
2256 => DB_ERROR_SYNTAX,
2257 => DB_ERROR_SYNTAX,
2627 => DB_ERROR_CONSTRAINT,
2714 => DB_ERROR_ALREADY_EXISTS,
3607 => DB_ERROR_DIVZERO,
3701 => DB_ERROR_NOSUCHTABLE,
7630 => DB_ERROR_SYNTAX,
8134 => DB_ERROR_DIVZERO,
9303 => DB_ERROR_SYNTAX,
9317 => DB_ERROR_SYNTAX,
9318 => DB_ERROR_SYNTAX,
9331 => DB_ERROR_SYNTAX,
9332 => DB_ERROR_SYNTAX,
15253 => DB_ERROR_SYNTAX,
);
 
/**
150,13 → 179,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_mssql()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
244,7 → 273,7
*/
function simpleQuery($query)
{
$ismanip = DB::isManip($query);
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
if (!@mssql_select_db($this->_db, $this->connection)) {
return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
316,7 → 345,7
}
}
if ($fetchmode & DB_FETCHMODE_ASSOC) {
$arr = @mssql_fetch_array($result, MSSQL_ASSOC);
$arr = @mssql_fetch_assoc($result);
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
$arr = array_change_key_case($arr, CASE_LOWER);
}
353,7 → 382,7
*/
function freeResult($result)
{
return @mssql_free_result($result);
return is_resource($result) ? mssql_free_result($result) : false;
}
 
// }}}
483,7 → 512,7
*/
function affectedRows()
{
if (DB::isManip($this->last_query)) {
if ($this->_last_query_manip) {
$res = @mssql_query('select @@rowcount', $this->connection);
if (!$res) {
return $this->mssqlRaiseError();
537,7 → 566,15
return $this->raiseError($result);
}
} elseif (!DB::isError($result)) {
$result =& $this->query("SELECT @@IDENTITY FROM $seqname");
$result = $this->query("SELECT IDENT_CURRENT('$seqname')");
if (DB::isError($result)) {
/* Fallback code for MS SQL Server 7.0, which doesn't have
* IDENT_CURRENT. This is *not* safe for concurrent
* requests, and really, if you're using it, you're in a
* world of hurt. Nevertheless, it's here to ensure BC. See
* bug #181 for the gory details.*/
$result = $this->query("SELECT @@IDENTITY FROM $seqname");
}
$repeat = 0;
} else {
$repeat = false;
587,6 → 624,27
}
 
// }}}
// {{{ escapeSimple()
 
/**
* Escapes a string in a manner suitable for SQL Server.
*
* @param string $str the string to be escaped
* @return string the escaped string
*
* @see DB_common::quoteSmart()
* @since Method available since Release 1.6.0
*/
function escapeSimple($str)
{
return str_replace(
array("'", "\\\r\n", "\\\n"),
array("''", "\\\\\r\n\r\n", "\\\\\n\n"),
$str
);
}
 
// }}}
// {{{ quoteIdentifier()
 
/**
745,16 → 803,22
}
 
for ($i = 0; $i < $count; $i++) {
if ($got_string) {
$flags = $this->_mssql_field_flags($result,
@mssql_field_name($id, $i));
if (DB::isError($flags)) {
return $flags;
}
} else {
$flags = '';
}
 
$res[$i] = array(
'table' => $got_string ? $case_func($result) : '',
'name' => $case_func(@mssql_field_name($id, $i)),
'type' => @mssql_field_type($id, $i),
'len' => @mssql_field_length($id, $i),
// We only support flags for table
'flags' => $got_string
? $this->_mssql_field_flags($result,
@mssql_field_name($id, $i))
: '',
'flags' => $flags,
);
if ($mode & DB_TABLEINFO_ORDER) {
$res['order'][$res[$i]['name']] = $i;
805,7 → 869,10
$tableName = $table;
 
// get unique and primary keys
$res = $this->getAll("EXEC SP_HELPINDEX[$table]", DB_FETCHMODE_ASSOC);
$res = $this->getAll("EXEC SP_HELPINDEX $table", DB_FETCHMODE_ASSOC);
if (DB::isError($res)) {
return $res;
}
 
foreach ($res as $val) {
$keys = explode(', ', $val['index_keys']);
828,7 → 895,10
}
 
// get auto_increment, not_null and timestamp
$res = $this->getAll("EXEC SP_COLUMNS[$table]", DB_FETCHMODE_ASSOC);
$res = $this->getAll("EXEC SP_COLUMNS $table", DB_FETCHMODE_ASSOC);
if (DB::isError($res)) {
return $res;
}
 
foreach ($res as $val) {
$val = array_change_key_case($val, CASE_LOWER);
/trunk/bibliotheque/pear/DB/sqlite.php
6,7 → 6,7
* The PEAR DB driver for PHP's sqlite extension
* for interacting with SQLite databases
*
* PHP versions 4 and 5
* PHP version 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:
19,9 → 19,9
* @author Urs Gehrig <urs@circle.ch>
* @author Mika Tuupola <tuupola@appelsiini.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0
* @version CVS: $Id: sqlite.php,v 1.109 2005/03/10 01:22:48 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
45,9 → 45,9
* @author Urs Gehrig <urs@circle.ch>
* @author Mika Tuupola <tuupola@appelsiini.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_sqlite extends DB_common
152,13 → 152,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_sqlite()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
182,7 → 182,7
* 'portability' => DB_PORTABILITY_ALL,
* );
*
* $db =& DB::connect($dsn, $options);
* $db = DB::connect($dsn, $options);
* if (PEAR::isError($db)) {
* die($db->getMessage());
* }
204,7 → 204,11
$this->dbsyntax = $dsn['dbsyntax'];
}
 
if ($dsn['database']) {
if (!$dsn['database']) {
return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
}
 
if ($dsn['database'] !== ':memory:') {
if (!file_exists($dsn['database'])) {
if (!touch($dsn['database'])) {
return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND);
229,14 → 233,12
if (!is_readable($dsn['database'])) {
return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
}
} else {
return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
}
 
$connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open';
 
// track_errors must remain on for simpleQuery()
ini_set('track_errors', 1);
@ini_set('track_errors', 1);
$php_errormsg = '';
 
if (!$this->connection = @$connect_function($dsn['database'])) {
280,7 → 282,7
*/
function simpleQuery($query)
{
$ismanip = DB::isManip($query);
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
$query = $this->modifyQuery($query);
 
357,6 → 359,16
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
$arr = array_change_key_case($arr, CASE_LOWER);
}
 
/* Remove extraneous " characters from the fields in the result.
* Fixes bug #11716. */
if (is_array($arr) && count($arr) > 0) {
$strippedArr = array();
foreach ($arr as $field => $value) {
$strippedArr[trim($field, '"')] = $value;
}
$arr = $strippedArr;
}
} else {
$arr = @sqlite_fetch_array($result, SQLITE_NUM);
}
727,6 → 739,11
function errorCode($errormsg)
{
static $error_regexps;
// PHP 5.2+ prepends the function name to $php_errormsg, so we need
// this hack to work around it, per bug #9599.
$errormsg = preg_replace('/^sqlite[a-z_]+\(\): /', '', $errormsg);
if (!isset($error_regexps)) {
$error_regexps = array(
'/^no such table:/' => DB_ERROR_NOSUCHTABLE,
738,6 → 755,7
'/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT,
'/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL,
'/^no such column:/' => DB_ERROR_NOSUCHFIELD,
'/no column named/' => DB_ERROR_NOSUCHFIELD,
'/column not present in both tables/i' => DB_ERROR_NOSUCHFIELD,
'/^near ".*": syntax error$/' => DB_ERROR_SYNTAX,
'/[0-9]+ values for [0-9]+ columns/i' => DB_ERROR_VALUE_COUNT_ON_ROW,
811,6 → 829,9
$flags = '';
if ($id[$i]['pk']) {
$flags .= 'primary_key ';
if (strtoupper($type) == 'INTEGER') {
$flags .= 'auto_increment ';
}
}
if ($id[$i]['notnull']) {
$flags .= 'not_null ';
/trunk/bibliotheque/pear/DB/oci8.php
6,7 → 6,7
* The PEAR DB driver for PHP's oci8 extension
* for interacting with Oracle databases
*
* PHP versions 4 and 5
* PHP version 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:
18,9 → 18,9
* @package DB
* @author James L. Pine <jlp@valinux.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: oci8.php,v 1.103 2005/04/11 15:10:22 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
45,9 → 45,9
* @package DB
* @author James L. Pine <jlp@valinux.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_oci8 extends DB_common
94,24 → 94,25
* @var array
*/
var $errorcode_map = array(
1 => DB_ERROR_CONSTRAINT,
900 => DB_ERROR_SYNTAX,
904 => DB_ERROR_NOSUCHFIELD,
913 => DB_ERROR_VALUE_COUNT_ON_ROW,
921 => DB_ERROR_SYNTAX,
923 => DB_ERROR_SYNTAX,
942 => DB_ERROR_NOSUCHTABLE,
955 => DB_ERROR_ALREADY_EXISTS,
1400 => DB_ERROR_CONSTRAINT_NOT_NULL,
1401 => DB_ERROR_INVALID,
1407 => DB_ERROR_CONSTRAINT_NOT_NULL,
1418 => DB_ERROR_NOT_FOUND,
1476 => DB_ERROR_DIVZERO,
1722 => DB_ERROR_INVALID_NUMBER,
2289 => DB_ERROR_NOSUCHTABLE,
2291 => DB_ERROR_CONSTRAINT,
2292 => DB_ERROR_CONSTRAINT,
2449 => DB_ERROR_CONSTRAINT,
1 => DB_ERROR_CONSTRAINT,
900 => DB_ERROR_SYNTAX,
904 => DB_ERROR_NOSUCHFIELD,
913 => DB_ERROR_VALUE_COUNT_ON_ROW,
921 => DB_ERROR_SYNTAX,
923 => DB_ERROR_SYNTAX,
942 => DB_ERROR_NOSUCHTABLE,
955 => DB_ERROR_ALREADY_EXISTS,
1400 => DB_ERROR_CONSTRAINT_NOT_NULL,
1401 => DB_ERROR_INVALID,
1407 => DB_ERROR_CONSTRAINT_NOT_NULL,
1418 => DB_ERROR_NOT_FOUND,
1476 => DB_ERROR_DIVZERO,
1722 => DB_ERROR_INVALID_NUMBER,
2289 => DB_ERROR_NOSUCHTABLE,
2291 => DB_ERROR_CONSTRAINT,
2292 => DB_ERROR_CONSTRAINT,
2449 => DB_ERROR_CONSTRAINT,
12899 => DB_ERROR_INVALID,
);
 
/**
160,18 → 161,25
*/
var $manip_query = array();
 
/**
* Store of prepared SQL queries.
* @var array
* @access private
*/
var $_prepared_queries = array();
 
 
// }}}
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_oci8()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
216,6 → 224,13
$this->dbsyntax = $dsn['dbsyntax'];
}
 
// Backwards compatibility with DB < 1.7.0
if (empty($dsn['database']) && !empty($dsn['hostspec'])) {
$db = $dsn['hostspec'];
} else {
$db = $dsn['database'];
}
 
if (function_exists('oci_connect')) {
if (isset($dsn['new_link'])
&& ($dsn['new_link'] == 'true' || $dsn['new_link'] === true))
225,12 → 240,8
$connect_function = $persistent ? 'oci_pconnect'
: 'oci_connect';
}
 
// Backwards compatibility with DB < 1.7.0
if (empty($dsn['database']) && !empty($dsn['hostspec'])) {
$db = $dsn['hostspec'];
} else {
$db = $dsn['database'];
if (isset($this->dsn['port']) && $this->dsn['port']) {
$db = '//'.$db.':'.$this->dsn['port'];
}
 
$char = empty($dsn['charset']) ? null : $dsn['charset'];
248,10 → 259,10
}
} else {
$connect_function = $persistent ? 'OCIPLogon' : 'OCILogon';
if ($dsn['hostspec']) {
if ($db) {
$this->connection = @$connect_function($dsn['username'],
$dsn['password'],
$dsn['hostspec']);
$db);
} elseif ($dsn['username'] || $dsn['password']) {
$this->connection = @$connect_function($dsn['username'],
$dsn['password']);
322,7 → 333,7
return $this->oci8RaiseError($result);
}
$this->last_stmt = $result;
if (DB::isManip($query)) {
if ($this->_checkManip($query)) {
return DB_OK;
} else {
@ocisetprefetch($result, $this->options['result_buffering']);
415,7 → 426,7
*/
function freeResult($result)
{
return @OCIFreeStatement($result);
return is_resource($result) ? OCIFreeStatement($result) : false;
}
 
/**
441,6 → 452,7
if (isset($this->prepare_types[(int)$stmt])) {
unset($this->prepare_types[(int)$stmt]);
unset($this->manip_query[(int)$stmt]);
unset($this->_prepared_queries[(int)$stmt]);
} else {
return false;
}
476,20 → 488,18
$save_query = $this->last_query;
$save_stmt = $this->last_stmt;
 
if (count($this->_data)) {
$smt = $this->prepare('SELECT COUNT(*) FROM ('.$this->last_query.')');
$count = $this->execute($smt, $this->_data);
} else {
$count =& $this->query($countquery);
}
$count = $this->query($countquery);
 
// Restore the last query and statement.
$this->last_query = $save_query;
$this->last_stmt = $save_stmt;
if (DB::isError($count) ||
DB::isError($row = $count->fetchRow(DB_FETCHMODE_ORDERED)))
{
$this->last_query = $save_query;
$this->last_stmt = $save_stmt;
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
 
return $row[0];
}
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
590,6 → 600,7
}
$this->prepare_types[(int)$stmt] = $types;
$this->manip_query[(int)$stmt] = DB::isManip($query);
$this->_prepared_queries[(int)$stmt] = $newquery;
return $stmt;
}
 
620,11 → 631,12
{
$data = (array)$data;
$this->last_parameters = $data;
$this->last_query = $this->_prepared_queries[(int)$stmt];
$this->_data = $data;
 
$types =& $this->prepare_types[(int)$stmt];
$types = $this->prepare_types[(int)$stmt];
if (count($types) != count($data)) {
$tmp =& $this->raiseError(DB_ERROR_MISMATCH);
$tmp = $this->raiseError(DB_ERROR_MISMATCH);
return $tmp;
}
 
643,16 → 655,24
} elseif ($types[$i] == DB_PARAM_OPAQUE) {
$fp = @fopen($data[$key], 'rb');
if (!$fp) {
$tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
$tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
return $tmp;
}
$data[$key] = fread($fp, filesize($data[$key]));
fclose($fp);
} elseif ($types[$i] == DB_PARAM_SCALAR) {
// Floats have to be converted to a locale-neutral
// representation.
if (is_float($data[$key])) {
$data[$key] = $this->quoteFloat($data[$key]);
}
}
if (!@OCIBindByName($stmt, ':bind' . $i, $data[$key], -1)) {
$tmp = $this->oci8RaiseError($stmt);
return $tmp;
}
$this->last_query = preg_replace("/:bind$i(?!\d)/",
$this->quoteSmart($data[$key]), $this->last_query, 1);
$i++;
}
if ($this->autocommit) {
665,11 → 685,14
return $tmp;
}
$this->last_stmt = $stmt;
if ($this->manip_query[(int)$stmt]) {
if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) {
$this->_last_query_manip = true;
$this->_next_query_manip = false;
$tmp = DB_OK;
} else {
$this->_last_query_manip = false;
@ocisetprefetch($stmt, $this->options['result_buffering']);
$tmp =& new DB_result($this, $stmt);
$tmp = new DB_result($this, $stmt);
}
return $tmp;
}
797,7 → 820,7
if (count($params)) {
$result = $this->prepare("SELECT * FROM ($query) "
. 'WHERE NULL = NULL');
$tmp =& $this->execute($result, $params);
$tmp = $this->execute($result, $params);
} else {
$q_fields = "SELECT * FROM ($query) WHERE NULL = NULL";
 
857,7 → 880,7
$repeat = 0;
do {
$this->expectError(DB_ERROR_NOSUCHTABLE);
$result =& $this->query("SELECT ${seqname}.nextval FROM dual");
$result = $this->query("SELECT ${seqname}.nextval FROM dual");
$this->popExpect();
if ($ondemand && DB::isError($result) &&
$result->getCode() == DB_ERROR_NOSUCHTABLE) {
1015,7 → 1038,7
if (!@OCIExecute($stmt, OCI_DEFAULT)) {
return $this->oci8RaiseError($stmt);
}
 
$i = 0;
while (@OCIFetch($stmt)) {
$res[$i] = array(
1098,6 → 1121,8
return 'SELECT table_name FROM user_tables';
case 'synonyms':
return 'SELECT synonym_name FROM user_synonyms';
case 'views':
return 'SELECT view_name FROM user_views';
default:
return null;
}
1104,7 → 1129,23
}
 
// }}}
// {{{ quoteFloat()
 
/**
* Formats a float value for use within a query in a locale-independent
* manner.
*
* @param float the float value to be quoted.
* @return string the quoted string.
* @see DB_common::quoteSmart()
* @since Method available since release 1.7.8.
*/
function quoteFloat($float) {
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
}
// }}}
 
}
 
/*
/trunk/bibliotheque/pear/DB/ibase.php
9,7 → 9,7
* While this class works with PHP 4, PHP's InterBase extension is
* unstable in PHP 4. Use PHP 5.
*
* PHP versions 4 and 5
* PHP version 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:
21,9 → 21,9
* @package DB
* @author Sterling Hughes <sterling@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: ibase.php,v 1.109 2005/03/04 23:12:36 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
47,9 → 47,9
* @package DB
* @author Sterling Hughes <sterling@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
* @since Class became stable in Release 1.7.0
*/
123,6 → 123,7
-625 => DB_ERROR_CONSTRAINT_NOT_NULL,
-803 => DB_ERROR_CONSTRAINT,
-804 => DB_ERROR_VALUE_COUNT_ON_ROW,
// -902 => // Covers too many errors, need to use regex on msg
-904 => DB_ERROR_CONNECT_FAILED,
-922 => DB_ERROR_NOSUCHDB,
-923 => DB_ERROR_CONNECT_FAILED,
179,13 → 180,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_ibase()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
275,7 → 276,7
*/
function simpleQuery($query)
{
$ismanip = DB::isManip($query);
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
$query = $this->modifyQuery($query);
$result = @ibase_query($this->connection, $query);
412,7 → 413,7
*/
function freeResult($result)
{
return @ibase_free_result($result);
return is_resource($result) ? ibase_free_result($result) : false;
}
 
// }}}
420,8 → 421,7
 
function freeQuery($query)
{
@ibase_free_query($query);
return true;
return is_resource($query) ? ibase_free_query($query) : false;
}
 
// }}}
521,8 → 521,14
$this->last_query = $query;
$newquery = $this->modifyQuery($newquery);
$stmt = @ibase_prepare($this->connection, $newquery);
$this->prepare_types[(int)$stmt] = $types;
$this->manip_query[(int)$stmt] = DB::isManip($query);
 
if ($stmt === false) {
$stmt = $this->ibaseRaiseError();
} else {
$this->prepare_types[(int)$stmt] = $types;
$this->manip_query[(int)$stmt] = DB::isManip($query);
}
 
return $stmt;
}
 
547,9 → 553,9
$data = (array)$data;
$this->last_parameters = $data;
 
$types =& $this->prepare_types[(int)$stmt];
$types = $this->prepare_types[(int)$stmt];
if (count($types) != count($data)) {
$tmp =& $this->raiseError(DB_ERROR_MISMATCH);
$tmp = $this->raiseError(DB_ERROR_MISMATCH);
return $tmp;
}
 
568,7 → 574,7
} elseif ($types[$i] == DB_PARAM_OPAQUE) {
$fp = @fopen($data[$key], 'rb');
if (!$fp) {
$tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
$tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
return $tmp;
}
$data[$key] = fread($fp, filesize($data[$key]));
581,7 → 587,7
 
$res = call_user_func_array('ibase_execute', $data);
if (!$res) {
$tmp =& $this->ibaseRaiseError();
$tmp = $this->ibaseRaiseError();
return $tmp;
}
/* XXX need this?
589,10 → 595,13
@ibase_commit($this->connection);
}*/
$this->last_stmt = $stmt;
if ($this->manip_query[(int)$stmt]) {
if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) {
$this->_last_query_manip = true;
$this->_next_query_manip = false;
$tmp = DB_OK;
} else {
$tmp =& new DB_result($this, $res);
$this->_last_query_manip = false;
$tmp = new DB_result($this, $res);
}
return $tmp;
}
698,7 → 707,7
$repeat = 0;
do {
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$result =& $this->query("SELECT GEN_ID(${sqn}, 1) "
$result = $this->query("SELECT GEN_ID(${sqn}, 1) "
. 'FROM RDB$GENERATORS '
. "WHERE RDB\$GENERATOR_NAME='${sqn}'");
$this->popErrorHandling();
856,7 → 865,7
if ($errno === null) {
$errno = $this->errorCode($this->errorNative());
}
$tmp =& $this->raiseError($errno, null, null, null, @ibase_errmsg());
$tmp = $this->raiseError($errno, null, null, null, @ibase_errmsg());
return $tmp;
}
 
907,6 → 916,8
$error_regexps = array(
'/generator .* is not defined/'
=> DB_ERROR_SYNTAX, // for compat. w ibase_errcode()
'/violation of [\w ]+ constraint/i'
=> DB_ERROR_CONSTRAINT,
'/table.*(not exist|not found|unknown)/i'
=> DB_ERROR_NOSUCHTABLE,
'/table .* already exists/i'
917,8 → 928,6
=> DB_ERROR_NOT_FOUND,
'/validation error for column .* value "\*\*\* null/i'
=> DB_ERROR_CONSTRAINT_NOT_NULL,
'/violation of [\w ]+ constraint/i'
=> DB_ERROR_CONSTRAINT,
'/conversion error from string/i'
=> DB_ERROR_INVALID_NUMBER,
'/no permission for/i'
925,6 → 934,8
=> DB_ERROR_ACCESS_VIOLATION,
'/arithmetic exception, numeric overflow, or string truncation/i'
=> DB_ERROR_INVALID,
'/feature is not supported/i'
=> DB_ERROR_NOT_CAPABLE,
);
}
 
/trunk/bibliotheque/pear/DB/storage.php
5,7 → 5,7
/**
* Provides an object interface to a table row
*
* PHP versions 4 and 5
* PHP version 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:
16,9 → 16,9
* @category Database
* @package DB
* @author Stig Bakken <stig@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: storage.php,v 1.21 2005/02/02 02:54:51 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
36,9 → 36,9
* @category Database
* @package DB
* @author Stig Bakken <stig@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_storage extends PEAR
94,7 → 94,7
* a reference to this object
*
*/
function DB_storage($table, $keycolumn, &$dbh, $validator = null)
function __construct($table, $keycolumn, &$dbh, $validator = null)
{
$this->PEAR('DB_Error');
$this->_table = $table;
293,7 → 293,7
function &create($table, &$data)
{
$classname = strtolower(get_class($this));
$obj =& new $classname($table);
$obj = new $classname($table);
foreach ($data as $name => $value) {
$obj->_properties[$name] = true;
$obj->$name = &$value;
445,6 → 445,8
*/
function store()
{
$params = array();
$vars = array();
foreach ($this->_changes as $name => $foo) {
$params[] = &$this->$name;
$vars[] = $name . ' = ?';
/trunk/bibliotheque/pear/DB/mysql.php
6,7 → 6,7
* The PEAR DB driver for PHP's mysql extension
* for interacting with MySQL databases
*
* PHP versions 4 and 5
* PHP version 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:
18,9 → 18,9
* @package DB
* @author Stig Bakken <ssb@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: mysql.php,v 1.117 2005/03/29 15:03:26 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
39,9 → 39,9
* @package DB
* @author Stig Bakken <ssb@php.net>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_mysql extends DB_common
111,6 → 111,9
1146 => DB_ERROR_NOSUCHTABLE,
1216 => DB_ERROR_CONSTRAINT,
1217 => DB_ERROR_CONSTRAINT,
1356 => DB_ERROR_DIVZERO,
1451 => DB_ERROR_CONSTRAINT,
1452 => DB_ERROR_CONSTRAINT,
);
 
/**
159,13 → 162,13
// {{{ constructor
 
/**
* This constructor calls <kbd>$this->DB_common()</kbd>
* This constructor calls <kbd>parent::__construct()</kbd>
*
* @return void
*/
function DB_mysql()
function __construct()
{
$this->DB_common();
parent::__construct();
}
 
// }}}
236,10 → 239,10
$this->connection = @call_user_func_array($connect_function,
$params);
} else {
ini_set('track_errors', 1);
@ini_set('track_errors', 1);
$this->connection = @call_user_func_array($connect_function,
$params);
ini_set('track_errors', $ini);
@ini_set('track_errors', $ini);
}
 
if (!$this->connection) {
297,7 → 300,7
*/
function simpleQuery($query)
{
$ismanip = DB::isManip($query);
$ismanip = $this->_checkManip($query);
$this->last_query = $query;
$query = $this->modifyQuery($query);
if ($this->_db) {
419,7 → 422,7
*/
function freeResult($result)
{
return @mysql_free_result($result);
return is_resource($result) ? mysql_free_result($result) : false;
}
 
// }}}
555,7 → 558,7
*/
function affectedRows()
{
if (DB::isManip($this->last_query)) {
if ($this->_last_query_manip) {
return @mysql_affected_rows($this->connection);
} else {
return 0;
752,9 → 755,10
 
/**
* Quotes a string so it can be safely used as a table or column name
* (WARNING: using names that require this is a REALLY BAD IDEA)
*
* MySQL can't handle the backtick character (<kbd>`</kbd>) in
* table or column names.
* WARNING: Older versions of MySQL can't handle the backtick
* character (<kbd>`</kbd>) in table or column names.
*
* @param string $str identifier name to be quoted
*
765,21 → 769,10
*/
function quoteIdentifier($str)
{
return '`' . $str . '`';
return '`' . str_replace('`', '``', $str) . '`';
}
 
// }}}
// {{{ quote()
 
/**
* @deprecated Deprecated in release 1.6.0
*/
function quote($str)
{
return $this->quoteSmart($str);
}
 
// }}}
// {{{ escapeSimple()
 
/**
852,7 → 845,7
*/
function modifyLimitQuery($query, $from, $count, $params = array())
{
if (DB::isManip($query)) {
if (DB::isManip($query) || $this->_next_query_manip) {
return $query . " LIMIT $count";
} else {
return $query . " LIMIT $from, $count";
928,12 → 921,19
function tableInfo($result, $mode = null)
{
if (is_string($result)) {
// Fix for bug #11580.
if ($this->_db) {
if (!@mysql_select_db($this->_db, $this->connection)) {
return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
}
}
/*
* Probably received a table name.
* Create a result resource identifier.
*/
$id = @mysql_list_fields($this->dsn['database'],
$result, $this->connection);
$id = @mysql_query("SELECT * FROM $result LIMIT 0",
$this->connection);
$got_string = true;
} elseif (isset($result->result)) {
/*
/trunk/bibliotheque/pear/PEAR/Remote.php
File deleted
/trunk/bibliotheque/pear/PEAR/PackageFileManager.php
File deleted
\ No newline at end of file
/trunk/bibliotheque/pear/PEAR/Info.php
File deleted
\ No newline at end of file
/trunk/bibliotheque/pear/PEAR/Dependency.php
File deleted
/trunk/bibliotheque/pear/PEAR/XMLParser.php
1,22 → 1,15
<?php
/**
* PEAR_FTP
* PEAR_XMLParser
*
* 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>
* @author Stephan Schmidt (original XML_Unserializer code)
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: XMLParser.php,v 1.12 2006/03/27 04:39:03 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
23,15 → 16,15
 
/**
* Parser for any xml file
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @author Stephan Schmidt (original XML_Unserializer code)
* @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
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @author Stephan Schmidt (original XML_Unserializer code)
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_XMLParser
{
51,13 → 44,13
* stack for all data that is found
* @var array $_dataStack
*/
var $_dataStack = array();
var $_dataStack = array();
 
/**
* stack for all values that are generated
* @var array $_valStack
*/
var $_valStack = array();
var $_valStack = array();
 
/**
* current tag depth
66,6 → 59,12
var $_depth = 0;
 
/**
* The XML encoding to use
* @var string $encoding
*/
var $encoding = 'ISO-8859-1';
 
/**
* @return array
*/
function getData()
83,22 → 82,19
include_once 'PEAR.php';
return PEAR::raiseError("XML Extension not found", 1);
}
$this->_valStack = array();
$this->_dataStack = array();
$this->_dataStack = $this->_valStack = array();
$this->_depth = 0;
 
if (version_compare(phpversion(), '5.0.0', 'lt')) {
if (strpos($data, 'encoding="UTF-8"')) {
$data = utf8_decode($data);
}
$xp = xml_parser_create('ISO-8859-1');
} else {
if (strpos($data, 'encoding="UTF-8"')) {
$xp = xml_parser_create('UTF-8');
} else {
$xp = xml_parser_create('ISO-8859-1');
}
if (
strpos($data, 'encoding="UTF-8"')
|| strpos($data, 'encoding="utf-8"')
|| strpos($data, "encoding='UTF-8'")
|| strpos($data, "encoding='utf-8'")
) {
$this->encoding = 'UTF-8';
}
 
$xp = xml_parser_create($this->encoding);
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, 0);
xml_set_object($xp, $this);
xml_set_element_handler($xp, 'startHandler', 'endHandler');
125,25 → 121,21
*/
function startHandler($parser, $element, $attribs)
{
$type = 'string';
 
$this->_depth++;
$this->_dataStack[$this->_depth] = null;
 
$val = array(
'name' => $element,
'value' => null,
'type' => $type,
'childrenKeys' => array(),
'aggregKeys' => array()
);
'name' => $element,
'value' => null,
'type' => 'string',
'childrenKeys' => array(),
'aggregKeys' => array()
);
 
if (count($attribs) > 0) {
$val['children'] = array();
$val['type'] = 'array';
 
$val['children']['attribs'] = $attribs;
 
}
 
array_push($this->_valStack, $val);
174,20 → 166,14
$data = $this->postProcess($this->_dataStack[$this->_depth], $element);
 
// adjust type of the value
switch(strtolower($value['type'])) {
 
/*
* unserialize an array
*/
switch (strtolower($value['type'])) {
// unserialize an array
case 'array':
if ($data !== '') {
$value['children']['_content'] = $data;
}
if (isset($value['children'])) {
$value['value'] = $value['children'];
} else {
$value['value'] = array();
}
 
$value['value'] = isset($value['children']) ? $value['children'] : array();
break;
 
/*
205,42 → 191,43
$value['value'] = $data;
break;
}
 
$parent = array_pop($this->_valStack);
if ($parent === null) {
$this->_unserializedData = &$value['value'];
$this->_root = &$value['name'];
return true;
} else {
// parent has to be an array
if (!isset($parent['children']) || !is_array($parent['children'])) {
$parent['children'] = array();
if ($parent['type'] != 'array') {
$parent['type'] = 'array';
}
}
 
// parent has to be an array
if (!isset($parent['children']) || !is_array($parent['children'])) {
$parent['children'] = array();
if ($parent['type'] != 'array') {
$parent['type'] = 'array';
}
}
 
if (!empty($value['name'])) {
// there already has been a tag with this name
if (in_array($value['name'], $parent['childrenKeys'])) {
// no aggregate has been created for this tag
if (!in_array($value['name'], $parent['aggregKeys'])) {
if (isset($parent['children'][$value['name']])) {
$parent['children'][$value['name']] = array($parent['children'][$value['name']]);
} else {
$parent['children'][$value['name']] = array();
}
array_push($parent['aggregKeys'], $value['name']);
if (!empty($value['name'])) {
// there already has been a tag with this name
if (in_array($value['name'], $parent['childrenKeys'])) {
// no aggregate has been created for this tag
if (!in_array($value['name'], $parent['aggregKeys'])) {
if (isset($parent['children'][$value['name']])) {
$parent['children'][$value['name']] = array($parent['children'][$value['name']]);
} else {
$parent['children'][$value['name']] = array();
}
array_push($parent['children'][$value['name']], $value['value']);
} else {
$parent['children'][$value['name']] = &$value['value'];
array_push($parent['childrenKeys'], $value['name']);
array_push($parent['aggregKeys'], $value['name']);
}
array_push($parent['children'][$value['name']], $value['value']);
} else {
array_push($parent['children'],$value['value']);
$parent['children'][$value['name']] = &$value['value'];
array_push($parent['childrenKeys'], $value['name']);
}
array_push($this->_valStack, $parent);
} else {
array_push($parent['children'],$value['value']);
}
array_push($this->_valStack, $parent);
 
$this->_depth--;
}
257,5 → 244,4
{
$this->_dataStack[$this->_depth] .= $cdata;
}
}
?>
}
/trunk/bibliotheque/pear/PEAR/REST.php
4,18 → 4,11
*
* 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: REST.php,v 1.21 2006/03/27 04:33:11 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
32,9 → 25,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
42,9 → 35,10
{
var $config;
var $_options;
function PEAR_REST(&$config, $options = array())
 
function __construct(&$config, $options = array())
{
$this->config = &$config;
$this->config = &$config;
$this->_options = $options;
}
 
59,14 → 53,16
* parsed using PEAR_XMLParser
* @return string|array
*/
function retrieveCacheFirst($url, $accept = false, $forcestring = false)
function retrieveCacheFirst($url, $accept = false, $forcestring = false, $channel = false)
{
$cachefile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
md5($url) . 'rest.cachefile';
 
if (file_exists($cachefile)) {
return unserialize(implode('', file($cachefile)));
}
return $this->retrieveData($url, $accept, $forcestring);
 
return $this->retrieveData($url, $accept, $forcestring, $channel);
}
 
/**
77,52 → 73,74
* parsed using PEAR_XMLParser
* @return string|array
*/
function retrieveData($url, $accept = false, $forcestring = false)
function retrieveData($url, $accept = false, $forcestring = false, $channel = false)
{
$cacheId = $this->getCacheId($url);
if ($ret = $this->useLocalCache($url, $cacheId)) {
return $ret;
}
 
$file = $trieddownload = false;
if (!isset($this->_options['offline'])) {
$trieddownload = true;
$file = $this->downloadHttp($url, $cacheId ? $cacheId['lastChange'] : false, $accept);
} else {
$trieddownload = false;
$file = false;
$file = $this->downloadHttp($url, $cacheId ? $cacheId['lastChange'] : false, $accept, $channel);
}
 
if (PEAR::isError($file)) {
if ($file->getCode() == -9276) {
$trieddownload = false;
$file = false; // use local copy if available on socket connect error
} else {
if ($file->getCode() !== -9276) {
return $file;
}
 
$trieddownload = false;
$file = false; // use local copy if available on socket connect error
}
 
if (!$file) {
$ret = $this->getCache($url);
if (!PEAR::isError($ret) && $trieddownload) {
// reset the age of the cache if the server says it was unmodified
$this->saveCache($url, $ret, null, true, $cacheId);
$result = $this->saveCache($url, $ret, null, true, $cacheId);
if (PEAR::isError($result)) {
return PEAR::raiseError($result->getMessage());
}
}
 
return $ret;
}
 
if (is_array($file)) {
$headers = $file[2];
$headers = $file[2];
$lastmodified = $file[1];
$content = $file[0];
$content = $file[0];
} else {
$content = $file;
$headers = array();
$lastmodified = false;
$headers = array();
$content = $file;
}
 
if ($forcestring) {
$this->saveCache($url, $content, $lastmodified, false, $cacheId);
$result = $this->saveCache($url, $content, $lastmodified, false, $cacheId);
if (PEAR::isError($result)) {
return PEAR::raiseError($result->getMessage());
}
 
return $content;
}
 
if (isset($headers['content-type'])) {
switch ($headers['content-type']) {
$content_type = explode(";", $headers['content-type']);
$content_type = $content_type[0];
switch ($content_type) {
case 'text/xml' :
case 'application/xml' :
case 'text/plain' :
if ($content_type === 'text/plain') {
$check = substr($content, 0, 5);
if ($check !== '<?xml') {
break;
}
}
 
$parser = new PEAR_XMLParser;
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$err = $parser->parse($content);
142,7 → 160,12
$parser->parse($content);
$content = $parser->getData();
}
$this->saveCache($url, $content, $lastmodified, false, $cacheId);
 
$result = $this->saveCache($url, $content, $lastmodified, false, $cacheId);
if (PEAR::isError($result)) {
return PEAR::raiseError($result->getMessage());
}
 
return $content;
}
 
151,17 → 174,19
if ($cacheid === null) {
$cacheidfile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
md5($url) . 'rest.cacheid';
if (file_exists($cacheidfile)) {
$cacheid = unserialize(implode('', file($cacheidfile)));
} else {
if (!file_exists($cacheidfile)) {
return false;
}
 
$cacheid = unserialize(implode('', file($cacheidfile)));
}
 
$cachettl = $this->config->get('cache_ttl');
// If cache is newer than $cachettl seconds, we use the cache!
if (time() - $cacheid['age'] < $cachettl) {
return $this->getCache($url);
}
 
return false;
}
 
169,12 → 194,13
{
$cacheidfile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
md5($url) . 'rest.cacheid';
if (file_exists($cacheidfile)) {
$ret = unserialize(implode('', file($cacheidfile)));
return $ret;
} else {
 
if (!file_exists($cacheidfile)) {
return false;
}
 
$ret = unserialize(implode('', file($cacheidfile)));
return $ret;
}
 
function getCache($url)
181,11 → 207,12
{
$cachefile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
md5($url) . 'rest.cachefile';
if (file_exists($cachefile)) {
return unserialize(implode('', file($cachefile)));
} else {
 
if (!file_exists($cachefile)) {
return PEAR::raiseError('No cached content available for "' . $url . '"');
}
 
return unserialize(implode('', file($cachefile)));
}
 
/**
197,54 → 224,96
*/
function saveCache($url, $contents, $lastmodified, $nochange = false, $cacheid = null)
{
$cacheidfile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
md5($url) . 'rest.cacheid';
$cachefile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR .
md5($url) . 'rest.cachefile';
$cache_dir = $this->config->get('cache_dir');
$d = $cache_dir . DIRECTORY_SEPARATOR . md5($url);
$cacheidfile = $d . 'rest.cacheid';
$cachefile = $d . 'rest.cachefile';
 
if (!is_dir($cache_dir)) {
if (System::mkdir(array('-p', $cache_dir)) === false) {
return PEAR::raiseError("The value of config option cache_dir ($cache_dir) is not a directory and attempts to create the directory failed.");
}
}
 
if (!is_writeable($cache_dir)) {
// If writing to the cache dir is not going to work, silently do nothing.
// An ugly hack, but retains compat with PEAR 1.9.1 where many commands
// work fine as non-root user (w/out write access to default cache dir).
return true;
}
 
if ($cacheid === null && $nochange) {
$cacheid = unserialize(implode('', file($cacheidfile)));
}
 
$fp = @fopen($cacheidfile, 'wb');
if (!$fp) {
$cache_dir = $this->config->get('cache_dir');
if (!is_dir($cache_dir)) {
System::mkdir(array('-p', $cache_dir));
$fp = @fopen($cacheidfile, 'wb');
if (!$fp) {
return false;
}
} else {
return false;
}
}
$idData = serialize(array(
'age' => time(),
'lastChange' => ($nochange ? $cacheid['lastChange'] : $lastmodified),
));
 
if ($nochange) {
fwrite($fp, serialize(array(
'age' => time(),
'lastChange' => $cacheid['lastChange'],
)));
fclose($fp);
$result = $this->saveCacheFile($cacheidfile, $idData);
if (PEAR::isError($result)) {
return $result;
} elseif ($nochange) {
return true;
} else {
fwrite($fp, serialize(array(
'age' => time(),
'lastChange' => $lastmodified,
)));
}
fclose($fp);
$fp = @fopen($cachefile, 'wb');
if (!$fp) {
 
$result = $this->saveCacheFile($cachefile, serialize($contents));
if (PEAR::isError($result)) {
if (file_exists($cacheidfile)) {
@unlink($cacheidfile);
@unlink($cacheidfile);
}
return false;
 
return $result;
}
fwrite($fp, serialize($contents));
fclose($fp);
 
return true;
}
 
function saveCacheFile($file, $contents)
{
$len = strlen($contents);
 
$cachefile_fp = @fopen($file, 'xb'); // x is the O_CREAT|O_EXCL mode
if ($cachefile_fp !== false) { // create file
if (fwrite($cachefile_fp, $contents, $len) < $len) {
fclose($cachefile_fp);
return PEAR::raiseError("Could not write $file.");
}
} else { // update file
$cachefile_fp = @fopen($file, 'r+b'); // do not truncate file
if (!$cachefile_fp) {
return PEAR::raiseError("Could not open $file for writing.");
}
 
if (OS_WINDOWS) {
$not_symlink = !is_link($file); // see bug #18834
} else {
$cachefile_lstat = lstat($file);
$cachefile_fstat = fstat($cachefile_fp);
$not_symlink = $cachefile_lstat['mode'] == $cachefile_fstat['mode']
&& $cachefile_lstat['ino'] == $cachefile_fstat['ino']
&& $cachefile_lstat['dev'] == $cachefile_fstat['dev']
&& $cachefile_fstat['nlink'] === 1;
}
 
if ($not_symlink) {
ftruncate($cachefile_fp, 0); // NOW truncate
if (fwrite($cachefile_fp, $contents, $len) < $len) {
fclose($cachefile_fp);
return PEAR::raiseError("Could not write $file.");
}
} else {
fclose($cachefile_fp);
$link = function_exists('readlink') ? readlink($file) : $file;
return PEAR::raiseError('SECURITY ERROR: Will not write to ' . $file . ' as it is symlinked to ' . $link . ' - Possible symlink attack');
}
}
 
fclose($cachefile_fp);
return true;
}
 
/**
* Efficiently Download a file through HTTP. Returns downloaded file as a string in-memory
* This is best used for small files
266,54 → 335,59
*
* @access public
*/
function downloadHttp($url, $lastmodified = null, $accept = false)
function downloadHttp($url, $lastmodified = null, $accept = false, $channel = false)
{
static $redirect = 0;
// always reset , so we are clean case of error
$wasredirect = $redirect;
$redirect = 0;
 
$info = parse_url($url);
if (!isset($info['scheme']) || !in_array($info['scheme'], array('http', 'https'))) {
return PEAR::raiseError('Cannot download non-http URL "' . $url . '"');
}
 
if (!isset($info['host'])) {
return PEAR::raiseError('Cannot download from non-URL "' . $url . '"');
} else {
$host = $info['host'];
if (!array_key_exists('port', $info)) {
$info['port'] = null;
}
if (!array_key_exists('path', $info)) {
$info['path'] = null;
}
$port = $info['port'];
$path = $info['path'];
}
 
$host = isset($info['host']) ? $info['host'] : null;
$port = isset($info['port']) ? $info['port'] : null;
$path = isset($info['path']) ? $info['path'] : null;
$schema = (isset($info['scheme']) && $info['scheme'] == 'https') ? 'https' : 'http';
 
$proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
if ($this->config->get('http_proxy')&&
$proxy = parse_url($this->config->get('http_proxy'))) {
if ($this->config->get('http_proxy')&&
$proxy = parse_url($this->config->get('http_proxy'))
) {
$proxy_host = isset($proxy['host']) ? $proxy['host'] : null;
if (isset($proxy['scheme']) && $proxy['scheme'] == 'https') {
if ($schema === 'https') {
$proxy_host = 'ssl://' . $proxy_host;
}
$proxy_port = isset($proxy['port']) ? $proxy['port'] : 8080;
$proxy_user = isset($proxy['user']) ? urldecode($proxy['user']) : null;
$proxy_pass = isset($proxy['pass']) ? urldecode($proxy['pass']) : null;
 
$proxy_port = isset($proxy['port']) ? $proxy['port'] : 8080;
$proxy_user = isset($proxy['user']) ? urldecode($proxy['user']) : null;
$proxy_pass = isset($proxy['pass']) ? urldecode($proxy['pass']) : null;
$proxy_schema = (isset($proxy['scheme']) && $proxy['scheme'] == 'https') ? 'https' : 'http';
}
 
if (empty($port)) {
if (isset($info['scheme']) && $info['scheme'] == 'https') {
$port = 443;
} else {
$port = 80;
}
$port = (isset($info['scheme']) && $info['scheme'] == 'https') ? 443 : 80;
}
If (isset($proxy['host'])) {
 
if (isset($proxy['host'])) {
$request = "GET $url HTTP/1.1\r\n";
} else {
$request = "GET $path HTTP/1.1\r\n";
}
 
$request .= "Host: $host\r\n";
$ifmodifiedsince = '';
if (is_array($lastmodified)) {
if (isset($lastmodified['Last-Modified'])) {
$ifmodifiedsince = 'If-Modified-Since: ' . $lastmodified['Last-Modified'] . "\r\n";
}
 
if (isset($lastmodified['ETag'])) {
$ifmodifiedsince .= "If-None-Match: $lastmodified[ETag]\r\n";
}
320,66 → 394,92
} else {
$ifmodifiedsince = ($lastmodified ? "If-Modified-Since: $lastmodified\r\n" : '');
}
$request .= "Host: $host:$port\r\n" . $ifmodifiedsince .
"User-Agent: PEAR/1.5.1/PHP/" . PHP_VERSION . "\r\n";
$username = $this->config->get('username');
$password = $this->config->get('password');
 
$request .= $ifmodifiedsince .
"User-Agent: PEAR/1.10.1/PHP/" . PHP_VERSION . "\r\n";
 
$username = $this->config->get('username', null, $channel);
$password = $this->config->get('password', null, $channel);
 
if ($username && $password) {
$tmp = base64_encode("$username:$password");
$request .= "Authorization: Basic $tmp\r\n";
}
 
if ($proxy_host != '' && $proxy_user != '') {
$request .= 'Proxy-Authorization: Basic ' .
base64_encode($proxy_user . ':' . $proxy_pass) . "\r\n";
}
 
if ($accept) {
$request .= 'Accept: ' . implode(', ', $accept) . "\r\n";
}
 
$request .= "Accept-Encoding:\r\n";
$request .= "Connection: close\r\n";
$request .= "\r\n";
 
if ($proxy_host != '') {
$fp = @fsockopen($proxy_host, $proxy_port, $errno, $errstr, 15);
if (!$fp) {
return PEAR::raiseError("Connection to `$proxy_host:$proxy_port' failed: $errstr",
-9276);
return PEAR::raiseError("Connection to `$proxy_host:$proxy_port' failed: $errstr", -9276);
}
} else {
if (isset($info['scheme']) && $info['scheme'] == 'https') {
if ($schema === 'https') {
$host = 'ssl://' . $host;
}
 
$fp = @fsockopen($host, $port, $errno, $errstr);
if (!$fp) {
return PEAR::raiseError("Connection to `$host:$port' failed: $errstr", $errno);
}
}
 
fwrite($fp, $request);
 
$headers = array();
while (trim($line = fgets($fp, 1024))) {
if (preg_match('/^([^:]+):\s+(.*)\s*$/', $line, $matches)) {
$reply = 0;
while ($line = trim(fgets($fp, 1024))) {
if (preg_match('/^([^:]+):\s+(.*)\s*\\z/', $line, $matches)) {
$headers[strtolower($matches[1])] = trim($matches[2]);
} elseif (preg_match('|^HTTP/1.[01] ([0-9]{3}) |', $line, $matches)) {
if ($matches[1] == 304 && ($lastmodified || ($lastmodified === false))) {
$reply = (int)$matches[1];
if ($reply == 304 && ($lastmodified || ($lastmodified === false))) {
return false;
}
if ($matches[1] != 200) {
return PEAR::raiseError("File http://$host:$port$path not valid (received: $line)", (int) $matches[1]);
 
if (!in_array($reply, array(200, 301, 302, 303, 305, 307))) {
return PEAR::raiseError("File $schema://$host:$port$path not valid (received: $line)");
}
}
}
if (isset($headers['content-length'])) {
$length = $headers['content-length'];
} else {
$length = -1;
 
if ($reply != 200) {
if (!isset($headers['location'])) {
return PEAR::raiseError("File $schema://$host:$port$path not valid (redirected but no location)");
}
 
if ($wasredirect > 4) {
return PEAR::raiseError("File $schema://$host:$port$path not valid (redirection looped more than 5 times)");
}
 
$redirect = $wasredirect + 1;
return $this->downloadHttp($headers['location'], $lastmodified, $accept, $channel);
}
 
$length = isset($headers['content-length']) ? $headers['content-length'] : -1;
 
$data = '';
while ($chunk = @fread($fp, 8192)) {
$data .= $chunk;
}
fclose($fp);
 
if ($lastmodified === false || $lastmodified) {
if (isset($headers['etag'])) {
$lastmodified = array('ETag' => $headers['etag']);
}
 
if (isset($headers['last-modified'])) {
if (is_array($lastmodified)) {
$lastmodified['Last-Modified'] = $headers['last-modified'];
387,9 → 487,10
$lastmodified = $headers['last-modified'];
}
}
 
return array($data, $lastmodified, $headers);
}
 
return $data;
}
}
?>
/trunk/bibliotheque/pear/PEAR/Packager.php
4,20 → 4,13
*
* 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 Stig Bakken <ssb@php.net>
* @author Tomas V. V. Cox <cox@idecnet.com>
* @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: Packager.php,v 1.70 2006/09/25 05:12:21 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
35,9 → 28,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
47,7 → 40,6
* @var PEAR_Registry
*/
var $_registry;
// {{{ package()
 
function package($pkgfile = null, $compress = true, $pkg2 = null)
{
55,9 → 47,10
if (empty($pkgfile)) {
$pkgfile = 'package.xml';
}
 
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$pkg = &new PEAR_PackageFile($this->config, $this->debug);
$pf = &$pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL);
$pkg = new PEAR_PackageFile($this->config, $this->debug);
$pf = &$pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL);
$main = &$pf;
PEAR::staticPopErrorHandling();
if (PEAR::isError($pf)) {
66,14 → 59,15
$this->log(0, 'Error: ' . $error['message']);
}
}
 
$this->log(0, $pf->getMessage());
return $this->raiseError("Cannot package, errors in package file");
} else {
foreach ($pf->getValidationWarnings() as $warning) {
$this->log(1, 'Warning: ' . $warning['message']);
}
}
 
foreach ($pf->getValidationWarnings() as $warning) {
$this->log(1, 'Warning: ' . $warning['message']);
}
 
// }}}
if ($pkg2) {
$this->log(0, 'Attempting to process the second package file');
88,29 → 82,34
}
$this->log(0, $pf2->getMessage());
return $this->raiseError("Cannot package, errors in second package file");
} else {
foreach ($pf2->getValidationWarnings() as $warning) {
$this->log(1, 'Warning: ' . $warning['message']);
}
}
 
foreach ($pf2->getValidationWarnings() as $warning) {
$this->log(1, 'Warning: ' . $warning['message']);
}
 
if ($pf2->getPackagexmlVersion() == '2.0' ||
$pf2->getPackagexmlVersion() == '2.1') {
$main = &$pf2;
$pf2->getPackagexmlVersion() == '2.1'
) {
$main = &$pf2;
$other = &$pf;
} else {
$main = &$pf;
$main = &$pf;
$other = &$pf2;
}
 
if ($main->getPackagexmlVersion() != '2.0' &&
$main->getPackagexmlVersion() != '2.1') {
return PEAR::raiseError('Error: cannot package two package.xml version 1.0, can ' .
'only package together a package.xml 1.0 and package.xml 2.0');
}
 
if ($other->getPackagexmlVersion() != '1.0') {
return PEAR::raiseError('Error: cannot package two package.xml version 2.0, can ' .
'only package together a package.xml 1.0 and package.xml 2.0');
}
}
 
$main->setLogger($this);
if (!$main->validate(PEAR_VALIDATE_PACKAGING)) {
foreach ($main->getValidationWarnings() as $warning) {
117,11 → 116,12
$this->log(0, 'Error: ' . $warning['message']);
}
return $this->raiseError("Cannot package, errors in package");
} else {
foreach ($main->getValidationWarnings() as $warning) {
$this->log(1, 'Warning: ' . $warning['message']);
}
}
 
foreach ($main->getValidationWarnings() as $warning) {
$this->log(1, 'Warning: ' . $warning['message']);
}
 
if ($pkg2) {
$other->setLogger($this);
$a = false;
129,26 → 129,31
foreach ($other->getValidationWarnings() as $warning) {
$this->log(0, 'Error: ' . $warning['message']);
}
 
foreach ($main->getValidationWarnings() as $warning) {
$this->log(0, 'Error: ' . $warning['message']);
}
 
if ($a) {
return $this->raiseError('The two package.xml files are not equivalent!');
}
 
return $this->raiseError("Cannot package, errors in package");
} else {
foreach ($other->getValidationWarnings() as $warning) {
$this->log(1, 'Warning: ' . $warning['message']);
}
}
 
foreach ($other->getValidationWarnings() as $warning) {
$this->log(1, 'Warning: ' . $warning['message']);
}
 
$gen = &$main->getDefaultGenerator();
$tgzfile = $gen->toTgz2($this, $other, $compress);
if (PEAR::isError($tgzfile)) {
return $tgzfile;
}
 
$dest_package = basename($tgzfile);
$pkgdir = dirname($pkgfile);
$pkgdir = dirname($pkgfile);
 
// TAR the Package -------------------------------------------
$this->log(1, "Package $dest_package done");
if (file_exists("$pkgdir/CVS/Root")) {
157,6 → 162,12
$this->log(1, 'Tag the released code with "pear cvstag ' .
$main->getPackageFile() . '"');
$this->log(1, "(or set the CVS tag $cvstag by hand)");
} elseif (file_exists("$pkgdir/.svn")) {
$svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
$svntag = $pf->getName() . "-$svnversion";
$this->log(1, 'Tag the released code with "pear svntag ' .
$main->getPackageFile() . '"');
$this->log(1, "(or set the SVN tag $svntag by hand)");
}
} else { // this branch is executed for single packagefile packaging
$gen = &$pf->getDefaultGenerator();
165,9 → 176,10
$this->log(0, $tgzfile->getMessage());
return $this->raiseError("Cannot package, errors in package");
}
 
$dest_package = basename($tgzfile);
$pkgdir = dirname($pkgfile);
$pkgdir = dirname($pkgfile);
 
// TAR the Package -------------------------------------------
$this->log(1, "Package $dest_package done");
if (file_exists("$pkgdir/CVS/Root")) {
175,25 → 187,14
$cvstag = "RELEASE_$cvsversion";
$this->log(1, "Tag the released code with `pear cvstag $pkgfile'");
$this->log(1, "(or set the CVS tag $cvstag by hand)");
} elseif (file_exists("$pkgdir/.svn")) {
$svnversion = preg_replace('/[^a-z0-9]/i', '.', $pf->getVersion());
$svntag = $pf->getName() . "-$svnversion";
$this->log(1, "Tag the released code with `pear svntag $pkgfile'");
$this->log(1, "(or set the SVN tag $svntag by hand)");
}
}
 
return $dest_package;
}
 
// }}}
}
 
// {{{ md5_file() utility function
if (!function_exists('md5_file')) {
function md5_file($file) {
if (!$fd = @fopen($file, 'r')) {
return false;
}
fclose($fd);
$md5 = md5(file_get_contents($file));
return $md5;
}
}
// }}}
 
?>
}
/trunk/bibliotheque/pear/PEAR/Command.php
4,19 → 4,12
*
* 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 Stig Bakken <ssb@php.net>
* @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: Command.php,v 1.38 2006/10/31 02:54:40 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
98,9 → 91,9
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
115,11 → 108,8
* @param object $config Instance of PEAR_Config object
*
* @return object the command object or a PEAR error
*
* @access public
* @static
*/
function &factory($command, &$config)
public static function &factory($command, &$config)
{
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
PEAR_Command::registerCommands();
140,13 → 130,13
return $a;
}
$ui =& PEAR_Command::getFrontendObject();
$obj = &new $class($ui, $config);
$obj = new $class($ui, $config);
return $obj;
}
 
// }}}
// {{{ & getObject()
function &getObject($command)
public static function &getObject($command)
{
$class = $GLOBALS['_PEAR_Command_commandlist'][$command];
if (!class_exists($class)) {
157,7 → 147,7
}
$ui =& PEAR_Command::getFrontendObject();
$config = &PEAR_Config::singleton();
$obj = &new $class($ui, $config);
$obj = new $class($ui, $config);
return $obj;
}
 
168,9 → 158,8
* Get instance of frontend object.
*
* @return object|PEAR_Error
* @static
*/
function &getFrontendObject()
public static function &getFrontendObject()
{
$a = &PEAR_Frontend::singleton();
return $a;
185,9 → 174,8
* @param string $uiclass Name of class implementing the frontend
*
* @return object the frontend object, or a PEAR error
* @static
*/
function &setFrontendClass($uiclass)
public static function &setFrontendClass($uiclass)
{
$a = &PEAR_Frontend::setFrontendClass($uiclass);
return $a;
202,9 → 190,8
* @param string $uitype Name of the frontend type (for example "CLI")
*
* @return object the frontend object, or a PEAR error
* @static
*/
function setFrontendType($uitype)
public static function setFrontendType($uitype)
{
$uiclass = 'PEAR_Frontend_' . $uitype;
return PEAR_Command::setFrontendClass($uiclass);
227,11 → 214,8
* included.
*
* @return bool TRUE on success, a PEAR error on failure
*
* @access public
* @static
*/
function registerCommands($merge = false, $dir = null)
public static function registerCommands($merge = false, $dir = null)
{
$parser = new PEAR_XMLParser;
if ($dir === null) {
247,27 → 231,31
if (!$merge) {
$GLOBALS['_PEAR_Command_commandlist'] = array();
}
while ($entry = readdir($dp)) {
if ($entry{0} == '.' || substr($entry, -4) != '.xml') {
 
while ($file = readdir($dp)) {
if ($file{0} == '.' || substr($file, -4) != '.xml') {
continue;
}
$class = "PEAR_Command_".substr($entry, 0, -4);
$file = "$dir/$entry";
$parser->parse(file_get_contents($file));
$implements = $parser->getData();
 
$f = substr($file, 0, -4);
$class = "PEAR_Command_" . $f;
// List of commands
if (empty($GLOBALS['_PEAR_Command_objects'][$class])) {
$GLOBALS['_PEAR_Command_objects'][$class] = "$dir/" . substr($entry, 0, -4) .
'.php';
$GLOBALS['_PEAR_Command_objects'][$class] = "$dir/" . $f . '.php';
}
 
$parser->parse(file_get_contents("$dir/$file"));
$implements = $parser->getData();
foreach ($implements as $command => $desc) {
if ($command == 'attribs') {
continue;
}
 
if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
return PEAR::raiseError('Command "' . $command . '" already registered in ' .
'class "' . $GLOBALS['_PEAR_Command_commandlist'][$command] . '"');
}
 
$GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
$GLOBALS['_PEAR_Command_commanddesc'][$command] = $desc['summary'];
if (isset($desc['shortcut'])) {
279,6 → 267,7
}
$GLOBALS['_PEAR_Command_shortcuts'][$shortcut] = $command;
}
 
if (isset($desc['options']) && $desc['options']) {
foreach ($desc['options'] as $oname => $option) {
if (isset($option['shortopt']) && strlen($option['shortopt']) > 1) {
291,6 → 280,7
}
}
}
 
ksort($GLOBALS['_PEAR_Command_shortcuts']);
ksort($GLOBALS['_PEAR_Command_commandlist']);
@closedir($dp);
305,11 → 295,8
* classes implement them.
*
* @return array command => implementing class
*
* @access public
* @static
*/
function getCommands()
public static function getCommands()
{
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
PEAR_Command::registerCommands();
324,11 → 311,8
* Get the list of command shortcuts.
*
* @return array shortcut => command
*
* @access public
* @static
*/
function getShortcuts()
public static function getShortcuts()
{
if (empty($GLOBALS['_PEAR_Command_shortcuts'])) {
PEAR_Command::registerCommands();
347,11 → 331,8
* @param array $long_args (reference) long getopt format
*
* @return void
*
* @access public
* @static
*/
function getGetoptArgs($command, &$short_args, &$long_args)
public static function getGetoptArgs($command, &$short_args, &$long_args)
{
if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
PEAR_Command::registerCommands();
375,11 → 356,8
* @param string $command Name of the command
*
* @return string command description
*
* @access public
* @static
*/
function getDescription($command)
public static function getDescription($command)
{
if (!isset($GLOBALS['_PEAR_Command_commanddesc'][$command])) {
return null;
394,11 → 372,8
* Get help for command.
*
* @param string $command Name of the command to return help for
*
* @access public
* @static
*/
function getHelp($command)
public static function getHelp($command)
{
$cmds = PEAR_Command::getCommands();
if (isset($GLOBALS['_PEAR_Command_shortcuts'][$command])) {
411,6 → 386,4
return false;
}
// }}}
}
 
?>
}
/trunk/bibliotheque/pear/PEAR/ErrorStack.php
21,9 → 21,8
* @category Debugging
* @package PEAR_ErrorStack
* @author Greg Beaver <cellog@php.net>
* @copyright 2004-2006 Greg Beaver
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: ErrorStack.php,v 1.26 2006/10/31 02:54:40 cellog Exp $
* @copyright 2004-2008 Greg Beaver
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR_ErrorStack
*/
 
132,12 → 131,11
* $local_stack = new PEAR_ErrorStack('MyPackage');
* </code>
* @author Greg Beaver <cellog@php.net>
* @version 1.5.1
* @version 1.10.1
* @package PEAR_ErrorStack
* @category Debugging
* @copyright 2004-2006 Greg Beaver
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: ErrorStack.php,v 1.26 2006/10/31 02:54:40 cellog Exp $
* @copyright 2004-2008 Greg Beaver
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR_ErrorStack
*/
class PEAR_ErrorStack {
194,12 → 192,12
* @access protected
*/
var $_contextCallback = false;
 
/**
* If set to a valid callback, this will be called every time an error
* is pushed onto the stack. The return value will be used to determine
* whether to allow an error to be pushed or logged.
*
*
* The return value must be one an PEAR_ERRORSTACK_* constant
* @see PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG
* @var false|string|array
206,7 → 204,7
* @access protected
*/
var $_errorCallback = array();
 
/**
* PEAR::Log object for logging errors
* @var false|Log
213,7 → 211,7
* @access protected
*/
var $_logger = false;
 
/**
* Error messages - designed to be overridden
* @var array
220,10 → 218,10
* @abstract
*/
var $_errorMsgs = array();
 
/**
* Set up a new error stack
*
*
* @param string $package name of the package this error stack represents
* @param callback $msgCallback callback used for error message generation
* @param callback $contextCallback callback used for context generation,
230,7 → 228,7
* defaults to {@link getFileLine()}
* @param boolean $throwPEAR_Error
*/
function PEAR_ErrorStack($package, $msgCallback = false, $contextCallback = false,
function __construct($package, $msgCallback = false, $contextCallback = false,
$throwPEAR_Error = false)
{
$this->_package = $package;
250,12 → 248,13
* defaults to {@link getFileLine()}
* @param boolean $throwPEAR_Error
* @param string $stackClass class to instantiate
* @static
*
* @return PEAR_ErrorStack
*/
function &singleton($package, $msgCallback = false, $contextCallback = false,
$throwPEAR_Error = false, $stackClass = 'PEAR_ErrorStack')
{
public static function &singleton(
$package, $msgCallback = false, $contextCallback = false,
$throwPEAR_Error = false, $stackClass = 'PEAR_ErrorStack'
) {
if (isset($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package])) {
return $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package];
}
297,15 → 296,14
/**
* Set up a PEAR::Log object for all error stacks that don't have one
* @param Log $log
* @static
*/
function setDefaultLogger(&$log)
public static function setDefaultLogger(&$log)
{
if (is_object($log) && method_exists($log, 'log') ) {
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] = &$log;
} elseif (is_callable($log)) {
$GLOBALS['_PEAR_ERRORSTACK_DEFAULT_LOGGER'] = &$log;
}
}
}
/**
358,9 → 356,8
* messages for a singleton
* @param array|string Callback function/method
* @param string Package name, or false for all packages
* @static
*/
function setDefaultCallback($callback = false, $package = false)
public static function setDefaultCallback($callback = false, $package = false)
{
if (!is_callable($callback)) {
$callback = false;
432,9 → 429,8
* @see PEAR_ERRORSTACK_PUSHANDLOG, PEAR_ERRORSTACK_PUSH, PEAR_ERRORSTACK_LOG
* @see staticPopCallback(), pushCallback()
* @param string|array $cb
* @static
*/
function staticPushCallback($cb)
public static function staticPushCallback($cb)
{
array_push($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'], $cb);
}
443,9 → 439,8
* Remove a temporary overriding error callback
* @see staticPushCallback()
* @return array|string|false
* @static
*/
function staticPopCallback()
public static function staticPopCallback()
{
$ret = array_pop($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK']);
if (!is_array($GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'])) {
604,11 → 599,11
* to find error context
* @return PEAR_Error|array if compatibility mode is on, a PEAR_Error is also
* thrown. see docs for {@link push()}
* @static
*/
function staticPush($package, $code, $level = 'error', $params = array(),
$msg = false, $repackage = false, $backtrace = false)
{
public static function staticPush(
$package, $code, $level = 'error', $params = array(),
$msg = false, $repackage = false, $backtrace = false
) {
$s = &PEAR_ErrorStack::singleton($package);
if ($s->_contextCallback) {
if (!$backtrace) {
750,9 → 745,8
* @param string|false Package name to check for errors
* @param string Level name to check for a particular severity
* @return boolean
* @static
*/
function staticHasErrors($package = false, $level = false)
public static function staticHasErrors($package = false, $level = false)
{
if ($package) {
if (!isset($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package])) {
776,12 → 770,13
* @param boolean $merge Set to return a flat array, not organized by package
* @param array $sortfunc Function used to sort a merged array - default
* sorts by time, and should be good for most cases
* @static
*
* @return array
*/
function staticGetErrors($purge = false, $level = false, $merge = false,
$sortfunc = array('PEAR_ErrorStack', '_sortErrors'))
{
public static function staticGetErrors(
$purge = false, $level = false, $merge = false,
$sortfunc = array('PEAR_ErrorStack', '_sortErrors')
) {
$ret = array();
if (!is_callable($sortfunc)) {
$sortfunc = array('PEAR_ErrorStack', '_sortErrors');
806,7 → 801,7
* Error sorting function, sorts by time
* @access private
*/
function _sortErrors($a, $b)
public static function _sortErrors($a, $b)
{
if ($a['time'] == $b['time']) {
return 0;
829,9 → 824,8
* @param unused
* @param integer backtrace frame.
* @param array Results of debug_backtrace()
* @static
*/
function getFileLine($code, $params, $backtrace = null)
public static function getFileLine($code, $params, $backtrace = null)
{
if ($backtrace === null) {
return false;
857,7 → 851,7
'line' => $filebacktrace['line']);
// rearrange for eval'd code or create function errors
if (strpos($filebacktrace['file'], '(') &&
preg_match(';^(.*?)\((\d+)\) : (.*?)$;', $filebacktrace['file'],
preg_match(';^(.*?)\((\d+)\) : (.*?)\\z;', $filebacktrace['file'],
$matches)) {
$ret['file'] = $matches[1];
$ret['line'] = $matches[2] + 0;
903,10 → 897,10
* @param PEAR_ErrorStack
* @param array
* @param string|false Pre-generated error message template
* @static
*
* @return string
*/
function getErrorMessage(&$stack, $err, $template = false)
public static function getErrorMessage(&$stack, $err, $template = false)
{
if ($template) {
$mainmsg = $template;
/trunk/bibliotheque/pear/PEAR/Frontend.php
4,23 → 4,21
*
* 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: Frontend.php,v 1.9 2006/03/03 13:13:07 pajoye Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
 
/**
* Include error handling
*/
//require_once 'PEAR.php';
 
/**
* Which user interface class is being used.
* @var string class name
*/
35,14 → 33,12
/**
* Singleton-based frontend for PEAR user input/output
*
* Note that frontend classes must implement userConfirm(), and shoul implement
* displayFatalError() and outputData()
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
51,9 → 47,8
/**
* Retrieve the frontend object
* @return PEAR_Frontend_CLI|PEAR_Frontend_Web|PEAR_Frontend_Gtk
* @static
*/
function &singleton($type = null)
public static function &singleton($type = null)
{
if ($type === null) {
if (!isset($GLOBALS['_PEAR_FRONTEND_SINGLETON'])) {
61,10 → 56,10
return $a;
}
return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
} else {
$a = PEAR_Frontend::setFrontendClass($type);
return $a;
}
 
$a = PEAR_Frontend::setFrontendClass($type);
return $a;
}
 
/**
74,14 → 69,14
* _ => DIRECTORY_SEPARATOR (PEAR_Frontend_CLI is in PEAR/Frontend/CLI.php)
* @param string $uiclass full class name
* @return PEAR_Frontend
* @static
*/
function &setFrontendClass($uiclass)
public static function &setFrontendClass($uiclass)
{
if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) &&
is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], $uiclass)) {
return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
}
 
if (!class_exists($uiclass)) {
$file = str_replace('_', '/', $uiclass) . '.php';
if (PEAR_Frontend::isIncludeable($file)) {
88,19 → 83,21
include_once $file;
}
}
 
if (class_exists($uiclass)) {
$obj = &new $uiclass;
$obj = new $uiclass;
// quick test to see if this class implements a few of the most
// important frontend methods
if (method_exists($obj, 'userConfirm')) {
if (is_a($obj, 'PEAR_Frontend')) {
$GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$obj;
$GLOBALS['_PEAR_FRONTEND_CLASS'] = $uiclass;
return $obj;
} else {
$err = PEAR::raiseError("not a frontend class: $uiclass");
return $err;
}
 
$err = PEAR::raiseError("not a frontend class: $uiclass");
return $err;
}
 
$err = PEAR::raiseError("no such class: $uiclass");
return $err;
}
111,52 → 108,41
* Frontends are expected to be a descendant of PEAR_Frontend
* @param PEAR_Frontend
* @return PEAR_Frontend
* @static
*/
function &setFrontendObject($uiobject)
public static function &setFrontendObject($uiobject)
{
if (is_object($GLOBALS['_PEAR_FRONTEND_SINGLETON']) &&
is_a($GLOBALS['_PEAR_FRONTEND_SINGLETON'], get_class($uiobject))) {
return $GLOBALS['_PEAR_FRONTEND_SINGLETON'];
}
 
if (!is_a($uiobject, 'PEAR_Frontend')) {
$err = PEAR::raiseError('not a valid frontend class: (' .
get_class($uiobject) . ')');
return $err;
}
// quick test to see if this class implements a few of the most
// important frontend methods
if (method_exists($uiobject, 'userConfirm')) {
$GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$uiobject;
$GLOBALS['_PEAR_FRONTEND_CLASS'] = get_class($uiobject);
return $uiobject;
} else {
$err = PEAR::raiseError("not a value frontend class: (" . get_class($uiobject)
. ')');
return $err;
}
 
$GLOBALS['_PEAR_FRONTEND_SINGLETON'] = &$uiobject;
$GLOBALS['_PEAR_FRONTEND_CLASS'] = get_class($uiobject);
return $uiobject;
}
 
/**
* @param string $path relative or absolute include path
* @return boolean
* @static
*/
function isIncludeable($path)
public static function isIncludeable($path)
{
if (file_exists($path) && is_readable($path)) {
return true;
}
$ipath = explode(PATH_SEPARATOR, ini_get('include_path'));
foreach ($ipath as $include) {
$test = realpath($include . DIRECTORY_SEPARATOR . $path);
if (!$test) { // support wrappers like phar (realpath just don't work with them)
$test = $include . DIRECTORY_SEPARATOR . $path;
}
if (file_exists($test) && is_readable($test)) {
return true;
}
 
$fp = @fopen($path, 'r', true);
if ($fp) {
fclose($fp);
return true;
}
 
return false;
}
 
179,8 → 165,59
$GLOBALS['_PEAR_Common_tempfiles'][] = $file;
}
 
/**
* Log an action
*
* @param string $msg the message to log
* @param boolean $append_crlf
* @return boolean true
* @abstract
*/
function log($msg, $append_crlf = true)
{
}
}
?>
 
/**
* Run a post-installation script
*
* @param array $scripts array of post-install scripts
* @abstract
*/
function runPostinstallScripts(&$scripts)
{
}
 
/**
* Display human-friendly output formatted depending on the
* $command parameter.
*
* This should be able to handle basic output data with no command
* @param mixed $data data structure containing the information to display
* @param string $command command from which this method was called
* @abstract
*/
function outputData($data, $command = '_default')
{
}
 
/**
* Display a modal form dialog and return the given input
*
* A frontend that requires multiple requests to retrieve and process
* data must take these needs into account, and implement the request
* handling code.
* @param string $command command from which this method was called
* @param array $prompts associative array. keys are the input field names
* and values are the description
* @param array $types array of input field types (text, password,
* etc.) keys have to be the same like in $prompts
* @param array $defaults array of default values. again keys have
* to be the same like in $prompts. Do not depend
* on a default value being set.
* @return array input sent by the user
* @abstract
*/
function userDialog($command, $prompts, $types = array(), $defaults = array())
{
}
}
/trunk/bibliotheque/pear/PEAR/ChannelFile/Parser.php
4,18 → 4,11
*
* 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: Parser.php,v 1.4 2006/01/06 04:47:36 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
30,9 → 23,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
58,11 → 51,13
if (PEAR::isError($err = parent::parse($data, $file))) {
return $err;
}
 
$ret = new PEAR_ChannelFile;
$ret->setConfig($this->_config);
if (isset($this->_logger)) {
$ret->setLogger($this->_logger);
}
 
$ret->fromArray($this->_unserializedData);
// make sure the filelist is in the easy to read format needed
$ret->flattenFilelist();
69,5 → 64,4
$ret->setPackagefile($file, $archive);
return $ret;
}
}
?>
}
/trunk/bibliotheque/pear/PEAR/DependencyDB.php
4,19 → 4,12
*
* 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 Tomas V. V. Cox <cox@idecnet.com>
* @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: DependencyDB.php,v 1.35 2007/01/06 04:03:32 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
34,9 → 27,9
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @author Tomas V.V.Cox <cox@idec.net.com>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.5.1
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
95,22 → 88,21
* @param PEAR_Config
* @param string|false full path to the dependency database, or false to use default
* @return PEAR_DependencyDB|PEAR_Error
* @static
*/
function &singleton(&$config, $depdb = false)
public static function &singleton(&$config, $depdb = false)
{
if (!isset($GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE']
[$config->get('php_dir', null, 'pear.php.net')])) {
$phpdir = $config->get('php_dir', null, 'pear.php.net');
if (!isset($GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE'][$phpdir])) {
$a = new PEAR_DependencyDB;
$GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE']
[$config->get('php_dir', null, 'pear.php.net')] = &$a;
$GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE'][$phpdir] = &$a;
$a->setConfig($config, $depdb);
if (PEAR::isError($e = $a->assertDepsDB())) {
$e = $a->assertDepsDB();
if (PEAR::isError($e)) {
return $e;
}
}
return $GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE']
[$config->get('php_dir', null, 'pear.php.net')];
 
return $GLOBALS['_PEAR_DEPENDENCYDB_INSTANCE'][$phpdir];
}
 
/**
125,13 → 117,18
} else {
$this->_config = &$config;
}
 
$this->_registry = &$this->_config->getRegistry();
if (!$depdb) {
$this->_depdb = $this->_config->get('php_dir', null, 'pear.php.net') .
DIRECTORY_SEPARATOR . '.depdb';
$dir = $this->_config->get('metadata_dir', null, 'pear.php.net');
if (!$dir) {
$dir = $this->_config->get('php_dir', null, 'pear.php.net');
}
$this->_depdb = $dir . DIRECTORY_SEPARATOR . '.depdb';
} else {
$this->_depdb = $depdb;
}
 
$this->_lockfile = dirname($this->_depdb) . DIRECTORY_SEPARATOR . '.depdblock';
}
// }}}
145,13 → 142,15
if ($dir != '.' && file_exists($dir)) {
if (is_writeable($dir)) {
return true;
} else {
return false;
}
 
return false;
}
}
 
return false;
}
 
return is_writeable($this->_depdb);
}
 
166,18 → 165,20
{
if (!is_file($this->_depdb)) {
$this->rebuildDB();
} else {
$depdb = $this->_getDepDB();
// Datatype format has been changed, rebuild the Deps DB
if ($depdb['_version'] < $this->_version) {
$this->rebuildDB();
}
if ($depdb['_version']{0} > $this->_version{0}) {
return PEAR::raiseError('Dependency database is version ' .
$depdb['_version'] . ', and we are version ' .
$this->_version . ', cannot continue');
}
return;
}
 
$depdb = $this->_getDepDB();
// Datatype format has been changed, rebuild the Deps DB
if ($depdb['_version'] < $this->_version) {
$this->rebuildDB();
}
 
if ($depdb['_version']{0} > $this->_version{0}) {
return PEAR::raiseError('Dependency database is version ' .
$depdb['_version'] . ', and we are version ' .
$this->_version . ', cannot continue');
}
}
 
/**
195,9 → 196,11
$channel = strtolower($pkg['channel']);
$package = strtolower($pkg['package']);
}
 
if (isset($data['packages'][$channel][$package])) {
return $data['packages'][$channel][$package];
}
 
return false;
}
 
217,19 → 220,25
$channel = strtolower($pkg['channel']);
$package = strtolower($pkg['package']);
}
 
$depend = $this->getDependentPackages($pkg);
if (!$depend) {
return false;
}
 
$dependencies = array();
foreach ($depend as $info) {
$temp = $this->getDependencies($info);
foreach ($temp as $dep) {
if (strtolower($dep['dep']['channel']) == strtolower($channel) &&
strtolower($dep['dep']['name']) == strtolower($package)) {
if (
isset($dep['dep'], $dep['dep']['channel'], $dep['dep']['name']) &&
strtolower($dep['dep']['channel']) == $channel &&
strtolower($dep['dep']['name']) == $package
) {
if (!isset($dependencies[$info['channel']])) {
$dependencies[$info['channel']] = array();
}
 
if (!isset($dependencies[$info['channel']][$info['package']])) {
$dependencies[$info['channel']][$info['package']] = array();
}
237,6 → 246,7
}
}
}
 
return $dependencies;
}
 
254,10 → 264,12
$channel = strtolower($pkg['channel']);
$package = strtolower($pkg['package']);
}
 
$data = $this->_getDepDB();
if (isset($data['dependencies'][$channel][$package])) {
return $data['dependencies'][$channel][$package];
}
 
return false;
}
 
272,7 → 284,7
$this->_getDepDB();
return $this->_dependsOn($parent, $child, $c);
}
 
function _dependsOn($parent, $child, &$checked)
{
if (is_object($parent)) {
282,6 → 294,7
$channel = strtolower($parent['channel']);
$package = strtolower($parent['package']);
}
 
if (is_object($child)) {
$depchannel = strtolower($child->getChannel());
$deppackage = strtolower($child->getPackage());
289,13 → 302,16
$depchannel = strtolower($child['channel']);
$deppackage = strtolower($child['package']);
}
 
if (isset($checked[$channel][$package][$depchannel][$deppackage])) {
return false; // avoid endless recursion
}
 
$checked[$channel][$package][$depchannel][$deppackage] = true;
if (!isset($this->_cache['dependencies'][$channel][$package])) {
return false;
}
 
foreach ($this->_cache['dependencies'][$channel][$package] as $info) {
if (isset($info['dep']['uri'])) {
if (is_object($child)) {
309,11 → 325,13
}
return false;
}
if (strtolower($info['dep']['channel']) == strtolower($depchannel) &&
strtolower($info['dep']['name']) == strtolower($deppackage)) {
 
if (strtolower($info['dep']['channel']) == $depchannel &&
strtolower($info['dep']['name']) == $deppackage) {
return true;
}
}
 
foreach ($this->_cache['dependencies'][$channel][$package] as $info) {
if (isset($info['dep']['uri'])) {
if ($this->_dependsOn(array(
329,6 → 347,7
}
}
}
 
return false;
}
 
362,50 → 381,51
$channel = strtolower($pkg['channel']);
$package = strtolower($pkg['package']);
}
 
if (!isset($data['dependencies'][$channel][$package])) {
return true;
}
 
foreach ($data['dependencies'][$channel][$package] as $dep) {
$found = false;
if (isset($dep['dep']['uri'])) {
$depchannel = '__uri';
} else {
$depchannel = strtolower($dep['dep']['channel']);
}
if (isset($data['packages'][$depchannel][strtolower($dep['dep']['name'])])) {
foreach ($data['packages'][$depchannel][strtolower($dep['dep']['name'])] as
$i => $info) {
if ($info['channel'] == $channel &&
$info['package'] == $package) {
$found = false;
$depchannel = isset($dep['dep']['uri']) ? '__uri' : strtolower($dep['dep']['channel']);
$depname = strtolower($dep['dep']['name']);
if (isset($data['packages'][$depchannel][$depname])) {
foreach ($data['packages'][$depchannel][$depname] as $i => $info) {
if ($info['channel'] == $channel && $info['package'] == $package) {
$found = true;
break;
}
}
}
 
if ($found) {
unset($data['packages'][$depchannel][strtolower($dep['dep']['name'])][$i]);
if (!count($data['packages'][$depchannel][strtolower($dep['dep']['name'])])) {
unset($data['packages'][$depchannel][strtolower($dep['dep']['name'])]);
unset($data['packages'][$depchannel][$depname][$i]);
if (!count($data['packages'][$depchannel][$depname])) {
unset($data['packages'][$depchannel][$depname]);
if (!count($data['packages'][$depchannel])) {
unset($data['packages'][$depchannel]);
}
} else {
$data['packages'][$depchannel][strtolower($dep['dep']['name'])] =
array_values(
$data['packages'][$depchannel][strtolower($dep['dep']['name'])]);
$data['packages'][$depchannel][$depname] =
array_values($data['packages'][$depchannel][$depname]);
}
}
}
 
unset($data['dependencies'][$channel][$package]);
if (!count($data['dependencies'][$channel])) {
unset($data['dependencies'][$channel]);
}
 
if (!count($data['dependencies'])) {
unset($data['dependencies']);
}
 
if (!count($data['packages'])) {
unset($data['packages']);
}
 
$this->_writeDepDB($data);
}
 
420,17 → 440,27
// allow startup for read-only with older Registry
return $depdb;
}
 
$packages = $this->_registry->listAllPackages();
if (PEAR::isError($packages)) {
return $packages;
}
 
foreach ($packages as $channel => $ps) {
foreach ($ps as $package) {
$package = $this->_registry->getPackage($package, $channel);
if (PEAR::isError($package)) {
return $package;
}
$this->_setPackageDeps($depdb, $package);
}
}
 
$error = $this->_writeDepDB($depdb);
if (PEAR::isError($error)) {
return $error;
}
 
$this->_cache = $depdb;
return true;
}
443,40 → 473,47
*/
function _lock($mode = LOCK_EX)
{
if (!eregi('Windows 9', php_uname())) {
if ($mode != LOCK_UN && is_resource($this->_lockFp)) {
// XXX does not check type of lock (LOCK_SH/LOCK_EX)
return true;
if (stristr(php_uname(), 'Windows 9')) {
return true;
}
 
if ($mode != LOCK_UN && is_resource($this->_lockFp)) {
// XXX does not check type of lock (LOCK_SH/LOCK_EX)
return true;
}
 
$open_mode = 'w';
// XXX People reported problems with LOCK_SH and 'w'
if ($mode === LOCK_SH) {
if (!file_exists($this->_lockfile)) {
touch($this->_lockfile);
} elseif (!is_file($this->_lockfile)) {
return PEAR::raiseError('could not create Dependency lock file, ' .
'it exists and is not a regular file');
}
$open_mode = 'w';
// XXX People reported problems with LOCK_SH and 'w'
if ($mode === LOCK_SH) {
if (!file_exists($this->_lockfile)) {
touch($this->_lockfile);
} elseif (!is_file($this->_lockfile)) {
return PEAR::raiseError('could not create Dependency lock file, ' .
'it exists and is not a regular file');
}
$open_mode = 'r';
$open_mode = 'r';
}
 
if (!is_resource($this->_lockFp)) {
$this->_lockFp = @fopen($this->_lockfile, $open_mode);
}
 
if (!is_resource($this->_lockFp)) {
return PEAR::raiseError("could not create Dependency lock file" .
(isset($php_errormsg) ? ": " . $php_errormsg : ""));
}
 
if (!(int)flock($this->_lockFp, $mode)) {
switch ($mode) {
case LOCK_SH: $str = 'shared'; break;
case LOCK_EX: $str = 'exclusive'; break;
case LOCK_UN: $str = 'unlock'; break;
default: $str = 'unknown'; break;
}
 
if (!is_resource($this->_lockFp)) {
$this->_lockFp = @fopen($this->_lockfile, $open_mode);
}
if (!is_resource($this->_lockFp)) {
return PEAR::raiseError("could not create Dependency lock file" .
(isset($php_errormsg) ? ": " . $php_errormsg : ""));
}
if (!(int)flock($this->_lockFp, $mode)) {
switch ($mode) {
case LOCK_SH: $str = 'shared'; break;
case LOCK_EX: $str = 'exclusive'; break;
case LOCK_UN: $str = 'unlock'; break;
default: $str = 'unknown'; break;
}
return PEAR::raiseError("could not acquire $str lock ($this->_lockfile)");
}
return PEAR::raiseError("could not acquire $str lock ($this->_lockfile)");
}
 
return true;
}
 
504,19 → 541,19
if (!$this->hasWriteAccess()) {
return array('_version' => $this->_version);
}
 
if (isset($this->_cache)) {
return $this->_cache;
}
 
if (!$fp = fopen($this->_depdb, 'r')) {
$err = PEAR::raiseError("Could not open dependencies file `".$this->_depdb."'");
return $err;
}
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
 
clearstatcache();
fclose($fp);
$data = unserialize(file_get_contents($this->_depdb));
set_magic_quotes_runtime($rt);
$this->_cache = $data;
return $data;
}
532,14 → 569,13
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
 
if (!$fp = fopen($this->_depdb, 'wb')) {
$this->_unlock();
return PEAR::raiseError("Could not open dependencies file `".$this->_depdb."' for writing");
}
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
 
fwrite($fp, serialize($deps));
set_magic_quotes_runtime($rt);
fclose($fp);
$this->_unlock();
$this->_cache = $deps;
562,70 → 598,89
} else {
$deps = $pkg->getDeps(true);
}
 
if (!$deps) {
return;
}
 
if (!is_array($data)) {
$data = array();
}
 
if (!isset($data['dependencies'])) {
$data['dependencies'] = array();
}
if (!isset($data['dependencies'][strtolower($pkg->getChannel())])) {
$data['dependencies'][strtolower($pkg->getChannel())] = array();
 
$channel = strtolower($pkg->getChannel());
$package = strtolower($pkg->getPackage());
 
if (!isset($data['dependencies'][$channel])) {
$data['dependencies'][$channel] = array();
}
$data['dependencies'][strtolower($pkg->getChannel())][strtolower($pkg->getPackage())]
= array();
 
$data['dependencies'][$channel][$package] = array();
if (isset($deps['required']['package'])) {
if (!isset($deps['required']['package'][0])) {
$deps['required']['package'] = array($deps['required']['package']);
}
 
foreach ($deps['required']['package'] as $dep) {
$this->_registerDep($data, $pkg, $dep, 'required');
}
}
 
if (isset($deps['optional']['package'])) {
if (!isset($deps['optional']['package'][0])) {
$deps['optional']['package'] = array($deps['optional']['package']);
}
 
foreach ($deps['optional']['package'] as $dep) {
$this->_registerDep($data, $pkg, $dep, 'optional');
}
}
 
if (isset($deps['required']['subpackage'])) {
if (!isset($deps['required']['subpackage'][0])) {
$deps['required']['subpackage'] = array($deps['required']['subpackage']);
}
 
foreach ($deps['required']['subpackage'] as $dep) {
$this->_registerDep($data, $pkg, $dep, 'required');
}
}
 
if (isset($deps['optional']['subpackage'])) {
if (!isset($deps['optional']['subpackage'][0])) {
$deps['optional']['subpackage'] = array($deps['optional']['subpackage']);
}
 
foreach ($deps['optional']['subpackage'] as $dep) {
$this->_registerDep($data, $pkg, $dep, 'optional');
}
}
 
if (isset($deps['group'])) {
if (!isset($deps['group'][0])) {
$deps['group'] = array($deps['group']);
}
 
foreach ($deps['group'] as $group) {
if (isset($group['package'])) {
if (!isset($group['package'][0])) {
$group['package'] = array($group['package']);
}
 
foreach ($group['package'] as $dep) {
$this->_registerDep($data, $pkg, $dep, 'optional',
$group['attribs']['name']);
}
}
 
if (isset($group['subpackage'])) {
if (!isset($group['subpackage'][0])) {
$group['subpackage'] = array($group['subpackage']);
}
 
foreach ($group['subpackage'] as $dep) {
$this->_registerDep($data, $pkg, $dep, 'optional',
$group['attribs']['name']);
633,12 → 688,11
}
}
}
if ($data['dependencies'][strtolower($pkg->getChannel())]
[strtolower($pkg->getPackage())] == array()) {
unset($data['dependencies'][strtolower($pkg->getChannel())]
[strtolower($pkg->getPackage())]);
if (!count($data['dependencies'][strtolower($pkg->getChannel())])) {
unset($data['dependencies'][strtolower($pkg->getChannel())]);
 
if ($data['dependencies'][$channel][$package] == array()) {
unset($data['dependencies'][$channel][$package]);
if (!count($data['dependencies'][$channel])) {
unset($data['dependencies'][$channel]);
}
}
}
653,55 → 707,58
function _registerDep(&$data, &$pkg, $dep, $type, $group = false)
{
$info = array(
'dep' => $dep,
'type' => $type,
'group' => $group);
'dep' => $dep,
'type' => $type,
'group' => $group
);
 
if (isset($dep['channel'])) {
$depchannel = $dep['channel'];
} else {
$depchannel = '__uri';
}
$dep = array_map('strtolower', $dep);
$depchannel = isset($dep['channel']) ? $dep['channel'] : '__uri';
if (!isset($data['dependencies'])) {
$data['dependencies'] = array();
}
if (!isset($data['dependencies'][strtolower($pkg->getChannel())])) {
$data['dependencies'][strtolower($pkg->getChannel())] = array();
 
$channel = strtolower($pkg->getChannel());
$package = strtolower($pkg->getPackage());
 
if (!isset($data['dependencies'][$channel])) {
$data['dependencies'][$channel] = array();
}
if (!isset($data['dependencies'][strtolower($pkg->getChannel())][strtolower($pkg->getPackage())])) {
$data['dependencies'][strtolower($pkg->getChannel())][strtolower($pkg->getPackage())] = array();
 
if (!isset($data['dependencies'][$channel][$package])) {
$data['dependencies'][$channel][$package] = array();
}
$data['dependencies'][strtolower($pkg->getChannel())][strtolower($pkg->getPackage())][]
= $info;
if (isset($data['packages'][strtolower($depchannel)][strtolower($dep['name'])])) {
 
$data['dependencies'][$channel][$package][] = $info;
if (isset($data['packages'][$depchannel][$dep['name']])) {
$found = false;
foreach ($data['packages'][strtolower($depchannel)][strtolower($dep['name'])]
as $i => $p) {
if ($p['channel'] == strtolower($pkg->getChannel()) &&
$p['package'] == strtolower($pkg->getPackage())) {
foreach ($data['packages'][$depchannel][$dep['name']] as $i => $p) {
if ($p['channel'] == $channel && $p['package'] == $package) {
$found = true;
break;
}
}
if (!$found) {
$data['packages'][strtolower($depchannel)][strtolower($dep['name'])][]
= array('channel' => strtolower($pkg->getChannel()),
'package' => strtolower($pkg->getPackage()));
}
} else {
if (!isset($data['packages'])) {
$data['packages'] = array();
}
if (!isset($data['packages'][strtolower($depchannel)])) {
$data['packages'][strtolower($depchannel)] = array();
 
if (!isset($data['packages'][$depchannel])) {
$data['packages'][$depchannel] = array();
}
if (!isset($data['packages'][strtolower($depchannel)][strtolower($dep['name'])])) {
$data['packages'][strtolower($depchannel)][strtolower($dep['name'])] = array();
 
if (!isset($data['packages'][$depchannel][$dep['name']])) {
$data['packages'][$depchannel][$dep['name']] = array();
}
$data['packages'][strtolower($depchannel)][strtolower($dep['name'])][]
= array('channel' => strtolower($pkg->getChannel()),
'package' => strtolower($pkg->getPackage()));
 
$found = false;
}
 
if (!$found) {
$data['packages'][$depchannel][$dep['name']][] = array(
'channel' => $channel,
'package' => $package
);
}
}
}
?>
/trunk/bibliotheque/pear/PEAR/Builder.php
4,22 → 4,15
*
* 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 Stig Bakken <ssb@php.net>
* @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: Builder.php,v 1.31 2007/01/10 05:32:51 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*
*
* TODO: log output parameters in PECL command line
* TODO: msdev path in configuration
*/
29,6 → 22,8
*/
require_once 'PEAR/Common.php';
require_once 'PEAR/PackageFile.php';
require_once 'System.php';
 
/**
* Class to handle building (compiling) extensions.
*
36,9 → 31,9
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since PHP 4.0.2
* @see http://pear.php.net/manual/en/core.ppm.pear-builder.php
45,8 → 40,6
*/
class PEAR_Builder extends PEAR_Common
{
// {{{ properties
 
var $php_api_version = 0;
var $zend_module_api_no = 0;
var $zend_extension_api_no = 0;
62,8 → 55,6
// used for msdev builds
var $_lastline = null;
var $_firstline = null;
// }}}
// {{{ constructor
 
/**
* PEAR_Builder constructor.
72,16 → 63,12
*
* @access public
*/
function PEAR_Builder(&$ui)
function __construct(&$ui)
{
parent::PEAR_Common();
parent::__construct();
$this->setFrontendObject($ui);
}
 
// }}}
 
// {{{ _build_win32()
 
/**
* Build an extension from source on windows.
* requires msdev
92,7 → 79,7
$pkg = $descfile;
$descfile = $pkg->getPackageFile();
} else {
$pf = &new PEAR_PackageFile($this->config, $this->debug);
$pf = new PEAR_PackageFile($this->config, $this->debug);
$pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($pkg)) {
return $pkg;
104,14 → 91,15
if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
return $this->raiseError("could not chdir to $dir");
}
 
// packages that were in a .tar have the packagefile in this directory
$vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
if (file_exists($dir) && is_dir($vdir)) {
if (chdir($vdir)) {
$dir = getcwd();
} else {
if (!chdir($vdir)) {
return $this->raiseError("could not chdir to " . realpath($vdir));
}
 
$dir = getcwd();
}
 
$this->log(2, "building in $dir");
136,7 → 124,7
$buildtype = $matches[2];
}
 
if (preg_match('/(.*)?\s-\s(\d+).*?(\d+)/',$this->_lastline,$matches)) {
if (preg_match('/(.*)?\s-\s(\d+).*?(\d+)/', $this->_lastline, $matches)) {
if ($matches[2]) {
// there were errors in the build
return $this->raiseError("There were errors during compilation.");
158,7 → 146,7
$buildtype.'").*?'.
'\/out:"(.*?)"/is';
 
if ($dsptext && preg_match($regex,$dsptext,$matches)) {
if ($dsptext && preg_match($regex, $dsptext, $matches)) {
// what we get back is a relative path to the output file itself.
$outfile = realpath($matches[2]);
} else {
188,9 → 176,7
$this->_lastline = $data;
call_user_func($this->current_callback, $what, $data);
}
// }}}
 
// {{{ _harventInstDir
/**
* @param string
* @param string
231,14 → 217,10
return $ret;
}
 
// }}}
 
// {{{ build()
 
/**
* Build an extension from source. Runs "phpize" in the source
* directory, but compiles in a temporary directory
* (/var/tmp/pear-build-USER/PACKAGE-VERSION).
* (TMPDIR/pear-build-USER/PACKAGE-VERSION).
*
* @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or
* a PEAR_PackageFile object
260,39 → 242,80
*/
function build($descfile, $callback = null)
{
if (preg_match('/(\\/|\\\\|^)([^\\/\\\\]+)?php([^\\/\\\\]+)?$/',
$this->config->get('php_bin'), $matches)) {
if (isset($matches[2]) && strlen($matches[2]) &&
trim($matches[2]) != trim($this->config->get('php_prefix'))) {
$this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') .
' appears to have a prefix ' . $matches[2] . ', but' .
' config variable php_prefix does not match');
}
 
if (isset($matches[3]) && strlen($matches[3]) &&
trim($matches[3]) != trim($this->config->get('php_suffix'))) {
$this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') .
' appears to have a suffix ' . $matches[3] . ', but' .
' config variable php_suffix does not match');
}
}
 
$this->current_callback = $callback;
if (PEAR_OS == "Windows") {
return $this->_build_win32($descfile,$callback);
return $this->_build_win32($descfile, $callback);
}
 
if (PEAR_OS != 'Unix') {
return $this->raiseError("building extensions not supported on this platform");
}
 
if (is_object($descfile)) {
$pkg = $descfile;
$descfile = $pkg->getPackageFile();
if (is_a($pkg, 'PEAR_PackageFile_v1')) {
$dir = dirname($descfile);
} else {
$dir = $pkg->_config->get('temp_dir') . '/' . $pkg->getName();
// automatically delete at session end
$this->addTempFile($dir);
}
} else {
$pf = &new PEAR_PackageFile($this->config);
$pf = new PEAR_PackageFile($this->config);
$pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($pkg)) {
return $pkg;
}
$dir = dirname($descfile);
}
$dir = dirname($descfile);
 
// Find config. outside of normal path - e.g. config.m4
foreach (array_keys($pkg->getInstallationFileList()) as $item) {
if (stristr(basename($item), 'config.m4') && dirname($item) != '.') {
$dir .= DIRECTORY_SEPARATOR . dirname($item);
break;
}
}
 
$old_cwd = getcwd();
if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
return $this->raiseError("could not chdir to $dir");
}
 
$vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
if (is_dir($vdir)) {
chdir($vdir);
}
 
$dir = getcwd();
$this->log(2, "building in $dir");
putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH'));
$err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback'));
$err = $this->_runCommand($this->config->get('php_prefix')
. "phpize" .
$this->config->get('php_suffix'),
array(&$this, 'phpizeCallback'));
if (PEAR::isError($err)) {
return $err;
}
 
if (!$err) {
return $this->raiseError("`phpize' failed");
}
299,6 → 322,16
 
// {{{ start of interactive part
$configure_command = "$dir/configure";
 
$phpConfigName = $this->config->get('php_prefix')
. 'php-config'
. $this->config->get('php_suffix');
$phpConfigPath = System::which($phpConfigName);
if ($phpConfigPath !== false) {
$configure_command .= ' --with-php-config='
. $phpConfigPath;
}
 
$configure_options = $pkg->getConfigureOptions();
if ($configure_options) {
foreach ($configure_options as $o) {
318,10 → 351,12
// }}} end of interactive part
 
// FIXME make configurable
if(!$user=getenv('USER')){
if (!$user=getenv('USER')) {
$user='defaultuser';
}
$build_basedir = "/var/tmp/pear-build-$user";
 
$tmpdir = $this->config->get('temp_dir');
$build_basedir = System::mktemp(' -t "' . $tmpdir . '" -d "pear-build-' . $user . '"');
$build_dir = "$build_basedir/$vdir";
$inst_dir = "$build_basedir/install-$vdir";
$this->log(1, "building in $build_dir");
328,9 → 363,11
if (is_dir($build_dir)) {
System::rm(array('-rf', $build_dir));
}
 
if (!System::mkDir(array('-p', $build_dir))) {
return $this->raiseError("could not create build dir: $build_dir");
}
 
$this->addTempFile($build_dir);
if (!System::mkDir(array('-p', $inst_dir))) {
return $this->raiseError("could not create temporary install dir: $inst_dir");
337,21 → 374,18
}
$this->addTempFile($inst_dir);
 
if (getenv('MAKE')) {
$make_command = getenv('MAKE');
} else {
$make_command = 'make';
}
$make_command = getenv('MAKE') ? getenv('MAKE') : 'make';
 
$to_run = array(
$configure_command,
$make_command,
"$make_command INSTALL_ROOT=\"$inst_dir\" install",
"find \"$inst_dir\" -ls"
"find \"$inst_dir\" | xargs ls -dils"
);
if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) {
return $this->raiseError("could not chdir to $build_dir");
}
putenv('PHP_PEAR_VERSION=1.5.1');
putenv('PHP_PEAR_VERSION=1.10.1');
foreach ($to_run as $cmd) {
$err = $this->_runCommand($cmd, $callback);
if (PEAR::isError($err)) {
368,15 → 402,14
return $this->raiseError("no `modules' directory found");
}
$built_files = array();
$prefix = exec("php-config --prefix");
$prefix = exec($this->config->get('php_prefix')
. "php-config" .
$this->config->get('php_suffix') . " --prefix");
$this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files);
chdir($old_cwd);
return $built_files;
}
 
// }}}
// {{{ phpizeCallback()
 
/**
* Message callback function used when running the "phpize"
* program. Extracts the API numbers used. Ignores other message
410,9 → 443,6
}
}
 
// }}}
// {{{ _runCommand()
 
/**
* Run an external command, using a message callback to report
* output. The command will be run through popen and output is
451,18 → 481,12
if ($callback && isset($olddbg)) {
$callback[0]->debug = $olddbg;
}
if (is_resource($pp)) {
$exitcode = pclose($pp);
} else {
$exitcode = -1;
}
 
$exitcode = is_resource($pp) ? pclose($pp) : -1;
return ($exitcode == 0);
}
 
// }}}
// {{{ log()
 
function log($level, $msg)
function log($level, $msg, $append_crlf = true)
{
if ($this->current_callback) {
if ($this->debug >= $level) {
470,10 → 494,6
}
return;
}
return PEAR_Common::log($level, $msg);
return parent::log($level, $msg, $append_crlf);
}
 
// }}}
}
 
?>
/trunk/bibliotheque/pear/PEAR/REST/10.php
4,18 → 4,11
*
* 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: 10.php,v 1.43 2006/11/01 05:09:05 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a12
*/
31,9 → 24,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a12
*/
43,9 → 36,9
* @var PEAR_REST
*/
var $_rest;
function PEAR_REST_10($config, $options = array())
function __construct($config, $options = array())
{
$this->_rest = &new PEAR_REST($config, $options);
$this->_rest = new PEAR_REST($config, $options);
}
 
/**
65,39 → 58,40
* @param bool $installed the installed version of this package to compare against
* @return array|false|PEAR_Error see {@link _returnDownloadURL()}
*/
function getDownloadURL($base, $packageinfo, $prefstate, $installed)
function getDownloadURL($base, $packageinfo, $prefstate, $installed, $channel = false)
{
$channel = $packageinfo['channel'];
$package = $packageinfo['package'];
$states = $this->betterStates($prefstate, true);
if (!$states) {
return PEAR::raiseError('"' . $prefstate . '" is not a valid state');
}
$state = $version = null;
if (isset($packageinfo['state'])) {
$state = $packageinfo['state'];
}
if (isset($packageinfo['version'])) {
$version = $packageinfo['version'];
}
$info = $this->_rest->retrieveData($base . 'r/' . strtolower($package) . '/allreleases.xml');
 
$channel = $packageinfo['channel'];
$package = $packageinfo['package'];
$state = isset($packageinfo['state']) ? $packageinfo['state'] : null;
$version = isset($packageinfo['version']) ? $packageinfo['version'] : null;
$restFile = $base . 'r/' . strtolower($package) . '/allreleases.xml';
 
$info = $this->_rest->retrieveData($restFile, false, false, $channel);
if (PEAR::isError($info)) {
return PEAR::raiseError('No releases available for package "' .
$channel . '/' . $package . '"');
}
 
if (!isset($info['r'])) {
return false;
}
$found = false;
$release = false;
 
$release = $found = false;
if (!is_array($info['r']) || !isset($info['r'][0])) {
$info['r'] = array($info['r']);
}
 
foreach ($info['r'] as $release) {
if (!isset($this->_rest->_options['force']) && ($installed &&
version_compare($release['v'], $installed, '<'))) {
continue;
}
 
if (isset($state)) {
// try our preferred state first
if ($release['s'] == $state) {
122,38 → 116,37
}
}
}
return $this->_returnDownloadURL($base, $package, $release, $info, $found);
 
return $this->_returnDownloadURL($base, $package, $release, $info, $found, false, $channel);
}
 
function getDepDownloadURL($base, $xsdversion, $dependency, $deppackage,
$prefstate = 'stable', $installed = false)
$prefstate = 'stable', $installed = false, $channel = false)
{
$channel = $dependency['channel'];
$package = $dependency['name'];
$states = $this->betterStates($prefstate, true);
if (!$states) {
return PEAR::raiseError('"' . $prefstate . '" is not a valid state');
}
$state = $version = null;
if (isset($packageinfo['state'])) {
$state = $packageinfo['state'];
}
if (isset($packageinfo['version'])) {
$version = $packageinfo['version'];
}
$info = $this->_rest->retrieveData($base . 'r/' . strtolower($package) . '/allreleases.xml');
 
$channel = $dependency['channel'];
$package = $dependency['name'];
$state = isset($dependency['state']) ? $dependency['state'] : null;
$version = isset($dependency['version']) ? $dependency['version'] : null;
$restFile = $base . 'r/' . strtolower($package) . '/allreleases.xml';
 
$info = $this->_rest->retrieveData($restFile, false, false, $channel);
if (PEAR::isError($info)) {
return PEAR::raiseError('Package "' . $deppackage['channel'] . '/' . $deppackage['package']
. '" dependency "' . $channel . '/' . $package . '" has no releases');
}
 
if (!is_array($info) || !isset($info['r'])) {
return false;
}
 
$exclude = array();
$min = $max = $recommended = false;
if ($xsdversion == '1.0') {
$pinfo['package'] = $dependency['name'];
$pinfo['channel'] = 'pear.php.net'; // this is always true - don't change this
switch ($dependency['rel']) {
case 'ge' :
$min = $dependency['version'];
177,7 → 170,6
break;
}
} else {
$pinfo['package'] = $dependency['name'];
$min = isset($dependency['min']) ? $dependency['min'] : false;
$max = isset($dependency['max']) ? $dependency['max'] : false;
$recommended = isset($dependency['recommended']) ?
188,8 → 180,7
}
}
}
$found = false;
$release = false;
$release = $found = false;
if (!is_array($info['r']) || !isset($info['r'][0])) {
$info['r'] = array($info['r']);
}
230,7 → 221,7
if (!in_array($release['s'], $states)) {
// the stability is too low, but we must return the
// recommended version if possible
return $this->_returnDownloadURL($base, $package, $release, $info, true);
return $this->_returnDownloadURL($base, $package, $release, $info, true, false, $channel);
}
}
}
248,7 → 239,7
break;
}
}
return $this->_returnDownloadURL($base, $package, $release, $info, $found);
return $this->_returnDownloadURL($base, $package, $release, $info, $found, false, $channel);
}
 
/**
259,123 → 250,244
* @param array $release an array of format array('v' => version, 's' => state)
* describing the release to download
* @param array $info list of all releases as defined by allreleases.xml
* @param bool $found determines whether the release was found or this is the next
* best alternative
* @param bool|null $found determines whether the release was found or this is the next
* best alternative. If null, then versions were skipped because
* of PHP dependency
* @return array|PEAR_Error
* @access private
*/
function _returnDownloadURL($base, $package, $release, $info, $found)
function _returnDownloadURL($base, $package, $release, $info, $found, $phpversion = false, $channel = false)
{
if (!$found) {
$release = $info['r'][0];
}
$pinfo = $this->_rest->retrieveCacheFirst($base . 'p/' . strtolower($package) . '/' .
'info.xml');
 
$packageLower = strtolower($package);
$pinfo = $this->_rest->retrieveCacheFirst($base . 'p/' . $packageLower . '/' .
'info.xml', false, false, $channel);
if (PEAR::isError($pinfo)) {
return PEAR::raiseError('Package "' . $package .
'" does not have REST info xml available');
}
$releaseinfo = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/' .
$release['v'] . '.xml');
 
$releaseinfo = $this->_rest->retrieveCacheFirst($base . 'r/' . $packageLower . '/' .
$release['v'] . '.xml', false, false, $channel);
if (PEAR::isError($releaseinfo)) {
return PEAR::raiseError('Package "' . $package . '" Version "' . $release['v'] .
'" does not have REST xml available');
}
$packagexml = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/' .
'deps.' . $release['v'] . '.txt', false, true);
 
$packagexml = $this->_rest->retrieveCacheFirst($base . 'r/' . $packageLower . '/' .
'deps.' . $release['v'] . '.txt', false, true, $channel);
if (PEAR::isError($packagexml)) {
return PEAR::raiseError('Package "' . $package . '" Version "' . $release['v'] .
'" does not have REST dependency information available');
}
 
$packagexml = unserialize($packagexml);
if (!$packagexml) {
$packagexml = array();
}
$allinfo = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
'/allreleases.xml');
 
$allinfo = $this->_rest->retrieveData($base . 'r/' . $packageLower .
'/allreleases.xml', false, false, $channel);
if (PEAR::isError($allinfo)) {
return $allinfo;
}
 
if (!is_array($allinfo['r']) || !isset($allinfo['r'][0])) {
$allinfo['r'] = array($allinfo['r']);
}
 
$compatible = false;
foreach ($allinfo['r'] as $release) {
if ($release['v'] != $releaseinfo['v']) {
continue;
}
 
if (!isset($release['co'])) {
break;
}
 
$compatible = array();
if (!is_array($release['co']) || !isset($release['co'][0])) {
$release['co'] = array($release['co']);
}
 
foreach ($release['co'] as $entry) {
$comp = array();
$comp['name'] = $entry['p'];
$comp['name'] = $entry['p'];
$comp['channel'] = $entry['c'];
$comp['min'] = $entry['min'];
$comp['max'] = $entry['max'];
$comp['min'] = $entry['min'];
$comp['max'] = $entry['max'];
if (isset($entry['x']) && !is_array($entry['x'])) {
$comp['exclude'] = $entry['x'];
}
 
$compatible[] = $comp;
}
 
if (count($compatible) == 1) {
$compatible = $compatible[0];
}
 
break;
}
 
$deprecated = false;
if (isset($pinfo['dc']) && isset($pinfo['dp'])) {
$deprecated = array('channel' => (string) $pinfo['dc'],
'package' => trim($pinfo['dp']['_content']));
} else {
$deprecated = false;
if (is_array($pinfo['dp'])) {
$deprecated = array('channel' => (string) $pinfo['dc'],
'package' => trim($pinfo['dp']['_content']));
} else {
$deprecated = array('channel' => (string) $pinfo['dc'],
'package' => trim($pinfo['dp']));
}
}
 
$return = array(
'version' => $releaseinfo['v'],
'info' => $packagexml,
'package' => $releaseinfo['p']['_content'],
'stability' => $releaseinfo['st'],
'compatible' => $compatible,
'deprecated' => $deprecated,
);
 
if ($found) {
return
array('version' => $releaseinfo['v'],
'info' => $packagexml,
'package' => $releaseinfo['p']['_content'],
'stability' => $releaseinfo['st'],
'url' => $releaseinfo['g'],
'compatible' => $compatible,
'deprecated' => $deprecated,
);
} else {
return
array('version' => $releaseinfo['v'],
'package' => $releaseinfo['p']['_content'],
'stability' => $releaseinfo['st'],
'info' => $packagexml,
'compatible' => $compatible,
'deprecated' => $deprecated,
);
$return['url'] = $releaseinfo['g'];
return $return;
}
 
$return['php'] = $phpversion;
return $return;
}
 
function listPackages($base)
function listPackages($base, $channel = false)
{
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml');
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml', false, false, $channel);
if (PEAR::isError($packagelist)) {
return $packagelist;
}
 
if (!is_array($packagelist) || !isset($packagelist['p'])) {
return array();
}
 
if (!is_array($packagelist['p'])) {
$packagelist['p'] = array($packagelist['p']);
}
 
return $packagelist['p'];
}
 
function listAll($base, $dostable, $basic = true, $searchpackage = false, $searchsummary = false)
/**
* List all categories of a REST server
*
* @param string $base base URL of the server
* @return array of categorynames
*/
function listCategories($base, $channel = false)
{
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml');
$categories = array();
 
// c/categories.xml does not exist;
// check for every package its category manually
// This is SLOOOWWWW : ///
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml', false, false, $channel);
if (PEAR::isError($packagelist)) {
return $packagelist;
}
 
if (!is_array($packagelist) || !isset($packagelist['p'])) {
$ret = array();
return $ret;
}
 
if (!is_array($packagelist['p'])) {
$packagelist['p'] = array($packagelist['p']);
}
 
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
foreach ($packagelist['p'] as $package) {
$inf = $this->_rest->retrieveData($base . 'p/' . strtolower($package) . '/info.xml', false, false, $channel);
if (PEAR::isError($inf)) {
PEAR::popErrorHandling();
return $inf;
}
$cat = $inf['ca']['_content'];
if (!isset($categories[$cat])) {
$categories[$cat] = $inf['ca'];
}
}
 
return array_values($categories);
}
 
/**
* List a category of a REST server
*
* @param string $base base URL of the server
* @param string $category name of the category
* @param boolean $info also download full package info
* @return array of packagenames
*/
function listCategory($base, $category, $info = false, $channel = false)
{
// gives '404 Not Found' error when category doesn't exist
$packagelist = $this->_rest->retrieveData($base.'c/'.urlencode($category).'/packages.xml', false, false, $channel);
if (PEAR::isError($packagelist)) {
return $packagelist;
}
 
if (!is_array($packagelist) || !isset($packagelist['p'])) {
return array();
}
 
if (!is_array($packagelist['p']) ||
!isset($packagelist['p'][0])) { // only 1 pkg
$packagelist = array($packagelist['p']);
} else {
$packagelist = $packagelist['p'];
}
 
if ($info == true) {
// get individual package info
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
foreach ($packagelist as $i => $packageitem) {
$url = sprintf('%s'.'r/%s/latest.txt',
$base,
strtolower($packageitem['_content']));
$version = $this->_rest->retrieveData($url, false, false, $channel);
if (PEAR::isError($version)) {
break; // skipit
}
$url = sprintf('%s'.'r/%s/%s.xml',
$base,
strtolower($packageitem['_content']),
$version);
$info = $this->_rest->retrieveData($url, false, false, $channel);
if (PEAR::isError($info)) {
break; // skipit
}
$packagelist[$i]['info'] = $info;
}
PEAR::popErrorHandling();
}
 
return $packagelist;
}
 
 
function listAll($base, $dostable, $basic = true, $searchpackage = false, $searchsummary = false, $channel = false)
{
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml', false, false, $channel);
if (PEAR::isError($packagelist)) {
return $packagelist;
}
if ($this->_rest->config->get('verbose') > 0) {
$ui = &PEAR_Frontend::singleton();
$ui->log('Retrieving data...0%', false);
$ui->log('Retrieving data...0%', true);
}
$ret = array();
if (!is_array($packagelist) || !isset($packagelist['p'])) {
384,6 → 496,17
if (!is_array($packagelist['p'])) {
$packagelist['p'] = array($packagelist['p']);
}
 
// only search-packagename = quicksearch !
if ($searchpackage && (!$searchsummary || empty($searchpackage))) {
$newpackagelist = array();
foreach ($packagelist['p'] as $package) {
if (!empty($searchpackage) && stristr($package, $searchpackage) !== false) {
$newpackagelist[] = $package;
}
}
$packagelist['p'] = $newpackagelist;
}
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$next = .1;
foreach ($packagelist['p'] as $progress => $package) {
397,13 → 520,14
$next += .1;
}
}
 
if ($basic) { // remote-list command
if ($dostable) {
$latest = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
'/stable.txt');
'/stable.txt', false, false, $channel);
} else {
$latest = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
'/latest.txt');
'/latest.txt', false, false, $channel);
}
if (PEAR::isError($latest)) {
$latest = false;
410,7 → 534,7
}
$info = array('stable' => $latest);
} else { // list-all command
$inf = $this->_rest->retrieveData($base . 'p/' . strtolower($package) . '/info.xml');
$inf = $this->_rest->retrieveData($base . 'p/' . strtolower($package) . '/info.xml', false, false, $channel);
if (PEAR::isError($inf)) {
PEAR::popErrorHandling();
return $inf;
425,7 → 549,7
};
}
$releases = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
'/allreleases.xml');
'/allreleases.xml', false, false, $channel);
if (PEAR::isError($releases)) {
continue;
}
479,7 → 603,7
}
if ($latest) {
$d = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/deps.' .
$latest . '.txt');
$latest . '.txt', false, false, $channel);
if (!PEAR::isError($d)) {
$d = unserialize($d);
if ($d) {
523,109 → 647,139
return $ret;
}
 
function listLatestUpgrades($base, $state, $installed, $channel, &$reg)
function listLatestUpgrades($base, $pref_state, $installed, $channel, &$reg)
{
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml');
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml', false, false, $channel);
if (PEAR::isError($packagelist)) {
return $packagelist;
}
 
$ret = array();
if (!is_array($packagelist) || !isset($packagelist['p'])) {
return $ret;
}
 
if (!is_array($packagelist['p'])) {
$packagelist['p'] = array($packagelist['p']);
}
if ($state) {
$states = $this->betterStates($state, true);
}
 
foreach ($packagelist['p'] as $package) {
if (!isset($installed[strtolower($package)])) {
continue;
}
 
$inst_version = $reg->packageInfo($package, 'version', $channel);
$inst_state = $reg->packageInfo($package, 'release_state', $channel);
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$info = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
'/allreleases.xml');
'/allreleases.xml', false, false, $channel);
PEAR::popErrorHandling();
if (PEAR::isError($info)) {
continue; // no remote releases
}
 
if (!isset($info['r'])) {
continue;
}
$found = false;
$release = false;
 
$release = $found = false;
if (!is_array($info['r']) || !isset($info['r'][0])) {
$info['r'] = array($info['r']);
}
 
// $info['r'] is sorted by version number
usort($info['r'], array($this, '_sortReleasesByVersionNumber'));
foreach ($info['r'] as $release) {
if ($inst_version && version_compare($release['v'], $inst_version, '<=')) {
continue;
// not newer than the one installed
break;
}
if ($state) {
if (in_array($release['s'], $states)) {
 
// new version > installed version
if (!$pref_state) {
// every state is a good state
$found = true;
break;
} else {
$new_state = $release['s'];
// if new state >= installed state: go
if (in_array($new_state, $this->betterStates($inst_state, true))) {
$found = true;
break;
} else {
// only allow to lower the state of package,
// if new state >= preferred state: go
if (in_array($new_state, $this->betterStates($pref_state, true))) {
$found = true;
break;
}
}
} else {
$found = true;
break;
}
}
 
if (!$found) {
continue;
}
$relinfo = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/' .
$release['v'] . '.xml');
 
$relinfo = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/' .
$release['v'] . '.xml', false, false, $channel);
if (PEAR::isError($relinfo)) {
return $relinfo;
}
 
$ret[$package] = array(
'version' => $release['v'],
'state' => $release['s'],
'filesize' => $relinfo['f'],
);
'version' => $release['v'],
'state' => $release['s'],
'filesize' => $relinfo['f'],
);
}
 
return $ret;
}
 
function packageInfo($base, $package)
function packageInfo($base, $package, $channel = false)
{
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pinfo = $this->_rest->retrieveData($base . 'p/' . strtolower($package) . '/info.xml');
$pinfo = $this->_rest->retrieveData($base . 'p/' . strtolower($package) . '/info.xml', false, false, $channel);
if (PEAR::isError($pinfo)) {
PEAR::popErrorHandling();
return PEAR::raiseError('Unknown package: "' . $package . '" (Debug: ' .
$pinfo->getMessage() . ')');
return PEAR::raiseError('Unknown package: "' . $package . '" in channel "' . $channel . '"' . "\n". 'Debug: ' .
$pinfo->getMessage());
}
 
$releases = array();
$allreleases = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
'/allreleases.xml');
'/allreleases.xml', false, false, $channel);
if (!PEAR::isError($allreleases)) {
if (!class_exists('PEAR_PackageFile_v2')) {
require_once 'PEAR/PackageFile/v2.php';
}
 
if (!is_array($allreleases['r']) || !isset($allreleases['r'][0])) {
$allreleases['r'] = array($allreleases['r']);
}
 
$pf = new PEAR_PackageFile_v2;
foreach ($allreleases['r'] as $release) {
$ds = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/deps.' .
$release['v'] . '.txt');
$release['v'] . '.txt', false, false, $channel);
if (PEAR::isError($ds)) {
continue;
}
 
if (!isset($latest)) {
$latest = $release['v'];
}
 
$pf->setDeps(unserialize($ds));
$ds = $pf->getDeps();
$info = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package)
. '/' . $release['v'] . '.xml');
. '/' . $release['v'] . '.xml', false, false, $channel);
 
if (PEAR::isError($info)) {
continue;
}
 
$releases[$release['v']] = array(
'doneby' => $info['m'],
'license' => $info['l'],
640,13 → 794,24
} else {
$latest = '';
}
 
PEAR::popErrorHandling();
if (isset($pinfo['dc']) && isset($pinfo['dp'])) {
$deprecated = array('channel' => (string) $pinfo['dc'],
'package' => trim($pinfo['dp']['_content']));
if (is_array($pinfo['dp'])) {
$deprecated = array('channel' => (string) $pinfo['dc'],
'package' => trim($pinfo['dp']['_content']));
} else {
$deprecated = array('channel' => (string) $pinfo['dc'],
'package' => trim($pinfo['dp']));
}
} else {
$deprecated = false;
}
 
if (!isset($latest)) {
$latest = '';
}
 
return array(
'name' => $pinfo['n'],
'channel' => $pinfo['c'],
675,10 → 840,31
if ($i === false) {
return false;
}
 
if ($include) {
$i--;
}
 
return array_slice($states, $i + 1);
}
 
/**
* Sort releases by version number
*
* @access private
*/
function _sortReleasesByVersionNumber($a, $b)
{
if (version_compare($a['v'], $b['v'], '=')) {
return 0;
}
 
if (version_compare($a['v'], $b['v'], '>')) {
return -1;
}
 
if (version_compare($a['v'], $b['v'], '<')) {
return 1;
}
}
}
?>
/trunk/bibliotheque/pear/PEAR/REST/11.php
4,18 → 4,11
*
* 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: 11.php,v 1.8 2007/01/27 16:10:23 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.3
*/
31,9 → 24,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.3
*/
44,27 → 37,29
*/
var $_rest;
 
function PEAR_REST_11($config, $options = array())
function __construct($config, $options = array())
{
$this->_rest = &new PEAR_REST($config, $options);
$this->_rest = new PEAR_REST($config, $options);
}
 
function listAll($base, $dostable, $basic = true)
function listAll($base, $dostable, $basic = true, $searchpackage = false, $searchsummary = false, $channel = false)
{
$categorylist = $this->_rest->retrieveData($base . 'c/categories.xml');
$categorylist = $this->_rest->retrieveData($base . 'c/categories.xml', false, false, $channel);
if (PEAR::isError($categorylist)) {
return $categorylist;
}
 
$ret = array();
if (!is_array($categorylist['c']) || !isset($categorylist['c'][0])) {
$categorylist['c'] = array($categorylist['c']);
}
 
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
 
foreach ($categorylist['c'] as $progress => $category) {
$category = $category['_content'];
$packagesinfo = $this->_rest->retrieveData($base .
'c/' . urlencode($category) . '/packagesinfo.xml');
'c/' . urlencode($category) . '/packagesinfo.xml', false, false, $channel);
 
if (PEAR::isError($packagesinfo)) {
continue;
79,8 → 74,12
}
 
foreach ($packagesinfo['pi'] as $packageinfo) {
$info = $packageinfo['p'];
$package = $info['n'];
if (empty($packageinfo)) {
continue;
}
 
$info = $packageinfo['p'];
$package = $info['n'];
$releases = isset($packageinfo['a']) ? $packageinfo['a'] : false;
unset($latest);
unset($unstable);
91,6 → 90,7
if (!isset($releases['r'][0])) {
$releases['r'] = array($releases['r']);
}
 
foreach ($releases['r'] as $release) {
if (!isset($latest)) {
if ($dostable && $release['s'] == 'stable') {
102,6 → 102,7
$state = $release['s'];
}
}
 
if (!isset($stable) && $release['s'] == 'stable') {
$stable = $release['v'];
if (!isset($unstable)) {
108,13 → 109,16
$unstable = $stable;
}
}
 
if (!isset($unstable) && $release['s'] != 'stable') {
$latest = $unstable = $release['v'];
$unstable = $release['v'];
$state = $release['s'];
}
 
if (isset($latest) && !isset($state)) {
$state = $release['s'];
}
 
if (isset($latest) && isset($stable) && isset($unstable)) {
break;
}
125,6 → 129,7
if (!isset($latest)) {
$latest = false;
}
 
if ($dostable) {
// $state is not set if there are no releases
if (isset($state) && $state == 'stable') {
135,11 → 140,11
} else {
$ret[$package] = array('stable' => $latest);
}
 
continue;
}
 
// list-all command
$deps = array();
if (!isset($unstable)) {
$unstable = false;
$state = 'stable';
154,13 → 159,14
$latest = false;
}
 
if ($latest && $packageinfo['deps'] !== null) {
if (isset($packageinfo['deps'])) {
if (!is_array($packageinfo['deps']) ||
!isset($packageinfo['deps'][0])) {
$packageinfo['deps'] = array($packageinfo['deps']);
}
$deps = array();
if ($latest && isset($packageinfo['deps'])) {
if (!is_array($packageinfo['deps']) ||
!isset($packageinfo['deps'][0])
) {
$packageinfo['deps'] = array($packageinfo['deps']);
}
 
$d = false;
foreach ($packageinfo['deps'] as $dep) {
if ($dep['v'] == $latest) {
167,40 → 173,150
$d = unserialize($dep['d']);
}
}
 
if ($d) {
if (isset($d['required'])) {
if (!class_exists('PEAR_PackageFile_v2')) {
require_once 'PEAR/PackageFile/v2.php';
}
 
if (!isset($pf)) {
$pf = new PEAR_PackageFile_v2;
}
 
$pf->setDeps($d);
$tdeps = $pf->getDeps();
} else {
$tdeps = $d;
}
 
foreach ($tdeps as $dep) {
if ($dep['type'] !== 'pkg') {
continue;
}
 
$deps[] = $dep;
}
}
}
 
$info = array('stable' => $latest, 'summary' => $info['s'],
'description' =>
$info['d'], 'deps' => $deps, 'category' => $info['ca']['_content'],
'unstable' => $unstable, 'state' => $state);
$info = array(
'stable' => $latest,
'summary' => $info['s'],
'description' => $info['d'],
'deps' => $deps,
'category' => $info['ca']['_content'],
'unstable' => $unstable,
'state' => $state
);
$ret[$package] = $info;
}
}
 
PEAR::popErrorHandling();
return $ret;
}
 
/**
* List all categories of a REST server
*
* @param string $base base URL of the server
* @return array of categorynames
*/
function listCategories($base, $channel = false)
{
$categorylist = $this->_rest->retrieveData($base . 'c/categories.xml', false, false, $channel);
if (PEAR::isError($categorylist)) {
return $categorylist;
}
 
if (!is_array($categorylist) || !isset($categorylist['c'])) {
return array();
}
 
if (isset($categorylist['c']['_content'])) {
// only 1 category
$categorylist['c'] = array($categorylist['c']);
}
 
return $categorylist['c'];
}
 
/**
* List packages in a category of a REST server
*
* @param string $base base URL of the server
* @param string $category name of the category
* @param boolean $info also download full package info
* @return array of packagenames
*/
function listCategory($base, $category, $info = false, $channel = false)
{
if ($info == false) {
$url = '%s'.'c/%s/packages.xml';
} else {
$url = '%s'.'c/%s/packagesinfo.xml';
}
$url = sprintf($url,
$base,
urlencode($category));
 
// gives '404 Not Found' error when category doesn't exist
$packagelist = $this->_rest->retrieveData($url, false, false, $channel);
if (PEAR::isError($packagelist)) {
return $packagelist;
}
if (!is_array($packagelist)) {
return array();
}
 
if ($info == false) {
if (!isset($packagelist['p'])) {
return array();
}
if (!is_array($packagelist['p']) ||
!isset($packagelist['p'][0])) { // only 1 pkg
$packagelist = array($packagelist['p']);
} else {
$packagelist = $packagelist['p'];
}
return $packagelist;
}
 
// info == true
if (!isset($packagelist['pi'])) {
return array();
}
 
if (!is_array($packagelist['pi']) ||
!isset($packagelist['pi'][0])) { // only 1 pkg
$packagelist_pre = array($packagelist['pi']);
} else {
$packagelist_pre = $packagelist['pi'];
}
 
$packagelist = array();
foreach ($packagelist_pre as $i => $item) {
// compatibility with r/<latest.txt>.xml
if (isset($item['a']['r'][0])) {
// multiple releases
$item['p']['v'] = $item['a']['r'][0]['v'];
$item['p']['st'] = $item['a']['r'][0]['s'];
} elseif (isset($item['a'])) {
// first and only release
$item['p']['v'] = $item['a']['r']['v'];
$item['p']['st'] = $item['a']['r']['s'];
}
 
$packagelist[$i] = array('attribs' => $item['p']['r'],
'_content' => $item['p']['n'],
'info' => $item['p']);
}
 
return $packagelist;
}
 
/**
* Return an array containing all of the states that are more stable than
* or equal to the passed in state
*
221,4 → 337,4
return array_slice($states, $i + 1);
}
}
?>
?>
/trunk/bibliotheque/pear/PEAR/REST/13.php
New file
0,0 → 1,396
<?php
/**
* PEAR_REST_13
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a12
*/
 
/**
* For downloading REST xml/txt files
*/
require_once 'PEAR/REST.php';
require_once 'PEAR/REST/10.php';
 
/**
* Implement REST 1.3
*
* @category pear
* @package PEAR
* @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.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a12
*/
class PEAR_REST_13 extends PEAR_REST_10
{
/**
* Retrieve information about a remote package to be downloaded from a REST server
*
* This is smart enough to resolve the minimum PHP version dependency prior to download
* @param string $base The uri to prepend to all REST calls
* @param array $packageinfo an array of format:
* <pre>
* array(
* 'package' => 'packagename',
* 'channel' => 'channelname',
* ['state' => 'alpha' (or valid state),]
* -or-
* ['version' => '1.whatever']
* </pre>
* @param string $prefstate Current preferred_state config variable value
* @param bool $installed the installed version of this package to compare against
* @return array|false|PEAR_Error see {@link _returnDownloadURL()}
*/
function getDownloadURL($base, $packageinfo, $prefstate, $installed, $channel = false)
{
$states = $this->betterStates($prefstate, true);
if (!$states) {
return PEAR::raiseError('"' . $prefstate . '" is not a valid state');
}
 
$channel = $packageinfo['channel'];
$package = $packageinfo['package'];
$state = isset($packageinfo['state']) ? $packageinfo['state'] : null;
$version = isset($packageinfo['version']) ? $packageinfo['version'] : null;
$restFile = $base . 'r/' . strtolower($package) . '/allreleases2.xml';
 
$info = $this->_rest->retrieveData($restFile, false, false, $channel);
if (PEAR::isError($info)) {
return PEAR::raiseError('No releases available for package "' .
$channel . '/' . $package . '"');
}
 
if (!isset($info['r'])) {
return false;
}
 
$release = $found = false;
if (!is_array($info['r']) || !isset($info['r'][0])) {
$info['r'] = array($info['r']);
}
 
$skippedphp = false;
foreach ($info['r'] as $release) {
if (!isset($this->_rest->_options['force']) && ($installed &&
version_compare($release['v'], $installed, '<'))) {
continue;
}
 
if (isset($state)) {
// try our preferred state first
if ($release['s'] == $state) {
if (!isset($version) && version_compare($release['m'], phpversion(), '>')) {
// skip releases that require a PHP version newer than our PHP version
$skippedphp = $release;
continue;
}
$found = true;
break;
}
 
// see if there is something newer and more stable
// bug #7221
if (in_array($release['s'], $this->betterStates($state), true)) {
if (!isset($version) && version_compare($release['m'], phpversion(), '>')) {
// skip releases that require a PHP version newer than our PHP version
$skippedphp = $release;
continue;
}
$found = true;
break;
}
} elseif (isset($version)) {
if ($release['v'] == $version) {
if (!isset($this->_rest->_options['force']) &&
!isset($version) &&
version_compare($release['m'], phpversion(), '>')) {
// skip releases that require a PHP version newer than our PHP version
$skippedphp = $release;
continue;
}
$found = true;
break;
}
} else {
if (in_array($release['s'], $states)) {
if (version_compare($release['m'], phpversion(), '>')) {
// skip releases that require a PHP version newer than our PHP version
$skippedphp = $release;
continue;
}
$found = true;
break;
}
}
}
 
if (!$found && $skippedphp) {
$found = null;
}
 
return $this->_returnDownloadURL($base, $package, $release, $info, $found, $skippedphp, $channel);
}
 
function getDepDownloadURL($base, $xsdversion, $dependency, $deppackage,
$prefstate = 'stable', $installed = false, $channel = false)
{
$states = $this->betterStates($prefstate, true);
if (!$states) {
return PEAR::raiseError('"' . $prefstate . '" is not a valid state');
}
 
$channel = $dependency['channel'];
$package = $dependency['name'];
$state = isset($dependency['state']) ? $dependency['state'] : null;
$version = isset($dependency['version']) ? $dependency['version'] : null;
$restFile = $base . 'r/' . strtolower($package) .'/allreleases2.xml';
 
$info = $this->_rest->retrieveData($restFile, false, false, $channel);
if (PEAR::isError($info)) {
return PEAR::raiseError('Package "' . $deppackage['channel'] . '/' . $deppackage['package']
. '" dependency "' . $channel . '/' . $package . '" has no releases');
}
 
if (!is_array($info) || !isset($info['r'])) {
return false;
}
 
$exclude = array();
$min = $max = $recommended = false;
if ($xsdversion == '1.0') {
$pinfo['package'] = $dependency['name'];
$pinfo['channel'] = 'pear.php.net'; // this is always true - don't change this
switch ($dependency['rel']) {
case 'ge' :
$min = $dependency['version'];
break;
case 'gt' :
$min = $dependency['version'];
$exclude = array($dependency['version']);
break;
case 'eq' :
$recommended = $dependency['version'];
break;
case 'lt' :
$max = $dependency['version'];
$exclude = array($dependency['version']);
break;
case 'le' :
$max = $dependency['version'];
break;
case 'ne' :
$exclude = array($dependency['version']);
break;
}
} else {
$pinfo['package'] = $dependency['name'];
$min = isset($dependency['min']) ? $dependency['min'] : false;
$max = isset($dependency['max']) ? $dependency['max'] : false;
$recommended = isset($dependency['recommended']) ?
$dependency['recommended'] : false;
if (isset($dependency['exclude'])) {
if (!isset($dependency['exclude'][0])) {
$exclude = array($dependency['exclude']);
}
}
}
 
$skippedphp = $found = $release = false;
if (!is_array($info['r']) || !isset($info['r'][0])) {
$info['r'] = array($info['r']);
}
 
foreach ($info['r'] as $release) {
if (!isset($this->_rest->_options['force']) && ($installed &&
version_compare($release['v'], $installed, '<'))) {
continue;
}
 
if (in_array($release['v'], $exclude)) { // skip excluded versions
continue;
}
 
// allow newer releases to say "I'm OK with the dependent package"
if ($xsdversion == '2.0' && isset($release['co'])) {
if (!is_array($release['co']) || !isset($release['co'][0])) {
$release['co'] = array($release['co']);
}
 
foreach ($release['co'] as $entry) {
if (isset($entry['x']) && !is_array($entry['x'])) {
$entry['x'] = array($entry['x']);
} elseif (!isset($entry['x'])) {
$entry['x'] = array();
}
 
if ($entry['c'] == $deppackage['channel'] &&
strtolower($entry['p']) == strtolower($deppackage['package']) &&
version_compare($deppackage['version'], $entry['min'], '>=') &&
version_compare($deppackage['version'], $entry['max'], '<=') &&
!in_array($release['v'], $entry['x'])) {
if (version_compare($release['m'], phpversion(), '>')) {
// skip dependency releases that require a PHP version
// newer than our PHP version
$skippedphp = $release;
continue;
}
 
$recommended = $release['v'];
break;
}
}
}
 
if ($recommended) {
if ($release['v'] != $recommended) { // if we want a specific
// version, then skip all others
continue;
}
 
if (!in_array($release['s'], $states)) {
// the stability is too low, but we must return the
// recommended version if possible
return $this->_returnDownloadURL($base, $package, $release, $info, true, false, $channel);
}
}
 
if ($min && version_compare($release['v'], $min, 'lt')) { // skip too old versions
continue;
}
 
if ($max && version_compare($release['v'], $max, 'gt')) { // skip too new versions
continue;
}
 
if ($installed && version_compare($release['v'], $installed, '<')) {
continue;
}
 
if (in_array($release['s'], $states)) { // if in the preferred state...
if (version_compare($release['m'], phpversion(), '>')) {
// skip dependency releases that require a PHP version
// newer than our PHP version
$skippedphp = $release;
continue;
}
 
$found = true; // ... then use it
break;
}
}
 
if (!$found && $skippedphp) {
$found = null;
}
 
return $this->_returnDownloadURL($base, $package, $release, $info, $found, $skippedphp, $channel);
}
 
/**
* List package upgrades but take the PHP version into account.
*/
function listLatestUpgrades($base, $pref_state, $installed, $channel, &$reg)
{
$packagelist = $this->_rest->retrieveData($base . 'p/packages.xml', false, false, $channel);
if (PEAR::isError($packagelist)) {
return $packagelist;
}
 
$ret = array();
if (!is_array($packagelist) || !isset($packagelist['p'])) {
return $ret;
}
 
if (!is_array($packagelist['p'])) {
$packagelist['p'] = array($packagelist['p']);
}
 
foreach ($packagelist['p'] as $package) {
if (!isset($installed[strtolower($package)])) {
continue;
}
 
$inst_version = $reg->packageInfo($package, 'version', $channel);
$inst_state = $reg->packageInfo($package, 'release_state', $channel);
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$info = $this->_rest->retrieveData($base . 'r/' . strtolower($package) .
'/allreleases2.xml', false, false, $channel);
PEAR::popErrorHandling();
if (PEAR::isError($info)) {
continue; // no remote releases
}
 
if (!isset($info['r'])) {
continue;
}
 
$release = $found = false;
if (!is_array($info['r']) || !isset($info['r'][0])) {
$info['r'] = array($info['r']);
}
 
// $info['r'] is sorted by version number
usort($info['r'], array($this, '_sortReleasesByVersionNumber'));
foreach ($info['r'] as $release) {
if ($inst_version && version_compare($release['v'], $inst_version, '<=')) {
// not newer than the one installed
break;
}
if (version_compare($release['m'], phpversion(), '>')) {
// skip dependency releases that require a PHP version
// newer than our PHP version
continue;
}
 
// new version > installed version
if (!$pref_state) {
// every state is a good state
$found = true;
break;
} else {
$new_state = $release['s'];
// if new state >= installed state: go
if (in_array($new_state, $this->betterStates($inst_state, true))) {
$found = true;
break;
} else {
// only allow to lower the state of package,
// if new state >= preferred state: go
if (in_array($new_state, $this->betterStates($pref_state, true))) {
$found = true;
break;
}
}
}
}
 
if (!$found) {
continue;
}
 
$relinfo = $this->_rest->retrieveCacheFirst($base . 'r/' . strtolower($package) . '/' .
$release['v'] . '.xml', false, false, $channel);
if (PEAR::isError($relinfo)) {
return $relinfo;
}
 
$ret[$package] = array(
'version' => $release['v'],
'state' => $release['s'],
'filesize' => $relinfo['f'],
);
}
 
return $ret;
}
}
/trunk/bibliotheque/pear/PEAR/Command/Install.xml
26,7 → 26,7
</soft>
<nobuild>
<shortopt>B</shortopt>
<doc>don&apos;t build C extensions</doc>
<doc>don&#039;t build C extensions</doc>
</nobuild>
<nocompress>
<shortopt>Z</shortopt>
34,10 → 34,16
</nocompress>
<installroot>
<shortopt>R</shortopt>
<doc>root directory used when installing files (ala PHP&#039;s INSTALL_ROOT), use packagingroot for RPM</doc>
<arg>DIR</arg>
<doc>root directory used when installing files (ala PHP&apos;s INSTALL_ROOT)</doc>
</installroot>
<packagingroot>
<shortopt>P</shortopt>
<doc>root directory used when packaging files, like RPM packaging</doc>
<arg>DIR</arg>
</packagingroot>
<ignore-errors>
<shortopt></shortopt>
<doc>force install even if there were errors</doc>
</ignore-errors>
<alldeps>
70,7 → 76,7
package.xml. Useful for testing, or for wrapping a PEAR package in
another package manager such as RPM.
 
&quot;Package[-version/state][.tar]&quot; : queries your default channel&apos;s server
&quot;Package[-version/state][.tar]&quot; : queries your default channel&#039;s server
({config master_server}) and downloads the newest package with
the preferred quality/state ({config preferred_state}).
 
90,6 → 96,11
<function>doInstall</function>
<shortcut>up</shortcut>
<options>
<channel>
<shortopt>c</shortopt>
<doc>upgrade packages from a specific channel</doc>
<arg>CHAN</arg>
</channel>
<force>
<shortopt>f</shortopt>
<doc>overwrite newer installed packages</doc>
108,7 → 119,7
</register-only>
<nobuild>
<shortopt>B</shortopt>
<doc>don&apos;t build C extensions</doc>
<doc>don&#039;t build C extensions</doc>
</nobuild>
<nocompress>
<shortopt>Z</shortopt>
116,10 → 127,11
</nocompress>
<installroot>
<shortopt>R</shortopt>
<doc>root directory used when installing files (ala PHP&#039;s INSTALL_ROOT)</doc>
<arg>DIR</arg>
<doc>root directory used when installing files (ala PHP&apos;s INSTALL_ROOT)</doc>
</installroot>
<ignore-errors>
<shortopt></shortopt>
<doc>force install even if there were errors</doc>
</ignore-errors>
<alldeps>
151,10 → 163,15
</doc>
</upgrade>
<upgrade-all>
<summary>Upgrade All Packages</summary>
<function>doInstall</function>
<summary>Upgrade All Packages [Deprecated in favor of calling upgrade with no parameters]</summary>
<function>doUpgradeAll</function>
<shortcut>ua</shortcut>
<options>
<channel>
<shortopt>c</shortopt>
<doc>upgrade packages from a specific channel</doc>
<arg>CHAN</arg>
</channel>
<nodeps>
<shortopt>n</shortopt>
<doc>ignore dependencies, upgrade anyway</doc>
165,7 → 182,7
</register-only>
<nobuild>
<shortopt>B</shortopt>
<doc>don&apos;t build C extensions</doc>
<doc>don&#039;t build C extensions</doc>
</nobuild>
<nocompress>
<shortopt>Z</shortopt>
173,17 → 190,21
</nocompress>
<installroot>
<shortopt>R</shortopt>
<doc>root directory used when installing files (ala PHP&#039;s INSTALL_ROOT), use packagingroot for RPM</doc>
<arg>DIR</arg>
<doc>root directory used when installing files (ala PHP&apos;s INSTALL_ROOT)</doc>
</installroot>
<ignore-errors>
<shortopt></shortopt>
<doc>force install even if there were errors</doc>
</ignore-errors>
<loose>
<shortopt></shortopt>
<doc>do not check for recommended dependency version</doc>
</loose>
</options>
<doc>
WARNING: This function is deprecated in favor of using the upgrade command with no params
 
Upgrades all packages that have a newer release available. Upgrades are
done only if there is a release available of the state specified in
&quot;preferred_state&quot; (currently {config preferred_state}), or a state considered
205,10 → 226,11
</register-only>
<installroot>
<shortopt>R</shortopt>
<doc>root directory used when installing files (ala PHP&#039;s INSTALL_ROOT)</doc>
<arg>DIR</arg>
<doc>root directory used when installing files (ala PHP&apos;s INSTALL_ROOT)</doc>
</installroot>
<ignore-errors>
<shortopt></shortopt>
<doc>force install even if there were errors</doc>
</ignore-errors>
<offline>
229,8 → 251,8
<options>
<destination>
<shortopt>d</shortopt>
<doc>Optional destination directory for unpacking (defaults to current path or &quot;ext&quot; if exists)</doc>
<arg>DIR</arg>
<doc>Optional destination directory for unpacking (defaults to current path or &quot;ext&quot; if exists)</doc>
</destination>
<force>
<shortopt>f</shortopt>
/trunk/bibliotheque/pear/PEAR/Command/Test.php
4,20 → 4,13
*
* 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 Stig Bakken <ssb@php.net>
* @author Martin Jansen <mj@php.net>
* @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: Test.php,v 1.15 2007/02/17 17:51:25 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
35,9 → 28,9
* @author Stig Bakken <ssb@php.net>
* @author Martin Jansen <mj@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
44,8 → 37,6
 
class PEAR_Command_Test extends PEAR_Command_Common
{
// {{{ properties
 
var $commands = array(
'run-tests' => array(
'summary' => 'Run Regression Tests',
79,7 → 70,8
),
'phpunit' => array(
'shortopt' => 'u',
'doc' => 'Search parameters for AllTests.php, and use that to run phpunit-based tests',
'doc' => 'Search parameters for AllTests.php, and use that to run phpunit-based tests
If none is found, all .phpt tests will be tried instead.',
),
'tapoutput' => array(
'shortopt' => 't',
90,6 → 82,14
'doc' => 'CGI php executable (needed for tests with POST/GET section)',
'arg' => 'PHPCGI',
),
'coverage' => array(
'shortopt' => 'x',
'doc' => 'Generate a code coverage report (requires Xdebug 2.0.0+)',
),
'showdiff' => array(
'shortopt' => 'd',
'doc' => 'Output diff on test failure',
),
),
'doc' => '[testfile|dir ...]
Run regression tests with PHP\'s regression testing script (run-tests.php).',
98,42 → 98,33
 
var $output;
 
// }}}
// {{{ constructor
 
/**
* PEAR_Command_Test constructor.
*
* @access public
*/
function PEAR_Command_Test(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
// }}}
// {{{ doRunTests()
 
function doRunTests($command, $options, $params)
{
if (isset($options['phpunit']) && isset($options['tapoutput'])) {
return $this->raiseError('ERROR: cannot use both --phpunit and --tapoutput at the same time');
}
 
require_once 'PEAR/Common.php';
require_once 'PEAR/RunTest.php';
require_once 'System.php';
$log = new PEAR_Common;
$log->ui = &$this->ui; // slightly hacky, but it will work
$run = new PEAR_RunTest($log, $options);
$tests = array();
if (isset($options['recur'])) {
$depth = 4;
} else {
$depth = 1;
}
$depth = isset($options['recur']) ? 14 : 1;
 
if (!count($params)) {
$params[] = '.';
}
 
if (isset($options['package'])) {
$oldparams = $params;
$params = array();
143,29 → 134,30
if (PEAR::isError($pname)) {
return $this->raiseError($pname);
}
 
$package = &$reg->getPackage($pname['package'], $pname['channel']);
if (!$package) {
return PEAR::raiseError('Unknown package "' .
$reg->parsedPackageNameToString($pname) . '"');
}
 
$filelist = $package->getFilelist();
foreach ($filelist as $name => $atts) {
if (isset($atts['role']) && $atts['role'] != 'test') {
continue;
}
if (isset($options['phpunit'])) {
if (!preg_match('/AllTests\.php$/i', $name)) {
continue;
}
} else {
if (!preg_match('/\.phpt$/', $name)) {
continue;
}
 
if (isset($options['phpunit']) && preg_match('/AllTests\.php\\z/i', $name)) {
$params[] = $atts['installed_as'];
continue;
} elseif (!preg_match('/\.phpt\\z/', $name)) {
continue;
}
$params[] = $atts['installed_as'];
}
}
}
 
foreach ($params as $p) {
if (is_dir($p)) {
if (isset($options['phpunit'])) {
172,75 → 164,115
$dir = System::find(array($p, '-type', 'f',
'-maxdepth', $depth,
'-name', 'AllTests.php'));
} else {
$dir = System::find(array($p, '-type', 'f',
'-maxdepth', $depth,
'-name', '*.phpt'));
if (count($dir)) {
foreach ($dir as $p) {
$p = realpath($p);
if (!count($tests) ||
(count($tests) && strlen($p) < strlen($tests[0]))) {
// this is in a higher-level directory, use this one instead.
$tests = array($p);
}
}
}
continue;
}
$tests = array_merge($tests, $dir);
 
$args = array($p, '-type', 'f', '-name', '*.phpt');
} else {
if (isset($options['phpunit'])) {
if (!preg_match('/AllTests\.php$/i', $p)) {
continue;
}
$tests[] = $p;
} else {
if (!file_exists($p)) {
if (!preg_match('/\.phpt$/', $p)) {
$p .= '.phpt';
if (preg_match('/AllTests\.php\\z/i', $p)) {
$p = realpath($p);
if (!count($tests) ||
(count($tests) && strlen($p) < strlen($tests[0]))) {
// this is in a higher-level directory, use this one instead.
$tests = array($p);
}
$dir = System::find(array(dirname($p), '-type', 'f',
'-maxdepth', $depth,
'-name', $p));
$tests = array_merge($tests, $dir);
} else {
$tests[] = $p;
}
continue;
}
 
if (file_exists($p) && preg_match('/\.phpt$/', $p)) {
$tests[] = $p;
continue;
}
 
if (!preg_match('/\.phpt\\z/', $p)) {
$p .= '.phpt';
}
 
$args = array(dirname($p), '-type', 'f', '-name', $p);
}
 
if (!isset($options['recur'])) {
$args[] = '-maxdepth';
$args[] = 1;
}
 
$dir = System::find($args);
$tests = array_merge($tests, $dir);
}
 
$ini_settings = '';
if (isset($options['ini'])) {
$ini_settings .= $options['ini'];
}
 
if (isset($_ENV['TEST_PHP_INCLUDE_PATH'])) {
$ini_settings .= " -d include_path={$_ENV['TEST_PHP_INCLUDE_PATH']}";
}
 
if ($ini_settings) {
$this->ui->outputData('Using INI settings: "' . $ini_settings . '"');
}
 
$skipped = $passed = $failed = array();
$this->ui->outputData('Running ' . count($tests) . ' tests', $command);
$tests_count = count($tests);
$this->ui->outputData('Running ' . $tests_count . ' tests', $command);
$start = time();
if (isset($options['realtimelog'])) {
if (file_exists('run-tests.log')) {
unlink('run-tests.log');
}
if (isset($options['realtimelog']) && file_exists('run-tests.log')) {
unlink('run-tests.log');
}
 
if (isset($options['tapoutput'])) {
$tap = '1..' . count($tests) . "\n";
$tap = '1..' . $tests_count . "\n";
}
$i = 1;
 
require_once 'PEAR/RunTest.php';
$run = new PEAR_RunTest($log, $options);
$run->tests_count = $tests_count;
 
if (isset($options['coverage']) && extension_loaded('xdebug')){
$run->xdebug_loaded = true;
} else {
$run->xdebug_loaded = false;
}
 
$j = $i = 1;
foreach ($tests as $t) {
if (isset($options['realtimelog'])) {
$fp = @fopen('run-tests.log', 'a');
if ($fp) {
fwrite($fp, "Running test $t...");
fwrite($fp, "Running test [$i / $tests_count] $t...");
fclose($fp);
}
}
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$result = $run->run($t, $ini_settings);
if (isset($options['phpunit'])) {
$result = $run->runPHPUnit($t, $ini_settings);
} else {
$result = $run->run($t, $ini_settings, $j);
}
PEAR::staticPopErrorHandling();
if (PEAR::isError($result)) {
$this->ui->log($result->getMessage());
continue;
}
 
if (isset($options['tapoutput'])) {
$tap .= $result[0] . ' ' . $i . $result[1] . "\n";
$i++;
continue;
}
 
if (isset($options['realtimelog'])) {
$fp = @fopen('run-tests.log', 'a');
if ($fp) {
248,16 → 280,20
fclose($fp);
}
}
 
if ($result == 'FAILED') {
$failed[] = $t;
$failed[] = $t;
}
if ($result == 'PASSED') {
$passed[] = $t;
$passed[] = $t;
}
if ($result == 'SKIPPED') {
$skipped[] = $t;
$skipped[] = $t;
}
 
$j++;
}
 
$total = date('i:s', time() - $start);
if (isset($options['tapoutput'])) {
$fp = @fopen('run-tests.log', 'w');
272,15 → 308,14
$output = "TOTAL TIME: $total\n";
$output .= count($passed) . " PASSED TESTS\n";
$output .= count($skipped) . " SKIPPED TESTS\n";
$output .= count($failed) . " FAILED TESTS:\n";
foreach ($failed as $failure) {
$output .= $failure . "\n";
}
if (isset($options['realtimelog'])) {
$fp = @fopen('run-tests.log', 'a');
} else {
$fp = @fopen('run-tests.log', 'w');
$output .= count($failed) . " FAILED TESTS:\n";
foreach ($failed as $failure) {
$output .= $failure . "\n";
}
 
$mode = isset($options['realtimelog']) ? 'a' : 'w';
$fp = @fopen('run-tests.log', $mode);
 
if ($fp) {
fwrite($fp, $output, strlen($output));
fclose($fp);
294,15 → 329,15
$this->ui->outputData(count($passed) . ' PASSED TESTS', $command);
$this->ui->outputData(count($skipped) . ' SKIPPED TESTS', $command);
if (count($failed)) {
$this->ui->outputData(count($failed) . ' FAILED TESTS:', $command);
foreach ($failed as $failure) {
$this->ui->outputData($failure, $command);
}
$this->ui->outputData(count($failed) . ' FAILED TESTS:', $command);
foreach ($failed as $failure) {
$this->ui->outputData($failure, $command);
}
}
 
return true;
if (count($failed) == 0) {
return true;
}
return $this->raiseError('Some tests failed');
}
// }}}
}
 
?>
/trunk/bibliotheque/pear/PEAR/Command/Pickle.xml
13,20 → 13,15
<doc>Print the name of the packaged file.</doc>
</showname>
</options>
<doc>[descfile] [descfile2]
Creates a PECL package from its description file (usually called
package.xml). If a second packagefile is passed in, then
the packager will check to make sure that one is a package.xml
version 1.0, and the other is a package.xml version 2.0. The
package.xml version 1.0 will be saved as &quot;package.xml&quot; in the archive,
and the other as &quot;package2.xml&quot; in the archive&quot;
<doc>[descfile]
Creates a PECL package from its package2.xml file.
 
If no second file is passed in, and [descfile] is a package.xml 2.0,
an automatic conversion will be made to a package.xml 1.0. Note that
An automatic conversion will be made to a package.xml 1.0 and written out to
disk in the current directory as &quot;package.xml&quot;. Note that
only simple package.xml 2.0 will be converted. package.xml 2.0 with:
 
- dependency types other than required/optional PECL package/ext/php/pearinstaller
- more than one extsrcrelease/zendextsrcrelease
- more than one extsrcrelease or zendextsrcrelease
- zendextbinrelease, extbinrelease, phprelease, or bundle release type
- dependency groups
- ignore tags in release filelist
35,6 → 30,7
 
will cause pickle to fail, and output an error message. If your package2.xml
uses any of these features, you are best off using PEAR_PackageFileManager to
generate both package.xml.</doc>
generate both package.xml.
</doc>
</pickle>
</commands>
/trunk/bibliotheque/pear/PEAR/Command/Registry.xml
13,6 → 13,10
<shortopt>a</shortopt>
<doc>list installed packages from all channels</doc>
</allchannels>
<channelinfo>
<shortopt>i</shortopt>
<doc>output fully channel-aware data, even on failure</doc>
</channelinfo>
</options>
<doc>&lt;package&gt;
If invoked without parameters, this command lists the PEAR packages
/trunk/bibliotheque/pear/PEAR/Command/Test.xml
31,7 → 31,8
</package>
<phpunit>
<shortopt>u</shortopt>
<doc>Search parameters for AllTests.php, and use that to run phpunit-based tests</doc>
<doc>Search parameters for AllTests.php, and use that to run phpunit-based tests
If none is found, all .phpt tests will be tried instead.</doc>
</phpunit>
<tapoutput>
<shortopt>t</shortopt>
42,8 → 43,12
<doc>CGI php executable (needed for tests with POST/GET section)</doc>
<arg>PHPCGI</arg>
</cgi>
<coverage>
<shortopt>x</shortopt>
<doc>Generate a code coverage report (requires Xdebug 2.0.0+)</doc>
</coverage>
</options>
<doc>[testfile|dir ...]
Run regression tests with PHP&apos;s regression testing script (run-tests.php).</doc>
Run regression tests with PHP&#039;s regression testing script (run-tests.php).</doc>
</run-tests>
</commands>
/trunk/bibliotheque/pear/PEAR/Command/Common.php
4,19 → 4,12
*
* 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 Stig Bakken <ssb@php.net>
* @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.35 2006/06/08 22:25:18 pajoye Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
33,16 → 26,14
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Common extends PEAR
{
// {{{ properties
 
/**
* PEAR_Config object used to pass user system and configuration
* on when executing commands
84,25 → 75,18
'sapi' => 'SAPI backend'
);
 
// }}}
// {{{ constructor
 
/**
* PEAR_Command_Common constructor.
*
* @access public
*/
function PEAR_Command_Common(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR();
parent::__construct();
$this->config = &$config;
$this->ui = &$ui;
}
 
// }}}
 
// {{{ getCommands()
 
/**
* Return a list of all the commands defined by this class.
* @return array list of commands
114,12 → 98,10
foreach (array_keys($this->commands) as $command) {
$ret[$command] = $this->commands[$command]['summary'];
}
 
return $ret;
}
 
// }}}
// {{{ getShortcuts()
 
/**
* Return a list of all the command shortcuts defined by this class.
* @return array shortcut => command
133,12 → 115,10
$ret[$this->commands[$command]['shortcut']] = $command;
}
}
 
return $ret;
}
 
// }}}
// {{{ getOptions()
 
function getOptions($command)
{
$shortcuts = $this->getShortcuts();
145,24 → 125,23
if (isset($shortcuts[$command])) {
$command = $shortcuts[$command];
}
 
if (isset($this->commands[$command]) &&
isset($this->commands[$command]['options'])) {
return $this->commands[$command]['options'];
} else {
return null;
}
 
return null;
}
 
// }}}
// {{{ getGetoptArgs()
 
function getGetoptArgs($command, &$short_args, &$long_args)
{
$short_args = "";
$short_args = '';
$long_args = array();
if (empty($this->commands[$command]) || empty($this->commands[$command]['options'])) {
return;
}
 
reset($this->commands[$command]['options']);
while (list($option, $info) = each($this->commands[$command]['options'])) {
$larg = $sarg = '';
177,15 → 156,15
$arg = $info['arg'];
}
}
 
if (isset($info['shortopt'])) {
$short_args .= $info['shortopt'] . $sarg;
}
 
$long_args[] = $option . $larg;
}
}
 
// }}}
// {{{ getHelp()
/**
* Returns the help message for the given command
*
200,10 → 179,12
if (!isset($this->commands[$command])) {
return "No such command \"$command\"";
}
 
$help = null;
if (isset($this->commands[$command]['doc'])) {
$help = $this->commands[$command]['doc'];
}
 
if (empty($help)) {
// XXX (cox) Fallback to summary if there is no doc (show both?)
if (!isset($this->commands[$command]['summary'])) {
211,22 → 192,22
}
$help = $this->commands[$command]['summary'];
}
 
if (preg_match_all('/{config\s+([^\}]+)}/e', $help, $matches)) {
foreach($matches[0] as $k => $v) {
$help = preg_replace("/$v/", $config->get($matches[1][$k]), $help);
}
}
 
return array($help, $this->getHelpArgs($command));
}
 
// }}}
// {{{ getHelpArgs()
/**
* Returns the help for the accepted arguments of a command
*
* @param string $command
* @return string The help string
*/
* Returns the help for the accepted arguments of a command
*
* @param string $command
* @return string The help string
*/
function getHelpArgs($command)
{
if (isset($this->commands[$command]['options']) &&
246,6 → 227,7
} else {
$sapp = $lapp = "";
}
 
if (isset($v['shortopt'])) {
$s = $v['shortopt'];
$help .= " -$s$sapp, --$k$lapp\n";
252,18 → 234,18
} else {
$help .= " --$k$lapp\n";
}
 
$p = " ";
$doc = rtrim(str_replace("\n", "\n$p", $v['doc']));
$help .= " $doc\n";
}
 
return $help;
}
 
return null;
}
 
// }}}
// {{{ run()
 
function run($command, $options, $params)
{
if (empty($this->commands[$command]['function'])) {
276,6 → 258,8
$func = $this->commands[$cmd]['function'];
}
$command = $cmd;
 
//$command = $this->commands[$cmd]['function'];
break;
}
}
282,10 → 266,7
} else {
$func = $this->commands[$command]['function'];
}
 
return $this->$func($command, $options, $params);
}
 
// }}}
}
 
?>
/trunk/bibliotheque/pear/PEAR/Command/Remote.php
5,19 → 5,12
*
* 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 Stig Bakken <ssb@php.net>
* @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: Remote.php,v 1.96 2006/09/24 03:08:57 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
35,16 → 28,14
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Remote extends PEAR_Command_Common
{
// {{{ command definitions
 
var $commands = array(
'remote-info' => array(
'summary' => 'Information About Remote Packages',
58,7 → 49,12
'summary' => 'List Available Upgrades',
'function' => 'doListUpgrades',
'shortcut' => 'lu',
'options' => array(),
'options' => array(
'channelinfo' => array(
'shortopt' => 'i',
'doc' => 'output fully channel-aware data, even on failure',
),
),
'doc' => '[preferred_state]
List releases on the server of packages you have installed where
a newer version is available with the same release state (stable etc.)
90,7 → 86,15
'shortopt' => 'c',
'doc' => 'specify a channel other than the default channel',
'arg' => 'CHAN',
)
),
'allchannels' => array(
'shortopt' => 'a',
'doc' => 'search packages from all known channels',
),
'channelinfo' => array(
'shortopt' => 'i',
'doc' => 'output fully channel-aware data, even on failure',
),
),
'doc' => '[packagename] [packageinfo]
Lists all packages which match the search parameters. The first
108,7 → 112,11
'shortopt' => 'c',
'doc' => 'specify a channel other than the default channel',
'arg' => 'CHAN',
)
),
'channelinfo' => array(
'shortopt' => 'i',
'doc' => 'output fully channel-aware data, even on failure',
),
),
'doc' => '
Lists the packages available on the configured server along with the
135,27 → 143,22
'shortcut' => 'cc',
'options' => array(),
'doc' => '
Clear the XML-RPC/REST cache. See also the cache_ttl configuration
Clear the REST cache. See also the cache_ttl configuration
parameter.
',
),
);
 
// }}}
// {{{ constructor
 
/**
* PEAR_Command_Remote constructor.
*
* @access public
*/
function PEAR_Command_Remote(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
// }}}
 
function _checkChannelForStatus($channel, $chan)
{
if (PEAR::isError($chan)) {
167,18 → 170,18
}
$rest = new PEAR_REST($this->config);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$mirror = $this->config->get('preferred_mirror', null,
$channel);
$a = $rest->downloadHttp('http://' . $channel .
'/channel.xml', $chan->lastModified());
PEAR::staticPopErrorHandling();
if (!PEAR::isError($a) && $a) {
$this->ui->outputData('WARNING: channel "' . $channel . '" has ' .
'updated its protocols, use "channel-update ' . $channel .
'updated its protocols, use "' . PEAR_RUNTYPE . ' channel-update ' . $channel .
'" to update');
}
}
 
// {{{ doRemoteInfo()
 
function doRemoteInfo($command, $options, $params)
{
if (sizeof($params) != 1) {
191,7 → 194,7
if (PEAR::isError($parsed)) {
return $this->raiseError('Invalid package name "' . $package . '"');
}
 
$channel = $parsed['channel'];
$this->config->set('default_channel', $channel);
$chan = $reg->getChannel($channel);
198,18 → 201,22
if (PEAR::isError($e = $this->_checkChannelForStatus($channel, $chan))) {
return $e;
}
if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
 
$mirror = $this->config->get('preferred_mirror');
if ($chan->supportsREST($mirror) && $base = $chan->getBaseURL('REST1.0', $mirror)) {
$rest = &$this->config->getREST('1.0', array());
$info = $rest->packageInfo($base, $parsed['package']);
} else {
$r = &$this->config->getRemote();
$info = $r->call('package.info', $parsed['package']);
$info = $rest->packageInfo($base, $parsed['package'], $channel);
}
 
if (!isset($info)) {
return $this->raiseError('No supported protocol was found');
}
 
if (PEAR::isError($info)) {
$this->config->set('default_channel', $savechannel);
return $this->raiseError($info);
}
 
if (!isset($info['name'])) {
return $this->raiseError('No remote package "' . $package . '" was found');
}
226,9 → 233,6
return true;
}
 
// }}}
// {{{ doRemoteList()
 
function doRemoteList($command, $options, $params)
{
$savechannel = $channel = $this->config->get('default_channel');
235,54 → 239,55
$reg = &$this->config->getRegistry();
if (isset($options['channel'])) {
$channel = $options['channel'];
if ($reg->channelExists($channel)) {
$this->config->set('default_channel', $channel);
} else {
if (!$reg->channelExists($channel)) {
return $this->raiseError('Channel "' . $channel . '" does not exist');
}
 
$this->config->set('default_channel', $channel);
}
 
$chan = $reg->getChannel($channel);
if (PEAR::isError($e = $this->_checkChannelForStatus($channel, $chan))) {
return $e;
}
 
$list_options = false;
if ($this->config->get('preferred_state') == 'stable') {
$list_options = true;
}
 
$available = array();
if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.1', $this->config->get('preferred_mirror'))) {
$base = $chan->getBaseURL('REST1.1', $this->config->get('preferred_mirror'))
) {
// use faster list-all if available
$rest = &$this->config->getREST('1.1', array());
$available = $rest->listAll($base, $list_options);
$available = $rest->listAll($base, $list_options, true, false, false, $chan->getName());
} elseif ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
$rest = &$this->config->getREST('1.0', array());
$available = $rest->listAll($base, $list_options);
} else {
$r = &$this->config->getRemote();
if ($channel == 'pear.php.net') {
// hack because of poor pearweb design
$available = $r->call('package.listAll', true, $list_options, false);
} else {
$available = $r->call('package.listAll', true, $list_options);
}
$available = $rest->listAll($base, $list_options, true, false, false, $chan->getName());
}
 
if (PEAR::isError($available)) {
$this->config->set('default_channel', $savechannel);
return $this->raiseError($available);
}
 
$i = $j = 0;
$data = array(
'caption' => 'Channel ' . $channel . ' Available packages:',
'border' => true,
'headline' => array('Package', 'Version'),
'channel' => $channel
);
if (count($available)==0) {
 
if (count($available) == 0) {
$data = '(no packages available yet)';
} else {
foreach ($available as $name => $info) {
$data['data'][] = array($name, (isset($info['stable']) && $info['stable'])
? $info['stable'] : '-n/a-');
$version = (isset($info['stable']) && $info['stable']) ? $info['stable'] : '-n/a-';
$data['data'][] = array($name, $version);
}
}
$this->ui->outputData($data, $command);
290,9 → 295,6
return true;
}
 
// }}}
// {{{ doListAll()
 
function doListAll($command, $options, $params)
{
$savechannel = $channel = $this->config->get('default_channel');
299,47 → 301,52
$reg = &$this->config->getRegistry();
if (isset($options['channel'])) {
$channel = $options['channel'];
if ($reg->channelExists($channel)) {
$this->config->set('default_channel', $channel);
} else {
if (!$reg->channelExists($channel)) {
return $this->raiseError("Channel \"$channel\" does not exist");
}
 
$this->config->set('default_channel', $channel);
}
 
$list_options = false;
if ($this->config->get('preferred_state') == 'stable') {
$list_options = true;
}
 
$chan = $reg->getChannel($channel);
if (PEAR::isError($e = $this->_checkChannelForStatus($channel, $chan))) {
return $e;
}
 
if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.1', $this->config->get('preferred_mirror'))) {
// use faster list-all if available
$rest = &$this->config->getREST('1.1', array());
$available = $rest->listAll($base, $list_options, false);
$available = $rest->listAll($base, $list_options, false, false, false, $chan->getName());
} elseif ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
$rest = &$this->config->getREST('1.0', array());
$available = $rest->listAll($base, $list_options, false);
} else {
$r = &$this->config->getRemote();
if ($channel == 'pear.php.net') {
// hack because of poor pearweb design
$available = $r->call('package.listAll', true, $list_options, false);
} else {
$available = $r->call('package.listAll', true, $list_options);
}
$available = $rest->listAll($base, $list_options, false, false, false, $chan->getName());
}
 
if (PEAR::isError($available)) {
$this->config->set('default_channel', $savechannel);
return $this->raiseError('The package list could not be fetched from the remote server. Please try again. (Debug info: "' . $available->getMessage() . '")');
}
 
$data = array(
'caption' => 'All packages:',
'caption' => 'All packages [Channel ' . $channel . ']:',
'border' => true,
'headline' => array('Package', 'Latest', 'Local'),
'channel' => $channel,
);
 
if (isset($options['channelinfo'])) {
// add full channelinfo
$data['caption'] = 'Channel ' . $channel . ' All packages:';
$data['headline'] = array('Channel', 'Package', 'Latest', 'Local',
'Description', 'Dependencies');
}
$local_pkgs = $reg->listPackages($channel);
 
foreach ($available as $name => $info) {
373,13 → 380,39
if (isset($info['stable']) && !$info['stable']) {
$info['stable'] = null;
}
$data['data'][$info['category']][] = array(
$reg->channelAlias($channel) . '/' . $name,
isset($info['stable']) ? $info['stable'] : null,
isset($installed['version']) ? $installed['version'] : null,
isset($desc) ? $desc : null,
isset($info['deps']) ? $info['deps'] : null,
 
if (isset($options['channelinfo'])) {
// add full channelinfo
if ($info['stable'] === $info['unstable']) {
$state = $info['state'];
} else {
$state = 'stable';
}
$latest = $info['stable'].' ('.$state.')';
$local = '';
if (isset($installed['version'])) {
$inst_state = $reg->packageInfo($name, 'release_state', $channel);
$local = $installed['version'].' ('.$inst_state.')';
}
 
$packageinfo = array(
$channel,
$name,
$latest,
$local,
isset($desc) ? $desc : null,
isset($info['deps']) ? $info['deps'] : null,
);
} else {
$packageinfo = array(
$reg->channelAlias($channel) . '/' . $name,
isset($info['stable']) ? $info['stable'] : null,
isset($installed['version']) ? $installed['version'] : null,
isset($desc) ? $desc : null,
isset($info['deps']) ? $info['deps'] : null,
);
}
$data['data'][$info['category']][] = $packageinfo;
}
 
if (isset($options['mode']) && in_array($options['mode'], array('notinstalled', 'upgrades'))) {
387,6 → 420,7
$this->ui->outputData($data, $command);
return true;
}
 
foreach ($local_pkgs as $name) {
$info = &$reg->getPackage($name, $channel);
$data['data']['Local'][] = array(
403,9 → 437,6
return true;
}
 
// }}}
// {{{ doSearch()
 
function doSearch($command, $options, $params)
{
if ((!isset($params[0]) || empty($params[0]))
412,47 → 443,94
&& (!isset($params[1]) || empty($params[1])))
{
return $this->raiseError('no valid search string supplied');
};
}
 
$channelinfo = isset($options['channelinfo']);
$reg = &$this->config->getRegistry();
if (isset($options['allchannels'])) {
// search all channels
unset($options['allchannels']);
$channels = $reg->getChannels();
$errors = array();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
foreach ($channels as $channel) {
if ($channel->getName() != '__uri') {
$options['channel'] = $channel->getName();
$ret = $this->doSearch($command, $options, $params);
if (PEAR::isError($ret)) {
$errors[] = $ret;
}
}
}
 
PEAR::staticPopErrorHandling();
if (count($errors) !== 0) {
// for now, only give first error
return PEAR::raiseError($errors[0]);
}
 
return true;
}
 
$savechannel = $channel = $this->config->get('default_channel');
$reg = &$this->config->getRegistry();
$package = $params[0];
$package = strtolower($params[0]);
$summary = isset($params[1]) ? $params[1] : false;
if (isset($options['channel'])) {
$reg = &$this->config->getRegistry();
$channel = $options['channel'];
if ($reg->channelExists($channel)) {
$this->config->set('default_channel', $channel);
} else {
if (!$reg->channelExists($channel)) {
return $this->raiseError('Channel "' . $channel . '" does not exist');
}
 
$this->config->set('default_channel', $channel);
}
 
$chan = $reg->getChannel($channel);
if (PEAR::isError($e = $this->_checkChannelForStatus($channel, $chan))) {
return $e;
}
 
if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
$rest = &$this->config->getREST('1.0', array());
$available = $rest->listAll($base, false, false, $package, $summary);
} else {
$r = &$this->config->getRemote();
$available = $r->call('package.search', $package, $summary, true,
$this->config->get('preferred_state') == 'stable', true);
$available = $rest->listAll($base, false, false, $package, $summary, $chan->getName());
}
 
if (PEAR::isError($available)) {
$this->config->set('default_channel', $savechannel);
return $this->raiseError($available);
}
if (!$available) {
return $this->raiseError('no packages found that match pattern "' . $package . '"');
 
if (!$available && !$channelinfo) {
// clean exit when not found, no error !
$data = 'no packages found that match pattern "' . $package . '", for channel '.$channel.'.';
$this->ui->outputData($data);
$this->config->set('default_channel', $channel);
return true;
}
$data = array(
'caption' => 'Matched packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Package', 'Stable/(Latest)', 'Local'),
);
 
if ($channelinfo) {
$data = array(
'caption' => 'Matched packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Channel', 'Package', 'Stable/(Latest)', 'Local'),
'channel' => $channel
);
} else {
$data = array(
'caption' => 'Matched packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Package', 'Stable/(Latest)', 'Local'),
'channel' => $channel
);
}
 
if (!$available && $channelinfo) {
unset($data['headline']);
$data['data'] = 'No packages found that match pattern "' . $package . '".';
$available = array();
}
 
foreach ($available as $name => $info) {
$installed = $reg->packageInfo($name, null, $channel);
$desc = $info['summary'];
459,37 → 537,50
if (isset($params[$name]))
$desc .= "\n\n".$info['description'];
 
$unstable = '';
if ($info['unstable']) {
$unstable = '/(' . $info['unstable'] . ' ' . $info['state'] . ')';
}
if (!isset($info['stable']) || !$info['stable']) {
$info['stable'] = 'none';
$version_remote = 'none';
} else {
if ($info['unstable']) {
$version_remote = $info['unstable'];
} else {
$version_remote = $info['stable'];
}
$version_remote .= ' ('.$info['state'].')';
}
$version = is_array($installed['version']) ? $installed['version']['release'] :
$installed['version'];
$data['data'][$info['category']][] = array(
$name,
$info['stable'] . $unstable,
$version,
$desc,
if ($channelinfo) {
$packageinfo = array(
$channel,
$name,
$version_remote,
$version,
$desc,
);
} else {
$packageinfo = array(
$name,
$version_remote,
$version,
$desc,
);
}
$data['data'][$info['category']][] = $packageinfo;
}
 
$this->ui->outputData($data, $command);
$this->config->set('default_channel', $channel);
return true;
}
 
// }}}
function &getDownloader($options)
{
if (!class_exists('PEAR_Downloader')) {
require_once 'PEAR/Downloader.php';
}
$a = &new PEAR_Downloader($this->ui, $options, $this->config);
$a = new PEAR_Downloader($this->ui, $options, $this->config);
return $a;
}
// {{{ doDownload()
 
function doDownload($command, $options, $params)
{
503,7 → 594,13
// eliminate error messages for preferred_state-related errors
 
$downloader = &$this->getDownloader($options);
$downloader->setDownloadDir(getcwd());
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$e = $downloader->setDownloadDir(getcwd());
PEAR::staticPopErrorHandling();
if (PEAR::isError($e)) {
return $this->raiseError('Current directory is not writeable, cannot download');
}
 
$errors = array();
$downloaded = array();
$err = $downloader->download($params);
510,17 → 607,23
if (PEAR::isError($err)) {
return $err;
}
 
$errors = $downloader->getErrorMsgs();
if (count($errors)) {
foreach ($errors as $error) {
$this->ui->outputData($error);
if ($error !== null) {
$this->ui->outputData($error);
}
}
 
return $this->raiseError("$command failed");
}
 
$downloaded = $downloader->getDownloadedPackages();
foreach ($downloaded as $pkg) {
$this->ui->outputData("File $pkg[file] downloaded", $command);
}
 
return true;
}
 
531,9 → 634,6
}
}
 
// }}}
// {{{ doListUpgrades()
 
function doListUpgrades($command, $options, $params)
{
require_once 'PEAR/Common.php';
540,6 → 640,7
if (isset($params[0]) && !is_array(PEAR_Common::betterStates($params[0]))) {
return $this->raiseError($params[0] . ' is not a valid state (stable/beta/alpha/devel/etc.) try "pear help list-upgrades"');
}
 
$savechannel = $channel = $this->config->get('default_channel');
$reg = &$this->config->getRegistry();
foreach ($reg->listChannels() as $channel) {
547,56 → 648,66
if (!count($inst)) {
continue;
}
 
if ($channel == '__uri') {
continue;
}
 
$this->config->set('default_channel', $channel);
if (empty($params[0])) {
$state = $this->config->get('preferred_state');
} else {
$state = $params[0];
}
$state = empty($params[0]) ? $this->config->get('preferred_state') : $params[0];
 
$caption = $channel . ' Available Upgrades';
$chan = $reg->getChannel($channel);
if (PEAR::isError($e = $this->_checkChannelForStatus($channel, $chan))) {
return $e;
}
if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
$rest = &$this->config->getREST('1.0', array());
 
$latest = array();
$base2 = false;
$preferred_mirror = $this->config->get('preferred_mirror');
if ($chan->supportsREST($preferred_mirror) &&
(
($base2 = $chan->getBaseURL('REST1.3', $preferred_mirror))
|| ($base = $chan->getBaseURL('REST1.0', $preferred_mirror))
)
 
) {
if ($base2) {
$rest = &$this->config->getREST('1.3', array());
$base = $base2;
} else {
$rest = &$this->config->getREST('1.0', array());
}
 
if (empty($state) || $state == 'any') {
$state = false;
} else {
$caption .= ' (' . implode(', ', PEAR_Common::betterStates($state, true)) . ')';
}
 
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$latest = $rest->listLatestUpgrades($base, $state, $inst, $channel, $reg);
PEAR::staticPopErrorHandling();
} else {
$remote = &$this->config->getRemote();
$remote->pushErrorHandling(PEAR_ERROR_RETURN);
if (empty($state) || $state == 'any') {
$latest = $remote->call("package.listLatestReleases");
} else {
$latest = $remote->call("package.listLatestReleases", $state);
$caption .= ' (' . implode(', ', PEAR_Common::betterStates($state, true)) . ')';
}
$remote->popErrorHandling();
}
 
if (PEAR::isError($latest)) {
$this->ui->outputData($latest->getMessage());
continue;
}
 
$caption .= ':';
if (PEAR::isError($latest)) {
$this->config->set('default_channel', $savechannel);
return $latest;
}
 
$data = array(
'caption' => $caption,
'border' => 1,
'headline' => array('Channel', 'Package', 'Local', 'Remote', 'Size'),
'channel' => $channel
);
 
foreach ((array)$latest as $pkg => $info) {
$package = strtolower($pkg);
if (!isset($inst[$package])) {
603,6 → 714,7
// skip packages we don't have installed
continue;
}
 
extract($info);
$inst_version = $reg->packageInfo($package, 'version', $channel);
$inst_state = $reg->packageInfo($package, 'release_state', $channel);
610,6 → 722,7
// installed version is up-to-date
continue;
}
 
if ($filesize >= 20480) {
$filesize += 1024 - ($filesize % 1024);
$fs = sprintf("%dkB", $filesize / 1024);
619,39 → 732,53
} else {
$fs = " -"; // XXX center instead
}
 
$data['data'][] = array($channel, $pkg, "$inst_version ($inst_state)", "$version ($state)", $fs);
}
if (empty($data['data'])) {
$this->ui->outputData('Channel ' . $channel . ': No upgrades available');
 
if (isset($options['channelinfo'])) {
if (empty($data['data'])) {
unset($data['headline']);
if (count($inst) == 0) {
$data['data'] = '(no packages installed)';
} else {
$data['data'] = '(no upgrades available)';
}
}
$this->ui->outputData($data, $command);
} else {
$this->ui->outputData($data, $command);
if (empty($data['data'])) {
$this->ui->outputData('Channel ' . $channel . ': No upgrades available');
} else {
$this->ui->outputData($data, $command);
}
}
}
 
$this->config->set('default_channel', $savechannel);
return true;
}
 
// }}}
// {{{ doClearCache()
 
function doClearCache($command, $options, $params)
{
$cache_dir = $this->config->get('cache_dir');
$verbose = $this->config->get('verbose');
$verbose = $this->config->get('verbose');
$output = '';
if (!file_exists($cache_dir) || !is_dir($cache_dir)) {
return $this->raiseError("$cache_dir does not exist or is not a directory");
}
 
if (!($dp = @opendir($cache_dir))) {
return $this->raiseError("opendir($cache_dir) failed: $php_errormsg");
}
 
if ($verbose >= 1) {
$output .= "reading directory $cache_dir\n";
}
 
$num = 0;
while ($ent = readdir($dp)) {
if (preg_match('/^xmlrpc_cache_[a-z0-9]{32}$/', $ent) ||
preg_match('/rest.cache(file|id)$/', $ent)) {
if (preg_match('/rest.cache(file|id)\\z/', $ent)) {
$path = $cache_dir . DIRECTORY_SEPARATOR . $ent;
if (file_exists($path)) {
$ok = @unlink($path);
659,6 → 786,7
$ok = false;
$php_errormsg = '';
}
 
if ($ok) {
if ($verbose >= 2) {
$output .= "deleted $path\n";
669,15 → 797,13
}
}
}
 
closedir($dp);
if ($verbose >= 1) {
$output .= "$num cache entries cleared\n";
}
 
$this->ui->outputData(rtrim($output), $command);
return $num;
}
 
// }}}
}
 
?>
/trunk/bibliotheque/pear/PEAR/Command/Channels.php
6,19 → 6,12
*
* 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 Stig Bakken <ssb@php.net>
* @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: Channels.php,v 1.46 2006/07/17 18:19:25 pajoye Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
28,6 → 21,8
*/
require_once 'PEAR/Command/Common.php';
 
define('PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS', -500);
 
/**
* PEAR commands for managing channels.
*
34,16 → 29,14
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_Command_Channels extends PEAR_Command_Common
{
// {{{ properties
 
var $commands = array(
'list-channels' => array(
'summary' => 'List Available Channels',
133,28 → 126,51
'shortcut' => 'di',
'options' => array(),
'doc' => '[<channel.xml>|<channel name>]
Initialize a Channel from its server and creates the local channel.xml.
Initialize a channel from its server and create a local channel.xml.
If <channel name> is in the format "<username>:<password>@<channel>" then
<username> and <password> will be set as the login username/password for
<channel>. Use caution when passing the username/password in this way, as
it may allow other users on your computer to briefly view your username/
password via the system\'s process list.
'
),
'channel-login' => array(
'summary' => 'Connects and authenticates to remote channel server',
'shortcut' => 'cli',
'function' => 'doLogin',
'options' => array(),
'doc' => '<channel name>
Log in to a remote channel server. If <channel name> is not supplied,
the default channel is used. To use remote functions in the installer
that require any kind of privileges, you need to log in first. The
username and password you enter here will be stored in your per-user
PEAR configuration (~/.pearrc on Unix-like systems). After logging
in, your username and password will be sent along in subsequent
operations on the remote server.',
),
'channel-logout' => array(
'summary' => 'Logs out from the remote channel server',
'shortcut' => 'clo',
'function' => 'doLogout',
'options' => array(),
'doc' => '<channel name>
Logs out from a remote channel server. If <channel name> is not supplied,
the default channel is used. This command does not actually connect to the
remote server, it only deletes the stored username and password from your user
configuration.',
),
);
 
// }}}
// {{{ constructor
 
/**
* PEAR_Command_Registry constructor.
*
* @access public
*/
function PEAR_Command_Channels(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
// }}}
 
// {{{ doList()
function _sortChannels($a, $b)
{
return strnatcasecmp($a->getName(), $b->getName());
169,160 → 185,51
$data = array(
'caption' => 'Registered Channels:',
'border' => true,
'headline' => array('Channel', 'Summary')
'headline' => array('Channel', 'Alias', 'Summary')
);
foreach ($registered as $channel) {
$data['data'][] = array($channel->getName(),
$channel->getSummary());
$channel->getAlias(),
$channel->getSummary());
}
if (count($registered)==0) {
 
if (count($registered) === 0) {
$data = '(no registered channels)';
}
$this->ui->outputData($data, $command);
return true;
}
 
function doUpdateAll($command, $options, $params)
{
$reg = &$this->config->getRegistry();
$savechannel = $this->config->get('default_channel');
if (isset($options['channel'])) {
if (!$reg->channelExists($options['channel'])) {
return $this->raiseError('Unknown channel "' . $options['channel'] . '"');
}
$this->config->set('default_channel', $options['channel']);
} else {
$this->config->set('default_channel', 'pear.php.net');
}
$remote = &$this->config->getRemote();
$channels = $remote->call('channel.listAll');
if (PEAR::isError($channels)) {
$this->config->set('default_channel', $savechannel);
return $channels;
}
if (!is_array($channels) || isset($channels['faultCode'])) {
$this->config->set('default_channel', $savechannel);
return $this->raiseError("Incorrect channel listing returned from channel '$chan'");
}
if (!count($channels)) {
$data = 'no updates available';
}
$dl = &$this->getDownloader();
if (!class_exists('System')) {
require_once 'System.php';
}
$tmpdir = System::mktemp(array('-d'));
$channels = $reg->getChannels();
 
$success = true;
foreach ($channels as $channel) {
$channel = $channel[0];
$save = $channel;
if ($reg->channelExists($channel, true)) {
$this->ui->outputData("Updating channel \"$channel\"", $command);
$test = $reg->getChannel($channel, true);
if (PEAR::isError($test)) {
$this->ui->outputData("Channel '$channel' is corrupt in registry!", $command);
$lastmodified = false;
if ($channel->getName() != '__uri') {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$err = $this->doUpdate('channel-update',
$options,
array($channel->getName()));
if (PEAR::isError($err)) {
$this->ui->outputData($err->getMessage(), $command);
$success = false;
} else {
$lastmodified = $test->lastModified();
$success &= $err;
}
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$contents = $dl->downloadHttp('http://' . $test->getName() . '/channel.xml',
$this->ui, $tmpdir, null, $lastmodified);
PEAR::staticPopErrorHandling();
if (PEAR::isError($contents)) {
$this->ui->outputData('ERROR: Cannot retrieve channel.xml for channel "' .
$test->getName() . '"', $command);
continue;
}
if (!$contents) {
$this->ui->outputData("Channel \"$channel\" is up-to-date", $command);
continue;
}
list($contents, $lastmodified) = $contents;
$info = implode('', file($contents));
if (!$info) {
$this->ui->outputData("Channel \"$channel\" is up-to-date", $command);
continue;
}
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$channelinfo = new PEAR_ChannelFile;
$channelinfo->fromXmlString($info);
if ($channelinfo->getErrors()) {
$this->ui->outputData("Downloaded channel data from channel \"$channel\" " .
'is corrupt, skipping', $command);
continue;
}
$channel = $channelinfo;
if ($channel->getName() != $save) {
$this->ui->outputData('ERROR: Security risk - downloaded channel ' .
'definition file for channel "'
. $channel->getName() . ' from channel "' . $save .
'". To use anyway, use channel-update', $command);
continue;
}
$reg->updateChannel($channel, $lastmodified);
} else {
if ($reg->isAlias($channel)) {
$temp = &$reg->getChannel($channel);
if (PEAR::isError($temp)) {
return $this->raiseError($temp);
}
$temp->setAlias($temp->getName(), true); // set the alias to the channel name
if ($reg->channelExists($temp->getName())) {
$this->ui->outputData('ERROR: existing channel "' . $temp->getName() .
'" is aliased to "' . $channel . '" already and cannot be ' .
're-aliased to "' . $temp->getName() . '" because a channel with ' .
'that name or alias already exists! Please re-alias and try ' .
'again.', $command);
continue;
}
}
$this->ui->outputData("Adding new channel \"$channel\"", $command);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$contents = $dl->downloadHttp('http://' . $channel . '/channel.xml',
$this->ui, $tmpdir, null, false);
PEAR::staticPopErrorHandling();
if (PEAR::isError($contents)) {
$this->ui->outputData('ERROR: Cannot retrieve channel.xml for channel "' .
$channel . '"', $command);
continue;
}
list($contents, $lastmodified) = $contents;
$info = implode('', file($contents));
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$channelinfo = new PEAR_Channelfile;
$channelinfo->fromXmlString($info);
if ($channelinfo->getErrors()) {
$this->ui->outputData("Downloaded channel data from channel \"$channel\"" .
' is corrupt, skipping', $command);
continue;
}
$channel = $channelinfo;
if ($channel->getName() != $save) {
$this->ui->outputData('ERROR: Security risk - downloaded channel ' .
'definition file for channel "'
. $channel->getName() . '" from channel "' . $save .
'". To use anyway, use channel-update', $command);
continue;
}
$reg->addChannel($channel, $lastmodified);
}
}
$this->config->set('default_channel', $savechannel);
$this->ui->outputData('update-channels complete', $command);
return true;
return $success;
}
 
function doInfo($command, $options, $params)
{
if (sizeof($params) != 1) {
if (count($params) !== 1) {
return $this->raiseError("No channel specified");
}
$reg = &$this->config->getRegistry();
 
$reg = &$this->config->getRegistry();
$channel = strtolower($params[0]);
if ($reg->channelExists($channel)) {
$chan = $reg->getChannel($channel);
332,27 → 239,26
} else {
if (strpos($channel, '://')) {
$downloader = &$this->getDownloader();
if (!class_exists('System')) {
require_once 'System.php';
}
$tmpdir = System::mktemp(array('-d'));
$tmpdir = $this->config->get('temp_dir');
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$loc = $downloader->downloadHttp($channel, $this->ui, $tmpdir);
PEAR::staticPopErrorHandling();
if (PEAR::isError($loc)) {
return $this->raiseError('Cannot open "' . $channel . '"');
return $this->raiseError('Cannot open "' . $channel .
'" (' . $loc->getMessage() . ')');
} else {
$contents = implode('', file($loc));
}
} else {
if (file_exists($params[0])) {
$fp = fopen($params[0], 'r');
if (!$fp) {
return $this->raiseError('Cannot open "' . $params[0] . '"');
}
} else {
if (!file_exists($params[0])) {
return $this->raiseError('Unknown channel "' . $channel . '"');
}
 
$fp = fopen($params[0], 'r');
if (!$fp) {
return $this->raiseError('Cannot open "' . $params[0] . '"');
}
 
$contents = '';
while (!feof($fp)) {
$contents .= fread($fp, 1024);
359,9 → 265,11
}
fclose($fp);
}
 
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$chan = new PEAR_ChannelFile;
$chan->fromXmlString($contents);
$chan->validate();
372,147 → 280,123
return $this->raiseError('Channel file "' . $params[0] . '" is not valid');
}
}
if ($chan) {
$channel = $chan->getName();
$caption = 'Channel ' . $channel . ' Information:';
$data1 = array(
'caption' => $caption,
'border' => true);
$data1['data']['server'] = array('Name and Server', $chan->getName());
if ($chan->getAlias() != $chan->getName()) {
$data1['data']['alias'] = array('Alias', $chan->getAlias());
}
$data1['data']['summary'] = array('Summary', $chan->getSummary());
$validate = $chan->getValidationPackage();
$data1['data']['vpackage'] = array('Validation Package Name', $validate['_content']);
$data1['data']['vpackageversion'] =
array('Validation Package Version', $validate['attribs']['version']);
$d = array();
$d['main'] = $data1;
 
$data['data'] = array();
$data['caption'] = 'Server Capabilities';
$data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
$capabilities = $chan->getFunctions('xmlrpc');
$soaps = $chan->getFunctions('soap');
if ($capabilities || $soaps || $chan->supportsREST()) {
if ($capabilities) {
if (!isset($capabilities[0])) {
$capabilities = array($capabilities);
}
foreach ($capabilities as $protocol) {
$data['data'][] = array('xmlrpc', $protocol['attribs']['version'],
$protocol['_content']);
}
if (!$chan) {
return $this->raiseError('Serious error: Channel "' . $params[0] .
'" has a corrupted registry entry');
}
 
$channel = $chan->getName();
$caption = 'Channel ' . $channel . ' Information:';
$data1 = array(
'caption' => $caption,
'border' => true);
$data1['data']['server'] = array('Name and Server', $chan->getName());
if ($chan->getAlias() != $chan->getName()) {
$data1['data']['alias'] = array('Alias', $chan->getAlias());
}
 
$data1['data']['summary'] = array('Summary', $chan->getSummary());
$validate = $chan->getValidationPackage();
$data1['data']['vpackage'] = array('Validation Package Name', $validate['_content']);
$data1['data']['vpackageversion'] =
array('Validation Package Version', $validate['attribs']['version']);
$d = array();
$d['main'] = $data1;
 
$data['data'] = array();
$data['caption'] = 'Server Capabilities';
$data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
if ($chan->supportsREST()) {
if ($chan->supportsREST()) {
$funcs = $chan->getFunctions('rest');
if (!isset($funcs[0])) {
$funcs = array($funcs);
}
if ($soaps) {
if (!isset($soaps[0])) {
$soaps = array($soaps);
}
foreach ($soaps as $protocol) {
$data['data'][] = array('soap', $protocol['attribs']['version'],
$protocol['_content']);
}
foreach ($funcs as $protocol) {
$data['data'][] = array('rest', $protocol['attribs']['type'],
$protocol['_content']);
}
if ($chan->supportsREST()) {
$funcs = $chan->getFunctions('rest');
if (!isset($funcs[0])) {
$funcs = array($funcs);
}
foreach ($funcs as $protocol) {
$data['data'][] = array('rest', $protocol['attribs']['type'],
$protocol['_content']);
}
}
} else {
$data['data'][] = array('No supported protocols');
}
$d['protocols'] = $data;
$data['data'] = array();
$mirrors = $chan->getMirrors();
if ($mirrors) {
$data['caption'] = 'Channel ' . $channel . ' Mirrors:';
unset($data['headline']);
foreach ($mirrors as $mirror) {
$data['data'][] = array($mirror['attribs']['host']);
$d['mirrors'] = $data;
}
foreach ($mirrors as $mirror) {
$data['data'] = array();
$data['caption'] = 'Mirror ' . $mirror['attribs']['host'] . ' Capabilities';
$data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
$capabilities = $chan->getFunctions('xmlrpc', $mirror['attribs']['host']);
$soaps = $chan->getFunctions('soap', $mirror['attribs']['host']);
if ($capabilities || $soaps || $chan->supportsREST($mirror['attribs']['host'])) {
if ($capabilities) {
if (!isset($capabilities[0])) {
$capabilities = array($capabilities);
}
foreach ($capabilities as $protocol) {
$data['data'][] = array('xmlrpc', $protocol['attribs']['version'],
$protocol['_content']);
}
} else {
$data['data'][] = array('No supported protocols');
}
 
$d['protocols'] = $data;
$data['data'] = array();
$mirrors = $chan->getMirrors();
if ($mirrors) {
$data['caption'] = 'Channel ' . $channel . ' Mirrors:';
unset($data['headline']);
foreach ($mirrors as $mirror) {
$data['data'][] = array($mirror['attribs']['host']);
$d['mirrors'] = $data;
}
 
foreach ($mirrors as $i => $mirror) {
$data['data'] = array();
$data['caption'] = 'Mirror ' . $mirror['attribs']['host'] . ' Capabilities';
$data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
if ($chan->supportsREST($mirror['attribs']['host'])) {
if ($chan->supportsREST($mirror['attribs']['host'])) {
$funcs = $chan->getFunctions('rest', $mirror['attribs']['host']);
if (!isset($funcs[0])) {
$funcs = array($funcs);
}
if ($soaps) {
if (!isset($soaps[0])) {
$soaps = array($soaps);
}
foreach ($soaps as $protocol) {
$data['data'][] = array('soap', $protocol['attribs']['version'],
$protocol['_content']);
}
 
foreach ($funcs as $protocol) {
$data['data'][] = array('rest', $protocol['attribs']['type'],
$protocol['_content']);
}
if ($chan->supportsREST($mirror['attribs']['host'])) {
$funcs = $chan->getFunctions('rest', $mirror['attribs']['host']);
if (!isset($funcs[0])) {
$funcs = array($funcs);
}
foreach ($funcs as $protocol) {
$data['data'][] = array('rest', $protocol['attribs']['type'],
$protocol['_content']);
}
}
} else {
$data['data'][] = array('No supported protocols');
}
$d['mirrorprotocols'] = $data;
} else {
$data['data'][] = array('No supported protocols');
}
$d['mirrorprotocols' . $i] = $data;
}
$this->ui->outputData($d, 'channel-info');
} else {
return $this->raiseError('Serious error: Channel "' . $params[0] .
'" has a corrupted registry entry');
}
$this->ui->outputData($d, 'channel-info');
}
 
// }}}
 
function doDelete($command, $options, $params)
{
if (sizeof($params) != 1) {
if (count($params) !== 1) {
return $this->raiseError('channel-delete: no channel specified');
}
 
$reg = &$this->config->getRegistry();
if (!$reg->channelExists($params[0])) {
return $this->raiseError('channel-delete: channel "' . $params[0] . '" does not exist');
}
 
$channel = $reg->channelName($params[0]);
if ($channel == 'pear.php.net') {
return $this->raiseError('Cannot delete the pear.php.net channel');
}
 
if ($channel == 'pecl.php.net') {
return $this->raiseError('Cannot delete the pecl.php.net channel');
}
 
if ($channel == 'doc.php.net') {
return $this->raiseError('Cannot delete the doc.php.net channel');
}
 
if ($channel == '__uri') {
return $this->raiseError('Cannot delete the __uri pseudo-channel');
}
 
if (PEAR::isError($err = $reg->listPackages($channel))) {
return $err;
}
 
if (count($err)) {
return $this->raiseError('Channel "' . $channel .
'" has installed packages, cannot delete');
}
 
if (!$reg->deleteChannel($channel)) {
return $this->raiseError('Channel "' . $channel . '" deletion failed');
} else {
523,32 → 407,51
 
function doAdd($command, $options, $params)
{
if (sizeof($params) != 1) {
if (count($params) !== 1) {
return $this->raiseError('channel-add: no channel file specified');
}
 
if (strpos($params[0], '://')) {
$downloader = &$this->getDownloader();
if (!class_exists('System')) {
$tmpdir = $this->config->get('temp_dir');
if (!file_exists($tmpdir)) {
require_once 'System.php';
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$err = System::mkdir(array('-p', $tmpdir));
PEAR::staticPopErrorHandling();
if (PEAR::isError($err)) {
return $this->raiseError('channel-add: temp_dir does not exist: "' .
$tmpdir .
'" - You can change this location with "pear config-set temp_dir"');
}
}
$tmpdir = System::mktemp(array('-d'));
 
if (!is_writable($tmpdir)) {
return $this->raiseError('channel-add: temp_dir is not writable: "' .
$tmpdir .
'" - You can change this location with "pear config-set temp_dir"');
}
 
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$loc = $downloader->downloadHttp($params[0], $this->ui, $tmpdir, null, false);
PEAR::staticPopErrorHandling();
if (PEAR::isError($loc)) {
return $this->raiseError('channel-add: Cannot open "' . $params[0] . '"');
} else {
list($loc, $lastmodified) = $loc;
$contents = implode('', file($loc));
return $this->raiseError('channel-add: Cannot open "' . $params[0] .
'" (' . $loc->getMessage() . ')');
}
 
list($loc, $lastmodified) = $loc;
$contents = implode('', file($loc));
} else {
$lastmodified = $fp = false;
if (file_exists($params[0])) {
$fp = fopen($params[0], 'r');
}
 
if (!$fp) {
return $this->raiseError('channel-add: cannot open "' . $params[0] . '"');
}
 
$contents = '';
while (!feof($fp)) {
$contents .= fread($fp, 1024);
555,9 → 458,11
}
fclose($fp);
}
 
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$channel = new PEAR_ChannelFile;
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$result = $channel->fromXmlString($contents);
576,19 → 481,23
}
}
}
 
$reg = &$this->config->getRegistry();
if ($reg->channelExists($channel->getName())) {
return $this->raiseError('channel-add: Channel "' . $channel->getName() .
'" exists, use channel-update to update entry');
'" exists, use channel-update to update entry', PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS);
}
 
$ret = $reg->addChannel($channel, $lastmodified);
if (PEAR::isError($ret)) {
return $ret;
}
 
if (!$ret) {
return $this->raiseError('channel-add: adding Channel "' . $channel->getName() .
'" to registry failed');
}
 
$this->config->setChannels($reg->listChannels());
$this->config->writeConfigFile();
$this->ui->outputData('Adding Channel "' . $channel->getName() . '" succeeded', $command);
596,14 → 505,30
 
function doUpdate($command, $options, $params)
{
if (!class_exists('System')) {
if (count($params) !== 1) {
return $this->raiseError("No channel file specified");
}
 
$tmpdir = $this->config->get('temp_dir');
if (!file_exists($tmpdir)) {
require_once 'System.php';
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$err = System::mkdir(array('-p', $tmpdir));
PEAR::staticPopErrorHandling();
if (PEAR::isError($err)) {
return $this->raiseError('channel-add: temp_dir does not exist: "' .
$tmpdir .
'" - You can change this location with "pear config-set temp_dir"');
}
}
$tmpdir = System::mktemp(array('-d'));
 
if (!is_writable($tmpdir)) {
return $this->raiseError('channel-add: temp_dir is not writable: "' .
$tmpdir .
'" - You can change this location with "pear config-set temp_dir"');
}
 
$reg = &$this->config->getRegistry();
if (sizeof($params) != 1) {
return $this->raiseError("No channel file specified");
}
$lastmodified = false;
if ((!file_exists($params[0]) || is_dir($params[0]))
&& $reg->channelExists(strtolower($params[0]))) {
611,7 → 536,8
if (PEAR::isError($c)) {
return $this->raiseError($c);
}
$this->ui->outputData('Retrieving channel.xml from remote server');
 
$this->ui->outputData("Updating channel \"$params[0]\"", $command);
$dl = &$this->getDownloader(array());
// if force is specified, use a timestamp of "1" to force retrieval
$lastmodified = isset($options['force']) ? false : $c->lastModified();
620,32 → 546,44
$this->ui, $tmpdir, null, $lastmodified);
PEAR::staticPopErrorHandling();
if (PEAR::isError($contents)) {
return $this->raiseError('Cannot retrieve channel.xml for channel "' .
$c->getName() . '"');
// Attempt to fall back to https
$this->ui->outputData("Channel \"$params[0]\" is not responding over http://, failed with message: " . $contents->getMessage());
$this->ui->outputData("Trying channel \"$params[0]\" over https:// instead");
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$contents = $dl->downloadHttp('https://' . $c->getName() . '/channel.xml',
$this->ui, $tmpdir, null, $lastmodified);
PEAR::staticPopErrorHandling();
if (PEAR::isError($contents)) {
return $this->raiseError('Cannot retrieve channel.xml for channel "' .
$c->getName() . '" (' . $contents->getMessage() . ')');
}
}
 
list($contents, $lastmodified) = $contents;
if (!$contents) {
$this->ui->outputData("Channel $params[0] channel.xml is up to date");
$this->ui->outputData("Channel \"$params[0]\" is up to date");
return;
}
 
$contents = implode('', file($contents));
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$channel = new PEAR_ChannelFile;
$channel->fromXmlString($contents);
if (!$channel->getErrors()) {
// security check: is the downloaded file for the channel we got it from?
if (strtolower($channel->getName()) != strtolower($c->getName())) {
if (isset($options['force'])) {
$this->ui->log(0, 'WARNING: downloaded channel definition file' .
' for channel "' . $channel->getName() . '" from channel "' .
strtolower($c->getName()) . '"');
} else {
if (!isset($options['force'])) {
return $this->raiseError('ERROR: downloaded channel definition file' .
' for channel "' . $channel->getName() . '" from channel "' .
strtolower($c->getName()) . '"');
}
 
$this->ui->log(0, 'WARNING: downloaded channel definition file' .
' for channel "' . $channel->getName() . '" from channel "' .
strtolower($c->getName()) . '"');
}
}
} else {
656,19 → 594,22
$this->ui, $tmpdir, null, $lastmodified);
PEAR::staticPopErrorHandling();
if (PEAR::isError($loc)) {
return $this->raiseError("Cannot open " . $params[0]);
} else {
list($loc, $lastmodified) = $loc;
$contents = implode('', file($loc));
return $this->raiseError("Cannot open " . $params[0] .
' (' . $loc->getMessage() . ')');
}
 
list($loc, $lastmodified) = $loc;
$contents = implode('', file($loc));
} else {
$fp = false;
if (file_exists($params[0])) {
$fp = fopen($params[0], 'r');
}
 
if (!$fp) {
return $this->raiseError("Cannot open " . $params[0]);
}
 
$contents = '';
while (!feof($fp)) {
$contents .= fread($fp, 1024);
675,12 → 616,15
}
fclose($fp);
}
 
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$channel = new PEAR_ChannelFile;
$channel->fromXmlString($contents);
}
 
$exit = false;
if (count($errors = $channel->getErrors(true))) {
foreach ($errors as $error) {
693,18 → 637,22
return $this->raiseError('Invalid channel.xml file');
}
}
 
if (!$reg->channelExists($channel->getName())) {
return $this->raiseError('Error: Channel "' . $channel->getName() .
'" does not exist, use channel-add to add an entry');
}
 
$ret = $reg->updateChannel($channel, $lastmodified);
if (PEAR::isError($ret)) {
return $ret;
}
 
if (!$ret) {
return $this->raiseError('Updating Channel "' . $channel->getName() .
'" in registry failed');
}
 
$this->config->setChannels($reg->listChannels());
$this->config->writeConfigFile();
$this->ui->outputData('Update of Channel "' . $channel->getName() . '" succeeded');
721,65 → 669,214
 
function doAlias($command, $options, $params)
{
$reg = &$this->config->getRegistry();
if (sizeof($params) == 1) {
if (count($params) === 1) {
return $this->raiseError('No channel alias specified');
}
if (sizeof($params) != 2) {
 
if (count($params) !== 2 || (!empty($params[1]) && $params[1]{0} == '-')) {
return $this->raiseError(
'Invalid format, correct is: channel-alias channel alias');
}
 
$reg = &$this->config->getRegistry();
if (!$reg->channelExists($params[0], true)) {
$extra = '';
if ($reg->isAlias($params[0])) {
$extra = ' (use "channel-alias ' . $reg->channelName($params[0]) . ' ' .
strtolower($params[1]) . '")';
} else {
$extra = '';
}
 
return $this->raiseError('"' . $params[0] . '" is not a valid channel' . $extra);
}
 
if ($reg->isAlias($params[1])) {
return $this->raiseError('Channel "' . $reg->channelName($params[1]) . '" is ' .
'already aliased to "' . strtolower($params[1]) . '", cannot re-alias');
}
$chan = &$reg->getChannel($params[0]);
 
$chan = $reg->getChannel($params[0]);
if (PEAR::isError($chan)) {
return $this->raiseError('Corrupt registry? Error retrieving channel "' . $params[0] .
'" information (' . $chan->getMessage() . ')');
}
 
// make it a local alias
if (!$chan->setAlias(strtolower($params[1]), true)) {
return $this->raiseError('Alias "' . strtolower($params[1]) .
'" is not a valid channel alias');
}
 
$reg->updateChannel($chan);
$this->ui->outputData('Channel "' . $chan->getName() . '" aliased successfully to "' .
strtolower($params[1]) . '"');
}
 
/**
* The channel-discover command
*
* @param string $command command name
* @param array $options option_name => value
* @param array $params list of additional parameters.
* $params[0] should contain a string with either:
* - <channel name> or
* - <username>:<password>@<channel name>
* @return null|PEAR_Error
*/
function doDiscover($command, $options, $params)
{
$reg = &$this->config->getRegistry();
if (sizeof($params) != 1) {
if (count($params) !== 1) {
return $this->raiseError("No channel server specified");
}
if ($reg->channelExists($params[0])) {
if ($reg->isAlias($params[0])) {
return $this->raiseError("A channel alias named \"$params[0]\" " .
'already exists, aliasing channel "' . $reg->channelName($params[0])
. '"');
} else {
return $this->raiseError("Channel \"$params[0]\" is already initialized");
 
// Look for the possible input format "<username>:<password>@<channel>"
if (preg_match('/^(.+):(.+)@(.+)\\z/', $params[0], $matches)) {
$username = $matches[1];
$password = $matches[2];
$channel = $matches[3];
} else {
$channel = $params[0];
}
 
$reg = &$this->config->getRegistry();
if ($reg->channelExists($channel)) {
if (!$reg->isAlias($channel)) {
return $this->raiseError("Channel \"$channel\" is already initialized", PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS);
}
 
return $this->raiseError("A channel alias named \"$channel\" " .
'already exists, aliasing channel "' . $reg->channelName($channel)
. '"');
}
 
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$err = $this->doAdd($command, $options, array('http://' . $params[0] . '/channel.xml'));
$err = $this->doAdd($command, $options, array('http://' . $channel . '/channel.xml'));
$this->popErrorHandling();
if (PEAR::isError($err)) {
return $this->raiseError("Discovery of channel \"$params[0]\" failed (" .
$err->getMessage() . ')');
if ($err->getCode() === PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS) {
return $this->raiseError("Discovery of channel \"$channel\" failed (" .
$err->getMessage() . ')');
}
// Attempt fetch via https
$this->ui->outputData("Discovering channel $channel over http:// failed with message: " . $err->getMessage());
$this->ui->outputData("Trying to discover channel $channel over https:// instead");
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$err = $this->doAdd($command, $options, array('https://' . $channel . '/channel.xml'));
$this->popErrorHandling();
if (PEAR::isError($err)) {
return $this->raiseError("Discovery of channel \"$channel\" failed (" .
$err->getMessage() . ')');
}
}
$this->ui->outputData("Discovery of channel \"$params[0]\" succeeded", $command);
 
// Store username/password if they were given
// Arguably we should do a logintest on the channel here, but since
// that's awkward on a REST-based channel (even "pear login" doesn't
// do it for those), and XML-RPC is deprecated, it's fairly pointless.
if (isset($username)) {
$this->config->set('username', $username, 'user', $channel);
$this->config->set('password', $password, 'user', $channel);
$this->config->store();
$this->ui->outputData("Stored login for channel \"$channel\" using username \"$username\"", $command);
}
 
$this->ui->outputData("Discovery of channel \"$channel\" succeeded", $command);
}
 
/**
* Execute the 'login' command.
*
* @param string $command command name
* @param array $options option_name => value
* @param array $params list of additional parameters
*
* @return bool TRUE on success or
* a PEAR error on failure
*
* @access public
*/
function doLogin($command, $options, $params)
{
$reg = &$this->config->getRegistry();
 
// If a parameter is supplied, use that as the channel to log in to
$channel = isset($params[0]) ? $params[0] : $this->config->get('default_channel');
 
$chan = $reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $this->raiseError($chan);
}
 
$server = $this->config->get('preferred_mirror', null, $channel);
$username = $this->config->get('username', null, $channel);
if (empty($username)) {
$username = isset($_ENV['USER']) ? $_ENV['USER'] : null;
}
$this->ui->outputData("Logging in to $server.", $command);
 
list($username, $password) = $this->ui->userDialog(
$command,
array('Username', 'Password'),
array('text', 'password'),
array($username, '')
);
$username = trim($username);
$password = trim($password);
 
$ourfile = $this->config->getConfFile('user');
if (!$ourfile) {
$ourfile = $this->config->getConfFile('system');
}
 
$this->config->set('username', $username, 'user', $channel);
$this->config->set('password', $password, 'user', $channel);
 
if ($chan->supportsREST()) {
$ok = true;
}
 
if ($ok !== true) {
return $this->raiseError('Login failed!');
}
 
$this->ui->outputData("Logged in.", $command);
// avoid changing any temporary settings changed with -d
$ourconfig = new PEAR_Config($ourfile, $ourfile);
$ourconfig->set('username', $username, 'user', $channel);
$ourconfig->set('password', $password, 'user', $channel);
$ourconfig->store();
 
return true;
}
 
/**
* Execute the 'logout' command.
*
* @param string $command command name
* @param array $options option_name => value
* @param array $params list of additional parameters
*
* @return bool TRUE on success or
* a PEAR error on failure
*
* @access public
*/
function doLogout($command, $options, $params)
{
$reg = &$this->config->getRegistry();
 
// If a parameter is supplied, use that as the channel to log in to
$channel = isset($params[0]) ? $params[0] : $this->config->get('default_channel');
 
$chan = $reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $this->raiseError($chan);
}
 
$server = $this->config->get('preferred_mirror', null, $channel);
$this->ui->outputData("Logging out from $server.", $command);
$this->config->remove('username', 'user', $channel);
$this->config->remove('password', 'user', $channel);
$this->config->store();
return true;
}
}
?>
/trunk/bibliotheque/pear/PEAR/Command/Package.php
5,20 → 5,13
*
* 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 Stig Bakken <ssb@php.net>
* @author Martin Jansen <mj@php.net>
* @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: Package.php,v 1.122 2006/06/07 23:38:14 pajoye Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
36,9 → 29,9
* @author Stig Bakken <ssb@php.net>
* @author Martin Jansen <mj@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
45,8 → 38,6
 
class PEAR_Command_Package extends PEAR_Command_Common
{
// {{{ properties
 
var $commands = array(
'package' => array(
'summary' => 'Build Package',
142,6 → 133,39
of a specific release.
',
),
'svntag' => array(
'summary' => 'Set SVN Release Tag',
'function' => 'doSvnTag',
'shortcut' => 'sv',
'options' => array(
'quiet' => array(
'shortopt' => 'q',
'doc' => 'Be quiet',
),
'slide' => array(
'shortopt' => 'F',
'doc' => 'Move (slide) tag if it exists',
),
'delete' => array(
'shortopt' => 'd',
'doc' => 'Remove tag',
),
'dry-run' => array(
'shortopt' => 'n',
'doc' => 'Don\'t do anything, just pretend',
),
),
'doc' => '<package.xml> [files...]
Sets a SVN tag on all files in a package. Use this command after you have
packaged a distribution tarball with the "package" command to tag what
revisions of what files were in that release. If need to fix something
after running svntag once, but before the tarball is released to the public,
use the "slide" option to move the release tag.
 
to include files (such as a second package.xml, or tests not included in the
release), pass them as additional parameters.
',
),
'cvstag' => array(
'summary' => 'Set CVS Release Tag',
'function' => 'doCvsTag',
184,14 → 208,20
'function' => 'doPackageDependencies',
'shortcut' => 'pd',
'options' => array(),
'doc' => '
List all dependencies the package has.'
'doc' => '<package-file> or <package.xml> or <install-package-name>
List all dependencies the package has.
Can take a tgz / tar file, package.xml or a package name of an installed package.'
),
'sign' => array(
'summary' => 'Sign a package distribution file',
'function' => 'doSign',
'shortcut' => 'si',
'options' => array(),
'options' => array(
'verbose' => array(
'shortopt' => 'v',
'doc' => 'Display GnuPG output',
),
),
'doc' => '<package-file>
Signs a package distribution (.tar or .tgz) file with GnuPG.',
),
247,23 → 277,16
 
var $output;
 
// }}}
// {{{ constructor
 
/**
* PEAR_Command_Package constructor.
*
* @access public
*/
function PEAR_Command_Package(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
// }}}
 
// {{{ _displayValidationResults()
 
function _displayValidationResults($err, $warn, $strict = false)
{
foreach ($err as $e) {
274,7 → 297,7
}
$this->output .= sprintf('Validation: %d error(s), %d warning(s)'."\n",
sizeof($err), sizeof($warn));
if ($strict && sizeof($err) > 0) {
if ($strict && count($err) > 0) {
$this->output .= "Fix these errors and try again.";
return false;
}
281,31 → 304,29
return true;
}
 
// }}}
function &getPackager()
{
if (!class_exists('PEAR_Packager')) {
require_once 'PEAR/Packager.php';
}
$a = &new PEAR_Packager;
$a = new PEAR_Packager;
return $a;
}
 
function &getPackageFile($config, $debug = false, $tmpdir = null)
function &getPackageFile($config, $debug = false)
{
if (!class_exists('PEAR_Common')) {
require_once 'PEAR/Common.php';
}
if (!class_exists('PEAR/PackageFile.php')) {
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$a = &new PEAR_PackageFile($config, $debug, $tmpdir);
$a = new PEAR_PackageFile($config, $debug);
$common = new PEAR_Common;
$common->ui = $this->ui;
$a->setLogger($common);
return $a;
}
// {{{ doPackage()
 
function doPackage($command, $options, $params)
{
312,36 → 333,36
$this->output = '';
$pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
$pkg2 = isset($params[1]) ? $params[1] : null;
if (!$pkg2 && !isset($params[0])) {
if (file_exists('package2.xml')) {
$pkg2 = 'package2.xml';
}
if (!$pkg2 && !isset($params[0]) && file_exists('package2.xml')) {
$pkg2 = 'package2.xml';
}
 
$packager = &$this->getPackager();
$compress = empty($options['nocompress']) ? true : false;
$result = $packager->package($pkginfofile, $compress, $pkg2);
$result = $packager->package($pkginfofile, $compress, $pkg2);
if (PEAR::isError($result)) {
return $this->raiseError($result);
}
 
// Don't want output, only the package file name just created
if (isset($options['showname'])) {
$this->output = $result;
}
 
if ($this->output) {
$this->ui->outputData($this->output, $command);
}
 
return true;
}
 
// }}}
// {{{ doPackageValidate()
 
function doPackageValidate($command, $options, $params)
{
$this->output = '';
if (sizeof($params) < 1) {
$params[0] = "package.xml";
if (count($params) < 1) {
$params[0] = 'package.xml';
}
 
$obj = &$this->getPackageFile($this->config, $this->_debug);
$obj->rawReturn();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
350,16 → 371,18
$info = $obj->fromPackageFile($params[0], PEAR_VALIDATE_NORMAL);
} else {
$archive = $info->getArchiveFile();
$tar = &new Archive_Tar($archive);
$tar = new Archive_Tar($archive);
$tar->extract(dirname($info->getPackageFile()));
$info->setPackageFile(dirname($info->getPackageFile()) . DIRECTORY_SEPARATOR .
$info->getPackage() . '-' . $info->getVersion() . DIRECTORY_SEPARATOR .
basename($info->getPackageFile()));
}
 
PEAR::staticPopErrorHandling();
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
 
$valid = false;
if ($info->getPackagexmlVersion() == '2.0') {
if ($valid = $info->validate(PEAR_VALIDATE_NORMAL)) {
369,10 → 392,10
} else {
$valid = $info->validate(PEAR_VALIDATE_PACKAGING);
}
$err = array();
$warn = array();
if (!$valid) {
foreach ($info->getValidationWarnings() as $error) {
 
$err = $warn = array();
if ($errors = $info->getValidationWarnings()) {
foreach ($errors as $error) {
if ($error['level'] == 'warning') {
$warn[] = $error['message'];
} else {
380,27 → 403,243
}
}
}
 
$this->_displayValidationResults($err, $warn);
$this->ui->outputData($this->output, $command);
return true;
}
 
// }}}
// {{{ doCvsTag()
function doSvnTag($command, $options, $params)
{
$this->output = '';
$_cmd = $command;
if (count($params) < 1) {
$help = $this->getHelp($command);
return $this->raiseError("$command: missing parameter: $help[0]");
}
 
$packageFile = realpath($params[0]);
$dir = dirname($packageFile);
$dir = substr($dir, strrpos($dir, DIRECTORY_SEPARATOR) + 1);
$obj = &$this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromAnyFile($packageFile, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
 
$err = $warn = array();
if (!$info->validate()) {
foreach ($info->getValidationWarnings() as $error) {
if ($error['level'] == 'warning') {
$warn[] = $error['message'];
} else {
$err[] = $error['message'];
}
}
}
 
if (!$this->_displayValidationResults($err, $warn, true)) {
$this->ui->outputData($this->output, $command);
return $this->raiseError('SVN tag failed');
}
 
$version = $info->getVersion();
$package = $info->getName();
$svntag = "$package-$version";
 
if (isset($options['delete'])) {
return $this->_svnRemoveTag($version, $package, $svntag, $packageFile, $options);
}
 
$path = $this->_svnFindPath($packageFile);
 
// Check if there are any modified files
$fp = popen('svn st --xml ' . dirname($packageFile), "r");
$out = '';
while ($line = fgets($fp, 1024)) {
$out .= rtrim($line)."\n";
}
pclose($fp);
 
if (!isset($options['quiet']) && strpos($out, 'item="modified"')) {
$params = array(array(
'name' => 'modified',
'type' => 'yesno',
'default' => 'no',
'prompt' => 'You have files in your SVN checkout (' . $path['from'] . ') that have been modified but not committed, do you still want to tag ' . $version . '?',
));
$answers = $this->ui->confirmDialog($params);
 
if (!in_array($answers['modified'], array('y', 'yes', 'on', '1'))) {
return true;
}
}
 
if (isset($options['slide'])) {
$this->_svnRemoveTag($version, $package, $svntag, $packageFile, $options);
}
 
// Check if tag already exists
$releaseTag = $path['local']['base'] . 'tags' . DIRECTORY_SEPARATOR . $svntag;
$existsCommand = 'svn ls ' . $path['base'] . 'tags/';
 
$fp = popen($existsCommand, "r");
$out = '';
while ($line = fgets($fp, 1024)) {
$out .= rtrim($line)."\n";
}
pclose($fp);
 
if (in_array($svntag . DIRECTORY_SEPARATOR, explode("\n", $out))) {
$this->ui->outputData($this->output, $command);
return $this->raiseError('SVN tag ' . $svntag . ' for ' . $package . ' already exists.');
} elseif (file_exists($path['local']['base'] . 'tags') === false) {
return $this->raiseError('Can not locate the tags directory at ' . $path['local']['base'] . 'tags');
} elseif (is_writeable($path['local']['base'] . 'tags') === false) {
return $this->raiseError('Can not write to the tag directory at ' . $path['local']['base'] . 'tags');
} else {
$makeCommand = 'svn mkdir ' . $releaseTag;
$this->output .= "+ $makeCommand\n";
if (empty($options['dry-run'])) {
// We need to create the tag dir.
$fp = popen($makeCommand, "r");
$out = '';
while ($line = fgets($fp, 1024)) {
$out .= rtrim($line)."\n";
}
pclose($fp);
$this->output .= "$out\n";
}
}
 
$command = 'svn';
if (isset($options['quiet'])) {
$command .= ' -q';
}
 
$command .= ' copy --parents ';
 
$dir = dirname($packageFile);
$dir = substr($dir, strrpos($dir, DIRECTORY_SEPARATOR) + 1);
$files = array_keys($info->getFilelist());
if (!in_array(basename($packageFile), $files)) {
$files[] = basename($packageFile);
}
 
array_shift($params);
if (count($params)) {
// add in additional files to be tagged (package files and such)
$files = array_merge($files, $params);
}
 
$commands = array();
foreach ($files as $file) {
if (!file_exists($file)) {
$file = $dir . DIRECTORY_SEPARATOR . $file;
}
$commands[] = $command . ' ' . escapeshellarg($file) . ' ' .
escapeshellarg($releaseTag . DIRECTORY_SEPARATOR . $file);
}
 
$this->output .= implode("\n", $commands) . "\n";
if (empty($options['dry-run'])) {
foreach ($commands as $command) {
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
$this->output .= rtrim($line)."\n";
}
pclose($fp);
}
}
 
$command = 'svn ci -m "Tagging the ' . $version . ' release" ' . $releaseTag . "\n";
$this->output .= "+ $command\n";
if (empty($options['dry-run'])) {
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
$this->output .= rtrim($line)."\n";
}
pclose($fp);
}
 
$this->ui->outputData($this->output, $_cmd);
return true;
}
 
function _svnFindPath($file)
{
$xml = '';
$command = "svn info --xml $file";
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
$xml .= rtrim($line)."\n";
}
pclose($fp);
$url_tag = strpos($xml, '<url>');
$url = substr($xml, $url_tag + 5, strpos($xml, '</url>', $url_tag + 5) - ($url_tag + 5));
 
$path = array();
$path['from'] = substr($url, 0, strrpos($url, '/'));
$path['base'] = substr($path['from'], 0, strrpos($path['from'], '/') + 1);
 
// Figure out the local paths - see http://pear.php.net/bugs/17463
$pos = strpos($file, DIRECTORY_SEPARATOR . 'trunk' . DIRECTORY_SEPARATOR);
if ($pos === false) {
$pos = strpos($file, DIRECTORY_SEPARATOR . 'branches' . DIRECTORY_SEPARATOR);
}
$path['local']['base'] = substr($file, 0, $pos + 1);
 
return $path;
}
 
function _svnRemoveTag($version, $package, $tag, $packageFile, $options)
{
$command = 'svn';
 
if (isset($options['quiet'])) {
$command .= ' -q';
}
 
$command .= ' remove';
$command .= ' -m "Removing tag for the ' . $version . ' release."';
 
$path = $this->_svnFindPath($packageFile);
$command .= ' ' . $path['base'] . 'tags/' . $tag;
 
 
if ($this->config->get('verbose') > 1) {
$this->output .= "+ $command\n";
}
 
$this->output .= "+ $command\n";
if (empty($options['dry-run'])) {
$fp = popen($command, "r");
while ($line = fgets($fp, 1024)) {
$this->output .= rtrim($line)."\n";
}
pclose($fp);
}
 
$this->ui->outputData($this->output, $command);
return true;
}
 
function doCvsTag($command, $options, $params)
{
$this->output = '';
$_cmd = $command;
if (sizeof($params) < 1) {
if (count($params) < 1) {
$help = $this->getHelp($command);
return $this->raiseError("$command: missing parameter: $help[0]");
}
$obj = &$this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
 
$packageFile = realpath($params[0]);
$obj = &$this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromAnyFile($packageFile, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
 
$err = $warn = array();
if (!$info->validate()) {
foreach ($info->getValidationWarnings() as $error) {
411,28 → 650,34
}
}
}
 
if (!$this->_displayValidationResults($err, $warn, true)) {
$this->ui->outputData($this->output, $command);
return $this->raiseError('CVS tag failed');
}
$version = $info->getVersion();
 
$version = $info->getVersion();
$cvsversion = preg_replace('/[^a-z0-9]/i', '_', $version);
$cvstag = "RELEASE_$cvsversion";
$files = array_keys($info->getFilelist());
$command = "cvs";
$cvstag = "RELEASE_$cvsversion";
$files = array_keys($info->getFilelist());
$command = 'cvs';
if (isset($options['quiet'])) {
$command .= ' -q';
}
 
if (isset($options['reallyquiet'])) {
$command .= ' -Q';
}
 
$command .= ' tag';
if (isset($options['slide'])) {
$command .= ' -F';
}
 
if (isset($options['delete'])) {
$command .= ' -d';
}
 
$command .= ' ' . $cvstag . ' ' . escapeshellarg($params[0]);
array_shift($params);
if (count($params)) {
439,12 → 684,20
// add in additional files to be tagged
$files = array_merge($files, $params);
}
 
$dir = dirname($packageFile);
$dir = substr($dir, strrpos($dir, '/') + 1);
foreach ($files as $file) {
if (!file_exists($file)) {
$file = $dir . DIRECTORY_SEPARATOR . $file;
}
$command .= ' ' . escapeshellarg($file);
}
 
if ($this->config->get('verbose') > 1) {
$this->output .= "+ $command\n";
}
 
$this->output .= "+ $command\n";
if (empty($options['dry-run'])) {
$fp = popen($command, "r");
453,13 → 706,11
}
pclose($fp);
}
 
$this->ui->outputData($this->output, $_cmd);
return true;
}
 
// }}}
// {{{ doCvsDiff()
 
function doCvsDiff($command, $options, $params)
{
$this->output = '';
467,11 → 718,14
$help = $this->getHelp($command);
return $this->raiseError("$command: missing parameter: $help[0]");
}
$obj = &$this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
 
$file = realpath($params[0]);
$obj = &$this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromAnyFile($file, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
 
$err = $warn = array();
if (!$info->validate()) {
foreach ($info->getValidationWarnings() as $error) {
482,10 → 736,12
}
}
}
 
if (!$this->_displayValidationResults($err, $warn, true)) {
$this->ui->outputData($this->output, $command);
return $this->raiseError('CVS diff failed');
}
 
$info1 = $info->getFilelist();
$files = $info1;
$cmd = "cvs";
493,10 → 749,12
$cmd .= ' -q';
unset($options['quiet']);
}
 
if (isset($options['reallyquiet'])) {
$cmd .= ' -Q';
unset($options['reallyquiet']);
}
 
if (isset($options['release'])) {
$cvsversion = preg_replace('/[^a-z0-9]/i', '_', $options['release']);
$cvstag = "RELEASE_$cvsversion";
503,11 → 761,13
$options['revision'] = $cvstag;
unset($options['release']);
}
 
$execute = true;
if (isset($options['dry-run'])) {
$execute = false;
unset($options['dry-run']);
}
 
$cmd .= ' diff';
// the rest of the options are passed right on to "cvs diff"
foreach ($options as $option => $optarg) {
521,12 → 781,15
$cmd .= ($short ? '' : '=') . escapeshellarg($optarg);
}
}
 
foreach ($files as $file) {
$cmd .= ' ' . escapeshellarg($file['name']);
}
 
if ($this->config->get('verbose') > 1) {
$this->output .= "+ $cmd\n";
}
 
if ($execute) {
$fp = popen($cmd, "r");
while ($line = fgets($fp, 1024)) {
534,24 → 797,30
}
pclose($fp);
}
 
$this->ui->outputData($this->output, $command);
return true;
}
 
// }}}
// {{{ doPackageDependencies()
 
function doPackageDependencies($command, $options, $params)
{
// $params[0] -> the PEAR package to list its information
if (sizeof($params) != 1) {
if (count($params) !== 1) {
return $this->raiseError("bad parameter(s), try \"help $command\"");
}
 
$obj = &$this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
if (is_file($params[0]) || strpos($params[0], '.xml') > 0) {
$info = $obj->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
} else {
$reg = $this->config->getRegistry();
$info = $obj->fromArray($reg->packageInfo($params[0]));
}
 
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
 
$deps = $info->getDeps();
if (is_array($deps)) {
if ($info->getPackagexmlVersion() == '1.0') {
571,6 → 840,7
} else {
$req = 'Yes';
}
 
if (isset($this->_deps_rel_trans[$d['rel']])) {
$rel = $this->_deps_rel_trans[$d['rel']];
} else {
610,25 → 880,30
);
foreach ($deps as $type => $subd) {
$req = ($type == 'required') ? 'Yes' : 'No';
if ($type == 'group') {
if ($type == 'group' && isset($subd['attribs']['name'])) {
$group = $subd['attribs']['name'];
} else {
$group = '';
}
 
if (!isset($subd[0])) {
$subd = array($subd);
}
 
foreach ($subd as $groupa) {
foreach ($groupa as $deptype => $depinfo) {
if ($deptype == 'attribs') {
continue;
}
 
if ($deptype == 'pearinstaller') {
$deptype = 'pear Installer';
}
 
if (!isset($depinfo[0])) {
$depinfo = array($depinfo);
}
 
foreach ($depinfo as $inf) {
$name = '';
if (isset($inf['channel'])) {
637,6 → 912,7
$alias = '(channel?) ' .$inf['channel'];
}
$name = $alias . '/';
 
}
if (isset($inf['name'])) {
$name .= $inf['name'];
645,14 → 921,17
} else {
$name .= '';
}
 
if (isset($inf['uri'])) {
$name .= ' [' . $inf['uri'] . ']';
}
 
if (isset($inf['conflicts'])) {
$ver = 'conflicts';
} else {
$ver = $d->_getExtraString($inf);
}
 
$data['data'][] = array($req, ucfirst($deptype), $name,
$ver, $group);
}
670,60 → 949,79
$this->ui->outputData("This package does not have any dependencies.", $command);
}
 
// }}}
// {{{ doSign()
 
function doSign($command, $options, $params)
{
require_once 'System.php';
require_once 'Archive/Tar.php';
// should move most of this code into PEAR_Packager
// so it'll be easy to implement "pear package --sign"
if (sizeof($params) != 1) {
if (count($params) !== 1) {
return $this->raiseError("bad parameter(s), try \"help $command\"");
}
 
require_once 'System.php';
require_once 'Archive/Tar.php';
 
if (!file_exists($params[0])) {
return $this->raiseError("file does not exist: $params[0]");
}
 
$obj = $this->getPackageFile($this->config, $this->_debug);
$info = $obj->fromTgzFile($params[0], PEAR_VALIDATE_NORMAL);
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
 
$tar = new Archive_Tar($params[0]);
$tmpdir = System::mktemp('-d pearsign');
if (!$tar->extractList('package2.xml package.sig', $tmpdir)) {
if (!$tar->extractList('package.xml package.sig', $tmpdir)) {
return $this->raiseError("failed to extract tar file");
}
 
$tmpdir = $this->config->get('temp_dir');
$tmpdir = System::mktemp(' -t "' . $tmpdir . '" -d pearsign');
if (!$tar->extractList('package2.xml package.xml package.sig', $tmpdir)) {
return $this->raiseError("failed to extract tar file");
}
 
if (file_exists("$tmpdir/package.sig")) {
return $this->raiseError("package already signed");
}
 
$packagexml = 'package.xml';
if (file_exists("$tmpdir/package2.xml")) {
$packagexml = 'package2.xml';
}
 
if (file_exists("$tmpdir/package.sig")) {
unlink("$tmpdir/package.sig");
}
 
if (!file_exists("$tmpdir/$packagexml")) {
return $this->raiseError("Extracted file $tmpdir/$packagexml not found.");
}
 
$input = $this->ui->userDialog($command,
array('GnuPG Passphrase'),
array('password'));
$gpg = popen("gpg --batch --passphrase-fd 0 --armor --detach-sign --output $tmpdir/package.sig $tmpdir/$packagexml 2>/dev/null", "w");
if (!isset($input[0])) {
//use empty passphrase
$input[0] = '';
}
 
$devnull = (isset($options['verbose'])) ? '' : ' 2>/dev/null';
$gpg = popen("gpg --batch --passphrase-fd 0 --armor --detach-sign --output $tmpdir/package.sig $tmpdir/$packagexml" . $devnull, "w");
if (!$gpg) {
return $this->raiseError("gpg command failed");
}
 
fwrite($gpg, "$input[0]\n");
if (pclose($gpg) || !file_exists("$tmpdir/package.sig")) {
return $this->raiseError("gpg sign failed");
}
$tar->addModify("$tmpdir/package.sig", '', $tmpdir);
 
if (!$tar->addModify("$tmpdir/package.sig", '', $tmpdir)) {
return $this->raiseError('failed adding signature to file');
}
 
$this->ui->outputData("Package signed.", $command);
return true;
}
 
// }}}
 
/**
* For unit testing purposes
*/
732,10 → 1030,10
if (!class_exists('PEAR_Installer')) {
require_once 'PEAR/Installer.php';
}
$a = &new PEAR_Installer($ui);
$a = new PEAR_Installer($ui);
return $a;
}
 
/**
* For unit testing purposes
*/
747,17 → 1045,16
include_once 'PEAR/Command/Packaging.php';
}
}
 
if (class_exists('PEAR_Command_Packaging')) {
$a = &new PEAR_Command_Packaging($ui, $config);
$a = new PEAR_Command_Packaging($ui, $config);
} else {
$a = null;
}
 
return $a;
}
 
// {{{ doMakeRPM()
 
function doMakeRPM($command, $options, $params)
{
 
770,17 → 1067,17
$this->ui->outputData('PEAR_Command_Packaging is installed; using '.
'newer "make-rpm-spec" command instead');
return $packaging_cmd->run('make-rpm-spec', $options, $params);
} else {
$this->ui->outputData('WARNING: "pear makerpm" is no longer available; an '.
'improved version is available via "pear make-rpm-spec", which '.
'is available by installing PEAR_Command_Packaging');
}
 
$this->ui->outputData('WARNING: "pear makerpm" is no longer available; an '.
'improved version is available via "pear make-rpm-spec", which '.
'is available by installing PEAR_Command_Packaging');
return true;
}
 
function doConvert($command, $options, $params)
{
$packagexml = isset($params[0]) ? $params[0] : 'package.xml';
$packagexml = isset($params[0]) ? $params[0] : 'package.xml';
$newpackagexml = isset($params[1]) ? $params[1] : dirname($packagexml) .
DIRECTORY_SEPARATOR . 'package2.xml';
$pkg = &$this->getPackageFile($this->config, $this->_debug);
787,32 → 1084,7
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$pf = $pkg->fromPackageFile($packagexml, PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
if (!PEAR::isError($pf)) {
if (is_a($pf, 'PEAR_PackageFile_v2')) {
$this->ui->outputData($packagexml . ' is already a package.xml version 2.0');
return true;
}
$gen = &$pf->getDefaultGenerator();
$newpf = &$gen->toV2();
$newpf->setPackagefile($newpackagexml);
$gen = &$newpf->getDefaultGenerator();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$state = (isset($options['flat']) ? PEAR_VALIDATE_PACKAGING : PEAR_VALIDATE_NORMAL);
$saved = $gen->toPackageFile(dirname($newpackagexml), $state,
basename($newpackagexml));
PEAR::staticPopErrorHandling();
if (PEAR::isError($saved)) {
if (is_array($saved->getUserInfo())) {
foreach ($saved->getUserInfo() as $warning) {
$this->ui->outputData($warning['message']);
}
}
$this->ui->outputData($saved->getMessage());
return true;
}
$this->ui->outputData('Wrote new version 2.0 package.xml to "' . $saved . '"');
return true;
} else {
if (PEAR::isError($pf)) {
if (is_array($pf->getUserInfo())) {
foreach ($pf->getUserInfo() as $warning) {
$this->ui->outputData($warning['message']);
820,9 → 1092,32
}
return $this->raiseError($pf);
}
 
if (is_a($pf, 'PEAR_PackageFile_v2')) {
$this->ui->outputData($packagexml . ' is already a package.xml version 2.0');
return true;
}
 
$gen = &$pf->getDefaultGenerator();
$newpf = &$gen->toV2();
$newpf->setPackagefile($newpackagexml);
$gen = &$newpf->getDefaultGenerator();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$state = (isset($options['flat']) ? PEAR_VALIDATE_PACKAGING : PEAR_VALIDATE_NORMAL);
$saved = $gen->toPackageFile(dirname($newpackagexml), $state, basename($newpackagexml));
PEAR::staticPopErrorHandling();
if (PEAR::isError($saved)) {
if (is_array($saved->getUserInfo())) {
foreach ($saved->getUserInfo() as $warning) {
$this->ui->outputData($warning['message']);
}
}
 
$this->ui->outputData($saved->getMessage());
return true;
}
 
$this->ui->outputData('Wrote new version 2.0 package.xml to "' . $saved . '"');
return true;
}
 
// }}}
}
 
?>
/trunk/bibliotheque/pear/PEAR/Command/Build.php
4,20 → 4,13
*
* 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 Stig Bakken <ssb@php.net>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @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: Build.php,v 1.13 2006/01/06 04:47:36 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
35,16 → 28,14
* @author Stig Bakken <ssb@php.net>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Build extends PEAR_Command_Common
{
// {{{ properties
 
var $commands = array(
'build' => array(
'summary' => 'Build an Extension From C Source',
56,24 → 47,16
),
);
 
// }}}
 
// {{{ constructor
 
/**
* PEAR_Command_Build constructor.
*
* @access public
*/
function PEAR_Command_Build(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
// }}}
 
// {{{ doBuild()
 
function doBuild($command, $options, $params)
{
require_once 'PEAR/Builder.php';
80,18 → 63,17
if (sizeof($params) < 1) {
$params[0] = 'package.xml';
}
$builder = &new PEAR_Builder($this->ui);
 
$builder = new PEAR_Builder($this->ui);
$this->debug = $this->config->get('verbose');
$err = $builder->build($params[0], array(&$this, 'buildCallback'));
if (PEAR::isError($err)) {
return $err;
}
 
return true;
}
 
// }}}
// {{{ buildCallback()
 
function buildCallback($what, $data)
{
if (($what == 'cmdoutput' && $this->debug > 1) ||
99,6 → 81,4
$this->ui->outputData(rtrim($data), 'build');
}
}
 
// }}}
}
/trunk/bibliotheque/pear/PEAR/Command/Auth.php
4,28 → 4,21
*
* 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 Stig Bakken <ssb@php.net>
* @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: Auth.php,v 1.24 2006/03/05 21:23:21 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
* @deprecated since 1.8.0alpha1
*/
 
/**
* base class
*/
require_once 'PEAR/Command/Common.php';
require_once 'PEAR/Config.php';
require_once 'PEAR/Command/Channels.php';
 
/**
* PEAR commands for login/logout
34,24 → 27,26
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
* @deprecated since 1.8.0alpha1
*/
class PEAR_Command_Auth extends PEAR_Command_Common
class PEAR_Command_Auth extends PEAR_Command_Channels
{
// {{{ properties
 
var $commands = array(
'login' => array(
'summary' => 'Connects and authenticates to remote server',
'summary' => 'Connects and authenticates to remote server [Deprecated in favor of channel-login]',
'shortcut' => 'li',
'function' => 'doLogin',
'options' => array(),
'doc' => '
Log in to the remote server. To use remote functions in the installer
'doc' => '<channel name>
WARNING: This function is deprecated in favor of using channel-login
 
Log in to a remote channel server. If <channel name> is not supplied,
the default channel is used. To use remote functions in the installer
that require any kind of privileges, you need to log in first. The
username and password you enter here will be stored in your per-user
PEAR configuration (~/.pearrc on Unix-like systems). After logging
59,11 → 54,13
operations on the remote server.',
),
'logout' => array(
'summary' => 'Logs out from the remote server',
'summary' => 'Logs out from the remote server [Deprecated in favor of channel-logout]',
'shortcut' => 'lo',
'function' => 'doLogout',
'options' => array(),
'doc' => '
WARNING: This function is deprecated in favor of using channel-logout
 
Logs out from the remote server. This command does not actually
connect to the remote server, it only deletes the stored username and
password from your user configuration.',
71,116 → 68,13
 
);
 
// }}}
 
// {{{ constructor
 
/**
* PEAR_Command_Auth constructor.
*
* @access public
*/
function PEAR_Command_Auth(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
// }}}
 
// {{{ doLogin()
 
/**
* Execute the 'login' command.
*
* @param string $command command name
*
* @param array $options option_name => value
*
* @param array $params list of additional parameters
*
* @return bool TRUE on success or
* a PEAR error on failure
*
* @access public
*/
function doLogin($command, $options, $params)
{
$reg = &$this->config->getRegistry();
$channel = $this->config->get('default_channel');
$chan = $reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $this->raiseError($chan);
}
$server = $this->config->get('preferred_mirror');
$remote = &$this->config->getRemote();
$username = $this->config->get('username');
if (empty($username)) {
$username = isset($_ENV['USER']) ? $_ENV['USER'] : null;
}
$this->ui->outputData("Logging in to $server.", $command);
list($username, $password) = $this->ui->userDialog(
$command,
array('Username', 'Password'),
array('text', 'password'),
array($username, '')
);
$username = trim($username);
$password = trim($password);
$this->config->set('username', $username);
$this->config->set('password', $password);
 
if ($chan->supportsREST()) {
$ok = true;
} else {
$remote->expectError(401);
$ok = $remote->call('logintest');
$remote->popExpect();
}
if ($ok === true) {
$this->ui->outputData("Logged in.", $command);
$this->config->store();
} else {
return $this->raiseError("Login failed!");
}
return true;
}
 
// }}}
// {{{ doLogout()
 
/**
* Execute the 'logout' command.
*
* @param string $command command name
*
* @param array $options option_name => value
*
* @param array $params list of additional parameters
*
* @return bool TRUE on success or
* a PEAR error on failure
*
* @access public
*/
function doLogout($command, $options, $params)
{
$reg = &$this->config->getRegistry();
$channel = $this->config->get('default_channel');
$chan = $reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $this->raiseError($chan);
}
$server = $this->config->get('preferred_mirror');
$this->ui->outputData("Logging out from $server.", $command);
$this->config->remove('username');
$this->config->remove('password');
$this->config->store();
return true;
}
 
// }}}
}
 
?>
/trunk/bibliotheque/pear/PEAR/Command/Remote.xml
11,7 → 11,12
<summary>List Available Upgrades</summary>
<function>doListUpgrades</function>
<shortcut>lu</shortcut>
<options />
<options>
<channelinfo>
<shortopt>i</shortopt>
<doc>output fully channel-aware data, even on failure</doc>
</channelinfo>
</options>
<doc>[preferred_state]
List releases on the server of packages you have installed where
a newer version is available with the same release state (stable etc.)
42,6 → 47,14
<doc>specify a channel other than the default channel</doc>
<arg>CHAN</arg>
</channel>
<allchannels>
<shortopt>a</shortopt>
<doc>search packages from all known channels</doc>
</allchannels>
<channelinfo>
<shortopt>i</shortopt>
<doc>output fully channel-aware data, even on failure</doc>
</channelinfo>
</options>
<doc>[packagename] [packageinfo]
Lists all packages which match the search parameters. The first
59,6 → 72,10
<doc>specify a channel other than the default channel</doc>
<arg>CHAN</arg>
</channel>
<channelinfo>
<shortopt>i</shortopt>
<doc>output fully channel-aware data, even on failure</doc>
</channelinfo>
</options>
<doc>
Lists the packages available on the configured server along with the
/trunk/bibliotheque/pear/PEAR/Command/Channels.xml
50,8 → 50,8
</force>
<channel>
<shortopt>c</shortopt>
<doc>will force download of new channel.xml if an existing channel name is used</doc>
<arg>CHANNEL</arg>
<doc>will force download of new channel.xml if an existing channel name is used</doc>
</channel>
</options>
<doc>[&lt;channel.xml&gt;|&lt;channel name&gt;]
87,7 → 87,37
<shortcut>di</shortcut>
<options />
<doc>[&lt;channel.xml&gt;|&lt;channel name&gt;]
Initialize a Channel from its server and create the local channel.xml.
Initialize a channel from its server and create a local channel.xml.
If &lt;channel name&gt; is in the format &quot;&lt;username&gt;:&lt;password&gt;@&lt;channel&gt;&quot; then
&lt;username&gt; and &lt;password&gt; will be set as the login username/password for
&lt;channel&gt;. Use caution when passing the username/password in this way, as
it may allow other users on your computer to briefly view your username/
password via the system&#039;s process list.
</doc>
</channel-discover>
</commands>
<channel-login>
<summary>Connects and authenticates to remote channel server</summary>
<function>doLogin</function>
<shortcut>cli</shortcut>
<options />
<doc>&lt;channel name&gt;
Log in to a remote channel server. If &lt;channel name&gt; is not supplied,
the default channel is used. To use remote functions in the installer
that require any kind of privileges, you need to log in first. The
username and password you enter here will be stored in your per-user
PEAR configuration (~/.pearrc on Unix-like systems). After logging
in, your username and password will be sent along in subsequent
operations on the remote server.</doc>
</channel-login>
<channel-logout>
<summary>Logs out from the remote channel server</summary>
<function>doLogout</function>
<shortcut>clo</shortcut>
<options />
<doc>&lt;channel name&gt;
Logs out from a remote channel server. If &lt;channel name&gt; is not supplied,
the default channel is used. This command does not actually connect to the
remote server, it only deletes the stored username and password from your user
configuration.</doc>
</channel-logout>
</commands>
/trunk/bibliotheque/pear/PEAR/Command/Package.xml
79,11 → 79,12
<doc>Ignore changes that insert or delete blank lines</doc>
</ignore-blank-lines>
<brief>
<shortopt></shortopt>
<doc>Report only whether the files differ, no details</doc>
</brief>
<dry-run>
<shortopt>n</shortopt>
<doc>Don&apos;t do anything, just pretend</doc>
<doc>Don&#039;t do anything, just pretend</doc>
</dry-run>
</options>
<doc>&lt;package.xml&gt;
93,6 → 94,39
of a specific release.
</doc>
</cvsdiff>
<svntag>
<summary>Set SVN Release Tag</summary>
<function>doSvnTag</function>
<shortcut>sv</shortcut>
<options>
<quiet>
<shortopt>q</shortopt>
<doc>Be quiet</doc>
</quiet>
<slide>
<shortopt>F</shortopt>
<doc>Move (slide) tag if it exists</doc>
</slide>
<delete>
<shortopt>d</shortopt>
<doc>Remove tag</doc>
</delete>
<dry-run>
<shortopt>n</shortopt>
<doc>Don&#039;t do anything, just pretend</doc>
</dry-run>
</options>
<doc>&lt;package.xml&gt; [files...]
Sets a SVN tag on all files in a package. Use this command after you have
packaged a distribution tarball with the &quot;package&quot; command to tag what
revisions of what files were in that release. If need to fix something
after running svntag once, but before the tarball is released to the public,
use the &quot;slide&quot; option to move the release tag.
 
to include files (such as a second package.xml, or tests not included in the
release), pass them as additional parameters.
</doc>
</svntag>
<cvstag>
<summary>Set CVS Release Tag</summary>
<function>doCvsTag</function>
116,15 → 150,18
</delete>
<dry-run>
<shortopt>n</shortopt>
<doc>Don&apos;t do anything, just pretend</doc>
<doc>Don&#039;t do anything, just pretend</doc>
</dry-run>
</options>
<doc>&lt;package.xml&gt;
<doc>&lt;package.xml&gt; [files...]
Sets a CVS tag on all files in a package. Use this command after you have
packaged a distribution tarball with the &quot;package&quot; command to tag what
revisions of what files were in that release. If need to fix something
after running cvstag once, but before the tarball is released to the public,
use the &quot;slide&quot; option to move the release tag.
 
to include files (such as a second package.xml, or tests not included in the
release), pass them as additional parameters.
</doc>
</cvstag>
<package-dependencies>
132,14 → 169,20
<function>doPackageDependencies</function>
<shortcut>pd</shortcut>
<options />
<doc>
List all dependencies the package has.</doc>
<doc>&lt;package-file&gt; or &lt;package.xml&gt; or &lt;install-package-name&gt;
List all dependencies the package has.
Can take a tgz / tar file, package.xml or a package name of an installed package.</doc>
</package-dependencies>
<sign>
<summary>Sign a package distribution file</summary>
<function>doSign</function>
<shortcut>si</shortcut>
<options />
<options>
<verbose>
<shortopt>v</shortopt>
<doc>Display GnuPG output</doc>
</verbose>
</options>
<doc>&lt;package-file&gt;
Signs a package distribution (.tar or .tgz) file with GnuPG.</doc>
</sign>
150,14 → 193,14
<options>
<spec-template>
<shortopt>t</shortopt>
<doc>Use FILE as RPM spec file template</doc>
<arg>FILE</arg>
<doc>Use FILE as RPM spec file template</doc>
</spec-template>
<rpm-pkgname>
<shortopt>p</shortopt>
<arg>FORMAT</arg>
<doc>Use FORMAT as format string for RPM package name, %s is replaced
by the PEAR package name, defaults to &quot;PEAR::%s&quot;.</doc>
<arg>FORMAT</arg>
</rpm-pkgname>
</options>
<doc>&lt;package-file&gt;
191,4 → 234,4
used for automated conversion or learning the format.
</doc>
</convert>
</commands>
</commands>
/trunk/bibliotheque/pear/PEAR/Command/Config.php
4,19 → 4,12
*
* 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 Stig Bakken <ssb@php.net>
* @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: Config.php,v 1.52 2006/03/05 21:32:47 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
33,16 → 26,14
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Config extends PEAR_Command_Common
{
// {{{ properties
 
var $commands = array(
'config-show' => array(
'summary' => 'Show All Settings',
136,29 → 127,21
),
);
 
// }}}
// {{{ constructor
 
/**
* PEAR_Command_Config constructor.
*
* @access public
*/
function PEAR_Command_Config(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
// }}}
 
// {{{ doConfigShow()
 
function doConfigShow($command, $options, $params)
{
$layer = null;
if (is_array($params)) {
$layer = isset($params[0]) ? $params[0] : NULL;
} else {
$layer = NULL;
$layer = isset($params[0]) ? $params[0] : null;
}
 
// $params[0] -> the layer
165,6 → 148,7
if ($error = $this->_checkLayer($layer)) {
return $this->raiseError("config-show:$error");
}
 
$keys = $this->config->getKeys();
sort($keys);
$channel = isset($options['channel']) ? $options['channel'] :
173,6 → 157,8
if (!$reg->channelExists($channel)) {
return $this->raiseError('Channel "' . $channel . '" does not exist');
}
 
$channel = $reg->channelName($channel);
$data = array('caption' => 'Configuration (channel ' . $channel . '):');
foreach ($keys as $key) {
$type = $this->config->getType($key);
180,13 → 166,16
if ($type == 'password' && $value) {
$value = '********';
}
 
if ($value === false) {
$value = 'false';
} elseif ($value === true) {
$value = 'true';
}
 
$data['data'][$this->config->getGroup($key)][] = array($this->config->getPrompt($key) , $key, $value);
}
 
foreach ($this->config->getLayers() as $layer) {
$data['data']['Config Files'][] = array(ucfirst($layer) . ' Configuration File', 'Filename' , $this->config->getConfFile($layer));
}
195,21 → 184,13
return true;
}
 
// }}}
// {{{ doConfigGet()
 
function doConfigGet($command, $options, $params)
{
if (!is_array($params)) {
$args_cnt = 0;
} else {
$args_cnt = count($params);
}
 
$args_cnt = is_array($params) ? count($params) : 0;
switch ($args_cnt) {
case 1:
$config_key = $params[0];
$layer = NULL;
$layer = null;
break;
case 2:
$config_key = $params[0];
223,21 → 204,17
return $this->raiseError("config-get expects 1 or 2 parameters");
}
 
$reg = &$this->config->getRegistry();
$channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
$reg = &$this->config->getRegistry();
 
if (!$reg->channelExists($channel)) {
return $this->raiseError('Channel "' . $channel . '" does not exist');
}
 
$channel = $reg->channelName($channel);
$this->ui->outputData($this->config->get($config_key, $layer, $channel), $command);
 
return true;
}
 
// }}}
// {{{ doConfigSet()
 
function doConfigSet($command, $options, $params)
{
// $param[0] -> a parameter to set
244,25 → 221,41
// $param[1] -> the value for the parameter
// $param[2] -> the layer
$failmsg = '';
if (sizeof($params) < 2 || sizeof($params) > 3) {
if (count($params) < 2 || count($params) > 3) {
$failmsg .= "config-set expects 2 or 3 parameters";
return PEAR::raiseError($failmsg);
}
 
if (isset($params[2]) && ($error = $this->_checkLayer($params[2]))) {
$failmsg .= $error;
return PEAR::raiseError("config-set:$failmsg");
}
$channel = isset($options['channel']) ? $options['channel'] :
$this->config->get('default_channel');
 
$channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
$reg = &$this->config->getRegistry();
if (!$reg->channelExists($channel)) {
return $this->raiseError('Channel "' . $channel . '" does not exist');
}
if ($params[0] == 'default_channel') {
if (!$reg->channelExists($params[1])) {
return $this->raiseError('Channel "' . $params[1] . '" does not exist');
}
 
$channel = $reg->channelName($channel);
if ($params[0] == 'default_channel' && !$reg->channelExists($params[1])) {
return $this->raiseError('Channel "' . $params[1] . '" does not exist');
}
 
if ($params[0] == 'preferred_mirror'
&& (
!$reg->mirrorExists($channel, $params[1]) &&
(!$reg->channelExists($params[1]) || $channel != $params[1])
)
) {
$msg = 'Channel Mirror "' . $params[1] . '" does not exist';
$msg .= ' in your registry for channel "' . $channel . '".';
$msg .= "\n" . 'Attempt to run "pear channel-update ' . $channel .'"';
$msg .= ' if you believe this mirror should exist as you may';
$msg .= ' have outdated channel information.';
return $this->raiseError($msg);
}
 
if (count($params) == 2) {
array_push($params, 'user');
$layer = 'user';
269,29 → 262,29
} else {
$layer = $params[2];
}
 
array_push($params, $channel);
if (!call_user_func_array(array(&$this->config, 'set'), $params))
{
if (!call_user_func_array(array(&$this->config, 'set'), $params)) {
array_pop($params);
$failmsg = "config-set (" . implode(", ", $params) . ") failed, channel $channel";
} else {
$this->config->store($layer);
}
 
if ($failmsg) {
return $this->raiseError($failmsg);
}
 
$this->ui->outputData('config-set succeeded', $command);
return true;
}
 
// }}}
// {{{ doConfigHelp()
 
function doConfigHelp($command, $options, $params)
{
if (empty($params)) {
$params = $this->config->getKeys();
}
 
$data['caption'] = "Config help" . ((count($params) == 1) ? " for $params[0]" : '');
$data['headline'] = array('Name', 'Type', 'Description');
$data['border'] = true;
302,14 → 295,13
$docs = rtrim($docs) . "\nValid set: " .
implode(' ', $this->config->getSetValues($name));
}
 
$data['data'][] = array($name, $type, $docs);
}
 
$this->ui->outputData($data, $command);
}
 
// }}}
// {{{ doConfigCreate()
 
function doConfigCreate($command, $options, $params)
{
if (count($params) != 2) {
316,6 → 308,7
return PEAR::raiseError('config-create: must have 2 parameters, root path and ' .
'filename to save as');
}
 
$root = $params[0];
// Clean up the DIRECTORY_SEPARATOR mess
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
323,38 → 316,45
array('/', '/', '/'),
$root);
if ($root{0} != '/') {
if (isset($options['windows'])) {
if (!preg_match('/^[A-Za-z]:/', $root)) {
return PEAR::raiseError('Root directory must be an absolute path beginning ' .
'with "\\" or "C:\\", was: "' . $root . '"');
}
} else {
if (!isset($options['windows'])) {
return PEAR::raiseError('Root directory must be an absolute path beginning ' .
'with "/", was: "' . $root . '"');
}
 
if (!preg_match('/^[A-Za-z]:/', $root)) {
return PEAR::raiseError('Root directory must be an absolute path beginning ' .
'with "\\" or "C:\\", was: "' . $root . '"');
}
}
 
$windows = isset($options['windows']);
if ($windows) {
$root = str_replace('/', '\\', $root);
}
if (!file_exists($params[1])) {
if (!@touch($params[1])) {
return PEAR::raiseError('Could not create "' . $params[1] . '"');
}
 
if (!file_exists($params[1]) && !@touch($params[1])) {
return PEAR::raiseError('Could not create "' . $params[1] . '"');
}
 
$params[1] = realpath($params[1]);
$config = &new PEAR_Config($params[1], '#no#system#config#', false, false);
$config = new PEAR_Config($params[1], '#no#system#config#', false, false);
if ($root{strlen($root) - 1} == '/') {
$root = substr($root, 0, strlen($root) - 1);
}
 
$config->noRegistry();
$config->set('php_dir', $windows ? "$root\\pear\\php" : "$root/pear/php", 'user');
$config->set('data_dir', $windows ? "$root\\pear\\data" : "$root/pear/data");
$config->set('www_dir', $windows ? "$root\\pear\\www" : "$root/pear/www");
$config->set('cfg_dir', $windows ? "$root\\pear\\cfg" : "$root/pear/cfg");
$config->set('ext_dir', $windows ? "$root\\pear\\ext" : "$root/pear/ext");
$config->set('doc_dir', $windows ? "$root\\pear\\docs" : "$root/pear/docs");
$config->set('test_dir', $windows ? "$root\\pear\\tests" : "$root/pear/tests");
$config->set('cache_dir', $windows ? "$root\\pear\\cache" : "$root/pear/cache");
$config->set('download_dir', $windows ? "$root\\pear\\download" : "$root/pear/download");
$config->set('temp_dir', $windows ? "$root\\pear\\temp" : "$root/pear/temp");
$config->set('bin_dir', $windows ? "$root\\pear" : "$root/pear");
$config->set('man_dir', $windows ? "$root\\pear\\man" : "$root/pear/man");
$config->writeConfigFile();
$this->_showConfig($config);
$this->ui->outputData('Successfully created default configuration file "' . $params[1] . '"',
361,8 → 361,6
$command);
}
 
// }}}
 
function _showConfig(&$config)
{
$params = array('user');
376,6 → 374,7
if ($type == 'password' && $value) {
$value = '********';
}
 
if ($value === false) {
$value = 'false';
} elseif ($value === true) {
384,6 → 383,7
$data['data'][$config->getGroup($key)][] =
array($config->getPrompt($key) , $key, $value);
}
 
foreach ($config->getLayers() as $layer) {
$data['data']['Config Files'][] =
array(ucfirst($layer) . ' Configuration File', 'Filename' ,
393,7 → 393,6
$this->ui->outputData($data, 'config-show');
return true;
}
// {{{ _checkLayer()
 
/**
* Checks if a layer is defined or not
409,10 → 408,7
return " only the layers: \"" . implode('" or "', $layers) . "\" are supported";
}
}
 
return false;
}
 
// }}}
}
 
?>
/trunk/bibliotheque/pear/PEAR/Command/Install.php
4,19 → 4,12
*
* 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 Stig Bakken <ssb@php.net>
* @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: Install.php,v 1.122 2007/02/13 04:30:05 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
34,9 → 27,9
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
140,6 → 133,11
'function' => 'doInstall',
'shortcut' => 'up',
'options' => array(
'channel' => array(
'shortopt' => 'c',
'doc' => 'upgrade packages from a specific channel',
'arg' => 'CHAN',
),
'force' => array(
'shortopt' => 'f',
'doc' => 'overwrite newer installed packages',
167,13 → 165,8
'installroot' => array(
'shortopt' => 'R',
'arg' => 'DIR',
'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT), use packagingroot for RPM',
'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
),
'packagingroot' => array(
'shortopt' => 'P',
'arg' => 'DIR',
'doc' => 'root directory used when packaging files, like RPM packaging',
),
'ignore-errors' => array(
'doc' => 'force install even if there were errors',
),
205,10 → 198,15
More than one package may be specified at once.
'),
'upgrade-all' => array(
'summary' => 'Upgrade All Packages',
'function' => 'doInstall',
'summary' => 'Upgrade All Packages [Deprecated in favor of calling upgrade with no parameters]',
'function' => 'doUpgradeAll',
'shortcut' => 'ua',
'options' => array(
'channel' => array(
'shortopt' => 'c',
'doc' => 'upgrade packages from a specific channel',
'arg' => 'CHAN',
),
'nodeps' => array(
'shortopt' => 'n',
'doc' => 'ignore dependencies, upgrade anyway',
238,6 → 236,8
),
),
'doc' => '
WARNING: This function is deprecated in favor of using the upgrade command with no params
 
Upgrades all packages that have a newer release available. Upgrades are
done only if there is a release available of the state specified in
"preferred_state" (currently {config preferred_state}), or a state considered
312,9 → 312,9
*
* @access public
*/
function PEAR_Command_Install(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
// }}}
327,7 → 327,7
if (!class_exists('PEAR_Downloader')) {
require_once 'PEAR/Downloader.php';
}
$a = &new PEAR_Downloader($ui, $options, $config);
$a = new PEAR_Downloader($ui, $options, $config);
return $a;
}
 
339,7 → 339,7
if (!class_exists('PEAR_Installer')) {
require_once 'PEAR/Installer.php';
}
$a = &new PEAR_Installer($ui);
$a = new PEAR_Installer($ui);
return $a;
}
 
352,10 → 352,6
if (PEAR::isError($ini)) {
return $ini;
}
$fp = @fopen($phpini, 'wb');
if (!$fp) {
return PEAR::raiseError('cannot open php.ini "' . $phpini . '" for writing');
}
$line = 0;
if ($type == 'extsrc' || $type == 'extbin') {
$search = 'extensions';
367,7 → 363,7
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
$ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
$ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
$enable = 'zend_extension' . $debug . $ts;
}
foreach ($ini[$search] as $line => $extension) {
389,6 → 385,10
$newini[] = $enable . '="' . $binary . '"' . (OS_UNIX ? "\n" : "\r\n");
}
$newini = array_merge($newini, array_slice($ini['all'], $line));
$fp = @fopen($phpini, 'wb');
if (!$fp) {
return PEAR::raiseError('cannot open php.ini "' . $phpini . '" for writing');
}
foreach ($newini as $line) {
fwrite($fp, $line);
}
416,7 → 416,7
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
$ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
$ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
$enable = 'zend_extension' . $debug . $ts;
}
$found = false;
451,70 → 451,71
 
function _parseIni($filename)
{
if (file_exists($filename)) {
if (filesize($filename) > 300000) {
return PEAR::raiseError('php.ini "' . $filename . '" is too large, aborting');
if (!file_exists($filename)) {
return PEAR::raiseError('php.ini "' . $filename . '" does not exist');
}
 
if (filesize($filename) > 300000) {
return PEAR::raiseError('php.ini "' . $filename . '" is too large, aborting');
}
 
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
$ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
$zend_extension_line = 'zend_extension' . $debug . $ts;
$all = @file($filename);
if ($all === false) {
return PEAR::raiseError('php.ini "' . $filename .'" could not be read');
}
$zend_extensions = $extensions = array();
// assume this is right, but pull from the php.ini if it is found
$extension_dir = ini_get('extension_dir');
foreach ($all as $linenum => $line) {
$line = trim($line);
if (!$line) {
continue;
}
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
$ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
$zend_extension_line = 'zend_extension' . $debug . $ts;
$all = @file($filename);
if (!$all) {
return PEAR::raiseError('php.ini "' . $filename .'" could not be read');
if ($line[0] == ';') {
continue;
}
$zend_extensions = $extensions = array();
// assume this is right, but pull from the php.ini if it is found
$extension_dir = ini_get('extension_dir');
foreach ($all as $linenum => $line) {
$line = trim($line);
if (!$line) {
if (strtolower(substr($line, 0, 13)) == 'extension_dir') {
$line = trim(substr($line, 13));
if ($line[0] == '=') {
$x = trim(substr($line, 1));
$x = explode(';', $x);
$extension_dir = str_replace('"', '', array_shift($x));
continue;
}
if ($line[0] == ';') {
}
if (strtolower(substr($line, 0, 9)) == 'extension') {
$line = trim(substr($line, 9));
if ($line[0] == '=') {
$x = trim(substr($line, 1));
$x = explode(';', $x);
$extensions[$linenum] = str_replace('"', '', array_shift($x));
continue;
}
if (strtolower(substr($line, 0, 13)) == 'extension_dir') {
$line = trim(substr($line, 13));
if ($line[0] == '=') {
$x = trim(substr($line, 1));
$x = explode(';', $x);
$extension_dir = str_replace('"', '', array_shift($x));
continue;
}
}
if (strtolower(substr($line, 0, strlen($zend_extension_line))) ==
$zend_extension_line) {
$line = trim(substr($line, strlen($zend_extension_line)));
if ($line[0] == '=') {
$x = trim(substr($line, 1));
$x = explode(';', $x);
$zend_extensions[$linenum] = str_replace('"', '', array_shift($x));
continue;
}
if (strtolower(substr($line, 0, 9)) == 'extension') {
$line = trim(substr($line, 9));
if ($line[0] == '=') {
$x = trim(substr($line, 1));
$x = explode(';', $x);
$extensions[$linenum] = str_replace('"', '', array_shift($x));
continue;
}
}
if (strtolower(substr($line, 0, strlen($zend_extension_line))) ==
$zend_extension_line) {
$line = trim(substr($line, strlen($zend_extension_line)));
if ($line[0] == '=') {
$x = trim(substr($line, 1));
$x = explode(';', $x);
$zend_extensions[$linenum] = str_replace('"', '', array_shift($x));
continue;
}
}
}
return array(
'extensions' => $extensions,
'zend_extensions' => $zend_extensions,
'extension_dir' => $extension_dir,
'all' => $all,
);
} else {
return PEAR::raiseError('php.ini "' . $filename . '" does not exist');
}
return array(
'extensions' => $extensions,
'zend_extensions' => $zend_extensions,
'extension_dir' => $extension_dir,
'all' => $all,
);
}
 
// {{{ doInstall()
521,98 → 522,176
 
function doInstall($command, $options, $params)
{
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
 
if (isset($options['installroot']) && isset($options['packagingroot'])) {
return $this->raiseError('ERROR: cannot use both --installroot and --packagingroot');
}
 
$reg = &$this->config->getRegistry();
$channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
if (!$reg->channelExists($channel)) {
return $this->raiseError('Channel "' . $channel . '" does not exist');
}
 
if (empty($this->installer)) {
$this->installer = &$this->getInstaller($this->ui);
}
if ($command == 'upgrade') {
 
if ($command == 'upgrade' || $command == 'upgrade-all') {
// If people run the upgrade command but pass nothing, emulate a upgrade-all
if ($command == 'upgrade' && empty($params)) {
return $this->doUpgradeAll($command, $options, $params);
}
$options['upgrade'] = true;
} else {
$packages = $params;
}
if (isset($options['installroot']) && isset($options['packagingroot'])) {
return $this->raiseError('ERROR: cannot use both --installroot and --packagingroot');
 
$instreg = &$reg; // instreg used to check if package is installed
if (isset($options['packagingroot']) && !isset($options['upgrade'])) {
$packrootphp_dir = $this->installer->_prependPath(
$this->config->get('php_dir', null, 'pear.php.net'),
$options['packagingroot']);
$metadata_dir = $this->config->get('metadata_dir', null, 'pear.php.net');
if ($metadata_dir) {
$metadata_dir = $this->installer->_prependPath(
$metadata_dir,
$options['packagingroot']);
}
$instreg = new PEAR_Registry($packrootphp_dir, false, false, $metadata_dir); // other instreg!
 
if ($this->config->get('verbose') > 2) {
$this->ui->outputData('using package root: ' . $options['packagingroot']);
}
}
if (isset($options['packagingroot']) && $this->config->get('verbose') > 2) {
$this->ui->outputData('using package root: ' . $options['packagingroot']);
}
$reg = &$this->config->getRegistry();
if ($command == 'upgrade-all') {
$options['upgrade'] = true;
$reg = &$this->config->getRegistry();
$savechannel = $this->config->get('default_channel');
$params = array();
foreach ($reg->listChannels() as $channel) {
if ($channel == '__uri') {
 
$abstractpackages = $otherpackages = array();
// parse params
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 
foreach ($params as $param) {
if (strpos($param, 'http://') === 0) {
$otherpackages[] = $param;
continue;
}
 
if (strpos($param, 'channel://') === false && @file_exists($param)) {
if (isset($options['force'])) {
$otherpackages[] = $param;
continue;
}
$this->config->set('default_channel', $channel);
$chan = &$reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $this->raiseError($chan);
 
$pkg = new PEAR_PackageFile($this->config);
$pf = $pkg->fromAnyFile($param, PEAR_VALIDATE_DOWNLOADING);
if (PEAR::isError($pf)) {
$otherpackages[] = $param;
continue;
}
if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
$dorest = true;
unset($remote);
} else {
$dorest = false;
$remote = &$this->config->getRemote($this->config);
}
$state = $this->config->get('preferred_state');
$installed = array_flip($reg->listPackages($channel));
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
if ($dorest) {
$rest = &$this->config->getREST('1.0', array());
$latest = $rest->listLatestUpgrades($base, $state, $installed, $channel, $reg);
} else {
if (empty($state) || $state == 'any') {
$latest = $remote->call("package.listLatestReleases");
} else {
$latest = $remote->call("package.listLatestReleases", $state);
 
$exists = $reg->packageExists($pf->getPackage(), $pf->getChannel());
$pversion = $reg->packageInfo($pf->getPackage(), 'version', $pf->getChannel());
$version_compare = version_compare($pf->getVersion(), $pversion, '<=');
if ($exists && $version_compare) {
if ($this->config->get('verbose')) {
$this->ui->outputData('Ignoring installed package ' .
$reg->parsedPackageNameToString(
array('package' => $pf->getPackage(),
'channel' => $pf->getChannel()), true));
}
}
PEAR::staticPopErrorHandling();
if (PEAR::isError($latest) || !is_array($latest)) {
continue;
}
foreach ($latest as $package => $info) {
$package = strtolower($package);
if (!isset($installed[$package])) {
// skip packages we don't have installed
$otherpackages[] = $param;
continue;
}
 
$e = $reg->parsePackageName($param, $channel);
if (PEAR::isError($e)) {
$otherpackages[] = $param;
} else {
$abstractpackages[] = $e;
}
}
PEAR::staticPopErrorHandling();
 
// if there are any local package .tgz or remote static url, we can't
// filter. The filter only works for abstract packages
if (count($abstractpackages) && !isset($options['force'])) {
// when not being forced, only do necessary upgrades/installs
if (isset($options['upgrade'])) {
$abstractpackages = $this->_filterUptodatePackages($abstractpackages, $command);
} else {
$count = count($abstractpackages);
foreach ($abstractpackages as $i => $package) {
if (isset($package['group'])) {
// do not filter out install groups
continue;
}
$inst_version = $reg->packageInfo($package, 'version', $channel);
if (version_compare("$info[version]", "$inst_version", "le")) {
// installed version is up-to-date
continue;
 
if ($instreg->packageExists($package['package'], $package['channel'])) {
if ($count > 1) {
if ($this->config->get('verbose')) {
$this->ui->outputData('Ignoring installed package ' .
$reg->parsedPackageNameToString($package, true));
}
unset($abstractpackages[$i]);
} elseif ($count === 1) {
// Lets try to upgrade it since it's already installed
$options['upgrade'] = true;
}
}
$params[] = $a = $reg->parsedPackageNameToString(array('package' => $package,
'channel' => $channel));
$this->ui->outputData(array('data' => "Will upgrade $a"), $command);
}
}
$this->config->set('default_channel', $savechannel);
$abstractpackages =
array_map(array($reg, 'parsedPackageNameToString'), $abstractpackages);
} elseif (count($abstractpackages)) {
$abstractpackages =
array_map(array($reg, 'parsedPackageNameToString'), $abstractpackages);
}
 
$packages = array_merge($abstractpackages, $otherpackages);
if (!count($packages)) {
$c = '';
if (isset($options['channel'])){
$c .= ' in channel "' . $options['channel'] . '"';
}
$this->ui->outputData('Nothing to ' . $command . $c);
return true;
}
 
$this->downloader = &$this->getDownloader($this->ui, $options, $this->config);
$errors = array();
$downloaded = array();
$downloaded = &$this->downloader->download($params);
$errors = $downloaded = $binaries = array();
$downloaded = &$this->downloader->download($packages);
if (PEAR::isError($downloaded)) {
return $this->raiseError($downloaded);
}
 
$errors = $this->downloader->getErrorMsgs();
if (count($errors)) {
$err = array();
$err['data'] = array();
foreach ($errors as $error) {
$err['data'][] = array($error);
if ($error !== null) {
$err['data'][] = array($error);
}
}
$err['headline'] = 'Install Errors';
$this->ui->outputData($err);
 
if (!empty($err['data'])) {
$err['headline'] = 'Install Errors';
$this->ui->outputData($err);
}
 
if (!count($downloaded)) {
return $this->raiseError("$command failed");
}
}
 
$data = array(
'headline' => 'Packages that would be Installed'
);
 
if (isset($options['pretend'])) {
foreach ($downloaded as $package) {
$data['data'][] = array($reg->parsedPackageNameToString($package->getParsedPackage()));
620,6 → 699,7
$this->ui->outputData($data, 'pretend');
return true;
}
 
$this->installer->setOptions($options);
$this->installer->sortPackagesForInstall($downloaded);
if (PEAR::isError($err = $this->installer->setDownloadedPackages($downloaded))) {
626,15 → 706,8
$this->raiseError($err->getMessage());
return true;
}
$extrainfo = array();
if (isset($options['packagingroot'])) {
$packrootphp_dir = $this->installer->_prependPath(
$this->config->get('php_dir', null, 'pear.php.net'),
$options['packagingroot']);
$instreg = new PEAR_Registry($packrootphp_dir);
} else {
$instreg = $reg;
}
 
$binaries = $extrainfo = array();
foreach ($downloaded as $param) {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = $this->installer->install($param, $options);
647,39 → 720,50
$this->ui->outputData('ERROR: ' .$oldinfo->getMessage());
continue;
}
 
// we just installed a different package than requested,
// let's change the param and info so that the rest of this works
$param = $info[0];
$info = $info[1];
$info = $info[1];
}
}
if (is_array($info)) {
if ($param->getPackageType() == 'extsrc' ||
$param->getPackageType() == 'extbin' ||
$param->getPackageType() == 'zendextsrc' ||
$param->getPackageType() == 'zendextbin') {
$pkg = &$param->getPackageFile();
if ($instbin = $pkg->getInstalledBinary()) {
$instpkg = &$instreg->getPackage($instbin, $pkg->getChannel());
} else {
$instpkg = &$instreg->getPackage($pkg->getPackage(), $pkg->getChannel());
 
if (!is_array($info)) {
return $this->raiseError("$command failed");
}
 
if ($param->getPackageType() == 'extsrc' ||
$param->getPackageType() == 'extbin' ||
$param->getPackageType() == 'zendextsrc' ||
$param->getPackageType() == 'zendextbin'
) {
$pkg = &$param->getPackageFile();
if ($instbin = $pkg->getInstalledBinary()) {
$instpkg = &$instreg->getPackage($instbin, $pkg->getChannel());
} else {
$instpkg = &$instreg->getPackage($pkg->getPackage(), $pkg->getChannel());
}
 
foreach ($instpkg->getFilelist() as $name => $atts) {
$pinfo = pathinfo($atts['installed_as']);
if (!isset($pinfo['extension']) ||
in_array($pinfo['extension'], array('c', 'h'))
) {
continue; // make sure we don't match php_blah.h
}
foreach ($instpkg->getFilelist() as $name => $atts) {
$pinfo = pathinfo($atts['installed_as']);
if (!isset($pinfo['extension']) ||
in_array($pinfo['extension'], array('c', 'h'))) {
continue; // make sure we don't match php_blah.h
}
if ((strpos($pinfo['basename'], 'php_') === 0 &&
$pinfo['extension'] == 'dll') ||
// most unices
$pinfo['extension'] == 'so' ||
// hp-ux
$pinfo['extension'] == 'sl') {
$binaries[] = array($atts['installed_as'], $pinfo);
break;
}
 
if ((strpos($pinfo['basename'], 'php_') === 0 &&
$pinfo['extension'] == 'dll') ||
// most unices
$pinfo['extension'] == 'so' ||
// hp-ux
$pinfo['extension'] == 'sl') {
$binaries[] = array($atts['installed_as'], $pinfo);
break;
}
}
 
if (count($binaries)) {
foreach ($binaries as $pinfo) {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$ret = $this->enableExtension(array($pinfo[0]), $param->getPackageType());
689,17 → 773,13
if ($param->getPackageType() == 'extsrc' ||
$param->getPackageType() == 'extbin') {
$exttype = 'extension';
$extpath = $pinfo[1]['basename'];
} else {
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
$ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
$exttype = 'zend_extension' . $debug . $ts;
$exttype = 'zend_extension';
$extpath = $atts['installed_as'];
}
$extrainfo[] = 'You should add "' . $exttype . '=' .
$pinfo[1]['basename'] . '" to php.ini';
$extpath . '" to php.ini';
} else {
$extrainfo[] = 'Extension ' . $instpkg->getProvidesExtension() .
' enabled in php.ini';
706,100 → 786,139
}
}
}
if ($this->config->get('verbose') > 0) {
$channel = $param->getChannel();
$label = $reg->parsedPackageNameToString(
array(
'channel' => $channel,
'package' => $param->getPackage(),
'version' => $param->getVersion(),
));
$out = array('data' => "$command ok: $label");
if (isset($info['release_warnings'])) {
$out['release_warnings'] = $info['release_warnings'];
}
$this->ui->outputData($out, $command);
if (!isset($options['register-only']) && !isset($options['offline'])) {
if ($this->config->isDefinedLayer('ftp')) {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = $this->installer->ftpInstall($param);
PEAR::staticPopErrorHandling();
if (PEAR::isError($info)) {
$this->ui->outputData($info->getMessage());
$this->ui->outputData("remote install failed: $label");
} else {
$this->ui->outputData("remote install ok: $label");
}
}
 
if ($this->config->get('verbose') > 0) {
$chan = $param->getChannel();
$label = $reg->parsedPackageNameToString(
array(
'channel' => $chan,
'package' => $param->getPackage(),
'version' => $param->getVersion(),
));
$out = array('data' => "$command ok: $label");
if (isset($info['release_warnings'])) {
$out['release_warnings'] = $info['release_warnings'];
}
$this->ui->outputData($out, $command);
 
if (!isset($options['register-only']) && !isset($options['offline'])) {
if ($this->config->isDefinedLayer('ftp')) {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = $this->installer->ftpInstall($param);
PEAR::staticPopErrorHandling();
if (PEAR::isError($info)) {
$this->ui->outputData($info->getMessage());
$this->ui->outputData("remote install failed: $label");
} else {
$this->ui->outputData("remote install ok: $label");
}
}
}
$deps = $param->getDeps();
if ($deps) {
if (isset($deps['group'])) {
$groups = $deps['group'];
if (!isset($groups[0])) {
$groups = array($groups);
}
 
$deps = $param->getDeps();
if ($deps) {
if (isset($deps['group'])) {
$groups = $deps['group'];
if (!isset($groups[0])) {
$groups = array($groups);
}
 
foreach ($groups as $group) {
if ($group['attribs']['name'] == 'default') {
// default group is always installed, unless the user
// explicitly chooses to install another group
continue;
}
foreach ($groups as $group) {
if ($group['attribs']['name'] == 'default') {
// default group is always installed, unless the user
// explicitly chooses to install another group
continue;
}
$this->ui->outputData($param->getPackage() . ': Optional feature ' .
$group['attribs']['name'] . ' available (' .
$group['attribs']['hint'] . ')');
}
$extrainfo[] = 'To install use "pear install ' .
$reg->parsedPackageNameToString(
array('package' => $param->getPackage(),
'channel' => $param->getChannel()), true) .
'#featurename"';
$extrainfo[] = $param->getPackage() . ': Optional feature ' .
$group['attribs']['name'] . ' available (' .
$group['attribs']['hint'] . ')';
}
 
$extrainfo[] = $param->getPackage() .
': To install optional features use "pear install ' .
$reg->parsedPackageNameToString(
array('package' => $param->getPackage(),
'channel' => $param->getChannel()), true) .
'#featurename"';
}
if (isset($options['installroot'])) {
$reg = &$this->config->getRegistry();
}
if (isset($options['packagingroot'])) {
$instreg = new PEAR_Registry($packrootphp_dir);
} else {
$instreg = $reg;
}
$pkg = &$instreg->getPackage($param->getPackage(), $param->getChannel());
// $pkg may be NULL if install is a 'fake' install via --packagingroot
if (is_object($pkg)) {
$pkg->setConfig($this->config);
if ($list = $pkg->listPostinstallScripts()) {
$pn = $reg->parsedPackageNameToString(array('channel' =>
$param->getChannel(), 'package' => $param->getPackage()), true);
$extrainfo[] = $pn . ' has post-install scripts:';
foreach ($list as $file) {
$extrainfo[] = $file;
}
$extrainfo[] = 'Use "pear run-scripts ' . $pn . '" to run';
$extrainfo[] = 'DO NOT RUN SCRIPTS FROM UNTRUSTED SOURCES';
}
 
$pkg = &$instreg->getPackage($param->getPackage(), $param->getChannel());
// $pkg may be NULL if install is a 'fake' install via --packagingroot
if (is_object($pkg)) {
$pkg->setConfig($this->config);
if ($list = $pkg->listPostinstallScripts()) {
$pn = $reg->parsedPackageNameToString(array('channel' =>
$param->getChannel(), 'package' => $param->getPackage()), true);
$extrainfo[] = $pn . ' has post-install scripts:';
foreach ($list as $file) {
$extrainfo[] = $file;
}
$extrainfo[] = $param->getPackage() .
': Use "pear run-scripts ' . $pn . '" to finish setup.';
$extrainfo[] = 'DO NOT RUN SCRIPTS FROM UNTRUSTED SOURCES';
}
} else {
return $this->raiseError("$command failed");
}
}
 
if (count($extrainfo)) {
foreach ($extrainfo as $info) {
$this->ui->outputData($info);
}
}
 
return true;
}
 
// }}}
// {{{ doUpgradeAll()
 
function doUpgradeAll($command, $options, $params)
{
$reg = &$this->config->getRegistry();
$upgrade = array();
 
if (isset($options['channel'])) {
$channels = array($options['channel']);
} else {
$channels = $reg->listChannels();
}
 
foreach ($channels as $channel) {
if ($channel == '__uri') {
continue;
}
 
// parse name with channel
foreach ($reg->listPackages($channel) as $name) {
$upgrade[] = $reg->parsedPackageNameToString(array(
'channel' => $channel,
'package' => $name
));
}
}
 
$err = $this->doInstall($command, $options, $upgrade);
if (PEAR::isError($err)) {
$this->ui->outputData($err->getMessage(), $command);
}
}
 
// }}}
// {{{ doUninstall()
 
function doUninstall($command, $options, $params)
{
if (count($params) < 1) {
return $this->raiseError("Please supply the package(s) you want to uninstall");
}
 
if (empty($this->installer)) {
$this->installer = &$this->getInstaller($this->ui);
}
 
if (isset($options['remoteconfig'])) {
$e = $this->config->readFTPConfigFile($options['remoteconfig']);
if (!PEAR::isError($e)) {
806,11 → 925,10
$this->installer->setConfig($this->config);
}
}
if (sizeof($params) < 1) {
return $this->raiseError("Please supply the package(s) you want to uninstall");
}
 
$reg = &$this->config->getRegistry();
$newparams = array();
$binaries = array();
$badparams = array();
foreach ($params as $pkg) {
$channel = $this->config->get('default_channel');
849,7 → 967,7
if (isset($parsed['group'])) {
$group = $info->getDependencyGroup($parsed['group']);
if ($group) {
$installed = &$reg->getInstalledGroup($group);
$installed = $reg->getInstalledGroup($group);
if ($installed) {
foreach ($installed as $i => $p) {
$newparams[] = &$installed[$i];
869,6 → 987,7
// for circular dependencies like subpackages
$this->installer->setUninstallPackages($newparams);
$params = array_merge($params, $badparams);
$binaries = array();
foreach ($params as $pkg) {
$this->installer->pushErrorHandling(PEAR_ERROR_RETURN);
if ($err = $this->installer->uninstall($pkg, $options)) {
884,6 → 1003,7
if ($instbin = $pkg->getInstalledBinary()) {
continue; // this will be uninstalled later
}
 
foreach ($pkg->getFilelist() as $name => $atts) {
$pinfo = pathinfo($atts['installed_as']);
if (!isset($pinfo['extension']) ||
900,29 → 1020,31
break;
}
}
foreach ($binaries as $pinfo) {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$ret = $this->disableExtension(array($pinfo[0]), $pkg->getPackageType());
PEAR::staticPopErrorHandling();
if (PEAR::isError($ret)) {
$extrainfo[] = $ret->getMessage();
if ($pkg->getPackageType() == 'extsrc' ||
$pkg->getPackageType() == 'extbin') {
$exttype = 'extension';
if (count($binaries)) {
foreach ($binaries as $pinfo) {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$ret = $this->disableExtension(array($pinfo[0]), $pkg->getPackageType());
PEAR::staticPopErrorHandling();
if (PEAR::isError($ret)) {
$extrainfo[] = $ret->getMessage();
if ($pkg->getPackageType() == 'extsrc' ||
$pkg->getPackageType() == 'extbin') {
$exttype = 'extension';
} else {
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
$ts = preg_match('/Thread Safety.+enabled/', $info) ? '_ts' : '';
$exttype = 'zend_extension' . $debug . $ts;
}
$this->ui->outputData('Unable to remove "' . $exttype . '=' .
$pinfo[1]['basename'] . '" from php.ini', $command);
} else {
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_contents();
ob_end_clean();
$debug = function_exists('leak') ? '_debug' : '';
$ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : '';
$exttype = 'zend_extension' . $debug . $ts;
$this->ui->outputData('Extension ' . $pkg->getProvidesExtension() .
' disabled in php.ini', $command);
}
$this->ui->outputData('Unable to remove "' . $exttype . '=' .
$pinfo[1]['basename'] . '" from php.ini', $command);
} else {
$this->ui->outputData('Extension ' . $pkg->getProvidesExtension() .
' disabled in php.ini', $command);
}
}
}
949,12 → 1071,13
}
} else {
$this->installer->popErrorHandling();
if (is_object($pkg)) {
$pkg = $reg->parsedPackageNameToString($pkg);
if (!is_object($pkg)) {
return $this->raiseError("uninstall failed: $pkg");
}
return $this->raiseError("uninstall failed: $pkg");
$pkg = $reg->parsedPackageNameToString($pkg);
}
}
 
return true;
}
 
970,10 → 1093,15
 
function doBundle($command, $options, $params)
{
$downloader = &$this->getDownloader($this->ui, array('force' => true, 'nodeps' => true,
'soft' => true, 'downloadonly' => true), $this->config);
$opts = array(
'force' => true,
'nodeps' => true,
'soft' => true,
'downloadonly' => true
);
$downloader = &$this->getDownloader($this->ui, $opts, $this->config);
$reg = &$this->config->getRegistry();
if (sizeof($params) < 1) {
if (count($params) < 1) {
return $this->raiseError("Please supply the package you want to bundle");
}
 
983,18 → 1111,24
}
$dest = realpath($options['destination']);
} else {
$pwd = getcwd();
if (is_dir($pwd . DIRECTORY_SEPARATOR . 'ext')) {
$dest = $pwd . DIRECTORY_SEPARATOR . 'ext';
} else {
$dest = $pwd;
}
$pwd = getcwd();
$dir = $pwd . DIRECTORY_SEPARATOR . 'ext';
$dest = is_dir($dir) ? $dir : $pwd;
}
$downloader->setDownloadDir($dest);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$err = $downloader->setDownloadDir($dest);
PEAR::staticPopErrorHandling();
if (PEAR::isError($err)) {
return PEAR::raiseError('download directory "' . $dest .
'" is not writeable.');
}
$result = &$downloader->download(array($params[0]));
if (PEAR::isError($result)) {
return $result;
}
if (!isset($result[0])) {
return $this->raiseError('unable to unpack ' . $params[0]);
}
$pkgfile = &$result[0]->getPackageFile();
$pkgname = $pkgfile->getName();
$pkgversion = $pkgfile->getVersion();
1003,7 → 1137,7
$dest .= DIRECTORY_SEPARATOR . $pkgname;
$orig = $pkgname . '-' . $pkgversion;
 
$tar = &new Archive_Tar($pkgfile->getArchiveFile());
$tar = new Archive_Tar($pkgfile->getArchiveFile());
if (!$tar->extractModify($dest, $orig)) {
return $this->raiseError('unable to unpack ' . $pkgfile->getArchiveFile());
}
1018,6 → 1152,7
if (!isset($params[0])) {
return $this->raiseError('run-scripts expects 1 parameter: a package name');
}
 
$reg = &$this->config->getRegistry();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
1025,15 → 1160,110
if (PEAR::isError($parsed)) {
return $this->raiseError($parsed);
}
 
$package = &$reg->getPackage($parsed['package'], $parsed['channel']);
if (is_object($package)) {
$package->setConfig($this->config);
$package->runPostinstallScripts();
} else {
if (!is_object($package)) {
return $this->raiseError('Could not retrieve package "' . $params[0] . '" from registry');
}
 
$package->setConfig($this->config);
$package->runPostinstallScripts();
$this->ui->outputData('Install scripts complete', $command);
return true;
}
 
/**
* Given a list of packages, filter out those ones that are already up to date
*
* @param $packages: packages, in parsed array format !
* @return list of packages that can be upgraded
*/
function _filterUptodatePackages($packages, $command)
{
$reg = &$this->config->getRegistry();
$latestReleases = array();
 
$ret = array();
foreach ($packages as $package) {
if (isset($package['group'])) {
$ret[] = $package;
continue;
}
 
$channel = $package['channel'];
$name = $package['package'];
if (!$reg->packageExists($name, $channel)) {
$ret[] = $package;
continue;
}
 
if (!isset($latestReleases[$channel])) {
// fill in cache for this channel
$chan = $reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $this->raiseError($chan);
}
 
$base2 = false;
$preferred_mirror = $this->config->get('preferred_mirror', null, $channel);
if ($chan->supportsREST($preferred_mirror) &&
(
//($base2 = $chan->getBaseURL('REST1.4', $preferred_mirror)) ||
($base = $chan->getBaseURL('REST1.0', $preferred_mirror))
)
) {
$dorest = true;
}
 
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
if (!isset($package['state'])) {
$state = $this->config->get('preferred_state', null, $channel);
} else {
$state = $package['state'];
}
 
if ($dorest) {
if ($base2) {
$rest = &$this->config->getREST('1.4', array());
$base = $base2;
} else {
$rest = &$this->config->getREST('1.0', array());
}
 
$installed = array_flip($reg->listPackages($channel));
$latest = $rest->listLatestUpgrades($base, $state, $installed, $channel, $reg);
}
 
PEAR::staticPopErrorHandling();
if (PEAR::isError($latest)) {
$this->ui->outputData('Error getting channel info from ' . $channel .
': ' . $latest->getMessage());
continue;
}
 
$latestReleases[$channel] = array_change_key_case($latest);
}
 
// check package for latest release
$name_lower = strtolower($name);
if (isset($latestReleases[$channel][$name_lower])) {
// if not set, up to date
$inst_version = $reg->packageInfo($name, 'version', $channel);
$channel_version = $latestReleases[$channel][$name_lower]['version'];
if (version_compare($channel_version, $inst_version, 'le')) {
// installed version is up-to-date
continue;
}
 
// maintain BC
if ($command == 'upgrade-all') {
$this->ui->outputData(array('data' => 'Will upgrade ' .
$reg->parsedPackageNameToString($package)), $command);
}
$ret[] = $package;
}
}
 
return $ret;
}
}
?>
/trunk/bibliotheque/pear/PEAR/Command/Pickle.php
4,18 → 4,11
*
* 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 2005-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: Pickle.php,v 1.6 2006/05/12 02:38:58 cellog Exp $
* @copyright 2005-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.1
*/
31,9 → 24,9
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 2005-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.5.1
* @copyright 2005-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.1
*/
82,12 → 75,11
*
* @access public
*/
function PEAR_Command_Pickle(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
 
/**
* For unit-testing ease
*
98,7 → 90,8
if (!class_exists('PEAR_Packager')) {
require_once 'PEAR/Packager.php';
}
$a = &new PEAR_Packager;
 
$a = new PEAR_Packager;
return $a;
}
 
110,15 → 103,17
* @param string|null $tmpdir
* @return PEAR_PackageFile
*/
function &getPackageFile($config, $debug = false, $tmpdir = null)
function &getPackageFile($config, $debug = false)
{
if (!class_exists('PEAR_Common')) {
require_once 'PEAR/Common.php';
}
if (!class_exists('PEAR/PackageFile.php')) {
 
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$a = &new PEAR_PackageFile($config, $debug, $tmpdir);
 
$a = new PEAR_PackageFile($config, $debug);
$common = new PEAR_Common;
$common->ui = $this->ui;
$a->setLogger($common);
133,15 → 128,18
if (PEAR::isError($err = $this->_convertPackage($pkginfofile))) {
return $err;
}
 
$compress = empty($options['nocompress']) ? true : false;
$result = $packager->package($pkginfofile, $compress, 'package.xml');
if (PEAR::isError($result)) {
return $this->raiseError($result);
}
 
// Don't want output, only the package file name just created
if (isset($options['showname'])) {
$this->ui->outputData($result, $command);
}
 
return true;
}
 
153,6 → 151,7
return $this->raiseError('Cannot process "' .
$packagexml . '", is not a package.xml 2.0');
}
 
require_once 'PEAR/PackageFile/v1.php';
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->config);
161,16 → 160,19
'", is not an extension source package. Using a PEAR_PackageFileManager-based ' .
'script is an option');
}
 
if (is_array($pf2->getUsesRole())) {
return $this->raiseError('Cannot safely convert "' . $packagexml .
'", contains custom roles. Using a PEAR_PackageFileManager-based script or ' .
'the convert command is an option');
}
 
if (is_array($pf2->getUsesTask())) {
return $this->raiseError('Cannot safely convert "' . $packagexml .
'", contains custom tasks. Using a PEAR_PackageFileManager-based script or ' .
'the convert command is an option');
}
 
$deps = $pf2->getDependencies();
if (isset($deps['group'])) {
return $this->raiseError('Cannot safely convert "' . $packagexml .
177,6 → 179,7
'", contains dependency groups. Using a PEAR_PackageFileManager-based script ' .
'or the convert command is an option');
}
 
if (isset($deps['required']['subpackage']) ||
isset($deps['optional']['subpackage'])) {
return $this->raiseError('Cannot safely convert "' . $packagexml .
183,16 → 186,19
'", contains subpackage dependencies. Using a PEAR_PackageFileManager-based '.
'script is an option');
}
 
if (isset($deps['required']['os'])) {
return $this->raiseError('Cannot safely convert "' . $packagexml .
'", contains os dependencies. Using a PEAR_PackageFileManager-based '.
'script is an option');
}
 
if (isset($deps['required']['arch'])) {
return $this->raiseError('Cannot safely convert "' . $packagexml .
'", contains arch dependencies. Using a PEAR_PackageFileManager-based '.
'script is an option');
}
 
$pf->setPackage($pf2->getPackage());
$pf->setSummary($pf2->getSummary());
$pf->setDescription($pf2->getDescription());
200,6 → 206,7
$pf->addMaintainer($maintainer['role'], $maintainer['handle'],
$maintainer['name'], $maintainer['email']);
}
 
$pf->setVersion($pf2->getVersion());
$pf->setDate($pf2->getDate());
$pf->setLicense($pf2->getLicense());
209,10 → 216,12
if (isset($deps['required']['php']['max'])) {
$pf->addPhpDep($deps['required']['php']['max'], 'le');
}
 
if (isset($deps['required']['package'])) {
if (!isset($deps['required']['package'][0])) {
$deps['required']['package'] = array($deps['required']['package']);
}
 
foreach ($deps['required']['package'] as $dep) {
if (!isset($dep['channel'])) {
return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
219,31 → 228,40
' contains uri-based dependency on a package. Using a ' .
'PEAR_PackageFileManager-based script is an option');
}
if ($dep['channel'] != 'pear.php.net' && $dep['channel'] != 'pecl.php.net') {
 
if ($dep['channel'] != 'pear.php.net'
&& $dep['channel'] != 'pecl.php.net'
&& $dep['channel'] != 'doc.php.net') {
return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
' contains dependency on a non-standard channel package. Using a ' .
'PEAR_PackageFileManager-based script is an option');
}
 
if (isset($dep['conflicts'])) {
return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
' contains conflicts dependency. Using a ' .
'PEAR_PackageFileManager-based script is an option');
}
 
if (isset($dep['exclude'])) {
$this->ui->outputData('WARNING: exclude tags are ignored in conversion');
}
 
if (isset($dep['min'])) {
$pf->addPackageDep($dep['name'], $dep['min'], 'ge');
}
 
if (isset($dep['max'])) {
$pf->addPackageDep($dep['name'], $dep['max'], 'le');
}
}
}
 
if (isset($deps['required']['extension'])) {
if (!isset($deps['required']['extension'][0])) {
$deps['required']['extension'] = array($deps['required']['extension']);
}
 
foreach ($deps['required']['extension'] as $dep) {
if (isset($dep['conflicts'])) {
return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
250,21 → 268,26
' contains conflicts dependency. Using a ' .
'PEAR_PackageFileManager-based script is an option');
}
 
if (isset($dep['exclude'])) {
$this->ui->outputData('WARNING: exclude tags are ignored in conversion');
}
 
if (isset($dep['min'])) {
$pf->addExtensionDep($dep['name'], $dep['min'], 'ge');
}
 
if (isset($dep['max'])) {
$pf->addExtensionDep($dep['name'], $dep['max'], 'le');
}
}
}
 
if (isset($deps['optional']['package'])) {
if (!isset($deps['optional']['package'][0])) {
$deps['optional']['package'] = array($deps['optional']['package']);
}
 
foreach ($deps['optional']['package'] as $dep) {
if (!isset($dep['channel'])) {
return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
271,72 → 294,90
' contains uri-based dependency on a package. Using a ' .
'PEAR_PackageFileManager-based script is an option');
}
if ($dep['channel'] != 'pear.php.net' && $dep['channel'] != 'pecl.php.net') {
 
if ($dep['channel'] != 'pear.php.net'
&& $dep['channel'] != 'pecl.php.net'
&& $dep['channel'] != 'doc.php.net') {
return $this->raiseError('Cannot safely convert "' . $packagexml . '"' .
' contains dependency on a non-standard channel package. Using a ' .
'PEAR_PackageFileManager-based script is an option');
}
 
if (isset($dep['exclude'])) {
$this->ui->outputData('WARNING: exclude tags are ignored in conversion');
}
 
if (isset($dep['min'])) {
$pf->addPackageDep($dep['name'], $dep['min'], 'ge', 'yes');
}
 
if (isset($dep['max'])) {
$pf->addPackageDep($dep['name'], $dep['max'], 'le', 'yes');
}
}
}
 
if (isset($deps['optional']['extension'])) {
if (!isset($deps['optional']['extension'][0])) {
$deps['optional']['extension'] = array($deps['optional']['extension']);
}
 
foreach ($deps['optional']['extension'] as $dep) {
if (isset($dep['exclude'])) {
$this->ui->outputData('WARNING: exclude tags are ignored in conversion');
}
 
if (isset($dep['min'])) {
$pf->addExtensionDep($dep['name'], $dep['min'], 'ge', 'yes');
}
 
if (isset($dep['max'])) {
$pf->addExtensionDep($dep['name'], $dep['max'], 'le', 'yes');
}
}
}
 
$contents = $pf2->getContents();
$release = $pf2->getReleases();
$release = $pf2->getReleases();
if (isset($releases[0])) {
return $this->raiseError('Cannot safely process "' . $packagexml . '" contains '
return $this->raiseError('Cannot safely process "' . $packagexml . '" contains '
. 'multiple extsrcrelease/zendextsrcrelease tags. Using a PEAR_PackageFileManager-based script ' .
'or the convert command is an option');
}
 
if ($configoptions = $pf2->getConfigureOptions()) {
foreach ($configoptions as $option) {
$pf->addConfigureOption($option['name'], $option['prompt'],
isset($option['default']) ? $option['default'] : false);
$default = isset($option['default']) ? $option['default'] : false;
$pf->addConfigureOption($option['name'], $option['prompt'], $default);
}
}
 
if (isset($release['filelist']['ignore'])) {
return $this->raiseError('Cannot safely process "' . $packagexml . '" contains '
return $this->raiseError('Cannot safely process "' . $packagexml . '" contains '
. 'ignore tags. Using a PEAR_PackageFileManager-based script or the convert' .
' command is an option');
}
 
if (isset($release['filelist']['install']) &&
!isset($release['filelist']['install'][0])) {
$release['filelist']['install'] = array($release['filelist']['install']);
}
 
if (isset($contents['dir']['attribs']['baseinstalldir'])) {
$baseinstalldir = $contents['dir']['attribs']['baseinstalldir'];
} else {
$baseinstalldir = false;
}
 
if (!isset($contents['dir']['file'][0])) {
$contents['dir']['file'] = array($contents['dir']['file']);
}
 
foreach ($contents['dir']['file'] as $file) {
if ($baseinstalldir && !isset($file['attribs']['baseinstalldir'])) {
$file['attribs']['baseinstalldir'] = $baseinstalldir;
}
 
$processFile = $file;
unset($processFile['attribs']);
if (count($processFile)) {
349,11 → 390,13
$file['attribs']['replace'][] = $task;
}
}
 
if (!in_array($file['attribs']['role'], PEAR_Common::getFileRoles())) {
return $this->raiseError('Cannot safely convert "' . $packagexml .
'", contains custom roles. Using a PEAR_PackageFileManager-based script ' .
'or the convert command is an option');
}
 
if (isset($release['filelist']['install'])) {
foreach ($release['filelist']['install'] as $installas) {
if ($installas['attribs']['name'] == $file['attribs']['name']) {
361,16 → 404,17
}
}
}
 
$pf->addFile('/', $file['attribs']['name'], $file['attribs']);
}
 
if ($pf2->getChangeLog()) {
$this->ui->outputData('WARNING: changelog is not translated to package.xml ' .
'1.0, use PEAR_PackageFileManager-based script if you need changelog-' .
'translation for package.xml 1.0');
}
 
$gen = &$pf->getDefaultGenerator();
$gen->toPackageFile('.');
}
}
 
?>
/trunk/bibliotheque/pear/PEAR/Command/Registry.php
4,19 → 4,12
*
* 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 Stig Bakken <ssb@php.net>
* @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: Registry.php,v 1.75 2006/11/19 23:50:09 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
33,16 → 26,14
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Registry extends PEAR_Command_Common
{
// {{{ properties
 
var $commands = array(
'list' => array(
'summary' => 'List Installed Packages In The Default Channel',
58,6 → 49,10
'shortopt' => 'a',
'doc' => 'list installed packages from all channels',
),
'channelinfo' => array(
'shortopt' => 'i',
'doc' => 'output fully channel-aware data, even on failure',
),
),
'doc' => '<package>
If invoked without parameters, this command lists the PEAR packages
97,23 → 92,16
)
);
 
// }}}
// {{{ constructor
 
/**
* PEAR_Command_Registry constructor.
*
* @access public
*/
function PEAR_Command_Registry(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
// }}}
 
// {{{ doList()
 
function _sortinfo($a, $b)
{
$apackage = isset($a['package']) ? $a['package'] : $a['name'];
123,67 → 111,131
 
function doList($command, $options, $params)
{
if (isset($options['allchannels'])) {
$reg = &$this->config->getRegistry();
$channelinfo = isset($options['channelinfo']);
if (isset($options['allchannels']) && !$channelinfo) {
return $this->doListAll($command, array(), $params);
}
$reg = &$this->config->getRegistry();
if (count($params) == 1) {
 
if (isset($options['allchannels']) && $channelinfo) {
// allchannels with $channelinfo
unset($options['allchannels']);
$channels = $reg->getChannels();
$errors = array();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
foreach ($channels as $channel) {
$options['channel'] = $channel->getName();
$ret = $this->doList($command, $options, $params);
 
if (PEAR::isError($ret)) {
$errors[] = $ret;
}
}
 
PEAR::staticPopErrorHandling();
if (count($errors)) {
// for now, only give first error
return PEAR::raiseError($errors[0]);
}
 
return true;
}
 
if (count($params) === 1) {
return $this->doFileList($command, $options, $params);
}
 
if (isset($options['channel'])) {
if ($reg->channelExists($options['channel'])) {
$channel = $reg->channelName($options['channel']);
} else {
if (!$reg->channelExists($options['channel'])) {
return $this->raiseError('Channel "' . $options['channel'] .'" does not exist');
}
 
$channel = $reg->channelName($options['channel']);
} else {
$channel = $this->config->get('default_channel');
}
 
$installed = $reg->packageInfo(null, null, $channel);
usort($installed, array(&$this, '_sortinfo'));
$i = $j = 0;
 
$data = array(
'caption' => 'Installed packages, channel ' .
$channel . ':',
'border' => true,
'headline' => array('Package', 'Version', 'State')
'headline' => array('Package', 'Version', 'State'),
'channel' => $channel,
);
if ($channelinfo) {
$data['headline'] = array('Channel', 'Package', 'Version', 'State');
}
 
if (count($installed) && !isset($data['data'])) {
$data['data'] = array();
}
 
foreach ($installed as $package) {
$pobj = $reg->getPackage(isset($package['package']) ?
$package['package'] : $package['name'], $channel);
$data['data'][] = array($pobj->getPackage(), $pobj->getVersion(),
if ($channelinfo) {
$packageinfo = array($pobj->getChannel(), $pobj->getPackage(), $pobj->getVersion(),
$pobj->getState() ? $pobj->getState() : null);
} else {
$packageinfo = array($pobj->getPackage(), $pobj->getVersion(),
$pobj->getState() ? $pobj->getState() : null);
}
$data['data'][] = $packageinfo;
}
if (count($installed)==0) {
$data = '(no packages installed from channel ' . $channel . ')';
 
if (count($installed) === 0) {
if (!$channelinfo) {
$data = '(no packages installed from channel ' . $channel . ')';
} else {
$data = array(
'caption' => 'Installed packages, channel ' .
$channel . ':',
'border' => true,
'channel' => $channel,
'data' => array(array('(no packages installed)')),
);
}
}
 
$this->ui->outputData($data, $command);
return true;
}
 
function doListAll($command, $options, $params)
{
// This duplicate code is deprecated over
// list --channelinfo, which gives identical
// output for list and list --allchannels.
$reg = &$this->config->getRegistry();
$installed = $reg->packageInfo(null, null, null);
foreach ($installed as $channel => $packages) {
usort($packages, array($this, '_sortinfo'));
$i = $j = 0;
$data = array(
'caption' => 'Installed packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Package', 'Version', 'State')
);
'caption' => 'Installed packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Package', 'Version', 'State'),
'channel' => $channel
);
 
foreach ($packages as $package) {
$pobj = $reg->getPackage(isset($package['package']) ?
$package['package'] : $package['name'], $channel);
$p = isset($package['package']) ? $package['package'] : $package['name'];
$pobj = $reg->getPackage($p, $channel);
$data['data'][] = array($pobj->getPackage(), $pobj->getVersion(),
$pobj->getState() ? $pobj->getState() : null);
}
if (count($packages)==0) {
 
// Adds a blank line after each section
$data['data'][] = array();
 
if (count($packages) === 0) {
$data = array(
'caption' => 'Installed packages, channel ' . $channel . ':',
'border' => true,
'data' => array(array('(no packages installed)')),
'data' => array(array('(no packages installed)'), array()),
'channel' => $channel
);
}
$this->ui->outputData($data, $command);
190,23 → 242,25
}
return true;
}
 
function doFileList($command, $options, $params)
{
if (count($params) != 1) {
if (count($params) !== 1) {
return $this->raiseError('list-files expects 1 parameter');
}
 
$reg = &$this->config->getRegistry();
$fp = false;
if (!is_dir($params[0]) && (file_exists($params[0]) || $fp = @fopen($params[0],
'r'))) {
if (!is_dir($params[0]) && (file_exists($params[0]) || $fp = @fopen($params[0], 'r'))) {
if ($fp) {
fclose($fp);
}
 
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$pkg = &new PEAR_PackageFile($this->config, $this->_debug);
 
$pkg = new PEAR_PackageFile($this->config, $this->_debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
219,16 → 273,20
if (PEAR::isError($parsed)) {
return $this->raiseError($parsed);
}
 
$info = &$reg->getPackage($parsed['package'], $parsed['channel']);
$headings = array('Type', 'Install Path');
$installed = true;
}
 
if (PEAR::isError($info)) {
return $this->raiseError($info);
}
 
if ($info === null) {
return $this->raiseError("`$params[0]' not installed");
}
 
$list = ($info->getPackagexmlVersion() == '1.0' || $installed) ?
$info->getFilelist() : $info->getContents();
if ($installed) {
236,6 → 294,7
} else {
$caption = 'Contents of ' . basename($params[0]);
}
 
$data = array(
'caption' => $caption,
'border' => true,
285,6 → 344,7
if (!isset($list['dir']['file'][0])) {
$list['dir']['file'] = array($list['dir']['file']);
}
 
foreach ($list['dir']['file'] as $att) {
$att = $att['attribs'];
$file = $att['name'];
303,18 → 363,17
$data['data'][] = array($file, $dest);
}
}
 
$this->ui->outputData($data, $command);
return true;
}
 
// }}}
// {{{ doShellTest()
 
function doShellTest($command, $options, $params)
{
if (count($params) < 1) {
return PEAR::raiseError('ERROR, usage: pear shell-test packagename [[relation] version]');
}
 
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$reg = &$this->config->getRegistry();
$info = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
321,6 → 380,7
if (PEAR::isError($info)) {
exit(1); // invalid package name
}
 
$package = $info['package'];
$channel = $info['channel'];
// "pear shell-test Foo"
331,18 → 391,19
}
}
}
if (sizeof($params) == 1) {
 
if (count($params) === 1) {
if (!$reg->packageExists($package, $channel)) {
exit(1);
}
// "pear shell-test Foo 1.0"
} elseif (sizeof($params) == 2) {
} elseif (count($params) === 2) {
$v = $reg->packageInfo($package, 'version', $channel);
if (!$v || !version_compare("$v", "{$params[1]}", "ge")) {
exit(1);
}
// "pear shell-test Foo ge 1.0"
} elseif (sizeof($params) == 3) {
} elseif (count($params) === 3) {
$v = $reg->packageInfo($package, 'version', $channel);
if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
exit(1);
354,24 → 415,26
}
}
 
// }}}
// {{{ doInfo
 
function doInfo($command, $options, $params)
{
if (count($params) != 1) {
if (count($params) !== 1) {
return $this->raiseError('pear info expects 1 parameter');
}
 
$info = $fp = false;
$reg = &$this->config->getRegistry();
if ((file_exists($params[0]) && is_file($params[0]) && !is_dir($params[0])) || $fp = @fopen($params[0], 'r')) {
if (is_file($params[0]) && !is_dir($params[0]) &&
(file_exists($params[0]) || $fp = @fopen($params[0], 'r'))
) {
if ($fp) {
fclose($fp);
}
 
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$pkg = &new PEAR_PackageFile($this->config, $this->_debug);
 
$pkg = new PEAR_PackageFile($this->config, $this->_debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
385,18 → 448,21
$this->ui->outputData($message);
}
}
 
return $this->raiseError($obj);
}
if ($obj->getPackagexmlVersion() == '1.0') {
$info = $obj->toArray();
} else {
 
if ($obj->getPackagexmlVersion() != '1.0') {
return $this->_doInfo2($command, $options, $params, $obj, false);
}
 
$info = $obj->toArray();
} else {
$parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
if (PEAR::isError($parsed)) {
return $this->raiseError($parsed);
}
 
$package = $parsed['package'];
$channel = $parsed['channel'];
$info = $reg->packageInfo($package, null, $channel);
405,13 → 471,16
return $this->_doInfo2($command, $options, $params, $obj, true);
}
}
 
if (PEAR::isError($info)) {
return $info;
}
 
if (empty($info)) {
$this->raiseError("No information found for `$params[0]'");
return;
}
 
unset($info['filelist']);
unset($info['dirtree']);
unset($info['changelog']);
419,10 → 488,12
$info['package.xml version'] = $info['xsdversion'];
unset($info['xsdversion']);
}
 
if (isset($info['packagerversion'])) {
$info['packaged with PEAR version'] = $info['packagerversion'];
unset($info['packagerversion']);
}
 
$keys = array_keys($info);
$longtext = array('description', 'summary');
foreach ($keys as $key) {
527,6 → 598,7
}
}
}
 
if ($key == '_lastmodified') {
$hdate = date('Y-m-d', $info[$key]);
unset($info[$key]);
541,6 → 613,7
}
}
}
 
$caption = 'About ' . $info['package'] . '-' . $info['version'];
$data = array(
'caption' => $caption,
554,8 → 627,6
$this->ui->outputData($data, 'package-info');
}
 
// }}}
 
/**
* @access private
*/
593,6 → 664,7
if ($src = $obj->getSourcePackage()) {
$extends .= ' (source package ' . $src['channel'] . '/' . $src['package'] . ')';
}
 
$info = array(
'Release Type' => $release,
'Name' => $extends,
606,21 → 678,27
if (!$leads) {
continue;
}
 
if (isset($leads['active'])) {
$leads = array($leads);
}
 
foreach ($leads as $lead) {
if (!empty($info['Maintainers'])) {
$info['Maintainers'] .= "\n";
}
 
$active = $lead['active'] == 'no' ? ', inactive' : '';
$info['Maintainers'] .= $lead['name'] . ' <';
$info['Maintainers'] .= $lead['email'] . "> ($role)";
$info['Maintainers'] .= $lead['email'] . "> ($role$active)";
}
}
 
$info['Release Date'] = $obj->getDate();
if ($time = $obj->getTime()) {
$info['Release Date'] .= ' ' . $time;
}
 
$info['Release Version'] = $obj->getVersion() . ' (' . $obj->getState() . ')';
$info['API Version'] = $obj->getVersion('api') . ' (' . $obj->getState('api') . ')';
$info['License'] = $obj->getLicense();
635,16 → 713,22
}
}
}
 
$info['Release Notes'] = $obj->getNotes();
if ($compat = $obj->getCompatible()) {
if (!isset($compat[0])) {
$compat = array($compat);
}
 
$info['Compatible with'] = '';
foreach ($compat as $package) {
$info['Compatible with'] .= $package['channel'] . '/' . $package['package'] .
$info['Compatible with'] .= $package['channel'] . '/' . $package['name'] .
"\nVersions >= " . $package['min'] . ', <= ' . $package['max'];
if (isset($package['exclude'])) {
if (is_array($package['exclude'])) {
$package['exclude'] = implode(', ', $package['exclude']);
}
 
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
651,15 → 735,17
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= $package['channel'] . '/' .
$package['package'] . "\nVersions " . $package['exclude'];
$package['name'] . "\nVersions " . $package['exclude'];
}
}
}
 
$usesrole = $obj->getUsesrole();
if ($usesrole) {
if (!isset($usesrole[0])) {
$usesrole = array($usesrole);
}
 
foreach ($usesrole as $roledata) {
if (isset($info['Uses Custom Roles'])) {
$info['Uses Custom Roles'] .= "\n";
666,6 → 752,7
} else {
$info['Uses Custom Roles'] = '';
}
 
if (isset($roledata['package'])) {
$rolepackage = $reg->parsedPackageNameToString($roledata, true);
} else {
674,11 → 761,13
$info['Uses Custom Roles'] .= $roledata['role'] . ' (' . $rolepackage . ')';
}
}
 
$usestask = $obj->getUsestask();
if ($usestask) {
if (!isset($usestask[0])) {
$usestask = array($usestask);
}
 
foreach ($usestask as $taskdata) {
if (isset($info['Uses Custom Tasks'])) {
$info['Uses Custom Tasks'] .= "\n";
685,6 → 774,7
} else {
$info['Uses Custom Tasks'] = '';
}
 
if (isset($taskdata['package'])) {
$taskpackage = $reg->parsedPackageNameToString($taskdata, true);
} else {
693,6 → 783,7
$info['Uses Custom Tasks'] .= $taskdata['task'] . ' (' . $taskpackage . ')';
}
}
 
$deps = $obj->getDependencies();
$info['Required Dependencies'] = 'PHP version ' . $deps['required']['php']['min'];
if (isset($deps['required']['php']['max'])) {
700,6 → 791,7
} else {
$info['Required Dependencies'] .= "\n";
}
 
if (isset($deps['required']['php']['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
706,6 → 798,7
} else {
$info['Not Compatible with'] .= "\n";
}
 
if (is_array($deps['required']['php']['exclude'])) {
$deps['required']['php']['exclude'] =
implode(', ', $deps['required']['php']['exclude']);
713,6 → 806,7
$info['Not Compatible with'] .= "PHP versions\n " .
$deps['required']['php']['exclude'];
}
 
$info['Required Dependencies'] .= 'PEAR installer version';
if (isset($deps['required']['pearinstaller']['max'])) {
$info['Required Dependencies'] .= 's ' .
722,6 → 816,7
$info['Required Dependencies'] .= ' ' .
$deps['required']['pearinstaller']['min'] . ' or newer';
}
 
if (isset($deps['required']['pearinstaller']['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
728,6 → 823,7
} else {
$info['Not Compatible with'] .= "\n";
}
 
if (is_array($deps['required']['pearinstaller']['exclude'])) {
$deps['required']['pearinstaller']['exclude'] =
implode(', ', $deps['required']['pearinstaller']['exclude']);
735,6 → 831,7
$info['Not Compatible with'] .= "PEAR installer\n Versions " .
$deps['required']['pearinstaller']['exclude'];
}
 
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($deps['required'][$index])) {
741,6 → 838,7
if (isset($deps['required'][$index]['name'])) {
$deps['required'][$index] = array($deps['required'][$index]);
}
 
foreach ($deps['required'][$index] as $package) {
if (isset($package['conflicts'])) {
$infoindex = 'Not Compatible with';
753,6 → 851,7
$infoindex = 'Required Dependencies';
$info[$infoindex] .= "\n";
}
 
if ($index == 'extension') {
$name = $package['name'];
} else {
762,11 → 861,13
$name = '__uri/' . $package['name'] . ' (static URI)';
}
}
 
$info[$infoindex] .= "$type $name";
if (isset($package['uri'])) {
$info[$infoindex] .= "\n Download URI: $package[uri]";
continue;
}
 
if (isset($package['max']) && isset($package['min'])) {
$info[$infoindex] .= " \n Versions " .
$package['min'] . '-' . $package['max'];
777,9 → 878,11
$info[$infoindex] .= " \n Version " .
$package['max'] . ' or older';
}
 
if (isset($package['recommended'])) {
$info[$infoindex] .= "\n Recommended version: $package[recommended]";
}
 
if (isset($package['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
786,9 → 889,11
} else {
$info['Not Compatible with'] .= "\n";
}
 
if (is_array($package['exclude'])) {
$package['exclude'] = implode(', ', $package['exclude']);
}
 
$package['package'] = $package['name']; // for parsedPackageNameToString
if (isset($package['conflicts'])) {
$info['Not Compatible with'] .= '=> except ';
800,10 → 905,12
}
}
}
 
if (isset($deps['required']['os'])) {
if (isset($deps['required']['os']['name'])) {
$dep['required']['os']['name'] = array($dep['required']['os']['name']);
}
 
foreach ($dep['required']['os'] as $os) {
if (isset($os['conflicts']) && $os['conflicts'] == 'yes') {
if (!isset($info['Not Compatible with'])) {
818,10 → 925,12
}
}
}
 
if (isset($deps['required']['arch'])) {
if (isset($deps['required']['arch']['pattern'])) {
$dep['required']['arch']['pattern'] = array($dep['required']['os']['pattern']);
}
 
foreach ($dep['required']['arch'] as $os) {
if (isset($os['conflicts']) && $os['conflicts'] == 'yes') {
if (!isset($info['Not Compatible with'])) {
836,6 → 945,7
}
}
}
 
if (isset($deps['optional'])) {
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
843,6 → 953,7
if (isset($deps['optional'][$index]['name'])) {
$deps['optional'][$index] = array($deps['optional'][$index]);
}
 
foreach ($deps['optional'][$index] as $package) {
if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
$infoindex = 'Not Compatible with';
859,6 → 970,7
$info['Optional Dependencies'] .= "\n";
}
}
 
if ($index == 'extension') {
$name = $package['name'];
} else {
868,15 → 980,18
$name = '__uri/' . $package['name'] . ' (static URI)';
}
}
 
$info[$infoindex] .= "$type $name";
if (isset($package['uri'])) {
$info[$infoindex] .= "\n Download URI: $package[uri]";
continue;
}
 
if ($infoindex == 'Not Compatible with') {
// conflicts is only used to say that all versions conflict
continue;
}
 
if (isset($package['max']) && isset($package['min'])) {
$info[$infoindex] .= " \n Versions " .
$package['min'] . '-' . $package['max'];
887,9 → 1002,11
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or older';
}
 
if (isset($package['recommended'])) {
$info[$infoindex] .= "\n Recommended version: $package[recommended]";
}
 
if (isset($package['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
896,9 → 1013,11
} else {
$info['Not Compatible with'] .= "\n";
}
 
if (is_array($package['exclude'])) {
$package['exclude'] = implode(', ', $package['exclude']);
}
 
$info['Not Compatible with'] .= "Package $package\n Versions " .
$package['exclude'];
}
906,10 → 1025,12
}
}
}
 
if (isset($deps['group'])) {
if (!isset($deps['group'][0])) {
$deps['group'] = array($deps['group']);
}
 
foreach ($deps['group'] as $group) {
$info['Dependency Group ' . $group['attribs']['name']] = $group['attribs']['hint'];
$groupindex = $group['attribs']['name'] . ' Contents';
920,10 → 1041,12
if (isset($group[$index]['name'])) {
$group[$index] = array($group[$index]);
}
 
foreach ($group[$index] as $package) {
if (!empty($info[$groupindex])) {
$info[$groupindex] .= "\n";
}
 
if ($index == 'extension') {
$name = $package['name'];
} else {
933,6 → 1056,7
$name = '__uri/' . $package['name'] . ' (static URI)';
}
}
 
if (isset($package['uri'])) {
if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
$info[$groupindex] .= "Not Compatible with $type $name";
939,13 → 1063,16
} else {
$info[$groupindex] .= "$type $name";
}
 
$info[$groupindex] .= "\n Download URI: $package[uri]";
continue;
}
 
if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
$info[$groupindex] .= "Not Compatible with $type $name";
continue;
}
 
$info[$groupindex] .= "$type $name";
if (isset($package['max']) && isset($package['min'])) {
$info[$groupindex] .= " \n Versions " .
957,9 → 1084,11
$info[$groupindex] .= " \n Version " .
$package['min'] . ' or older';
}
 
if (isset($package['recommended'])) {
$info[$groupindex] .= "\n Recommended version: $package[recommended]";
}
 
if (isset($package['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
966,6 → 1095,7
} else {
$info[$groupindex] .= "Not Compatible with\n";
}
 
if (is_array($package['exclude'])) {
$package['exclude'] = implode(', ', $package['exclude']);
}
977,6 → 1107,7
}
}
}
 
if ($obj->getPackageType() == 'bundle') {
$info['Bundled Packages'] = '';
foreach ($obj->getBundledPackages() as $package) {
983,6 → 1114,7
if (!empty($info['Bundled Packages'])) {
$info['Bundled Packages'] .= "\n";
}
 
if (isset($package['uri'])) {
$info['Bundled Packages'] .= '__uri/' . $package['name'];
$info['Bundled Packages'] .= "\n (URI: $package[uri]";
991,21 → 1123,22
}
}
}
 
$info['package.xml version'] = '2.0';
if ($installed) {
if ($obj->getLastModified()) {
$info['Last Modified'] = date('Y-m-d H:i', $obj->getLastModified());
}
 
$v = $obj->getLastInstalledVersion();
$info['Previous Installed Version'] = $v ? $v : '- None -';
}
 
foreach ($info as $key => $value) {
$data['data'][] = array($key, $value);
}
 
$data['raw'] = $obj->getArray(); // no validation needed
 
$this->ui->outputData($data, 'package-info');
}
}
 
?>
/trunk/bibliotheque/pear/PEAR/Command/Mirror.php
4,18 → 4,11
*
* 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 Alexander Merz <alexmerz@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: Mirror.php,v 1.18 2006/03/02 18:14:13 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.2.0
*/
31,16 → 24,14
* @category pear
* @package PEAR
* @author Alexander Merz <alexmerz@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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.2.0
*/
class PEAR_Command_Mirror extends PEAR_Command_Common
{
// {{{ properties
 
var $commands = array(
'download-all' => array(
'summary' => 'Downloads each available package from the default channel',
61,10 → 52,6
),
);
 
// }}}
 
// {{{ constructor
 
/**
* PEAR_Command_Mirror constructor.
*
72,13 → 59,11
* @param object PEAR_Frontend a reference to an frontend
* @param object PEAR_Config a reference to the configuration data
*/
function PEAR_Command_Mirror(&$ui, &$config)
function __construct(&$ui, &$config)
{
parent::PEAR_Command_Common($ui, $config);
parent::__construct($ui, $config);
}
 
// }}}
 
/**
* For unit-testing
*/
88,7 → 73,6
return $a;
}
 
// {{{ doDownloadAll()
/**
* retrieves a list of avaible Packages from master server
* and downloads them
97,8 → 81,8
* @param string $command the command
* @param array $options the command options before the command
* @param array $params the stuff after the command name
* @return bool true if succesful
* @throw PEAR_Error
* @return bool true if successful
* @throw PEAR_Error
*/
function doDownloadAll($command, $options, $params)
{
111,32 → 95,34
return $this->raiseError('Channel "' . $channel . '" does not exist');
}
$this->config->set('default_channel', $channel);
 
$this->ui->outputData('Using Channel ' . $this->config->get('default_channel'));
$chan = $reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $this->raiseError($chan);
}
 
if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
$rest = &$this->config->getREST('1.0', array());
$remoteInfo = array_flip($rest->listPackages($base));
} else {
$remote = &$this->config->getRemote();
$stable = ($this->config->get('preferred_state') == 'stable');
$remoteInfo = $remote->call("package.listAll", true, $stable, false);
$remoteInfo = array_flip($rest->listPackages($base, $channel));
}
 
if (PEAR::isError($remoteInfo)) {
return $remoteInfo;
}
 
$cmd = &$this->factory("download");
if (PEAR::isError($cmd)) {
return $cmd;
}
 
$this->ui->outputData('Using Preferred State of ' .
$this->config->get('preferred_state'));
$this->ui->outputData('Gathering release information, please wait...');
 
/**
* Error handling not necessary, because already done by
* Error handling not necessary, because already done by
* the download command
*/
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
146,8 → 132,7
if (PEAR::isError($err)) {
$this->ui->outputData($err->getMessage());
}
 
return true;
}
 
// }}}
}
/trunk/bibliotheque/pear/PEAR/Command/Auth.xml
1,11 → 1,14
<commands version="1.0">
<login>
<summary>Connects and authenticates to remote server</summary>
<summary>Connects and authenticates to remote server [Deprecated in favor of channel-login]</summary>
<function>doLogin</function>
<shortcut>li</shortcut>
<function>doLogin</function>
<options />
<doc>
Log in to the remote server. To use remote functions in the installer
<doc>&lt;channel name&gt;
WARNING: This function is deprecated in favor of using channel-login
 
Log in to a remote channel server. If &lt;channel name&gt; is not supplied,
the default channel is used. To use remote functions in the installer
that require any kind of privileges, you need to log in first. The
username and password you enter here will be stored in your per-user
PEAR configuration (~/.pearrc on Unix-like systems). After logging
13,11 → 16,13
operations on the remote server.</doc>
</login>
<logout>
<summary>Logs out from the remote server</summary>
<summary>Logs out from the remote server [Deprecated in favor of channel-logout]</summary>
<function>doLogout</function>
<shortcut>lo</shortcut>
<function>doLogout</function>
<options />
<doc>
WARNING: This function is deprecated in favor of using channel-logout
 
Logs out from the remote server. This command does not actually
connect to the remote server, it only deletes the stored username and
password from your user configuration.</doc>
/trunk/bibliotheque/pear/PEAR/Common.php
4,20 → 4,13
*
* 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 Stig Bakken <ssb@php.net>
* @author Tomas V. V. Cox <cox@idecnet.com>
* @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.157 2006/05/12 02:38:58 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1.0
* @deprecated File deprecated since Release 1.4.0a1
28,39 → 21,37
*/
require_once 'PEAR.php';
 
// {{{ constants and globals
 
/**
* PEAR_Common error when an invalid PHP file is passed to PEAR_Common::analyzeSourceCode()
*/
define('PEAR_COMMON_ERROR_INVALIDPHP', 1);
define('_PEAR_COMMON_PACKAGE_NAME_PREG', '[A-Za-z][a-zA-Z0-9_]+');
define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/');
define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '\\z/');
 
// this should allow: 1, 1.0, 1.0RC1, 1.0dev, 1.0dev123234234234, 1.0a1, 1.0b1, 1.0pl1
define('_PEAR_COMMON_PACKAGE_VERSION_PREG', '\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?');
define('PEAR_COMMON_PACKAGE_VERSION_PREG', '/^' . _PEAR_COMMON_PACKAGE_VERSION_PREG . '$/i');
define('PEAR_COMMON_PACKAGE_VERSION_PREG', '/^' . _PEAR_COMMON_PACKAGE_VERSION_PREG . '\\z/i');
 
// XXX far from perfect :-)
define('_PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '(' . _PEAR_COMMON_PACKAGE_NAME_PREG .
')(-([.0-9a-zA-Z]+))?');
define('PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '/^' . _PEAR_COMMON_PACKAGE_DOWNLOAD_PREG .
'$/');
'\\z/');
 
define('_PEAR_CHANNELS_NAME_PREG', '[A-Za-z][a-zA-Z0-9\.]+');
define('PEAR_CHANNELS_NAME_PREG', '/^' . _PEAR_CHANNELS_NAME_PREG . '$/');
define('PEAR_CHANNELS_NAME_PREG', '/^' . _PEAR_CHANNELS_NAME_PREG . '\\z/');
 
// this should allow any dns or IP address, plus a path - NO UNDERSCORES ALLOWED
define('_PEAR_CHANNELS_SERVER_PREG', '[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*(\/[a-zA-Z0-9\-]+)*');
define('PEAR_CHANNELS_SERVER_PREG', '/^' . _PEAR_CHANNELS_SERVER_PREG . '$/i');
define('PEAR_CHANNELS_SERVER_PREG', '/^' . _PEAR_CHANNELS_SERVER_PREG . '\\z/i');
 
define('_PEAR_CHANNELS_PACKAGE_PREG', '(' ._PEAR_CHANNELS_SERVER_PREG . ')\/('
. _PEAR_COMMON_PACKAGE_NAME_PREG . ')');
define('PEAR_CHANNELS_PACKAGE_PREG', '/^' . _PEAR_CHANNELS_PACKAGE_PREG . '$/i');
define('PEAR_CHANNELS_PACKAGE_PREG', '/^' . _PEAR_CHANNELS_PACKAGE_PREG . '\\z/i');
 
define('_PEAR_COMMON_CHANNEL_DOWNLOAD_PREG', '(' . _PEAR_CHANNELS_NAME_PREG . ')::('
. _PEAR_COMMON_PACKAGE_NAME_PREG . ')(-([.0-9a-zA-Z]+))?');
define('PEAR_COMMON_CHANNEL_DOWNLOAD_PREG', '/^' . _PEAR_COMMON_CHANNEL_DOWNLOAD_PREG . '$/');
define('PEAR_COMMON_CHANNEL_DOWNLOAD_PREG', '/^' . _PEAR_COMMON_CHANNEL_DOWNLOAD_PREG . '\\z/');
 
/**
* List of temporary files and directories registered by
117,8 → 108,6
*/
$GLOBALS['_PEAR_Common_script_phases'] = array('pre-install', 'post-install', 'pre-uninstall', 'post-uninstall', 'pre-build', 'post-build', 'pre-configure', 'post-configure', 'pre-setup', 'post-setup');
 
// }}}
 
/**
* Class providing common functionality for PEAR administration classes.
* @category pear
126,9 → 115,9
* @author Stig Bakken <ssb@php.net>
* @author Tomas V. V. Cox <cox@idecnet.com>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
* @deprecated This class will disappear, and its components will be spread
136,8 → 125,19
*/
class PEAR_Common extends PEAR
{
// {{{ properties
/**
* User Interface object (PEAR_Frontend_* class). If null,
* the log() method uses print.
* @var object
*/
var $ui = null;
 
/**
* Configuration object (PEAR_Config).
* @var PEAR_Config
*/
var $config = null;
 
/** stack of elements, gives some sort of XML context */
var $element_stack = array();
 
150,27 → 150,9
/** assoc with information about a package */
var $pkginfo = array();
 
/**
* User Interface object (PEAR_Frontend_* class). If null,
* the log() method uses print.
* @var object
*/
var $ui = null;
 
/**
* Configuration object (PEAR_Config).
* @var object
*/
var $config = null;
 
var $current_path = null;
 
/**
* PEAR_SourceAnalyzer instance
* @var object
*/
var $source_analyzer = null;
/**
* Flag variable used to mark a valid package file
* @var boolean
* @access private
177,25 → 159,18
*/
var $_validPackageFile;
 
// }}}
 
// {{{ constructor
 
/**
* PEAR_Common constructor
*
* @access public
*/
function PEAR_Common()
function __construct()
{
parent::PEAR();
parent::__construct();
$this->config = &PEAR_Config::singleton();
$this->debug = $this->config->get('verbose');
}
 
// }}}
// {{{ destructor
 
/**
* PEAR_Common destructor
*
211,6 → 186,7
if (!class_exists('System')) {
require_once 'System.php';
}
 
System::rm(array('-rf', $file));
} elseif (file_exists($file)) {
unlink($file);
218,9 → 194,6
}
}
 
// }}}
// {{{ addTempFile()
 
/**
* Register a temporary file or directory. When the destructor is
* executed, all registered temporary files and directories are
240,9 → 213,6
PEAR_Frontend::addTempFile($file);
}
 
// }}}
// {{{ mkDirHier()
 
/**
* Wrapper to System::mkDir(), creates a directory as well as
* any necessary parent directories.
255,6 → 225,7
*/
function mkDirHier($dir)
{
// Only used in Installer - move it there ?
$this->log(2, "+ create dir $dir");
if (!class_exists('System')) {
require_once 'System.php';
262,9 → 233,6
return System::mkDir(array('-p', $dir));
}
 
// }}}
// {{{ log()
 
/**
* Logging method.
*
272,16 → 240,14
* @param string $msg message to write to the log
*
* @return void
*
* @access public
* @static
*/
function log($level, $msg, $append_crlf = true)
public function log($level, $msg, $append_crlf = true)
{
if ($this->debug >= $level) {
if (!class_exists('PEAR_Frontend')) {
require_once 'PEAR/Frontend.php';
}
 
$ui = &PEAR_Frontend::singleton();
if (is_a($ui, 'PEAR_Frontend')) {
$ui->log($msg, $append_crlf);
291,9 → 257,6
}
}
 
// }}}
// {{{ mkTempDir()
 
/**
* Create and register a temporary directory.
*
307,25 → 270,20
*/
function mkTempDir($tmpdir = '')
{
if ($tmpdir) {
$topt = array('-t', $tmpdir);
} else {
$topt = array();
}
$topt = $tmpdir ? array('-t', $tmpdir) : array();
$topt = array_merge($topt, array('-d', 'pear'));
if (!class_exists('System')) {
require_once 'System.php';
}
 
if (!$tmpdir = System::mktemp($topt)) {
return false;
}
 
$this->addTempFile($tmpdir);
return $tmpdir;
}
 
// }}}
// {{{ setFrontendObject()
 
/**
* Set object that represents the frontend to be used.
*
338,11 → 296,173
$this->ui = &$ui;
}
 
// }}}
/**
* Return an array containing all of the states that are more stable than
* or equal to the passed in state
*
* @param string Release state
* @param boolean Determines whether to include $state in the list
* @return false|array False if $state is not a valid release state
*/
function betterStates($state, $include = false)
{
static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable');
$i = array_search($state, $states);
if ($i === false) {
return false;
}
if ($include) {
$i--;
}
return array_slice($states, $i + 1);
}
 
// {{{ infoFromTgzFile()
/**
* Get the valid roles for a PEAR package maintainer
*
* @return array
*/
public static function getUserRoles()
{
return $GLOBALS['_PEAR_Common_maintainer_roles'];
}
 
/**
* Get the valid package release states of packages
*
* @return array
*/
public static function getReleaseStates()
{
return $GLOBALS['_PEAR_Common_release_states'];
}
 
/**
* Get the implemented dependency types (php, ext, pkg etc.)
*
* @return array
*/
public static function getDependencyTypes()
{
return $GLOBALS['_PEAR_Common_dependency_types'];
}
 
/**
* Get the implemented dependency relations (has, lt, ge etc.)
*
* @return array
*/
public static function getDependencyRelations()
{
return $GLOBALS['_PEAR_Common_dependency_relations'];
}
 
/**
* Get the implemented file roles
*
* @return array
*/
public static function getFileRoles()
{
return $GLOBALS['_PEAR_Common_file_roles'];
}
 
/**
* Get the implemented file replacement types in
*
* @return array
*/
public static function getReplacementTypes()
{
return $GLOBALS['_PEAR_Common_replacement_types'];
}
 
/**
* Get the implemented file replacement types in
*
* @return array
*/
public static function getProvideTypes()
{
return $GLOBALS['_PEAR_Common_provide_types'];
}
 
/**
* Get the implemented file replacement types in
*
* @return array
*/
public static function getScriptPhases()
{
return $GLOBALS['_PEAR_Common_script_phases'];
}
 
/**
* Test whether a string contains a valid package name.
*
* @param string $name the package name to test
*
* @return bool
*
* @access public
*/
function validPackageName($name)
{
return (bool)preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $name);
}
 
/**
* Test whether a string contains a valid package version.
*
* @param string $ver the package version to test
*
* @return bool
*
* @access public
*/
function validPackageVersion($ver)
{
return (bool)preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver);
}
 
/**
* @param string $path relative or absolute include path
* @return boolean
*/
public static function isIncludeable($path)
{
if (file_exists($path) && is_readable($path)) {
return true;
}
 
$ipath = explode(PATH_SEPARATOR, ini_get('include_path'));
foreach ($ipath as $include) {
$test = realpath($include . DIRECTORY_SEPARATOR . $path);
if (file_exists($test) && is_readable($test)) {
return true;
}
}
 
return false;
}
 
function _postProcessChecks($pf)
{
if (!PEAR::isError($pf)) {
return $this->_postProcessValidPackagexml($pf);
}
 
$errs = $pf->getUserinfo();
if (is_array($errs)) {
foreach ($errs as $error) {
$e = $this->raiseError($error['message'], $error['code'], null, null, $error);
}
}
 
return $pf;
}
 
/**
* Returns information about a package file. Expects the name of
* a gzipped tar file as input.
*
356,23 → 476,11
*/
function infoFromTgzFile($file)
{
$packagefile = &new PEAR_PackageFile($this->config);
$packagefile = new PEAR_PackageFile($this->config);
$pf = &$packagefile->fromTgzFile($file, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($pf)) {
$errs = $pf->getUserinfo();
if (is_array($errs)) {
foreach ($errs as $error) {
$e = $this->raiseError($error['message'], $error['code'], null, null, $error);
}
}
return $pf;
}
return $this->_postProcessValidPackagexml($pf);
return $this->_postProcessChecks($pf);
}
 
// }}}
// {{{ infoFromDescriptionFile()
 
/**
* Returns information about a package file. Expects the name of
* a package xml file as input.
387,23 → 495,11
*/
function infoFromDescriptionFile($descfile)
{
$packagefile = &new PEAR_PackageFile($this->config);
$packagefile = new PEAR_PackageFile($this->config);
$pf = &$packagefile->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($pf)) {
$errs = $pf->getUserinfo();
if (is_array($errs)) {
foreach ($errs as $error) {
$e = $this->raiseError($error['message'], $error['code'], null, null, $error);
}
}
return $pf;
}
return $this->_postProcessValidPackagexml($pf);
return $this->_postProcessChecks($pf);
}
 
// }}}
// {{{ infoFromString()
 
/**
* Returns information about a package file. Expects the contents
* of a package xml file as input.
418,20 → 514,10
*/
function infoFromString($data)
{
$packagefile = &new PEAR_PackageFile($this->config);
$packagefile = new PEAR_PackageFile($this->config);
$pf = &$packagefile->fromXmlString($data, PEAR_VALIDATE_NORMAL, false);
if (PEAR::isError($pf)) {
$errs = $pf->getUserinfo();
if (is_array($errs)) {
foreach ($errs as $error) {
$e = $this->raiseError($error['message'], $error['code'], null, null, $error);
}
}
return $pf;
}
return $this->_postProcessValidPackagexml($pf);
return $this->_postProcessChecks($pf);
}
// }}}
 
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
439,37 → 525,24
*/
function _postProcessValidPackagexml(&$pf)
{
if (is_a($pf, 'PEAR_PackageFile_v2')) {
// sort of make this into a package.xml 1.0-style array
// changelog is not converted to old format.
$arr = $pf->toArray(true);
$arr = array_merge($arr, $arr['old']);
unset($arr['old']);
unset($arr['xsdversion']);
unset($arr['contents']);
unset($arr['compatible']);
unset($arr['channel']);
unset($arr['uri']);
unset($arr['dependencies']);
unset($arr['phprelease']);
unset($arr['extsrcrelease']);
unset($arr['zendextsrcrelease']);
unset($arr['extbinrelease']);
unset($arr['zendextbinrelease']);
unset($arr['bundle']);
unset($arr['lead']);
unset($arr['developer']);
unset($arr['helper']);
unset($arr['contributor']);
$arr['filelist'] = $pf->getFilelist();
$this->pkginfo = $arr;
return $arr;
} else {
if (!is_a($pf, 'PEAR_PackageFile_v2')) {
$this->pkginfo = $pf->toArray();
return $this->pkginfo;
}
 
// sort of make this into a package.xml 1.0-style array
// changelog is not converted to old format.
$arr = $pf->toArray(true);
$arr = array_merge($arr, $arr['old']);
unset($arr['old'], $arr['xsdversion'], $arr['contents'], $arr['compatible'],
$arr['channel'], $arr['uri'], $arr['dependencies'], $arr['phprelease'],
$arr['extsrcrelease'], $arr['zendextsrcrelease'], $arr['extbinrelease'],
$arr['zendextbinrelease'], $arr['bundle'], $arr['lead'], $arr['developer'],
$arr['helper'], $arr['contributor']);
$arr['filelist'] = $pf->getFilelist();
$this->pkginfo = $arr;
return $arr;
}
// {{{ infoFromAny()
 
/**
* Returns package information from different sources
485,7 → 558,7
function infoFromAny($info)
{
if (is_string($info) && file_exists($info)) {
$packagefile = &new PEAR_PackageFile($this->config);
$packagefile = new PEAR_PackageFile($this->config);
$pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
if (PEAR::isError($pf)) {
$errs = $pf->getUserinfo();
494,16 → 567,16
$e = $this->raiseError($error['message'], $error['code'], null, null, $error);
}
}
 
return $pf;
}
 
return $this->_postProcessValidPackagexml($pf);
}
 
return $info;
}
 
// }}}
// {{{ xmlFromInfo()
 
/**
* Return an XML document based on the package info (as returned
* by the PEAR_Common::infoFrom* methods).
517,16 → 590,13
*/
function xmlFromInfo($pkginfo)
{
$config = &PEAR_Config::singleton();
$packagefile = &new PEAR_PackageFile($config);
$config = &PEAR_Config::singleton();
$packagefile = new PEAR_PackageFile($config);
$pf = &$packagefile->fromArray($pkginfo);
$gen = &$pf->getDefaultGenerator();
return $gen->toXml(PEAR_VALIDATE_PACKAGING);
}
 
// }}}
// {{{ validatePackageInfo()
 
/**
* Validate XML package definition file.
*
542,8 → 612,8
*/
function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '')
{
$config = &PEAR_Config::singleton();
$packagefile = &new PEAR_PackageFile($config);
$config = &PEAR_Config::singleton();
$packagefile = new PEAR_PackageFile($config);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
if (strpos($info, '<?xml') !== false) {
$pf = &$packagefile->fromXmlString($info, PEAR_VALIDATE_NORMAL, '');
550,6 → 620,7
} else {
$pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
}
 
PEAR::staticPopErrorHandling();
if (PEAR::isError($pf)) {
$errs = $pf->getUserinfo();
562,14 → 633,13
}
}
}
 
return false;
}
 
return true;
}
 
// }}}
// {{{ buildProvidesArray()
 
/**
* Build a "provides" array from data returned by
* analyzeSourceCode(). The format of the built array is like
596,6 → 666,7
if (isset($this->_packageName)) {
$pn = $this->_packageName;
}
 
$pnl = strlen($pn);
foreach ($srcinfo['declared_classes'] as $class) {
$key = "class;$class";
602,6 → 673,7
if (isset($this->pkginfo['provides'][$key])) {
continue;
}
 
$this->pkginfo['provides'][$key] =
array('file'=> $file, 'type' => 'class', 'name' => $class);
if (isset($srcinfo['inheritance'][$class])) {
609,6 → 681,7
$srcinfo['inheritance'][$class];
}
}
 
foreach ($srcinfo['declared_methods'] as $class => $methods) {
foreach ($methods as $method) {
$function = "$class::$method";
617,6 → 690,7
isset($this->pkginfo['provides'][$key])) {
continue;
}
 
$this->pkginfo['provides'][$key] =
array('file'=> $file, 'type' => 'function', 'name' => $function);
}
627,17 → 701,16
if ($function{0} == '_' || isset($this->pkginfo['provides'][$key])) {
continue;
}
 
if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {
$warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";
}
 
$this->pkginfo['provides'][$key] =
array('file'=> $file, 'type' => 'function', 'name' => $function);
}
}
 
// }}}
// {{{ analyzeSourceCode()
 
/**
* Analyze the source code of the given PHP file
*
647,231 → 720,28
*/
function analyzeSourceCode($file)
{
if (!function_exists("token_get_all")) {
return false;
if (!class_exists('PEAR_PackageFile_v2_Validator')) {
require_once 'PEAR/PackageFile/v2/Validator.php';
}
if (!defined('T_DOC_COMMENT')) {
define('T_DOC_COMMENT', T_COMMENT);
}
if (!defined('T_INTERFACE')) {
define('T_INTERFACE', -1);
}
if (!defined('T_IMPLEMENTS')) {
define('T_IMPLEMENTS', -1);
}
if (!$fp = @fopen($file, "r")) {
return false;
}
fclose($fp);
$contents = file_get_contents($file);
$tokens = token_get_all($contents);
/*
for ($i = 0; $i < sizeof($tokens); $i++) {
@list($token, $data) = $tokens[$i];
if (is_string($token)) {
var_dump($token);
} else {
print token_name($token) . ' ';
var_dump(rtrim($data));
}
}
*/
$look_for = 0;
$paren_level = 0;
$bracket_level = 0;
$brace_level = 0;
$lastphpdoc = '';
$current_class = '';
$current_interface = '';
$current_class_level = -1;
$current_function = '';
$current_function_level = -1;
$declared_classes = array();
$declared_interfaces = array();
$declared_functions = array();
$declared_methods = array();
$used_classes = array();
$used_functions = array();
$extends = array();
$implements = array();
$nodeps = array();
$inquote = false;
$interface = false;
for ($i = 0; $i < sizeof($tokens); $i++) {
if (is_array($tokens[$i])) {
list($token, $data) = $tokens[$i];
} else {
$token = $tokens[$i];
$data = '';
}
if ($inquote) {
if ($token != '"') {
continue;
} else {
$inquote = false;
continue;
}
}
switch ($token) {
case T_WHITESPACE:
continue;
case ';':
if ($interface) {
$current_function = '';
$current_function_level = -1;
}
break;
case '"':
$inquote = true;
break;
case T_CURLY_OPEN:
case T_DOLLAR_OPEN_CURLY_BRACES:
case '{': $brace_level++; continue 2;
case '}':
$brace_level--;
if ($current_class_level == $brace_level) {
$current_class = '';
$current_class_level = -1;
}
if ($current_function_level == $brace_level) {
$current_function = '';
$current_function_level = -1;
}
continue 2;
case '[': $bracket_level++; continue 2;
case ']': $bracket_level--; continue 2;
case '(': $paren_level++; continue 2;
case ')': $paren_level--; continue 2;
case T_INTERFACE:
$interface = true;
case T_CLASS:
if (($current_class_level != -1) || ($current_function_level != -1)) {
PEAR::raiseError("Parser error: invalid PHP found in file \"$file\"",
PEAR_COMMON_ERROR_INVALIDPHP);
return false;
}
case T_FUNCTION:
case T_NEW:
case T_EXTENDS:
case T_IMPLEMENTS:
$look_for = $token;
continue 2;
case T_STRING:
if (version_compare(zend_version(), '2.0', '<')) {
if (in_array(strtolower($data),
array('public', 'private', 'protected', 'abstract',
'interface', 'implements', 'throw')
)) {
PEAR::raiseError('Error: PHP5 token encountered in ' . $file .
'packaging should be done in PHP 5');
return false;
}
}
if ($look_for == T_CLASS) {
$current_class = $data;
$current_class_level = $brace_level;
$declared_classes[] = $current_class;
} elseif ($look_for == T_INTERFACE) {
$current_interface = $data;
$current_class_level = $brace_level;
$declared_interfaces[] = $current_interface;
} elseif ($look_for == T_IMPLEMENTS) {
$implements[$current_class] = $data;
} elseif ($look_for == T_EXTENDS) {
$extends[$current_class] = $data;
} elseif ($look_for == T_FUNCTION) {
if ($current_class) {
$current_function = "$current_class::$data";
$declared_methods[$current_class][] = $data;
} elseif ($current_interface) {
$current_function = "$current_interface::$data";
$declared_methods[$current_interface][] = $data;
} else {
$current_function = $data;
$declared_functions[] = $current_function;
}
$current_function_level = $brace_level;
$m = array();
} elseif ($look_for == T_NEW) {
$used_classes[$data] = true;
}
$look_for = 0;
continue 2;
case T_VARIABLE:
$look_for = 0;
continue 2;
case T_DOC_COMMENT:
case T_COMMENT:
if (preg_match('!^/\*\*\s!', $data)) {
$lastphpdoc = $data;
if (preg_match_all('/@nodep\s+(\S+)/', $lastphpdoc, $m)) {
$nodeps = array_merge($nodeps, $m[1]);
}
}
continue 2;
case T_DOUBLE_COLON:
if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
PEAR::raiseError("Parser error: invalid PHP found in file \"$file\"",
PEAR_COMMON_ERROR_INVALIDPHP);
return false;
}
$class = $tokens[$i - 1][1];
if (strtolower($class) != 'parent') {
$used_classes[$class] = true;
}
continue 2;
}
}
return array(
"source_file" => $file,
"declared_classes" => $declared_classes,
"declared_interfaces" => $declared_interfaces,
"declared_methods" => $declared_methods,
"declared_functions" => $declared_functions,
"used_classes" => array_diff(array_keys($used_classes), $nodeps),
"inheritance" => $extends,
"implements" => $implements,
);
}
 
// }}}
// {{{ betterStates()
 
/**
* Return an array containing all of the states that are more stable than
* or equal to the passed in state
*
* @param string Release state
* @param boolean Determines whether to include $state in the list
* @return false|array False if $state is not a valid release state
*/
function betterStates($state, $include = false)
{
static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable');
$i = array_search($state, $states);
if ($i === false) {
return false;
}
if ($include) {
$i--;
}
return array_slice($states, $i + 1);
$a = new PEAR_PackageFile_v2_Validator;
return $a->analyzeSourceCode($file);
}
 
// }}}
// {{{ detectDependencies()
 
function detectDependencies($any, $status_callback = null)
{
if (!function_exists("token_get_all")) {
return false;
}
 
if (PEAR::isError($info = $this->infoFromAny($any))) {
return $this->raiseError($info);
}
 
if (!is_array($info)) {
return false;
}
 
$deps = array();
$used_c = $decl_c = $decl_f = $decl_m = array();
foreach ($info['filelist'] as $file => $fa) {
882,9 → 752,11
$decl_m = @array_merge($decl_m, $tmp['declared_methods']);
$inheri = @array_merge($inheri, $tmp['inheritance']);
}
 
$used_c = array_unique($used_c);
$decl_c = array_unique($decl_c);
$undecl_c = array_diff($used_c, $decl_c);
 
return array('used_classes' => $used_c,
'declared_classes' => $decl_c,
'declared_methods' => $decl_m,
894,159 → 766,7
);
}
 
// }}}
// {{{ getUserRoles()
 
/**
* Get the valid roles for a PEAR package maintainer
*
* @return array
* @static
*/
function getUserRoles()
{
return $GLOBALS['_PEAR_Common_maintainer_roles'];
}
 
// }}}
// {{{ getReleaseStates()
 
/**
* Get the valid package release states of packages
*
* @return array
* @static
*/
function getReleaseStates()
{
return $GLOBALS['_PEAR_Common_release_states'];
}
 
// }}}
// {{{ getDependencyTypes()
 
/**
* Get the implemented dependency types (php, ext, pkg etc.)
*
* @return array
* @static
*/
function getDependencyTypes()
{
return $GLOBALS['_PEAR_Common_dependency_types'];
}
 
// }}}
// {{{ getDependencyRelations()
 
/**
* Get the implemented dependency relations (has, lt, ge etc.)
*
* @return array
* @static
*/
function getDependencyRelations()
{
return $GLOBALS['_PEAR_Common_dependency_relations'];
}
 
// }}}
// {{{ getFileRoles()
 
/**
* Get the implemented file roles
*
* @return array
* @static
*/
function getFileRoles()
{
return $GLOBALS['_PEAR_Common_file_roles'];
}
 
// }}}
// {{{ getReplacementTypes()
 
/**
* Get the implemented file replacement types in
*
* @return array
* @static
*/
function getReplacementTypes()
{
return $GLOBALS['_PEAR_Common_replacement_types'];
}
 
// }}}
// {{{ getProvideTypes()
 
/**
* Get the implemented file replacement types in
*
* @return array
* @static
*/
function getProvideTypes()
{
return $GLOBALS['_PEAR_Common_provide_types'];
}
 
// }}}
// {{{ getScriptPhases()
 
/**
* Get the implemented file replacement types in
*
* @return array
* @static
*/
function getScriptPhases()
{
return $GLOBALS['_PEAR_Common_script_phases'];
}
 
// }}}
// {{{ validPackageName()
 
/**
* Test whether a string contains a valid package name.
*
* @param string $name the package name to test
*
* @return bool
*
* @access public
*/
function validPackageName($name)
{
return (bool)preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $name);
}
 
 
// }}}
// {{{ validPackageVersion()
 
/**
* Test whether a string contains a valid package version.
*
* @param string $ver the package version to test
*
* @return bool
*
* @access public
*/
function validPackageVersion($ver)
{
return (bool)preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver);
}
 
 
// }}}
 
// {{{ downloadHttp()
 
/**
* Download a file through HTTP. Considers suggested file name in
* Content-disposition: header and can run a callback function for
* different events. The callback will be called with two
1081,46 → 801,38
* @param string $save_dir (optional) directory to save file in
* @param mixed $callback (optional) function/method to call for status
* updates
* @param false|string|array $lastmodified header values to check against
* for caching
* use false to return the header
* values from this download
* @param false|array $accept Accept headers to send
* @param false|string $channel Channel to use for retrieving
* authentication
*
* @return string Returns the full path of the downloaded file or a PEAR
* error on failure. If the error is caused by
* socket-related errors, the error object will
* have the fsockopen error code available through
* getCode().
* @return mixed Returns the full path of the downloaded file or a PEAR
* error on failure. If the error is caused by
* socket-related errors, the error object will
* have the fsockopen error code available through
* getCode(). If caching is requested, then return the header
* values.
* If $lastmodified was given and the there are no changes,
* boolean false is returned.
*
* @access public
* @deprecated in favor of PEAR_Downloader::downloadHttp()
*/
function downloadHttp($url, &$ui, $save_dir = '.', $callback = null)
{
function downloadHttp(
$url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null,
$accept = false, $channel = false
) {
if (!class_exists('PEAR_Downloader')) {
require_once 'PEAR/Downloader.php';
}
return PEAR_Downloader::downloadHttp($url, $ui, $save_dir, $callback);
return PEAR_Downloader::_downloadHttp(
$this, $url, $ui, $save_dir, $callback, $lastmodified,
$accept, $channel
);
}
}
 
// }}}
 
/**
* @param string $path relative or absolute include path
* @return boolean
* @static
*/
function isIncludeable($path)
{
if (file_exists($path) && is_readable($path)) {
return true;
}
$ipath = explode(PATH_SEPARATOR, ini_get('include_path'));
foreach ($ipath as $include) {
$test = realpath($include . DIRECTORY_SEPARATOR . $path);
if (file_exists($test) && is_readable($test)) {
return true;
}
}
return false;
}
}
require_once 'PEAR/Config.php';
require_once 'PEAR/PackageFile.php';
?>
/trunk/bibliotheque/pear/PEAR/Validate.php
4,18 → 4,11
*
* 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: Validate.php,v 1.50 2006/09/25 05:12:21 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
36,9 → 29,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
68,7 → 61,7
*/
function _validPackageName($name)
{
return (bool) preg_match('/^' . $this->packageregex . '$/', $name);
return (bool) preg_match('/^' . $this->packageregex . '\\z/', $name);
}
 
/**
80,7 → 73,7
{
if ($validatepackagename) {
if (strtolower($name) == strtolower($validatepackagename)) {
return (bool) preg_match('/^[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*$/', $name);
return (bool) preg_match('/^[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*\\z/', $name);
}
}
return $this->_validPackageName($name);
91,11 → 84,10
* to the PEAR naming convention, so the method is final and static.
* @param string
* @final
* @static
*/
function validGroupName($name)
public static function validGroupName($name)
{
return (bool) preg_match('/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/', $name);
return (bool) preg_match('/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '\\z/', $name);
}
 
/**
102,10 → 94,9
* Determine whether $state represents a valid stability level
* @param string
* @return bool
* @static
* @final
*/
function validState($state)
public static function validState($state)
{
return in_array($state, array('snapshot', 'devel', 'alpha', 'beta', 'stable'));
}
113,10 → 104,9
/**
* Get a list of valid stability levels
* @return array
* @static
* @final
*/
function getValidStates()
public static function getValidStates()
{
return array('snapshot', 'devel', 'alpha', 'beta', 'stable');
}
126,10 → 116,9
* by version_compare
* @param string
* @return bool
* @static
* @final
*/
function validVersion($ver)
public static function validVersion($ver)
{
return (bool) preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver);
}
213,7 → 202,8
$this->_packagexml->getExtends()) {
$version = $this->_packagexml->getVersion() . '';
$name = $this->_packagexml->getPackage();
$test = array_shift($a = explode('.', $version));
$a = explode('.', $version);
$test = array_shift($a);
if ($test == '0') {
return true;
}
458,7 → 448,6
return false;
}
 
 
if ($this->_state == PEAR_VALIDATE_PACKAGING &&
$this->_packagexml->getDate() != date('Y-m-d')) {
$this->_addWarning('date', 'Release Date "' .
477,8 → 466,8
// default of no time value set
return true;
}
// packager automatically sets time, so only validate if
// pear validate is called
 
// packager automatically sets time, so only validate if pear validate is called
if ($this->_state = PEAR_VALIDATE_NORMAL) {
if (!preg_match('/\d\d:\d\d:\d\d/',
$this->_packagexml->getTime())) {
486,12 → 475,15
$this->_packagexml->getTime() . '"');
return false;
}
if (strtotime($this->_packagexml->getTime()) == -1) {
 
$result = preg_match('|\d{2}\:\d{2}\:\d{2}|', $this->_packagexml->getTime(), $matches);
if ($result === false || empty($matches)) {
$this->_addFailure('time', 'invalid release time "' .
$this->_packagexml->getTime() . '"');
return false;
}
}
 
return true;
}
 
630,5 → 622,4
{
return true;
}
}
?>
}
/trunk/bibliotheque/pear/PEAR/Frontend/CLI.php
4,19 → 4,12
*
* 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 Stig Bakken <ssb@php.net>
* @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: CLI.php,v 1.66 2006/11/19 23:56:32 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
31,16 → 24,14
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Frontend_CLI extends PEAR_Frontend
{
// {{{ properties
 
/**
* What type of user interface this frontend is for.
* @var string
51,28 → 42,23
 
var $params = array();
var $term = array(
'bold' => '',
'bold' => '',
'normal' => '',
);
);
 
// }}}
 
// {{{ constructor
 
function PEAR_Frontend_CLI()
function __construct()
{
parent::PEAR();
parent::__construct();
$term = getenv('TERM'); //(cox) $_ENV is empty for me in 4.1.1
if (function_exists('posix_isatty') && !posix_isatty(1)) {
// output is being redirected to a file or through a pipe
} elseif ($term) {
// XXX can use ncurses extension here, if available
if (preg_match('/^(xterm|vt220|linux)/', $term)) {
$this->term['bold'] = sprintf("%c%c%c%c", 27, 91, 49, 109);
$this->term['normal']=sprintf("%c%c%c", 27, 91, 109);
$this->term['bold'] = sprintf("%c%c%c%c", 27, 91, 49, 109);
$this->term['normal'] = sprintf("%c%c%c", 27, 91, 109);
} elseif (preg_match('/^vt100/', $term)) {
$this->term['bold'] = sprintf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0);
$this->term['normal']=sprintf("%c%c%c%c%c", 27, 91, 109, 0, 0);
$this->term['bold'] = sprintf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0);
$this->term['normal'] = sprintf("%c%c%c%c%c", 27, 91, 109, 0, 0);
}
} elseif (OS_WINDOWS) {
// XXX add ANSI codes here
79,47 → 65,14
}
}
 
// }}}
 
// {{{ displayLine(text)
 
function displayLine($text)
{
trigger_error("PEAR_Frontend_CLI::displayLine deprecated", E_USER_ERROR);
}
 
function _displayLine($text)
{
print "$this->lp$text\n";
}
 
// }}}
// {{{ display(text)
 
function display($text)
{
trigger_error("PEAR_Frontend_CLI::display deprecated", E_USER_ERROR);
}
 
function _display($text)
{
print $text;
}
 
// }}}
// {{{ displayError(eobj)
 
/**
* @param object PEAR_Error object
*/
function displayError($eobj)
function displayError($e)
{
return $this->_displayLine($eobj->getMessage());
return $this->_displayLine($e->getMessage());
}
 
// }}}
// {{{ displayFatalError(eobj)
 
/**
* @param object PEAR_Error object
*/
131,54 → 84,34
if ($config->get('verbose') > 5) {
if (function_exists('debug_print_backtrace')) {
debug_print_backtrace();
} elseif (function_exists('debug_backtrace')) {
$trace = debug_backtrace();
$raised = false;
foreach ($trace as $i => $frame) {
if (!$raised) {
if (isset($frame['class']) && strtolower($frame['class']) ==
'pear' && strtolower($frame['function']) == 'raiseerror') {
$raised = true;
} else {
continue;
}
exit(1);
}
 
$raised = false;
foreach (debug_backtrace() as $i => $frame) {
if (!$raised) {
if (isset($frame['class'])
&& strtolower($frame['class']) == 'pear'
&& strtolower($frame['function']) == 'raiseerror'
) {
$raised = true;
} else {
continue;
}
if (!isset($frame['class'])) {
$frame['class'] = '';
}
if (!isset($frame['type'])) {
$frame['type'] = '';
}
if (!isset($frame['function'])) {
$frame['function'] = '';
}
if (!isset($frame['line'])) {
$frame['line'] = '';
}
$this->_displayLine("#$i: $frame[class]$frame[type]$frame[function] $frame[line]");
}
 
$frame['class'] = !isset($frame['class']) ? '' : $frame['class'];
$frame['type'] = !isset($frame['type']) ? '' : $frame['type'];
$frame['function'] = !isset($frame['function']) ? '' : $frame['function'];
$frame['line'] = !isset($frame['line']) ? '' : $frame['line'];
$this->_displayLine("#$i: $frame[class]$frame[type]$frame[function] $frame[line]");
}
}
}
 
exit(1);
}
 
// }}}
// {{{ displayHeading(title)
 
function displayHeading($title)
{
trigger_error("PEAR_Frontend_CLI::displayHeading deprecated", E_USER_ERROR);
}
 
function _displayHeading($title)
{
print $this->lp.$this->bold($title)."\n";
print $this->lp.str_repeat("=", strlen($title))."\n";
}
 
// }}}
 
/**
* Instruct the runInstallScript method to skip a paramgroup that matches the
* id value passed in.
210,94 → 143,105
$this->_skipSections = array();
if (!is_array($xml) || !isset($xml['paramgroup'])) {
$script->run(array(), '_default');
} else {
$completedPhases = array();
if (!isset($xml['paramgroup'][0])) {
$xml['paramgroup'] = array($xml['paramgroup']);
return;
}
 
$completedPhases = array();
if (!isset($xml['paramgroup'][0])) {
$xml['paramgroup'] = array($xml['paramgroup']);
}
 
foreach ($xml['paramgroup'] as $group) {
if (isset($this->_skipSections[$group['id']])) {
// the post-install script chose to skip this section dynamically
continue;
}
foreach ($xml['paramgroup'] as $group) {
if (isset($this->_skipSections[$group['id']])) {
// the post-install script chose to skip this section dynamically
 
if (isset($group['name'])) {
$paramname = explode('::', $group['name']);
if ($lastgroup['id'] != $paramname[0]) {
continue;
}
if (isset($group['name'])) {
$paramname = explode('::', $group['name']);
if ($lastgroup['id'] != $paramname[0]) {
continue;
}
$group['name'] = $paramname[1];
if (isset($answers)) {
if (isset($answers[$group['name']])) {
switch ($group['conditiontype']) {
case '=' :
if ($answers[$group['name']] != $group['value']) {
continue 2;
}
break;
case '!=' :
if ($answers[$group['name']] == $group['value']) {
continue 2;
}
break;
case 'preg_match' :
if (!@preg_match('/' . $group['value'] . '/',
$answers[$group['name']])) {
continue 2;
}
break;
default :
return;
 
$group['name'] = $paramname[1];
if (!isset($answers)) {
return;
}
 
if (isset($answers[$group['name']])) {
switch ($group['conditiontype']) {
case '=' :
if ($answers[$group['name']] != $group['value']) {
continue 2;
}
}
} else {
break;
case '!=' :
if ($answers[$group['name']] == $group['value']) {
continue 2;
}
break;
case 'preg_match' :
if (!@preg_match('/' . $group['value'] . '/',
$answers[$group['name']])) {
continue 2;
}
break;
default :
return;
}
}
$lastgroup = $group;
if (isset($group['instructions'])) {
$this->_display($group['instructions']);
}
if (!isset($group['param'][0])) {
$group['param'] = array($group['param']);
}
if (isset($group['param'])) {
if (method_exists($script, 'postProcessPrompts')) {
$prompts = $script->postProcessPrompts($group['param'], $group['id']);
if (!is_array($prompts) || count($prompts) != count($group['param'])) {
$this->outputData('postinstall', 'Error: post-install script did not ' .
'return proper post-processed prompts');
$prompts = $group['param'];
} else {
foreach ($prompts as $i => $var) {
if (!is_array($var) || !isset($var['prompt']) ||
!isset($var['name']) ||
($var['name'] != $group['param'][$i]['name']) ||
($var['type'] != $group['param'][$i]['type'])) {
$this->outputData('postinstall', 'Error: post-install script ' .
'modified the variables or prompts, severe security risk. ' .
'Will instead use the defaults from the package.xml');
$prompts = $group['param'];
}
}
 
$lastgroup = $group;
if (isset($group['instructions'])) {
$this->_display($group['instructions']);
}
 
if (!isset($group['param'][0])) {
$group['param'] = array($group['param']);
}
 
if (isset($group['param'])) {
if (method_exists($script, 'postProcessPrompts')) {
$prompts = $script->postProcessPrompts($group['param'], $group['id']);
if (!is_array($prompts) || count($prompts) != count($group['param'])) {
$this->outputData('postinstall', 'Error: post-install script did not ' .
'return proper post-processed prompts');
$prompts = $group['param'];
} else {
foreach ($prompts as $i => $var) {
if (!is_array($var) || !isset($var['prompt']) ||
!isset($var['name']) ||
($var['name'] != $group['param'][$i]['name']) ||
($var['type'] != $group['param'][$i]['type'])
) {
$this->outputData('postinstall', 'Error: post-install script ' .
'modified the variables or prompts, severe security risk. ' .
'Will instead use the defaults from the package.xml');
$prompts = $group['param'];
}
}
$answers = $this->confirmDialog($prompts);
} else {
$answers = $this->confirmDialog($group['param']);
}
 
$answers = $this->confirmDialog($prompts);
} else {
$answers = $this->confirmDialog($group['param']);
}
if ((isset($answers) && $answers) || !isset($group['param'])) {
if (!isset($answers)) {
$answers = array();
}
array_unshift($completedPhases, $group['id']);
if (!$script->run($answers, $group['id'])) {
$script->run($completedPhases, '_undoOnError');
return;
}
} else {
}
 
if ((isset($answers) && $answers) || !isset($group['param'])) {
if (!isset($answers)) {
$answers = array();
}
 
array_unshift($completedPhases, $group['id']);
if (!$script->run($answers, $group['id'])) {
$script->run($completedPhases, '_undoOnError');
return;
}
} else {
$script->run($completedPhases, '_undoOnError');
return;
}
}
}
310,17 → 254,13
*/
function confirmDialog($params)
{
$answers = array();
$prompts = $types = array();
$answers = $prompts = $types = array();
foreach ($params as $param) {
$prompts[$param['name']] = $param['prompt'];
$types[$param['name']] = $param['type'];
if (isset($param['default'])) {
$answers[$param['name']] = $param['default'];
} else {
$answers[$param['name']] = '';
}
$types[$param['name']] = $param['type'];
$answers[$param['name']] = isset($param['default']) ? $param['default'] : '';
}
 
$tried = false;
do {
if ($tried) {
332,30 → 272,27
$i++;
}
}
 
$answers = $this->userDialog('', $prompts, $types, $answers);
$tried = true;
$tried = true;
} while (is_array($answers) && count(array_filter($answers)) != count($prompts));
 
return $answers;
}
// {{{ userDialog(prompt, [type], [default])
 
function userDialog($command, $prompts, $types = array(), $defaults = array(),
$screensize = 20)
function userDialog($command, $prompts, $types = array(), $defaults = array(), $screensize = 20)
{
if (!is_array($prompts)) {
return array();
}
 
$testprompts = array_keys($prompts);
$result = $defaults;
if (!defined('STDIN')) {
$fp = fopen('php://stdin', 'r');
} else {
$fp = STDIN;
}
$result = $defaults;
 
reset($prompts);
if (count($prompts) == 1 && $types[key($prompts)] == 'yesno') {
if (count($prompts) === 1) {
foreach ($prompts as $key => $prompt) {
$type = $types[$key];
$type = $types[$key];
$default = @$defaults[$key];
print "$prompt ";
if ($default) {
362,70 → 299,62
print "[$default] ";
}
print ": ";
if (version_compare(phpversion(), '5.0.0', '<')) {
$line = fgets($fp, 2048);
} else {
if (!defined('STDIN')) {
define('STDIN', fopen('php://stdin', 'r'));
}
$line = fgets(STDIN, 2048);
}
if ($default && trim($line) == "") {
$result[$key] = $default;
} else {
$result[$key] = trim($line);
}
 
$line = fgets(STDIN, 2048);
$result[$key] = ($default && trim($line) == '') ? $default : trim($line);
}
 
return $result;
}
 
$first_run = true;
while (true) {
$descLength = max(array_map('strlen', $prompts));
$descFormat = "%-{$descLength}s";
$last = count($prompts);
$last = count($prompts);
 
$i = 0;
foreach ($prompts as $n => $var) {
printf("%2d. $descFormat : %s\n", ++$i, $prompts[$n], isset($result[$n]) ?
$result[$n] : null);
$res = isset($result[$n]) ? $result[$n] : null;
printf("%2d. $descFormat : %s\n", ++$i, $prompts[$n], $res);
}
print "\n1-$last, 'all', 'abort', or Enter to continue: ";
 
print "\n1-$last, 'all', 'abort', or Enter to continue: ";
$tmp = trim(fgets($fp, 1024));
$tmp = trim(fgets(STDIN, 1024));
if (empty($tmp)) {
break;
}
 
if ($tmp == 'abort') {
return false;
}
 
if (isset($testprompts[(int)$tmp - 1])) {
$var = $testprompts[(int)$tmp - 1];
$desc = $prompts[$var];
$var = $testprompts[(int)$tmp - 1];
$desc = $prompts[$var];
$current = @$result[$var];
print "$desc [$current] : ";
$tmp = trim(fgets($fp, 1024));
if (trim($tmp) !== '') {
$result[$var] = trim($tmp);
$tmp = trim(fgets(STDIN, 1024));
if ($tmp !== '') {
$result[$var] = $tmp;
}
} elseif ($tmp == 'all') {
foreach ($prompts as $var => $desc) {
$current = $result[$var];
print "$desc [$current] : ";
$tmp = trim(fgets($fp, 1024));
$tmp = trim(fgets(STDIN, 1024));
if (trim($tmp) !== '') {
$result[$var] = trim($tmp);
}
}
}
 
$first_run = false;
}
if (!defined('STDIN')) {
fclose($fp);
}
 
return $result;
}
 
// }}}
// {{{ userConfirm(prompt, [default])
 
function userConfirm($prompt, $default = 'yes')
{
trigger_error("PEAR_Frontend_CLI::userConfirm not yet converted", E_USER_ERROR);
451,48 → 380,219
return false;
}
 
// }}}
// {{{ startTable([params])
function outputData($data, $command = '_default')
{
switch ($command) {
case 'channel-info':
foreach ($data as $type => $section) {
if ($type == 'main') {
$section['data'] = array_values($section['data']);
}
 
function startTable($params = array())
$this->outputData($section);
}
break;
case 'install':
case 'upgrade':
case 'upgrade-all':
if (is_array($data) && isset($data['release_warnings'])) {
$this->_displayLine('');
$this->_startTable(array(
'border' => false,
'caption' => 'Release Warnings'
));
$this->_tableRow(array($data['release_warnings']), null, array(1 => array('wrap' => 55)));
$this->_endTable();
$this->_displayLine('');
}
 
$this->_displayLine(is_array($data) ? $data['data'] : $data);
break;
case 'search':
$this->_startTable($data);
if (isset($data['headline']) && is_array($data['headline'])) {
$this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
}
 
$packages = array();
foreach($data['data'] as $category) {
foreach($category as $name => $pkg) {
$packages[$pkg[0]] = $pkg;
}
}
 
$p = array_keys($packages);
natcasesort($p);
foreach ($p as $name) {
$this->_tableRow($packages[$name], null, array(1 => array('wrap' => 55)));
}
 
$this->_endTable();
break;
case 'list-all':
if (!isset($data['data'])) {
$this->_displayLine('No packages in channel');
break;
}
 
$this->_startTable($data);
if (isset($data['headline']) && is_array($data['headline'])) {
$this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
}
 
$packages = array();
foreach($data['data'] as $category) {
foreach($category as $name => $pkg) {
$packages[$pkg[0]] = $pkg;
}
}
 
$p = array_keys($packages);
natcasesort($p);
foreach ($p as $name) {
$pkg = $packages[$name];
unset($pkg[4], $pkg[5]);
$this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
}
 
$this->_endTable();
break;
case 'config-show':
$data['border'] = false;
$opts = array(
0 => array('wrap' => 30),
1 => array('wrap' => 20),
2 => array('wrap' => 35)
);
 
$this->_startTable($data);
if (isset($data['headline']) && is_array($data['headline'])) {
$this->_tableRow($data['headline'], array('bold' => true), $opts);
}
 
foreach ($data['data'] as $group) {
foreach ($group as $value) {
if ($value[2] == '') {
$value[2] = "<not set>";
}
 
$this->_tableRow($value, null, $opts);
}
}
 
$this->_endTable();
break;
case 'remote-info':
$d = $data;
$data = array(
'caption' => 'Package details:',
'border' => false,
'data' => array(
array("Latest", $data['stable']),
array("Installed", $data['installed']),
array("Package", $data['name']),
array("License", $data['license']),
array("Category", $data['category']),
array("Summary", $data['summary']),
array("Description", $data['description']),
),
);
 
if (isset($d['deprecated']) && $d['deprecated']) {
$conf = &PEAR_Config::singleton();
$reg = $conf->getRegistry();
$name = $reg->parsedPackageNameToString($d['deprecated'], true);
$data['data'][] = array('Deprecated! use', $name);
}
default: {
if (is_array($data)) {
$this->_startTable($data);
$count = count($data['data'][0]);
if ($count == 2) {
$opts = array(0 => array('wrap' => 25),
1 => array('wrap' => 48)
);
} elseif ($count == 3) {
$opts = array(0 => array('wrap' => 30),
1 => array('wrap' => 20),
2 => array('wrap' => 35)
);
} else {
$opts = null;
}
if (isset($data['headline']) && is_array($data['headline'])) {
$this->_tableRow($data['headline'],
array('bold' => true),
$opts);
}
 
if (is_array($data['data'])) {
foreach($data['data'] as $row) {
$this->_tableRow($row, null, $opts);
}
} else {
$this->_tableRow(array($data['data']), null, $opts);
}
$this->_endTable();
} else {
$this->_displayLine($data);
}
}
}
}
 
function log($text, $append_crlf = true)
{
trigger_error("PEAR_Frontend_CLI::startTable deprecated", E_USER_ERROR);
if ($append_crlf) {
return $this->_displayLine($text);
}
 
return $this->_display($text);
}
 
function _startTable($params = array())
function bold($text)
{
$params['table_data'] = array();
$params['widest'] = array(); // indexed by column
$params['highest'] = array(); // indexed by row
$params['ncols'] = 0;
$this->params = $params;
if (empty($this->term['bold'])) {
return strtoupper($text);
}
 
return $this->term['bold'] . $text . $this->term['normal'];
}
 
// }}}
// {{{ tableRow(columns, [rowparams], [colparams])
function _displayHeading($title)
{
print $this->lp.$this->bold($title)."\n";
print $this->lp.str_repeat("=", strlen($title))."\n";
}
 
function tableRow($columns, $rowparams = array(), $colparams = array())
function _startTable($params = array())
{
trigger_error("PEAR_Frontend_CLI::tableRow deprecated", E_USER_ERROR);
$params['table_data'] = array();
$params['widest'] = array(); // indexed by column
$params['highest'] = array(); // indexed by row
$params['ncols'] = 0;
$this->params = $params;
}
 
function _tableRow($columns, $rowparams = array(), $colparams = array())
{
$highest = 1;
for ($i = 0; $i < sizeof($columns); $i++) {
for ($i = 0; $i < count($columns); $i++) {
$col = &$columns[$i];
if (isset($colparams[$i]) && !empty($colparams[$i]['wrap'])) {
$col = wordwrap($col, $colparams[$i]['wrap'], "\n", 0);
$col = wordwrap($col, $colparams[$i]['wrap']);
}
 
if (strpos($col, "\n") !== false) {
$multiline = explode("\n", $col);
$w = 0;
foreach ($multiline as $n => $line) {
if (strlen($line) > $w) {
$w = strlen($line);
$len = strlen($line);
if ($len > $w) {
$w = $len;
}
}
$lines = sizeof($multiline);
$lines = count($multiline);
} else {
$w = strlen($col);
}
504,6 → 604,7
} else {
$this->params['widest'][$i] = $w;
}
 
$tmp = count_chars($columns[$i], 1);
// handle unix, mac and windows formats
$lines = (isset($tmp[10]) ? $tmp[10] : (isset($tmp[13]) ? $tmp[13] : 0)) + 1;
511,26 → 612,20
$highest = $lines;
}
}
if (sizeof($columns) > $this->params['ncols']) {
$this->params['ncols'] = sizeof($columns);
 
if (count($columns) > $this->params['ncols']) {
$this->params['ncols'] = count($columns);
}
 
$new_row = array(
'data' => $columns,
'height' => $highest,
'data' => $columns,
'height' => $highest,
'rowparams' => $rowparams,
'colparams' => $colparams,
);
);
$this->params['table_data'][] = $new_row;
}
 
// }}}
// {{{ endTable()
 
function endTable()
{
trigger_error("PEAR_Frontend_CLI::endTable deprecated", E_USER_ERROR);
}
 
function _endTable()
{
extract($this->params);
537,9 → 632,11
if (!empty($caption)) {
$this->_displayHeading($caption);
}
if (count($table_data) == 0) {
 
if (count($table_data) === 0) {
return;
}
 
if (!isset($width)) {
$width = $widest;
} else {
549,18 → 646,19
}
}
}
 
$border = false;
if (empty($border)) {
$cellstart = '';
$cellend = ' ';
$rowend = '';
$padrowend = false;
$cellstart = '';
$cellend = ' ';
$rowend = '';
$padrowend = false;
$borderline = '';
} else {
$cellstart = '| ';
$cellend = ' ';
$rowend = '|';
$padrowend = true;
$cellstart = '| ';
$cellend = ' ';
$rowend = '|';
$padrowend = true;
$borderline = '+';
foreach ($width as $w) {
$borderline .= str_repeat('-', $w + strlen($cellstart) + strlen($cellend) - 1);
567,38 → 665,44
$borderline .= '+';
}
}
 
if ($borderline) {
$this->_displayLine($borderline);
}
for ($i = 0; $i < sizeof($table_data); $i++) {
 
for ($i = 0; $i < count($table_data); $i++) {
extract($table_data[$i]);
if (!is_array($rowparams)) {
$rowparams = array();
}
 
if (!is_array($colparams)) {
$colparams = array();
}
 
$rowlines = array();
if ($height > 1) {
for ($c = 0; $c < sizeof($data); $c++) {
for ($c = 0; $c < count($data); $c++) {
$rowlines[$c] = preg_split('/(\r?\n|\r)/', $data[$c]);
if (sizeof($rowlines[$c]) < $height) {
if (count($rowlines[$c]) < $height) {
$rowlines[$c] = array_pad($rowlines[$c], $height, '');
}
}
} else {
for ($c = 0; $c < sizeof($data); $c++) {
for ($c = 0; $c < count($data); $c++) {
$rowlines[$c] = array($data[$c]);
}
}
 
for ($r = 0; $r < $height; $r++) {
$rowtext = '';
for ($c = 0; $c < sizeof($data); $c++) {
for ($c = 0; $c < count($data); $c++) {
if (isset($colparams[$c])) {
$attribs = array_merge($rowparams, $colparams);
} else {
$attribs = $rowparams;
}
 
$w = isset($width[$c]) ? $width[$c] : 0;
//$cell = $data[$c];
$cell = $rowlines[$c][$r];
606,9 → 710,11
if ($l > $w) {
$cell = substr($cell, 0, $w);
}
 
if (isset($attribs['bold'])) {
$cell = $this->bold($cell);
}
 
if ($l < $w) {
// not using str_pad here because we may
// add bold escape characters to $cell
617,174 → 723,28
 
$rowtext .= $cellstart . $cell . $cellend;
}
 
if (!$border) {
$rowtext = rtrim($rowtext);
}
 
$rowtext .= $rowend;
$this->_displayLine($rowtext);
}
}
 
if ($borderline) {
$this->_displayLine($borderline);
}
}
 
// }}}
// {{{ outputData()
 
function outputData($data, $command = '_default')
function _displayLine($text)
{
switch ($command) {
case 'channel-info':
foreach ($data as $type => $section) {
if ($type == 'main') {
$section['data'] = array_values($section['data']);
}
$this->outputData($section);
}
break;
case 'install':
case 'upgrade':
case 'upgrade-all':
if (isset($data['release_warnings'])) {
$this->_displayLine('');
$this->_startTable(array(
'border' => false,
'caption' => 'Release Warnings'
));
$this->_tableRow(array($data['release_warnings']), null, array(1 => array('wrap' => 55)));
$this->_endTable();
$this->_displayLine('');
}
$this->_displayLine($data['data']);
break;
case 'search':
$this->_startTable($data);
if (isset($data['headline']) && is_array($data['headline'])) {
$this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
}
 
foreach($data['data'] as $category) {
foreach($category as $pkg) {
$this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
}
};
$this->_endTable();
break;
case 'list-all':
$this->_startTable($data);
if (isset($data['headline']) && is_array($data['headline'])) {
$this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
}
 
foreach($data['data'] as $category) {
foreach($category as $pkg) {
unset($pkg[4]);
unset($pkg[5]);
$this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
}
};
$this->_endTable();
break;
case 'config-show':
$data['border'] = false;
$opts = array(0 => array('wrap' => 30),
1 => array('wrap' => 20),
2 => array('wrap' => 35));
$this->_startTable($data);
if (isset($data['headline']) && is_array($data['headline'])) {
$this->_tableRow($data['headline'],
array('bold' => true),
$opts);
}
foreach($data['data'] as $group) {
foreach($group as $value) {
if ($value[2] == '') {
$value[2] = "<not set>";
}
$this->_tableRow($value, null, $opts);
}
}
$this->_endTable();
break;
case 'remote-info':
$d = $data;
$data = array(
'caption' => 'Package details:',
'border' => false,
'data' => array(
array("Latest", $data['stable']),
array("Installed", $data['installed']),
array("Package", $data['name']),
array("License", $data['license']),
array("Category", $data['category']),
array("Summary", $data['summary']),
array("Description", $data['description']),
),
);
if (isset($d['deprecated']) && $d['deprecated']) {
$conf = &PEAR_Config::singleton();
$reg = $conf->getRegistry();
$name = $reg->parsedPackageNameToString($d['deprecated'], true);
$data['data'][] = array('Deprecated! use', $name);
}
default: {
if (is_array($data)) {
$this->_startTable($data);
$count = count($data['data'][0]);
if ($count == 2) {
$opts = array(0 => array('wrap' => 25),
1 => array('wrap' => 48)
);
} elseif ($count == 3) {
$opts = array(0 => array('wrap' => 30),
1 => array('wrap' => 20),
2 => array('wrap' => 35)
);
} else {
$opts = null;
}
if (isset($data['headline']) && is_array($data['headline'])) {
$this->_tableRow($data['headline'],
array('bold' => true),
$opts);
}
foreach($data['data'] as $row) {
$this->_tableRow($row, null, $opts);
}
$this->_endTable();
} else {
$this->_displayLine($data);
}
}
}
print "$this->lp$text\n";
}
 
// }}}
// {{{ log(text)
 
 
function log($text, $append_crlf = true)
function _display($text)
{
if ($append_crlf) {
return $this->_displayLine($text);
}
return $this->_display($text);
print $text;
}
 
 
// }}}
// {{{ bold($text)
 
function bold($text)
{
if (empty($this->term['bold'])) {
return strtoupper($text);
}
return $this->term['bold'] . $text . $this->term['normal'];
}
 
// }}}
}
 
?>
/trunk/bibliotheque/pear/PEAR/PackageFile.php
4,18 → 4,11
*
* 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: PackageFile.php,v 1.40 2006/09/25 05:12:21 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
39,9 → 32,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
52,11 → 45,7
*/
var $_config;
var $_debug;
/**
* Temp directory for uncompressing tgz files.
* @var string|false
*/
var $_tmpdir;
 
var $_logger = false;
/**
* @var boolean
64,6 → 53,13
var $_rawReturn = false;
 
/**
* helper for extracting Archive_Tar errors
* @var array
* @access private
*/
var $_extractErrors = array();
 
/**
*
* @param PEAR_Config $config
* @param ? $debug
70,11 → 66,10
* @param string @tmpdir Optional temporary directory for uncompressing
* files
*/
function PEAR_PackageFile(&$config, $debug = false, $tmpdir = false)
function __construct(&$config, $debug = false)
{
$this->_config = $config;
$this->_debug = $debug;
$this->_tmpdir = $tmpdir;
}
 
/**
103,6 → 98,7
$a = false;
return $a;
}
 
include_once 'PEAR/PackageFile/Parser/v' . $version{0} . '.php';
$version = $version{0};
$class = "PEAR_PackageFile_Parser_v$version";
130,6 → 126,7
$a = false;
return $a;
}
 
include_once 'PEAR/PackageFile/v' . $version{0} . '.php';
$version = $version{0};
$class = $this->getClassPrefix() . $version;
153,22 → 150,25
if ($this->_logger) {
$obj->setLogger($this->_logger);
}
 
$obj->setConfig($this->_config);
$obj->fromArray($arr);
return $obj;
}
 
if (isset($arr['package']['attribs']['version'])) {
$obj = &$this->factory($arr['package']['attribs']['version']);
} else {
if (isset($arr['package']['attribs']['version'])) {
$obj = &$this->factory($arr['package']['attribs']['version']);
} else {
$obj = &$this->factory('1.0');
}
if ($this->_logger) {
$obj->setLogger($this->_logger);
}
$obj->setConfig($this->_config);
$obj->fromArray($arr);
return $obj;
$obj = &$this->factory('1.0');
}
 
if ($this->_logger) {
$obj->setLogger($this->_logger);
}
 
$obj->setConfig($this->_config);
$obj->fromArray($arr);
return $obj;
}
 
/**
185,50 → 185,53
*/
function &fromXmlString($data, $state, $file, $archive = false)
{
if (preg_match('/<package[^>]+version="([0-9]+\.[0-9]+)"/', $data, $packageversion)) {
if (preg_match('/<package[^>]+version=[\'"]([0-9]+\.[0-9]+)[\'"]/', $data, $packageversion)) {
if (!in_array($packageversion[1], array('1.0', '2.0', '2.1'))) {
return PEAR::raiseError('package.xml version "' . $packageversion[1] .
'" is not supported, only 1.0, 2.0, and 2.1 are supported.');
}
 
$object = &$this->parserFactory($packageversion[1]);
if ($this->_logger) {
$object->setLogger($this->_logger);
}
 
$object->setConfig($this->_config);
$pf = $object->parse($data, $file, $archive);
if (PEAR::isError($pf)) {
return $pf;
}
 
if ($this->_rawReturn) {
return $pf;
}
if ($pf->validate($state)) {
if ($this->_logger) {
if ($pf->getValidationWarnings(false)) {
foreach ($pf->getValidationWarnings() as $warning) {
$this->_logger->log(0, 'WARNING: ' . $warning['message']);
}
 
if (!$pf->validate($state)) {;
if ($this->_config->get('verbose') > 0
&& $this->_logger && $pf->getValidationWarnings(false)
) {
foreach ($pf->getValidationWarnings(false) as $warning) {
$this->_logger->log(0, 'ERROR: ' . $warning['message']);
}
}
if (method_exists($pf, 'flattenFilelist')) {
$pf->flattenFilelist(); // for v2
}
return $pf;
} else {
if ($this->_config->get('verbose') > 0) {
if ($this->_logger) {
if ($pf->getValidationWarnings(false)) {
foreach ($pf->getValidationWarnings(false) as $warning) {
$this->_logger->log(0, 'ERROR: ' . $warning['message']);
}
}
}
}
 
$a = PEAR::raiseError('Parsing of package.xml from file "' . $file . '" failed',
2, null, null, $pf->getValidationWarnings());
return $a;
}
} elseif (preg_match('/<package[^>]+version="([^"]+)"/', $data, $packageversion)) {
 
if ($this->_logger && $pf->getValidationWarnings(false)) {
foreach ($pf->getValidationWarnings() as $warning) {
$this->_logger->log(0, 'WARNING: ' . $warning['message']);
}
}
 
if (method_exists($pf, 'flattenFilelist')) {
$pf->flattenFilelist(); // for v2
}
 
return $pf;
} elseif (preg_match('/<package[^>]+version=[\'"]([^"\']+)[\'"]/', $data, $packageversion)) {
$a = PEAR::raiseError('package.xml file "' . $file .
'" has unsupported package.xml <package> version "' . $packageversion[1] . '"');
return $a;
236,6 → 239,7
if (!class_exists('PEAR_ErrorStack')) {
require_once 'PEAR/ErrorStack.php';
}
 
PEAR_ErrorStack::staticPush('PEAR_PackageFile',
PEAR_PACKAGEFILE_ERROR_NO_PACKAGEVERSION,
'warning', array('xml' => $data), 'package.xml "' . $file .
246,26 → 250,28
if (PEAR::isError($pf)) {
return $pf;
}
 
if ($this->_rawReturn) {
return $pf;
}
if ($pf->validate($state)) {
if ($this->_logger) {
if ($pf->getValidationWarnings(false)) {
foreach ($pf->getValidationWarnings() as $warning) {
$this->_logger->log(0, 'WARNING: ' . $warning['message']);
}
}
}
if (method_exists($pf, 'flattenFilelist')) {
$pf->flattenFilelist(); // for v2
}
return $pf;
} else {
 
if (!$pf->validate($state)) {
$a = PEAR::raiseError('Parsing of package.xml from file "' . $file . '" failed',
2, null, null, $pf->getValidationWarnings());
return $a;
}
 
if ($this->_logger && $pf->getValidationWarnings(false)) {
foreach ($pf->getValidationWarnings() as $warning) {
$this->_logger->log(0, 'WARNING: ' . $warning['message']);
}
}
 
if (method_exists($pf, 'flattenFilelist')) {
$pf->flattenFilelist(); // for v2
}
 
return $pf;
}
}
 
297,14 → 303,17
if (!class_exists('Archive_Tar')) {
require_once 'Archive/Tar.php';
}
 
$tar = new Archive_Tar($file);
if ($this->_debug <= 1) {
$tar->pushErrorHandling(PEAR_ERROR_RETURN);
}
 
$content = $tar->listContent();
if ($this->_debug <= 1) {
$tar->popErrorHandling();
}
 
if (!is_array($content)) {
if (is_string($file) && strlen($file < 255) &&
(!file_exists($file) || !@is_file($file))) {
311,17 → 320,19
$ret = PEAR::raiseError("could not open file \"$file\"");
return $ret;
}
 
$file = realpath($file);
$ret = PEAR::raiseError("Could not get contents of package \"$file\"".
'. Invalid tgz file.');
return $ret;
} else {
if (!count($content) && !@is_file($file)) {
$ret = PEAR::raiseError("could not open file \"$file\"");
return $ret;
}
}
$xml = null;
 
if (!count($content) && !@is_file($file)) {
$ret = PEAR::raiseError("could not open file \"$file\"");
return $ret;
}
 
$xml = null;
$origfile = $file;
foreach ($content as $file) {
$name = $file['filename'];
329,32 → 340,39
$xml = $name;
break;
}
 
if ($name == 'package.xml') {
$xml = $name;
break;
} elseif (ereg('package.xml$', $name, $match)) {
} elseif (preg_match('/package.xml$/', $name, $match)) {
$xml = $name;
break;
}
}
if ($this->_tmpdir) {
$tmpdir = $this->_tmpdir;
} else {
$tmpdir = System::mkTemp(array('-d', 'pear'));
PEAR_PackageFile::addTempFile($tmpdir);
 
$tmpdir = System::mktemp('-t "' . $this->_config->get('temp_dir') . '" -d pear');
if ($tmpdir === false) {
$ret = PEAR::raiseError("there was a problem with getting the configured temp directory");
return $ret;
}
 
PEAR_PackageFile::addTempFile($tmpdir);
 
$this->_extractErrors();
PEAR::staticPushErrorHandling(PEAR_ERROR_CALLBACK, array($this, '_extractErrors'));
 
if (!$xml || !$tar->extractList(array($xml), $tmpdir)) {
$extra = implode("\n", $this->_extractErrors());
if ($extra) {
$extra = ' ' . $extra;
}
 
PEAR::staticPopErrorHandling();
$ret = PEAR::raiseError('could not extract the package.xml file from "' .
$origfile . '"' . $extra);
return $ret;
}
 
PEAR::staticPopErrorHandling();
$ret = &PEAR_PackageFile::fromPackageFile("$tmpdir/$xml", $state, $origfile);
return $ret;
361,13 → 379,6
}
 
/**
* helper for extracting Archive_Tar errors
* @var array
* @access private
*/
var $_extractErrors = array();
 
/**
* helper callback for extracting Archive_Tar errors
*
* @param PEAR_Error|null $err
399,9 → 410,13
*/
function &fromPackageFile($descfile, $state, $archive = false)
{
$fp = false;
if (is_string($descfile) && strlen($descfile) < 255 &&
(!file_exists($descfile) || !is_file($descfile) || !is_readable($descfile) ||
(!$fp = @fopen($descfile, 'r')))) {
(
!file_exists($descfile) || !is_file($descfile) || !is_readable($descfile)
|| (!$fp = @fopen($descfile, 'r'))
)
) {
$a = PEAR::raiseError("Unable to open $descfile");
return $a;
}
414,7 → 429,6
return $ret;
}
 
 
/**
* Create a PEAR_PackageFile_v* from a .tgz archive or package.xml file.
*
439,15 → 453,19
} else {
$info = PEAR::raiseError("No package definition found in '$info' directory");
}
 
return $info;
}
 
$fp = false;
if (is_string($info) && strlen($info) < 255 &&
(file_exists($info) || ($fp = @fopen($info, 'r')))) {
(file_exists($info) || ($fp = @fopen($info, 'r')))
) {
 
if ($fp) {
fclose($fp);
}
 
$tmp = substr($info, -4);
if ($tmp == '.xml') {
$info = &PEAR_PackageFile::fromPackageFile($info, $state);
454,21 → 472,20
} elseif ($tmp == '.tar' || $tmp == '.tgz') {
$info = &PEAR_PackageFile::fromTgzFile($info, $state);
} else {
$fp = fopen($info, "r");
$fp = fopen($info, 'r');
$test = fread($fp, 5);
fclose($fp);
if ($test == "<?xml") {
if ($test == '<?xml') {
$info = &PEAR_PackageFile::fromPackageFile($info, $state);
} else {
$info = &PEAR_PackageFile::fromTgzFile($info, $state);
}
}
} else {
$info = PEAR::raiseError("Cannot open '$info' for parsing");
 
return $info;
}
 
$info = PEAR::raiseError("Cannot open '$info' for parsing");
return $info;
}
}
 
?>
/trunk/bibliotheque/pear/PEAR/Installer.php
4,12 → 4,6
*
* 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 Stig Bakken <ssb@php.net>
16,9 → 10,8
* @author Tomas V.V. Cox <cox@idecnet.com>
* @author Martin Jansen <mj@php.net>
* @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: Installer.php,v 1.243 2007/02/16 04:00:37 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
40,9 → 33,9
* @author Tomas V.V. Cox <cox@idecnet.com>
* @author Martin Jansen <mj@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
122,9 → 115,9
*
* @access public
*/
function PEAR_Installer(&$ui)
function __construct(&$ui)
{
parent::PEAR_Common();
parent::__construct($ui, array(), null);
$this->setFrontendObject($ui);
$this->debug = $this->config->get('verbose');
}
136,7 → 129,7
 
function setConfig(&$config)
{
$this->config = &$config;
$this->config = &$config;
$this->_registry = &$config->getRegistry();
}
 
165,9 → 158,11
if (!$channel) {
$channel = 'pear.php.net';
}
 
if (!strlen($package)) {
return $this->raiseError("No package to uninstall given");
}
 
if (strtolower($package) == 'pear' && $channel == 'pear.php.net') {
// to avoid race conditions, include all possible needed files
require_once 'PEAR/Task/Common.php';
179,25 → 174,31
require_once 'PEAR/PackageFile/Generator/v1.php';
require_once 'PEAR/PackageFile/Generator/v2.php';
}
 
$filelist = $this->_registry->packageInfo($package, 'filelist', $channel);
if ($filelist == null) {
return $this->raiseError("$channel/$package not installed");
}
 
$ret = array();
foreach ($filelist as $file => $props) {
if (empty($props['installed_as'])) {
continue;
}
 
$path = $props['installed_as'];
if ($backup) {
$this->addFileOperation('backup', array($path));
$ret[] = $path;
}
 
$this->addFileOperation('delete', array($path));
}
 
if ($backup) {
return $ret;
}
 
return true;
}
 
218,17 → 219,20
if (!isset($this->_registry)) {
$this->_registry = &$this->config->getRegistry();
}
 
if (isset($atts['platform'])) {
if (empty($os)) {
$os = new OS_Guess();
}
 
if (strlen($atts['platform']) && $atts['platform']{0} == '!') {
$negate = true;
$negate = true;
$platform = substr($atts['platform'], 1);
} else {
$negate = false;
$negate = false;
$platform = $atts['platform'];
}
 
if ((bool) $os->matchSignature($platform) === $negate) {
$this->log(3, "skipped $file (meant for $atts[platform], we are ".$os->getSignature().")");
return PEAR_INSTALLER_SKIPPED;
239,6 → 243,10
$channel = $this->pkginfo->getChannel();
// {{{ assemble the destination paths
switch ($atts['role']) {
case 'src':
case 'extsrc':
$this->source_files++;
return;
case 'doc':
case 'data':
case 'test':
253,20 → 261,19
case 'script':
$dest_dir = $this->config->get('bin_dir', null, $channel);
break;
case 'src':
case 'extsrc':
$this->source_files++;
return;
default:
return $this->raiseError("Invalid role `$atts[role]' for file $file");
}
 
$save_destdir = $dest_dir;
if (!empty($atts['baseinstalldir'])) {
$dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
}
 
if (dirname($file) != '.' && empty($atts['install-as'])) {
$dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
}
 
if (empty($atts['install-as'])) {
$dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
} else {
283,16 → 290,19
array($dest_file, $orig_file));
$final_dest_file = $installed_as = $dest_file;
if (isset($this->_options['packagingroot'])) {
$installedas_dest_dir = dirname($final_dest_file);
$installedas_dest_dir = dirname($final_dest_file);
$installedas_dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);
$final_dest_file = $this->_prependPath($final_dest_file,
$this->_options['packagingroot']);
$final_dest_file = $this->_prependPath($final_dest_file, $this->_options['packagingroot']);
} else {
$installedas_dest_dir = dirname($final_dest_file);
$installedas_dest_dir = dirname($final_dest_file);
$installedas_dest_file = $installedas_dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);
}
$dest_dir = dirname($final_dest_file);
 
$dest_dir = dirname($final_dest_file);
$dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);
if (preg_match('~/\.\.(/|\\z)|^\.\./~', str_replace('\\', '/', $dest_file))) {
return $this->raiseError("SECURITY ERROR: file $file (installed to $dest_file) contains parent directory reference ..", PEAR_INSTALLER_FAILED);
}
// }}}
 
if (empty($this->_options['register-only']) &&
303,6 → 313,7
}
$this->log(3, "+ mkdir $dest_dir");
}
 
// pretty much nothing happens if we are only registering the install
if (empty($this->_options['register-only'])) {
if (empty($atts['replacements'])) {
310,10 → 321,12
return $this->raiseError("file $orig_file does not exist",
PEAR_INSTALLER_FAILED);
}
 
if (!@copy($orig_file, $dest_file)) {
return $this->raiseError("failed to write $dest_file: $php_errormsg",
PEAR_INSTALLER_FAILED);
}
 
$this->log(3, "+ cp $orig_file $dest_file");
if (isset($atts['md5sum'])) {
$md5sum = md5_file($dest_file);
324,18 → 337,21
return $this->raiseError("file does not exist",
PEAR_INSTALLER_FAILED);
}
 
$contents = file_get_contents($orig_file);
if ($contents === false) {
$contents = '';
}
 
if (isset($atts['md5sum'])) {
$md5sum = md5($contents);
}
 
$subst_from = $subst_to = array();
foreach ($atts['replacements'] as $a) {
$to = '';
if ($a['type'] == 'php-const') {
if (preg_match('/^[a-z0-9_]+$/i', $a['to'])) {
if (preg_match('/^[a-z0-9_]+\\z/i', $a['to'])) {
eval("\$to = $a[to];");
} else {
if (!isset($options['soft'])) {
375,25 → 391,30
$subst_to[] = $to;
}
}
 
$this->log(3, "doing ".sizeof($subst_from)." substitution(s) for $final_dest_file");
if (sizeof($subst_from)) {
$contents = str_replace($subst_from, $subst_to, $contents);
}
 
$wp = @fopen($dest_file, "wb");
if (!is_resource($wp)) {
return $this->raiseError("failed to create $dest_file: $php_errormsg",
PEAR_INSTALLER_FAILED);
}
 
if (@fwrite($wp, $contents) === false) {
return $this->raiseError("failed writing to $dest_file: $php_errormsg",
PEAR_INSTALLER_FAILED);
}
 
fclose($wp);
// }}}
}
 
// {{{ check the md5
if (isset($md5sum)) {
if (strtolower($md5sum) == strtolower($atts['md5sum'])) {
if (strtolower($md5sum) === strtolower($atts['md5sum'])) {
$this->log(2, "md5sum ok: $final_dest_file");
} else {
if (empty($options['force'])) {
401,14 → 422,15
if (file_exists($dest_file)) {
unlink($dest_file);
}
 
if (!isset($options['ignore-errors'])) {
return $this->raiseError("bad md5sum for file $final_dest_file",
PEAR_INSTALLER_FAILED);
} else {
if (!isset($options['soft'])) {
$this->log(0, "warning : bad md5sum for file $final_dest_file");
}
}
 
if (!isset($options['soft'])) {
$this->log(0, "warning : bad md5sum for file $final_dest_file");
}
} else {
if (!isset($options['soft'])) {
$this->log(0, "warning : bad md5sum for file $final_dest_file");
425,21 → 447,40
} else {
$mode = 0666 & ~(int)octdec($this->config->get('umask'));
}
$this->addFileOperation("chmod", array($mode, $dest_file));
if (!@chmod($dest_file, $mode)) {
if (!isset($options['soft'])) {
$this->log(0, "failed to change mode of $dest_file: $php_errormsg");
 
if ($atts['role'] != 'src') {
$this->addFileOperation("chmod", array($mode, $dest_file));
if (!@chmod($dest_file, $mode)) {
if (!isset($options['soft'])) {
$this->log(0, "failed to change mode of $dest_file: $php_errormsg");
}
}
}
}
// }}}
$this->addFileOperation("rename", array($dest_file, $final_dest_file,
$atts['role'] == 'ext'));
 
if ($atts['role'] == 'src') {
rename($dest_file, $final_dest_file);
$this->log(2, "renamed source file $dest_file to $final_dest_file");
} else {
$this->addFileOperation("rename", array($dest_file, $final_dest_file,
$atts['role'] == 'ext'));
}
}
 
// Store the full path where the file was installed for easy unistall
$this->addFileOperation("installed_as", array($file, $installed_as,
$save_destdir, dirname(substr($installedas_dest_file, strlen($save_destdir)))));
if ($atts['role'] != 'script') {
$loc = $this->config->get($atts['role'] . '_dir');
} else {
$loc = $this->config->get('bin_dir');
}
 
if ($atts['role'] != 'src') {
$this->addFileOperation("installed_as", array($file, $installed_as,
$loc,
dirname(substr($installedas_dest_file, strlen($loc)))));
}
 
//$this->log(2, "installed: $dest_file");
return PEAR_INSTALLER_OK;
}
455,8 → 496,9
* @param array options from command-line
* @access private
*/
function _installFile2(&$pkg, $file, $atts, $tmp_path, $options)
function _installFile2(&$pkg, $file, &$real_atts, $tmp_path, $options)
{
$atts = $real_atts;
if (!isset($this->_registry)) {
$this->_registry = &$this->config->getRegistry();
}
468,26 → 510,34
return $this->raiseError('Invalid role `' . $atts['attribs']['role'] .
"' for file $file");
}
 
$role = &PEAR_Installer_Role::factory($pkg, $atts['attribs']['role'], $this->config);
$err = $role->setup($this, $pkg, $atts['attribs'], $file);
$err = $role->setup($this, $pkg, $atts['attribs'], $file);
if (PEAR::isError($err)) {
return $err;
}
 
if (!$role->isInstallable()) {
return;
}
 
$info = $role->processInstallation($pkg, $atts['attribs'], $file, $tmp_path);
if (PEAR::isError($info)) {
return $info;
} else {
list($save_destdir, $dest_dir, $dest_file, $orig_file) = $info;
}
 
list($save_destdir, $dest_dir, $dest_file, $orig_file) = $info;
if (preg_match('~/\.\.(/|\\z)|^\.\./~', str_replace('\\', '/', $dest_file))) {
return $this->raiseError("SECURITY ERROR: file $file (installed to $dest_file) contains parent directory reference ..", PEAR_INSTALLER_FAILED);
}
 
$final_dest_file = $installed_as = $dest_file;
if (isset($this->_options['packagingroot'])) {
$final_dest_file = $this->_prependPath($final_dest_file,
$this->_options['packagingroot']);
}
$dest_dir = dirname($final_dest_file);
 
$dest_dir = dirname($final_dest_file);
$dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);
// }}}
 
500,6 → 550,7
$this->log(3, "+ mkdir $dest_dir");
}
}
 
$attribs = $atts['attribs'];
unset($atts['attribs']);
// pretty much nothing happens if we are only registering the install
509,10 → 560,12
return $this->raiseError("file $orig_file does not exist",
PEAR_INSTALLER_FAILED);
}
 
if (!@copy($orig_file, $dest_file)) {
return $this->raiseError("failed to write $dest_file: $php_errormsg",
PEAR_INSTALLER_FAILED);
}
 
$this->log(3, "+ cp $orig_file $dest_file");
if (isset($attribs['md5sum'])) {
$md5sum = md5_file($dest_file);
522,18 → 575,20
return $this->raiseError("file $orig_file does not exist",
PEAR_INSTALLER_FAILED);
}
 
$contents = file_get_contents($orig_file);
if ($contents === false) {
$contents = '';
}
 
if (isset($attribs['md5sum'])) {
$md5sum = md5($contents);
}
 
foreach ($atts as $tag => $raw) {
$tag = str_replace(array($pkg->getTasksNs() . ':', '-'),
array('', '_'), $tag);
$tag = str_replace(array($pkg->getTasksNs() . ':', '-'), array('', '_'), $tag);
$task = "PEAR_Task_$tag";
$task = &new $task($this->config, $this, PEAR_TASK_INSTALL);
$task = new $task($this->config, $this, PEAR_TASK_INSTALL);
if (!$task->isScript()) { // scripts are only handled after installation
$task->init($raw, $attribs, $pkg->getLastInstalledVersion());
$res = $task->startSession($pkg, $contents, $final_dest_file);
540,27 → 595,39
if ($res === false) {
continue; // skip this file
}
 
if (PEAR::isError($res)) {
return $res;
}
 
$contents = $res; // save changes
}
 
$wp = @fopen($dest_file, "wb");
if (!is_resource($wp)) {
return $this->raiseError("failed to create $dest_file: $php_errormsg",
PEAR_INSTALLER_FAILED);
}
 
if (fwrite($wp, $contents) === false) {
return $this->raiseError("failed writing to $dest_file: $php_errormsg",
PEAR_INSTALLER_FAILED);
}
 
fclose($wp);
}
}
 
// {{{ check the md5
if (isset($md5sum)) {
if (strtolower($md5sum) == strtolower($attribs['md5sum'])) {
// Make sure the original md5 sum matches with expected
if (strtolower($md5sum) === strtolower($attribs['md5sum'])) {
$this->log(2, "md5sum ok: $final_dest_file");
 
if (isset($contents)) {
// set md5 sum based on $content in case any tasks were run.
$real_atts['attribs']['md5sum'] = md5($contents);
}
} else {
if (empty($options['force'])) {
// delete the file
567,14 → 634,15
if (file_exists($dest_file)) {
unlink($dest_file);
}
 
if (!isset($options['ignore-errors'])) {
return $this->raiseError("bad md5sum for file $final_dest_file",
PEAR_INSTALLER_FAILED);
} else {
if (!isset($options['soft'])) {
$this->log(0, "warning : bad md5sum for file $final_dest_file");
}
}
 
if (!isset($options['soft'])) {
$this->log(0, "warning : bad md5sum for file $final_dest_file");
}
} else {
if (!isset($options['soft'])) {
$this->log(0, "warning : bad md5sum for file $final_dest_file");
581,7 → 649,10
}
}
}
} else {
$real_atts['attribs']['md5sum'] = md5_file($dest_file);
}
 
// }}}
// {{{ set file permissions
if (!OS_WINDOWS) {
591,19 → 662,33
} else {
$mode = 0666 & ~(int)octdec($this->config->get('umask'));
}
$this->addFileOperation("chmod", array($mode, $dest_file));
if (!@chmod($dest_file, $mode)) {
if (!isset($options['soft'])) {
$this->log(0, "failed to change mode of $dest_file: $php_errormsg");
 
if ($attribs['role'] != 'src') {
$this->addFileOperation("chmod", array($mode, $dest_file));
if (!@chmod($dest_file, $mode)) {
if (!isset($options['soft'])) {
$this->log(0, "failed to change mode of $dest_file: $php_errormsg");
}
}
}
}
// }}}
$this->addFileOperation("rename", array($dest_file, $final_dest_file, $role->isExtension()));
 
if ($attribs['role'] == 'src') {
rename($dest_file, $final_dest_file);
$this->log(2, "renamed source file $dest_file to $final_dest_file");
} else {
$this->addFileOperation("rename", array($dest_file, $final_dest_file, $role->isExtension()));
}
}
 
// Store the full path where the file was installed for easy uninstall
$this->addFileOperation("installed_as", array($file, $installed_as,
$save_destdir, dirname(substr($dest_file, strlen($save_destdir)))));
if ($attribs['role'] != 'src') {
$loc = $this->config->get($role->getLocationConfig(), null, $channel);
$this->addFileOperation('installed_as', array($file, $installed_as,
$loc,
dirname(substr($installed_as, strlen($loc)))));
}
 
//$this->log(2, "installed: $dest_file");
return PEAR_INSTALLER_OK;
642,6 → 727,7
return $this->raiseError('Internal Error: $data in addFileOperation'
. ' must be an array, was ' . gettype($data));
}
 
if ($type == 'chmod') {
$octmode = decoct($data[0]);
$this->log(3, "adding to transaction: $type $octmode $data[1]");
667,11 → 753,9
 
function commitFileTransaction()
{
$n = count($this->file_operations);
$this->log(2, "about to commit $n file operations");
// {{{ first, check permissions and such manually
$errors = array();
foreach ($this->file_operations as $tr) {
foreach ($this->file_operations as $key => $tr) {
list($type, $data) = $tr;
switch ($type) {
case 'rename':
678,6 → 762,7
if (!file_exists($data[0])) {
$errors[] = "cannot rename file $data[0], doesn't exist";
}
 
// check that dest dir. is writable
if (!is_writable(dirname($data[1]))) {
$errors[] = "permission denied ($type): $data[1]";
707,6 → 792,27
fclose($fp);
}
}
 
/* Verify we are not deleting a file owned by another package
* This can happen when a file moves from package A to B in
* an upgrade ala http://pear.php.net/17986
*/
$info = array(
'package' => strtolower($this->pkginfo->getName()),
'channel' => strtolower($this->pkginfo->getChannel()),
);
$result = $this->_registry->checkFileMap($data[0], $info, '1.1');
if (is_array($result)) {
$res = array_diff($result, $info);
if (!empty($res)) {
$new = $this->_registry->getPackage($result[1], $result[0]);
$this->file_operations[$key] = false;
$pkginfoName = $this->pkginfo->getName();
$newChannel = $new->getChannel();
$newPackage = $new->getName();
$this->log(3, "file $data[0] was scheduled for removal from $pkginfoName but is owned by $newChannel/$newPackage, removal has been cancelled.");
}
}
}
break;
}
713,7 → 819,11
 
}
// }}}
$m = sizeof($errors);
 
$n = count($this->file_operations);
$this->log(2, "about to commit $n file operations for " . $this->pkginfo->getName());
 
$m = count($errors);
if ($m > 0) {
foreach ($errors as $error) {
if (!isset($this->_options['soft'])) {
720,10 → 830,12
$this->log(1, $error);
}
}
 
if (!isset($this->_options['ignore-errors'])) {
return false;
}
}
 
$this->_dirtree = array();
// {{{ really commit the transaction
foreach ($this->file_operations as $i => $tr) {
731,6 → 843,7
// support removal of non-existing backups
continue;
}
 
list($type, $data) = $tr;
switch ($type) {
case 'backup':
738,6 → 851,7
$this->file_operations[$i] = false;
break;
}
 
if (!@copy($data[0], $data[0] . '.bak')) {
$this->log(1, 'Could not copy ' . $data[0] . ' to ' . $data[0] .
'.bak ' . $php_errormsg);
752,11 → 866,7
}
break;
case 'rename':
if (file_exists($data[1])) {
$test = @unlink($data[1]);
} else {
$test = null;
}
$test = file_exists($data[1]) ? @unlink($data[1]) : null;
if (!$test && file_exists($data[1])) {
if ($data[2]) {
$extra = ', this extension must be installed manually. Rename to "' .
764,14 → 874,17
} else {
$extra = '';
}
 
if (!isset($this->_options['soft'])) {
$this->log(1, 'Could not delete ' . $data[1] . ', cannot rename ' .
$data[0] . $extra);
}
 
if (!isset($this->_options['ignore-errors'])) {
return false;
}
}
 
// permissions issues with rename - copy() is far superior
$perms = @fileperms($data[0]);
if (!@copy($data[0], $data[1])) {
779,6 → 892,7
' ' . $php_errormsg);
return false;
}
 
// copy over permissions, otherwise they are lost
@chmod($data[1], $perms);
@unlink($data[0]);
790,6 → 904,7
decoct($data[0]) . ' ' . $php_errormsg);
return false;
}
 
$octmode = decoct($data[0]);
$this->log(3, "+ chmod $octmode $data[1]");
break;
815,6 → 930,7
break 2; // this directory is not empty and can't be
// deleted
}
 
closedir($testme);
if (!@rmdir($data[0])) {
$this->log(1, 'Could not rmdir ' . $data[0] . ' ' .
831,8 → 947,8
$this->_dirtree[dirname($data[1])] = true;
$this->pkginfo->setDirtree(dirname($data[1]));
 
while(!empty($data[3]) && $data[3] != '/' && $data[3] != '\\'
&& $data[3] != '.') {
while(!empty($data[3]) && dirname($data[3]) != $data[3] &&
$data[3] != '/' && $data[3] != '\\') {
$this->pkginfo->setDirtree($pp =
$this->_prependPath($data[3], $data[2]));
$this->_dirtree[$pp] = true;
904,62 → 1020,12
}
 
// }}}
// {{{ download()
 
/**
* Download any files and their dependencies, if necessary
*
* @param array a mixed list of package names, local files, or package.xml
* @param PEAR_Config
* @param array options from the command line
* @param array this is the array that will be populated with packages to
* install. Format of each entry:
*
* <code>
* array('pkg' => 'package_name', 'file' => '/path/to/local/file',
* 'info' => array() // parsed package.xml
* );
* </code>
* @param array this will be populated with any error messages
* @param false private recursion variable
* @param false private recursion variable
* @param false private recursion variable
* @deprecated in favor of PEAR_Downloader
*/
function download($packages, $options, &$config, &$installpackages,
&$errors, $installed = false, $willinstall = false, $state = false)
{
// trickiness: initialize here
parent::PEAR_Downloader($this->ui, $options, $config);
$ret = parent::download($packages);
$errors = $this->getErrorMsgs();
$installpackages = $this->getDownloadedPackages();
trigger_error("PEAR Warning: PEAR_Installer::download() is deprecated " .
"in favor of PEAR_Downloader class", E_USER_WARNING);
return $ret;
}
 
// }}}
// {{{ _parsePackageXml()
 
function _parsePackageXml(&$descfile, &$tmpdir)
function _parsePackageXml(&$descfile)
{
if (substr($descfile, -4) == '.xml') {
$tmpdir = false;
} else {
// {{{ Decompress pack in tmp dir -------------------------------------
 
// To allow relative package file names
$descfile = realpath($descfile);
 
if (PEAR::isError($tmpdir = System::mktemp('-d'))) {
return $tmpdir;
}
$this->log(3, '+ tmp dir created at ' . $tmpdir);
// }}}
}
// Parse xml file -----------------------------------------------
$pkg = new PEAR_PackageFile($this->config, $this->debug, $tmpdir);
$pkg = new PEAR_PackageFile($this->config, $this->debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$p = &$pkg->fromAnyFile($descfile, PEAR_VALIDATE_INSTALLING);
PEAR::staticPopErrorHandling();
973,9 → 1039,9
}
}
return $this->raiseError('Installation failed: invalid package file');
} else {
$descfile = $p->getPackageFile();
}
 
$descfile = $p->getPackageFile();
return $p;
}
 
1031,26 → 1097,29
*
* @return array|PEAR_Error package info if successful
*/
 
function install($pkgfile, $options = array())
{
$this->_options = $options;
$this->_registry = &$this->config->getRegistry();
if (is_object($pkgfile)) {
$dlpkg = &$pkgfile;
$pkg = $pkgfile->getPackageFile();
$pkgfile = $pkg->getArchiveFile();
$dlpkg = &$pkgfile;
$pkg = $pkgfile->getPackageFile();
$pkgfile = $pkg->getArchiveFile();
$descfile = $pkg->getPackageFile();
$tmpdir = dirname($descfile);
} else {
$descfile = $pkgfile;
$tmpdir = '';
if (PEAR::isError($pkg = &$this->_parsePackageXml($descfile, $tmpdir))) {
$pkg = $this->_parsePackageXml($descfile);
if (PEAR::isError($pkg)) {
return $pkg;
}
}
 
$tmpdir = dirname($descfile);
if (realpath($descfile) != realpath($pkgfile)) {
// Use the temp_dir since $descfile can contain the download dir path
$tmpdir = $this->config->get('temp_dir', null, 'pear.php.net');
$tmpdir = System::mktemp('-d -t "' . $tmpdir . '"');
 
$tar = new Archive_Tar($pkgfile);
if (!$tar->extract($tmpdir)) {
return $this->raiseError("unable to unpack $pkgfile");
1059,14 → 1128,6
 
$pkgname = $pkg->getName();
$channel = $pkg->getChannel();
if (isset($this->_options['packagingroot'])) {
$regdir = $this->_prependPath(
$this->config->get('php_dir', null, 'pear.php.net'),
$this->_options['packagingroot']);
$packrootphp_dir = $this->_prependPath(
$this->config->get('php_dir', null, $channel),
$this->_options['packagingroot']);
}
 
if (isset($options['installroot'])) {
$this->config->setInstallRoot($options['installroot']);
1078,7 → 1139,21
$this->config->setInstallRoot(false);
$this->_registry = &$this->config->getRegistry();
if (isset($this->_options['packagingroot'])) {
$installregistry = &new PEAR_Registry($regdir);
$regdir = $this->_prependPath(
$this->config->get('php_dir', null, 'pear.php.net'),
$this->_options['packagingroot']);
 
$metadata_dir = $this->config->get('metadata_dir', null, 'pear.php.net');
if ($metadata_dir) {
$metadata_dir = $this->_prependPath(
$metadata_dir,
$this->_options['packagingroot']);
}
$packrootphp_dir = $this->_prependPath(
$this->config->get('php_dir', null, $channel),
$this->_options['packagingroot']);
 
$installregistry = new PEAR_Registry($regdir, false, false, $metadata_dir);
if (!$installregistry->channelExists($channel, true)) {
// we need to fake a channel-discover of this channel
$chanobj = $this->_registry->getChannel($channel, true);
1101,6 → 1176,7
if (PEAR::isError($instfilelist)) {
return $instfilelist;
}
 
// ensure we have the most accurate registry
$installregistry->flushFileMap();
$test = $installregistry->checkFileMap($instfilelist, $testp, '1.1');
1107,6 → 1183,7
if (PEAR::isError($test)) {
return $test;
}
 
if (sizeof($test)) {
$pkgs = $this->getInstallPackages();
$found = false;
1116,6 → 1193,7
break;
}
}
 
if ($found) {
// subpackages can conflict with earlier versions of parent packages
$parentreg = $installregistry->packageInfo($param->getPackage(), null, $param->getChannel());
1123,24 → 1201,52
foreach ($tmp as $file => $info) {
if (is_array($info)) {
if (strtolower($info[1]) == strtolower($param->getPackage()) &&
strtolower($info[0]) == strtolower($param->getChannel())) {
strtolower($info[0]) == strtolower($param->getChannel())
) {
if (isset($parentreg['filelist'][$file])) {
unset($parentreg['filelist'][$file]);
} else{
$pos = strpos($file, '/');
$basedir = substr($file, 0, $pos);
$file2 = substr($file, $pos + 1);
if (isset($parentreg['filelist'][$file2]['baseinstalldir'])
&& $parentreg['filelist'][$file2]['baseinstalldir'] === $basedir
) {
unset($parentreg['filelist'][$file2]);
}
}
 
unset($test[$file]);
unset($parentreg['filelist'][$file]);
}
} else {
if (strtolower($param->getChannel()) != 'pear.php.net') {
continue;
}
 
if (strtolower($info) == strtolower($param->getPackage())) {
if (isset($parentreg['filelist'][$file])) {
unset($parentreg['filelist'][$file]);
} else{
$pos = strpos($file, '/');
$basedir = substr($file, 0, $pos);
$file2 = substr($file, $pos + 1);
if (isset($parentreg['filelist'][$file2]['baseinstalldir'])
&& $parentreg['filelist'][$file2]['baseinstalldir'] === $basedir
) {
unset($parentreg['filelist'][$file2]);
}
}
 
unset($test[$file]);
unset($parentreg['filelist'][$file]);
}
}
}
$pfk = &new PEAR_PackageFile($this->config);
 
$pfk = new PEAR_PackageFile($this->config);
$parentpkg = &$pfk->fromArray($parentreg);
$installregistry->updatePackage2($parentpkg);
}
 
if ($param->getChannel() == 'pecl.php.net' && isset($options['upgrade'])) {
$tmp = $test;
foreach ($tmp as $file => $info) {
1153,7 → 1259,8
}
}
}
if (sizeof($test)) {
 
if (count($test)) {
$msg = "$channel/$pkgname: conflicting files found:\n";
$longest = max(array_map("strlen", array_keys($test)));
$fmt = "%${longest}s (%s)\n";
1164,13 → 1271,14
$info = $info[0] . '/' . $info[1];
$msg .= sprintf($fmt, $file, $info);
}
 
if (!isset($options['ignore-errors'])) {
return $this->raiseError($msg);
} else {
if (!isset($options['soft'])) {
$this->log(0, "WARNING: $msg");
}
}
 
if (!isset($options['soft'])) {
$this->log(0, "WARNING: $msg");
}
}
}
}
1178,30 → 1286,24
 
$this->startFileTransaction();
 
$usechannel = $channel;
if ($channel == 'pecl.php.net') {
$test = $installregistry->packageExists($pkgname, $channel);
if (!$test) {
$test = $installregistry->packageExists($pkgname, 'pear.php.net');
$usechannel = 'pear.php.net';
}
} else {
$test = $installregistry->packageExists($pkgname, $channel);
}
 
if (empty($options['upgrade']) && empty($options['soft'])) {
// checks to do only when installing new packages
if ($channel == 'pecl.php.net') {
$test = $installregistry->packageExists($pkgname, $channel);
if (!$test) {
$test = $installregistry->packageExists($pkgname, 'pear.php.net');
}
} else {
$test = $installregistry->packageExists($pkgname, $channel);
}
if (empty($options['force']) && $test) {
return $this->raiseError("$channel/$pkgname is already installed");
}
} else {
$usechannel = $channel;
if ($channel == 'pecl.php.net') {
$test = $installregistry->packageExists($pkgname, $channel);
if (!$test) {
$test = $installregistry->packageExists($pkgname, 'pear.php.net');
$usechannel = 'pear.php.net';
}
} else {
$test = $installregistry->packageExists($pkgname, $channel);
}
// Upgrade
if ($test) {
$v1 = $installregistry->packageInfo($pkgname, 'version', $usechannel);
$v2 = $pkg->getVersion();
1209,21 → 1311,23
if (empty($options['force']) && !version_compare("$v2", "$v1", 'gt')) {
return $this->raiseError("upgrade to a newer version ($v2 is not newer than $v1)");
}
if (empty($options['register-only'])) {
// when upgrading, remove old release's files first:
if (PEAR::isError($err = $this->_deletePackageFiles($pkgname, $usechannel,
true))) {
if (!isset($options['ignore-errors'])) {
return $this->raiseError($err);
} else {
if (!isset($options['soft'])) {
$this->log(0, 'WARNING: ' . $err->getMessage());
}
}
} else {
$backedup = $err;
}
}
}
 
// Do cleanups for upgrade and install, remove old release's files first
if ($test && empty($options['register-only'])) {
// when upgrading, remove old release's files first:
if (PEAR::isError($err = $this->_deletePackageFiles($pkgname, $usechannel,
true))) {
if (!isset($options['ignore-errors'])) {
return $this->raiseError($err);
}
 
if (!isset($options['soft'])) {
$this->log(0, 'WARNING: ' . $err->getMessage());
}
} else {
$backedup = $err;
}
}
 
1241,9 → 1345,8
}
}
 
$tmp_path = dirname($descfile);
if (substr($pkgfile, -4) != '.xml') {
$tmp_path .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkg->getVersion();
$tmpdir .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkg->getVersion();
}
 
$this->configSet('default_channel', $channel);
1255,22 → 1358,26
} else {
$filelist = $pkg->getFileList();
}
 
if (PEAR::isError($filelist)) {
return $filelist;
}
 
$p = &$installregistry->getPackage($pkgname, $channel);
$dirtree = (empty($options['register-only']) && $p) ? $p->getDirTree() : false;
 
$pkg->resetFilelist();
$pkg->setLastInstalledVersion($installregistry->packageInfo($pkg->getPackage(),
'version', $pkg->getChannel()));
foreach ($filelist as $file => $atts) {
$this->expectError(PEAR_INSTALLER_FAILED);
if ($pkg->getPackagexmlVersion() == '1.0') {
$this->expectError(PEAR_INSTALLER_FAILED);
$res = $this->_installFile($file, $atts, $tmp_path, $options);
$this->popExpect();
$res = $this->_installFile($file, $atts, $tmpdir, $options);
} else {
$this->expectError(PEAR_INSTALLER_FAILED);
$res = $this->_installFile2($pkg, $file, $atts, $tmp_path, $options);
$this->popExpect();
$res = $this->_installFile2($pkg, $file, $atts, $tmpdir, $options);
}
$this->popExpect();
 
if (PEAR::isError($res)) {
if (empty($options['ignore-errors'])) {
$this->rollbackFileTransaction();
1277,14 → 1384,17
if ($res->getMessage() == "file does not exist") {
$this->raiseError("file $file in package.xml does not exist");
}
 
return $this->raiseError($res);
} else {
if (!isset($options['soft'])) {
$this->log(0, "Warning: " . $res->getMessage());
}
}
 
if (!isset($options['soft'])) {
$this->log(0, "Warning: " . $res->getMessage());
}
}
if ($res == PEAR_INSTALLER_OK) {
 
$real = isset($atts['attribs']) ? $atts['attribs'] : $atts;
if ($res == PEAR_INSTALLER_OK && $real['role'] != 'src') {
// Register files that were installed
$pkg->installedFile($file, $atts);
}
1303,6 → 1413,7
if (isset($backedup)) {
$this->_removeBackups($backedup);
}
 
if (!$this->commitFileTransaction()) {
$this->rollbackFileTransaction();
$this->configSet('default_channel', $savechannel);
1310,9 → 1421,9
}
// }}}
 
$ret = false;
$ret = false;
$installphase = 'install';
$oldversion = false;
$oldversion = false;
// {{{ Register that the package is installed -----------------------
if (empty($options['upgrade'])) {
// if 'force' is used, replace the info in registry
1326,6 → 1437,7
} else {
$test = $installregistry->packageExists($pkgname, $channel);
}
 
if (!empty($options['force']) && $test) {
$oldversion = $installregistry->packageInfo($pkgname, 'version', $usechannel);
$installregistry->deletePackage($pkgname, $usechannel);
1332,6 → 1444,16
}
$ret = $installregistry->addPackage2($pkg);
} else {
if ($dirtree) {
$this->startFileTransaction();
// attempt to delete empty directories
uksort($dirtree, array($this, '_sortDirs'));
foreach($dirtree as $dir => $notused) {
$this->addFileOperation('rmdir', array($dir));
}
$this->commitFileTransaction();
}
 
$usechannel = $channel;
if ($channel == 'pecl.php.net') {
$test = $installregistry->packageExists($pkgname, $channel);
1342,6 → 1464,7
} else {
$test = $installregistry->packageExists($pkgname, $channel);
}
 
// new: upgrade installs a package if it isn't installed
if (!$test) {
$ret = $installregistry->addPackage2($pkg);
1355,11 → 1478,13
$installphase = 'upgrade';
}
}
 
if (!$ret) {
$this->configSet('default_channel', $savechannel);
return $this->raiseError("Adding package $channel/$pkgname to registry failed");
}
// }}}
 
$this->configSet('default_channel', $savechannel);
if (class_exists('PEAR_Task_Common')) { // this is auto-included if any tasks exist
if (PEAR_Task_Common::hasPostinstallTasks()) {
1366,6 → 1491,7
PEAR_Task_Common::runPostinstallTasks($installphase);
}
}
 
return $pkg->toArray(true);
}
 
1380,7 → 1506,7
{
require_once 'PEAR/Builder.php';
$this->log(1, "$this->source_files source files, building");
$bob = &new PEAR_Builder($this->ui);
$bob = new PEAR_Builder($this->ui);
$bob->debug = $this->debug;
$built = $bob->build($filelist, array(&$this, '_buildCallback'));
if (PEAR::isError($built)) {
1388,6 → 1514,7
$this->configSet('default_channel', $savechannel);
return $built;
}
 
$this->log(1, "\nBuild process completed successfully");
foreach ($built as $ext) {
$bn = basename($ext['file']);
1402,17 → 1529,17
} else {
$role = 'src';
}
 
$dest = $ext['dest'];
$packagingroot = '';
if (isset($this->_options['packagingroot'])) {
$packagingroot = $this->_options['packagingroot'];
}
 
$copyto = $this->_prependPath($dest, $packagingroot);
if ($copyto != $dest) {
$this->log(1, "Installing '$dest' as '$copyto'");
} else {
$this->log(1, "Installing '$dest'");
}
$extra = $copyto != $dest ? " as '$copyto'" : '';
$this->log(1, "Installing '$dest'$extra");
 
$copydir = dirname($copyto);
// pretty much nothing happens if we are only registering the install
if (empty($this->_options['register-only'])) {
1421,11 → 1548,14
return $this->raiseError("failed to mkdir $copydir",
PEAR_INSTALLER_FAILED);
}
 
$this->log(3, "+ mkdir $copydir");
}
 
if (!@copy($ext['file'], $copyto)) {
return $this->raiseError("failed to write $copyto ($php_errormsg)", PEAR_INSTALLER_FAILED);
}
 
$this->log(3, "+ cp $ext[file] $copyto");
$this->addFileOperation('rename', array($ext['file'], $copyto));
if (!OS_WINDOWS) {
1437,24 → 1567,20
}
}
 
 
$data = array(
'role' => $role,
'name' => $bn,
'installed_as' => $dest,
'php_api' => $ext['php_api'],
'zend_mod_api' => $ext['zend_mod_api'],
'zend_ext_api' => $ext['zend_ext_api'],
);
 
if ($filelist->getPackageXmlVersion() == '1.0') {
$filelist->installedFile($bn, array(
'role' => $role,
'name' => $bn,
'installed_as' => $dest,
'php_api' => $ext['php_api'],
'zend_mod_api' => $ext['zend_mod_api'],
'zend_ext_api' => $ext['zend_ext_api'],
));
$filelist->installedFile($bn, $data);
} else {
$filelist->installedFile($bn, array('attribs' => array(
'role' => $role,
'name' => $bn,
'installed_as' => $dest,
'php_api' => $ext['php_api'],
'zend_mod_api' => $ext['zend_mod_api'],
'zend_ext_api' => $ext['zend_ext_api'],
)));
$filelist->installedFile($bn, array('attribs' => $data));
}
}
}
1481,17 → 1607,14
*/
function uninstall($package, $options = array())
{
if (isset($options['installroot'])) {
$this->config->setInstallRoot($options['installroot']);
$this->installroot = '';
} else {
$this->config->setInstallRoot('');
$this->installroot = '';
}
$installRoot = isset($options['installroot']) ? $options['installroot'] : '';
$this->config->setInstallRoot($installRoot);
 
$this->installroot = '';
$this->_registry = &$this->config->getRegistry();
if (is_object($package)) {
$channel = $package->getChannel();
$pkg = $package;
$pkg = $package;
$package = $pkg->getPackage();
} else {
$pkg = false;
1500,11 → 1623,13
$channel = $info['channel'];
$package = $info['package'];
}
 
$savechannel = $this->config->get('default_channel');
$this->configSet('default_channel', $channel);
if (!is_object($pkg)) {
$pkg = $this->_registry->getPackage($package, $channel);
}
 
if (!$pkg) {
$this->configSet('default_channel', $savechannel);
return $this->raiseError($this->_registry->parsedPackageNameToString(
1513,16 → 1638,19
'package' => $package
), true) . ' not installed');
}
 
if ($pkg->getInstalledBinary()) {
// this is just an alias for a binary package
return $this->_registry->deletePackage($package, $channel);
}
 
$filelist = $pkg->getFilelist();
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
$depchecker = &new PEAR_Dependency2($this->config, $options,
 
$depchecker = new PEAR_Dependency2($this->config, $options,
array('channel' => $channel, 'package' => $package),
PEAR_VALIDATE_UNINSTALLING);
$e = $depchecker->validatePackageUninstall($this);
1530,16 → 1658,17
if (PEAR::isError($e)) {
if (!isset($options['ignore-errors'])) {
return $this->raiseError($e);
} else {
if (!isset($options['soft'])) {
$this->log(0, 'WARNING: ' . $e->getMessage());
}
}
 
if (!isset($options['soft'])) {
$this->log(0, 'WARNING: ' . $e->getMessage());
}
} elseif (is_array($e)) {
if (!isset($options['soft'])) {
$this->log(0, $e[0]);
}
}
 
$this->pkginfo = &$pkg;
// pretty much nothing happens if we are only registering the uninstall
if (empty($options['register-only'])) {
1552,38 → 1681,45
$this->configSet('default_channel', $savechannel);
if (!isset($options['ignore-errors'])) {
return $this->raiseError($err);
} else {
if (!isset($options['soft'])) {
$this->log(0, 'WARNING: ' . $err->getMessage());
}
}
 
if (!isset($options['soft'])) {
$this->log(0, 'WARNING: ' . $err->getMessage());
}
} else {
PEAR::popErrorHandling();
}
 
if (!$this->commitFileTransaction()) {
$this->rollbackFileTransaction();
if (!isset($options['ignore-errors'])) {
return $this->raiseError("uninstall failed");
} elseif (!isset($options['soft'])) {
}
 
if (!isset($options['soft'])) {
$this->log(0, 'WARNING: uninstall failed');
}
} else {
$this->startFileTransaction();
if ($dirtree = $pkg->getDirTree()) {
// attempt to delete empty directories
uksort($dirtree, array($this, '_sortDirs'));
foreach($dirtree as $dir => $notused) {
$this->addFileOperation('rmdir', array($dir));
}
} else {
$dirtree = $pkg->getDirTree();
if ($dirtree === false) {
$this->configSet('default_channel', $savechannel);
return $this->_registry->deletePackage($package, $channel);
}
 
// attempt to delete empty directories
uksort($dirtree, array($this, '_sortDirs'));
foreach($dirtree as $dir => $notused) {
$this->addFileOperation('rmdir', array($dir));
}
 
if (!$this->commitFileTransaction()) {
$this->rollbackFileTransaction();
if (!isset($options['ignore-errors'])) {
return $this->raiseError("uninstall failed");
} elseif (!isset($options['soft'])) {
}
 
if (!isset($options['soft'])) {
$this->log(0, 'WARNING: uninstall failed');
}
}
1656,17 → 1792,3
 
// }}}
}
 
// {{{ md5_file() utility function
if (!function_exists("md5_file")) {
function md5_file($filename) {
if (!$fd = @fopen($file, 'r')) {
return false;
}
fclose($fd);
return md5(file_get_contents($filename));
}
}
// }}}
 
?>
/trunk/bibliotheque/pear/PEAR/Exception.php
5,12 → 5,6
*
* 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 Tomas V. V. Cox <cox@idecnet.com>
17,9 → 11,8
* @author Hans Lellelid <hans@velum.net>
* @author Bertrand Mansion <bmansion@mamasam.com>
* @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: Exception.php,v 1.26 2006/10/30 03:47:48 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.3.3
*/
93,9 → 86,9
* @author Hans Lellelid <hans@velum.net>
* @author Bertrand Mansion <bmansion@mamasam.com>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.3.3
*
260,7 → 253,9
'line' => $this->cause->getLine());
} elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
$causes[] = array('class' => get_class($this->cause),
'message' => $this->cause->getMessage());
'message' => $this->cause->getMessage(),
'file' => 'unknown',
'line' => 'unknown');
} elseif (is_array($this->cause)) {
foreach ($this->cause as $cause) {
if ($cause instanceof PEAR_Exception) {
272,7 → 267,9
'line' => $cause->getLine());
} elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
$causes[] = array('class' => get_class($cause),
'message' => $cause->getMessage());
'message' => $cause->getMessage(),
'file' => 'unknown',
'line' => 'unknown');
} elseif (is_array($cause) && isset($cause['message'])) {
// PEAR_ErrorStack warning
$causes[] = array(
291,7 → 288,7
}
 
public function getTraceSafe()
{
{
if (!isset($this->_trace)) {
$this->_trace = $this->getTrace();
if (empty($this->_trace)) {
327,21 → 324,21
$trace = $this->getTraceSafe();
$causes = array();
$this->getCauseMessage($causes);
$html = '<table border="1" cellspacing="0">' . "\n";
$html = '<table style="border: 1px" cellspacing="0">' . "\n";
foreach ($causes as $i => $cause) {
$html .= '<tr><td colspan="3" bgcolor="#ff9999">'
$html .= '<tr><td colspan="3" style="background: #ff9999">'
. str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
. htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
. 'on line <b>' . $cause['line'] . '</b>'
. "</td></tr>\n";
}
$html .= '<tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr>' . "\n"
. '<tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td>'
. '<td align="center" bgcolor="#cccccc"><b>Function</b></td>'
. '<td align="center" bgcolor="#cccccc"><b>Location</b></td></tr>' . "\n";
$html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n"
. '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
. '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
. '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
 
foreach ($trace as $k => $v) {
$html .= '<tr><td align="center">' . $k . '</td>'
$html .= '<tr><td style="text-align: center;">' . $k . '</td>'
. '<td>';
if (!empty($v['class'])) {
$html .= $v['class'] . $v['type'];
369,7 → 366,7
. ':' . (isset($v['line']) ? $v['line'] : 'unknown')
. '</td></tr>' . "\n";
}
$html .= '<tr><td align="center">' . ($k+1) . '</td>'
$html .= '<tr><td style="text-align: center;">' . ($k+1) . '</td>'
. '<td>{main}</td>'
. '<td>&nbsp;</td></tr>' . "\n"
. '</table>';
388,6 → 385,4
}
return $causeMsg . $this->getTraceAsString();
}
}
 
?>
}
/trunk/bibliotheque/pear/PEAR/Downloader.php
4,12 → 4,6
*
* 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>
16,9 → 10,8
* @author Stig Bakken <ssb@php.net>
* @author Tomas V. V. Cox <cox@idecnet.com>
* @author Martin Jansen <mj@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: Downloader.php,v 1.123 2007/02/20 00:16:12 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.3.0
*/
43,9 → 36,9
* @author Stig Bakken <ssb@php.net>
* @author Tomas V. V. Cox <cox@idecnet.com>
* @author Martin Jansen <mj@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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.3.0
*/
58,12 → 51,6
var $_registry;
 
/**
* @var PEAR_Remote
* @access private
*/
var $_remote;
 
/**
* Preferred Installation State (snapshot, devel, alpha, beta, stable)
* @var string|null
* @access private
132,7 → 119,7
* @access private
*/
var $_errorStack = array();
 
/**
* @var boolean
* @access private
151,19 → 138,33
* @var string
*/
var $_downloadDir;
// {{{ PEAR_Downloader()
 
/**
* List of methods that can be called both statically and non-statically.
* @var array
*/
protected static $bivalentMethods = array(
'setErrorHandling' => true,
'raiseError' => true,
'throwError' => true,
'pushErrorHandling' => true,
'popErrorHandling' => true,
'downloadHttp' => true,
);
 
/**
* @param PEAR_Frontend_*
* @param array
* @param PEAR_Config
*/
function PEAR_Downloader(&$ui, $options, &$config)
function __construct($ui = null, $options = array(), $config = null)
{
parent::PEAR_Common();
parent::__construct();
$this->_options = $options;
$this->config = &$config;
$this->_preferredState = $this->config->get('preferred_state');
if ($config !== null) {
$this->config = &$config;
$this->_preferredState = $this->config->get('preferred_state');
}
$this->ui = &$ui;
if (!$this->_preferredState) {
// don't inadvertantly use a non-set preferred_state
170,11 → 171,12
$this->_preferredState = null;
}
 
if (isset($this->_options['installroot'])) {
$this->config->setInstallRoot($this->_options['installroot']);
if ($config !== null) {
if (isset($this->_options['installroot'])) {
$this->config->setInstallRoot($this->_options['installroot']);
}
$this->_registry = &$config->getRegistry();
}
$this->_registry = &$config->getRegistry();
$this->_remote = &$config->getRemote();
 
if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {
$this->_installed = $this->_registry->listAllPackages();
202,16 → 204,27
if (!class_exists('System')) {
require_once 'System.php';
}
$a = $this->downloadHttp('http://' . $channel . '/channel.xml', $this->ui,
System::mktemp(array('-d')), $callback, false);
 
$tmpdir = $this->config->get('temp_dir');
$tmp = System::mktemp('-d -t "' . $tmpdir . '"');
$a = $this->downloadHttp('http://' . $channel . '/channel.xml', $this->ui, $tmp, $callback, false);
PEAR::popErrorHandling();
if (PEAR::isError($a)) {
return false;
// Attempt to fallback to https automatically.
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$this->log(1, 'Attempting fallback to https instead of http on channel "' . $channel . '"...');
$a = $this->downloadHttp('https://' . $channel . '/channel.xml', $this->ui, $tmp, $callback, false);
PEAR::popErrorHandling();
if (PEAR::isError($a)) {
return false;
}
}
 
list($a, $lastmodified) = $a;
if (!class_exists('PEAR/ChannelFile.php')) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$b = new PEAR_ChannelFile;
if ($b->fromXmlFile($a)) {
unlink($a);
221,11 → 234,14
if ($b->getName() == $this->_registry->channelName($b->getAlias())) {
$alias = $b->getAlias();
}
 
$this->log(1, 'Auto-discovered channel "' . $channel .
'", alias "' . $alias . '", adding to registry');
}
 
return true;
}
 
unlink($a);
return false;
}
235,12 → 251,12
* @param PEAR_Downloader
* @return PEAR_Downloader_Package
*/
function &newDownloaderPackage(&$t)
function newDownloaderPackage(&$t)
{
if (!class_exists('PEAR_Downloader_Package')) {
require_once 'PEAR/Downloader/Package.php';
}
$a = &new PEAR_Downloader_Package($t);
$a = new PEAR_Downloader_Package($t);
return $a;
}
 
253,10 → 269,10
*/
function &getDependency2Object(&$c, $i, $p, $s)
{
if (!class_exists('PEAR/Dependency2.php')) {
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
$z = &new PEAR_Dependency2($c, $i, $p, $s);
$z = new PEAR_Dependency2($c, $i, $p, $s);
return $z;
}
 
266,16 → 282,15
$a = array();
return $a;
}
 
if (!isset($this->_registry)) {
$this->_registry = &$this->config->getRegistry();
}
if (!isset($this->_remote)) {
$this->_remote = &$this->config->getRemote();
}
 
$channelschecked = array();
// convert all parameters into PEAR_Downloader_Package objects
foreach ($params as $i => $param) {
$params[$i] = &$this->newDownloaderPackage($this);
$params[$i] = $this->newDownloaderPackage($this);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$err = $params[$i]->initialize($param);
PEAR::staticPopErrorHandling();
283,51 → 298,75
// skip parameters that were missed by preferred_state
continue;
}
 
if (PEAR::isError($err)) {
if (!isset($this->_options['soft'])) {
if (!isset($this->_options['soft']) && $err->getMessage() !== '') {
$this->log(0, $err->getMessage());
}
 
$params[$i] = false;
if (is_object($param)) {
$param = $param->getChannel() . '/' . $param->getPackage();
}
$this->pushError('Package "' . $param . '" is not valid',
PEAR_INSTALLER_SKIPPED);
 
if (!isset($this->_options['soft'])) {
$this->log(2, 'Package "' . $param . '" is not valid');
}
 
// Message logged above in a specific verbose mode, passing null to not show up on CLI
$this->pushError(null, PEAR_INSTALLER_SKIPPED);
} else {
do {
if ($params[$i] && $params[$i]->getType() == 'local') {
// bug #7090
// skip channel.xml check for local packages
// bug #7090 skip channel.xml check for local packages
break;
}
 
if ($params[$i] && !isset($channelschecked[$params[$i]->getChannel()]) &&
!isset($this->_options['offline'])) {
!isset($this->_options['offline'])
) {
$channelschecked[$params[$i]->getChannel()] = true;
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
if (!class_exists('System')) {
require_once 'System.php';
}
$curchannel = &$this->_registry->getChannel($params[$i]->getChannel());
 
$curchannel = $this->_registry->getChannel($params[$i]->getChannel());
if (PEAR::isError($curchannel)) {
PEAR::staticPopErrorHandling();
return $this->raiseError($curchannel);
}
 
if (PEAR::isError($dir = $this->getDownloadDir())) {
PEAR::staticPopErrorHandling();
break;
}
$a = $this->downloadHttp('http://' . $params[$i]->getChannel() .
'/channel.xml', $this->ui, $dir, null, $curchannel->lastModified());
 
$mirror = $this->config->get('preferred_mirror', null, $params[$i]->getChannel());
$url = 'http://' . $mirror . '/channel.xml';
$a = $this->downloadHttp($url, $this->ui, $dir, null, $curchannel->lastModified());
 
PEAR::staticPopErrorHandling();
if (PEAR::isError($a) || !$a) {
if ($a === false) {
//channel.xml not modified
break;
} else if (PEAR::isError($a)) {
// Attempt fallback to https automatically
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$a = $this->downloadHttp('https://' . $mirror .
'/channel.xml', $this->ui, $dir, null, $curchannel->lastModified());
 
PEAR::staticPopErrorHandling();
if (PEAR::isError($a) || !$a) {
break;
}
}
$this->log(0, 'WARNING: channel "' . $params[$i]->getChannel() . '" has ' .
'updated its protocols, use "channel-update ' . $params[$i]->getChannel() .
'updated its protocols, use "' . PEAR_RUNTYPE . ' channel-update ' . $params[$i]->getChannel() .
'" to update');
}
} while (false);
 
if ($params[$i] && !isset($this->_options['downloadonly'])) {
if (isset($this->_options['packagingroot'])) {
$checkdir = $this->_prependPath(
337,12 → 376,15
$checkdir = $this->config->get('php_dir',
null, $params[$i]->getChannel());
}
 
while ($checkdir && $checkdir != '/' && !file_exists($checkdir)) {
$checkdir = dirname($checkdir);
}
 
if ($checkdir == '.') {
$checkdir = '/';
}
 
if (!is_writeable($checkdir)) {
return PEAR::raiseError('Cannot install, php_dir for channel "' .
$params[$i]->getChannel() . '" is not writeable by the current user');
350,6 → 392,7
}
}
}
 
unset($channelschecked);
PEAR_Downloader_Package::removeDuplicates($params);
if (!count($params)) {
356,11 → 399,15
$a = array();
return $a;
}
 
if (!isset($this->_options['nodeps']) && !isset($this->_options['offline'])) {
$reverify = true;
while ($reverify) {
$reverify = false;
foreach ($params as $i => $param) {
//PHP Bug 40768 / PEAR Bug #10944
//Nested foreaches fail in PHP 5.2.1
key($params);
$ret = $params[$i]->detectDependencies($params);
if (PEAR::isError($ret)) {
$reverify = true;
374,15 → 421,30
}
}
}
 
if (isset($this->_options['offline'])) {
$this->log(3, 'Skipping dependency download check, --offline specified');
}
 
if (!count($params)) {
$a = array();
return $a;
}
 
while (PEAR_Downloader_Package::mergeDependencies($params));
PEAR_Downloader_Package::removeDuplicates($params, true);
$errorparams = array();
if (PEAR_Downloader_Package::detectStupidDuplicates($params, $errorparams)) {
if (count($errorparams)) {
foreach ($errorparams as $param) {
$name = $this->_registry->parsedPackageNameToString($param->getParsedPackage());
$this->pushError('Duplicate package ' . $name . ' found', PEAR_INSTALLER_FAILED);
}
$a = array();
return $a;
}
}
 
PEAR_Downloader_Package::removeInstalled($params);
if (!count($params)) {
$this->pushError('No valid packages found', PEAR_INSTALLER_FAILED);
389,6 → 451,7
$a = array();
return $a;
}
 
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$err = $this->analyzeDependencies($params);
PEAR::popErrorHandling();
397,11 → 460,14
$a = array();
return $a;
}
 
$ret = array();
$newparams = array();
if (isset($this->_options['pretend'])) {
return $params;
}
 
$somefailed = false;
foreach ($params as $i => $package) {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$pf = &$params[$i]->download();
414,13 → 480,30
true) .
'"');
}
$somefailed = true;
continue;
}
 
$newparams[] = &$params[$i];
$ret[] = array('file' => $pf->getArchiveFile(),
'info' => &$pf,
'pkg' => $pf->getPackage());
$ret[] = array(
'file' => $pf->getArchiveFile(),
'info' => &$pf,
'pkg' => $pf->getPackage()
);
}
 
if ($somefailed) {
// remove params that did not download successfully
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$err = $this->analyzeDependencies($newparams, true);
PEAR::popErrorHandling();
if (!count($newparams)) {
$this->pushError('Download failed', PEAR_INSTALLER_FAILED);
$a = array();
return $a;
}
}
 
$this->_downloadedPackages = $ret;
return $newparams;
}
428,15 → 511,15
/**
* @param array all packages to be installed
*/
function analyzeDependencies(&$params)
function analyzeDependencies(&$params, $force = false)
{
$hasfailed = $failed = false;
if (isset($this->_options['downloadonly'])) {
return;
}
 
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$redo = true;
$reset = false;
$redo = true;
$reset = $hasfailed = $failed = false;
while ($redo) {
$redo = false;
foreach ($params as $i => $param) {
444,52 → 527,52
if (!$deps) {
$depchecker = &$this->getDependency2Object($this->config, $this->getOptions(),
$param->getParsedPackage(), PEAR_VALIDATE_DOWNLOADING);
if ($param->getType() == 'xmlrpc') {
$send = $param->getDownloadURL();
} else {
$send = $param->getPackageFile();
}
$send = $param->getPackageFile();
 
$installcheck = $depchecker->validatePackage($send, $this, $params);
if (PEAR::isError($installcheck)) {
if (!isset($this->_options['soft'])) {
$this->log(0, $installcheck->getMessage());
}
$hasfailed = true;
$hasfailed = true;
$params[$i] = false;
$reset = true;
$redo = true;
$failed = false;
$reset = true;
$redo = true;
$failed = false;
PEAR_Downloader_Package::removeDuplicates($params);
continue 2;
}
continue;
}
if (!$reset && $param->alreadyValidated()) {
 
if (!$reset && $param->alreadyValidated() && !$force) {
continue;
}
 
if (count($deps)) {
$depchecker = &$this->getDependency2Object($this->config, $this->getOptions(),
$param->getParsedPackage(), PEAR_VALIDATE_DOWNLOADING);
if ($param->getType() == 'xmlrpc') {
$send = $param->getPackageFile();
if ($send === null) {
$send = $param->getDownloadURL();
} else {
$send = $param->getPackageFile();
}
 
$installcheck = $depchecker->validatePackage($send, $this, $params);
if (PEAR::isError($installcheck)) {
if (!isset($this->_options['soft'])) {
$this->log(0, $installcheck->getMessage());
}
$hasfailed = true;
$hasfailed = true;
$params[$i] = false;
$reset = true;
$redo = true;
$failed = false;
$reset = true;
$redo = true;
$failed = false;
PEAR_Downloader_Package::removeDuplicates($params);
continue 2;
}
 
$failed = false;
if (isset($deps['required'])) {
if (isset($deps['required']) && is_array($deps['required'])) {
foreach ($deps['required'] as $type => $dep) {
// note: Dependency2 will never return a PEAR_Error if ignore-errors
// is specified, so soft is needed to turn off logging
522,7 → 605,8
}
}
}
if (isset($deps['optional'])) {
 
if (isset($deps['optional']) && is_array($deps['optional'])) {
foreach ($deps['optional'] as $type => $dep) {
if (!isset($dep[0])) {
if (PEAR::isError($e =
555,11 → 639,13
}
}
}
 
$groupname = $param->getGroup();
if (isset($deps['group']) && $groupname) {
if (!isset($deps['group'][0])) {
$deps['group'] = array($deps['group']);
}
 
$found = false;
foreach ($deps['group'] as $group) {
if ($group['attribs']['name'] == $groupname) {
567,6 → 653,7
break;
}
}
 
if ($found) {
unset($group['attribs']);
foreach ($group as $type => $dep) {
618,17 → 705,19
}
$params[$i]->setValidated();
}
 
if ($failed) {
$hasfailed = true;
$hasfailed = true;
$params[$i] = false;
$reset = true;
$redo = true;
$failed = false;
$reset = true;
$redo = true;
$failed = false;
PEAR_Downloader_Package::removeDuplicates($params);
continue 2;
}
}
}
 
PEAR::staticPopErrorHandling();
if ($hasfailed && (isset($this->_options['ignore-errors']) ||
isset($this->_options['nodeps']))) {
649,33 → 738,49
if (isset($this->_downloadDir)) {
return $this->_downloadDir;
}
 
$downloaddir = $this->config->get('download_dir');
if (empty($downloaddir)) {
if (empty($downloaddir) || (is_dir($downloaddir) && !is_writable($downloaddir))) {
if (is_dir($downloaddir) && !is_writable($downloaddir)) {
$this->log(0, 'WARNING: configuration download directory "' . $downloaddir .
'" is not writeable. Change download_dir config variable to ' .
'a writeable dir to avoid this warning');
}
 
if (!class_exists('System')) {
require_once 'System.php';
}
 
if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
return $downloaddir;
}
$this->log(3, '+ tmp dir created at ' . $downloaddir);
}
 
if (!is_writable($downloaddir)) {
if (PEAR::isError(System::mkdir(array('-p', $downloaddir)))) {
if (PEAR::isError(System::mkdir(array('-p', $downloaddir))) ||
!is_writable($downloaddir)) {
return PEAR::raiseError('download directory "' . $downloaddir .
'" is not writeable. Change download_dir config variable to ' .
'a writeable dir');
}
}
 
return $this->_downloadDir = $downloaddir;
}
 
function setDownloadDir($dir)
{
if (!@is_writable($dir)) {
if (PEAR::isError(System::mkdir(array('-p', $dir)))) {
return PEAR::raiseError('download directory "' . $dir .
'" is not writeable. Change download_dir config variable to ' .
'a writeable dir');
}
}
$this->_downloadDir = $dir;
}
 
// }}}
// {{{ configSet()
function configSet($key, $value, $layer = 'user', $channel = false)
{
$this->config->set($key, $value, $layer, $channel);
686,40 → 791,18
}
}
 
// }}}
// {{{ setOptions()
function setOptions($options)
{
$this->_options = $options;
}
 
// }}}
// {{{ setOptions()
function getOptions()
{
return $this->_options;
}
 
// }}}
 
/**
* For simpler unit-testing
* @param PEAR_Config
* @param int
* @param string
*/
function &getPackagefileObject(&$c, $d, $t = false)
{
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$a = &new PEAR_PackageFile($c, $d, $t);
return $a;
}
 
// {{{ _getPackageDownloadUrl()
 
/**
* @param array output of {@link parsePackageName()}
* @access private
*/
733,149 → 816,127
$state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');
if (!$this->_registry->channelExists($parr['channel'])) {
do {
if ($this->config->get('auto_discover')) {
if ($this->discover($parr['channel'])) {
break;
}
if ($this->config->get('auto_discover') && $this->discover($parr['channel'])) {
break;
}
 
$this->configSet('default_channel', $curchannel);
return PEAR::raiseError('Unknown remote channel: ' . $remotechannel);
return PEAR::raiseError('Unknown remote channel: ' . $parr['channel']);
} while (false);
}
$chan = &$this->_registry->getChannel($parr['channel']);
 
$chan = $this->_registry->getChannel($parr['channel']);
if (PEAR::isError($chan)) {
return $chan;
}
$version = $this->_registry->packageInfo($parr['package'], 'version',
$parr['channel']);
if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
 
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$version = $this->_registry->packageInfo($parr['package'], 'version', $parr['channel']);
$stability = $this->_registry->packageInfo($parr['package'], 'stability', $parr['channel']);
// package is installed - use the installed release stability level
if (!isset($parr['state']) && $stability !== null) {
$state = $stability['release'];
}
PEAR::staticPopErrorHandling();
$base2 = false;
 
$preferred_mirror = $this->config->get('preferred_mirror');
if (!$chan->supportsREST($preferred_mirror) ||
(
!($base2 = $chan->getBaseURL('REST1.3', $preferred_mirror))
&&
!($base = $chan->getBaseURL('REST1.0', $preferred_mirror))
)
) {
return $this->raiseError($parr['channel'] . ' is using a unsupported protocol - This should never happen.');
}
 
if ($base2) {
$rest = &$this->config->getREST('1.3', $this->_options);
$base = $base2;
} else {
$rest = &$this->config->getREST('1.0', $this->_options);
if (!isset($parr['version']) && !isset($parr['state']) && $version
&& !isset($this->_options['downloadonly'])) {
$url = $rest->getDownloadURL($base, $parr, $state, $version);
} else {
$url = $rest->getDownloadURL($base, $parr, $state, false);
}
if (PEAR::isError($url)) {
$this->configSet('default_channel', $curchannel);
return $url;
}
if ($parr['channel'] != $curchannel) {
$this->configSet('default_channel', $curchannel);
}
if (!is_array($url)) {
return $url;
}
$url['raw'] = false; // no checking is necessary for REST
if (!is_array($url['info'])) {
return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' .
'this should never happen');
}
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$testversion = $this->_registry->packageInfo($url['package'], 'version',
$parr['channel']);
PEAR::staticPopErrorHandling();
if (!isset($this->_options['force']) &&
!isset($this->_options['downloadonly']) &&
!PEAR::isError($testversion) &&
!isset($parr['group'])) {
if (version_compare($testversion, $url['version'], '>=')) {
return PEAR::raiseError($this->_registry->parsedPackageNameToString(
$parr, true) . ' is already installed and is newer than detected ' .
'release version ' . $url['version'], -976);
}
}
if (isset($url['info']['required']) || $url['compatible']) {
require_once 'PEAR/PackageFile/v2.php';
$pf = new PEAR_PackageFile_v2;
$pf->setRawChannel($parr['channel']);
if ($url['compatible']) {
$pf->setRawCompatible($url['compatible']);
}
} else {
require_once 'PEAR/PackageFile/v1.php';
$pf = new PEAR_PackageFile_v1;
}
$pf->setRawPackage($url['package']);
$pf->setDeps($url['info']);
if ($url['compatible']) {
$pf->setCompatible($url['compatible']);
}
$pf->setRawState($url['stability']);
$url['info'] = &$pf;
if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
$ext = '.tar';
} else {
$ext = '.tgz';
}
if (is_array($url)) {
if (isset($url['url'])) {
$url['url'] .= $ext;
}
}
return $url;
} elseif ($chan->supports('xmlrpc', 'package.getDownloadURL', false, '1.1')) {
// don't install with the old version information unless we're doing a plain
// vanilla simple installation. If the user says to install a particular
// version or state, ignore the current installed version
if (!isset($parr['version']) && !isset($parr['state']) && $version
&& !isset($this->_options['downloadonly'])) {
$url = $this->_remote->call('package.getDownloadURL', $parr, $state, $version);
} else {
$url = $this->_remote->call('package.getDownloadURL', $parr, $state);
}
} else {
$url = $this->_remote->call('package.getDownloadURL', $parr, $state);
}
 
$downloadVersion = false;
if (!isset($parr['version']) && !isset($parr['state']) && $version
&& !PEAR::isError($version)
&& !isset($this->_options['downloadonly'])
) {
$downloadVersion = $version;
}
 
$url = $rest->getDownloadURL($base, $parr, $state, $downloadVersion, $chan->getName());
if (PEAR::isError($url)) {
$this->configSet('default_channel', $curchannel);
return $url;
}
 
if ($parr['channel'] != $curchannel) {
$this->configSet('default_channel', $curchannel);
}
if (isset($url['__PEAR_ERROR_CLASS__'])) {
return PEAR::raiseError($url['message']);
}
 
if (!is_array($url)) {
return $url;
}
$url['raw'] = $url['info'];
if (isset($this->_options['downloadonly'])) {
$pkg = &$this->getPackagefileObject($this->config, $this->debug);
} else {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
if (PEAR::isError($dir = $this->getDownloadDir())) {
PEAR::staticPopErrorHandling();
return $dir;
 
$url['raw'] = false; // no checking is necessary for REST
if (!is_array($url['info'])) {
return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' .
'this should never happen');
}
 
if (!isset($this->_options['force']) &&
!isset($this->_options['downloadonly']) &&
$version &&
!PEAR::isError($version) &&
!isset($parr['group'])
) {
if (version_compare($version, $url['version'], '=')) {
return PEAR::raiseError($this->_registry->parsedPackageNameToString(
$parr, true) . ' is already installed and is the same as the ' .
'released version ' . $url['version'], -976);
}
PEAR::staticPopErrorHandling();
$pkg = &$this->getPackagefileObject($this->config, $this->debug, $dir);
 
if (version_compare($version, $url['version'], '>')) {
return PEAR::raiseError($this->_registry->parsedPackageNameToString(
$parr, true) . ' is already installed and is newer than detected ' .
'released version ' . $url['version'], -976);
}
}
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$pinfo = &$pkg->fromXmlString($url['info'], PEAR_VALIDATE_DOWNLOADING, 'remote');
PEAR::staticPopErrorHandling();
if (PEAR::isError($pinfo)) {
if (!isset($this->_options['soft'])) {
$this->log(0, $pinfo->getMessage());
 
if (isset($url['info']['required']) || $url['compatible']) {
require_once 'PEAR/PackageFile/v2.php';
$pf = new PEAR_PackageFile_v2;
$pf->setRawChannel($parr['channel']);
if ($url['compatible']) {
$pf->setRawCompatible($url['compatible']);
}
return PEAR::raiseError('Remote package.xml is not valid - this should never happen');
} else {
require_once 'PEAR/PackageFile/v1.php';
$pf = new PEAR_PackageFile_v1;
}
$url['info'] = &$pinfo;
 
$pf->setRawPackage($url['package']);
$pf->setDeps($url['info']);
if ($url['compatible']) {
$pf->setCompatible($url['compatible']);
}
 
$pf->setRawState($url['stability']);
$url['info'] = &$pf;
if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
$ext = '.tar';
} else {
$ext = '.tgz';
}
if (is_array($url)) {
if (isset($url['url'])) {
$url['url'] .= $ext;
}
 
if (is_array($url) && isset($url['url'])) {
$url['url'] .= $ext;
}
 
return $url;
}
// }}}
// {{{ getDepPackageDownloadUrl()
 
/**
* @param array dependency array
887,10 → 948,11
$curchannel = $this->config->get('default_channel');
if (isset($dep['uri'])) {
$xsdversion = '2.0';
$chan = &$this->_registry->getChannel('__uri');
$chan = $this->_registry->getChannel('__uri');
if (PEAR::isError($chan)) {
return $chan;
}
 
$version = $this->_registry->packageInfo($dep['name'], 'version', '__uri');
$this->configSet('default_channel', '__uri');
} else {
899,6 → 961,7
} else {
$remotechannel = 'pear.php.net';
}
 
if (!$this->_registry->channelExists($remotechannel)) {
do {
if ($this->config->get('auto_discover')) {
909,20 → 972,23
return PEAR::raiseError('Unknown remote channel: ' . $remotechannel);
} while (false);
}
$chan = &$this->_registry->getChannel($remotechannel);
 
$chan = $this->_registry->getChannel($remotechannel);
if (PEAR::isError($chan)) {
return $chan;
}
$version = $this->_registry->packageInfo($dep['name'], 'version',
$remotechannel);
 
$version = $this->_registry->packageInfo($dep['name'], 'version', $remotechannel);
$this->configSet('default_channel', $remotechannel);
}
 
$state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');
if (isset($parr['state']) && isset($parr['version'])) {
unset($parr['state']);
}
 
if (isset($dep['uri'])) {
$info = &$this->newDownloaderPackage($this);
$info = $this->newDownloaderPackage($this);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$err = $info->initialize($dep);
PEAR::staticPopErrorHandling();
930,10 → 996,12
// skip parameters that were missed by preferred_state
return PEAR::raiseError('Cannot initialize dependency');
}
 
if (PEAR::isError($err)) {
if (!isset($this->_options['soft'])) {
$this->log(0, $err->getMessage());
}
 
if (is_object($info)) {
$param = $info->getChannel() . '/' . $info->getPackage();
}
940,25 → 1008,41
return PEAR::raiseError('Package "' . $param . '" is not valid');
}
return $info;
} elseif ($chan->supportsREST($this->config->get('preferred_mirror')) &&
$base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
$rest = &$this->config->getREST('1.0', $this->_options);
} elseif ($chan->supportsREST($this->config->get('preferred_mirror'))
&&
(
($base2 = $chan->getBaseURL('REST1.3', $this->config->get('preferred_mirror')))
||
($base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror')))
)
) {
if ($base2) {
$base = $base2;
$rest = &$this->config->getREST('1.3', $this->_options);
} else {
$rest = &$this->config->getREST('1.0', $this->_options);
}
 
$url = $rest->getDepDownloadURL($base, $xsdversion, $dep, $parr,
$state, $version);
$state, $version, $chan->getName());
if (PEAR::isError($url)) {
return $url;
}
 
if ($parr['channel'] != $curchannel) {
$this->configSet('default_channel', $curchannel);
}
 
if (!is_array($url)) {
return $url;
}
 
$url['raw'] = false; // no checking is necessary for REST
if (!is_array($url['info'])) {
return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' .
'this should never happen');
}
 
if (isset($url['info']['required'])) {
if (!class_exists('PEAR_PackageFile_v2')) {
require_once 'PEAR/PackageFile/v2.php';
970,6 → 1054,7
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
 
}
$pf->setRawPackage($url['package']);
$pf->setDeps($url['info']);
976,6 → 1061,7
if ($url['compatible']) {
$pf->setCompatible($url['compatible']);
}
 
$pf->setRawState($url['stability']);
$url['info'] = &$pf;
if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
983,58 → 1069,16
} else {
$ext = '.tgz';
}
if (is_array($url)) {
if (isset($url['url'])) {
$url['url'] .= $ext;
}
 
if (is_array($url) && isset($url['url'])) {
$url['url'] .= $ext;
}
 
return $url;
} elseif ($chan->supports('xmlrpc', 'package.getDepDownloadURL', false, '1.1')) {
if ($version) {
$url = $this->_remote->call('package.getDepDownloadURL', $xsdversion, $dep, $parr,
$state, $version);
} else {
$url = $this->_remote->call('package.getDepDownloadURL', $xsdversion, $dep, $parr,
$state);
}
} else {
$url = $this->_remote->call('package.getDepDownloadURL', $xsdversion, $dep, $parr, $state);
}
if ($this->config->get('default_channel') != $curchannel) {
$this->configSet('default_channel', $curchannel);
}
if (!is_array($url)) {
return $url;
}
if (isset($url['__PEAR_ERROR_CLASS__'])) {
return PEAR::raiseError($url['message']);
}
$url['raw'] = $url['info'];
$pkg = &$this->getPackagefileObject($this->config, $this->debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$pinfo = &$pkg->fromXmlString($url['info'], PEAR_VALIDATE_DOWNLOADING, 'remote');
PEAR::staticPopErrorHandling();
if (PEAR::isError($pinfo)) {
if (!isset($this->_options['soft'])) {
$this->log(0, $pinfo->getMessage());
}
return PEAR::raiseError('Remote package.xml is not valid - this should never happen');
}
$url['info'] = &$pinfo;
if (is_array($url)) {
if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
$ext = '.tar';
} else {
$ext = '.tgz';
}
if (isset($url['url'])) {
$url['url'] .= $ext;
}
}
return $url;
 
return $this->raiseError($parr['channel'] . ' is using a unsupported protocol - This should never happen.');
}
// }}}
// {{{ getPackageDownloadUrl()
 
/**
* @deprecated in favor of _getPackageDownloadUrl
1059,9 → 1103,6
return $package;
}
 
// }}}
// {{{ getDownloadedPackages()
 
/**
* Retrieve a list of downloaded packages after a call to {@link download()}.
*
1076,9 → 1117,6
return $ret;
}
 
// }}}
// {{{ _downloadCallback()
 
function _downloadCallback($msg, $params = null)
{
switch ($msg) {
1111,9 → 1149,6
$this->ui->_downloadCallback($msg, $params);
}
 
// }}}
// {{{ _prependPath($path, $prepend)
 
function _prependPath($path, $prepend)
{
if (strlen($prepend) > 0) {
1130,8 → 1165,6
}
return $path;
}
// }}}
// {{{ pushError($errmsg, $code)
 
/**
* @param string
1142,9 → 1175,6
array_push($this->_errorStack, array($errmsg, $code));
}
 
// }}}
// {{{ getErrorMsgs()
 
function getErrorMsgs()
{
$msgs = array();
1156,14 → 1186,14
return $msgs;
}
 
// }}}
 
/**
* for BC
*
* @deprecated
*/
function sortPkgDeps(&$packages, $uninstall = false)
{
$uninstall ?
$uninstall ?
$this->sortPackagesForUninstall($packages) :
$this->sortPackagesForInstall($packages);
}
1194,6 → 1224,7
$nodes[$pname]->setData($packages[$i]);
$depgraph->addNode($nodes[$pname]);
}
 
$deplinks = array();
foreach ($nodes as $package => $node) {
$pf = &$node->getData();
1201,6 → 1232,7
if (!$pdeps) {
continue;
}
 
if ($pf->getPackagexmlVersion() == '1.0') {
foreach ($pdeps as $dep) {
if ($dep['type'] != 'pkg' ||
1207,30 → 1239,34
(isset($dep['optional']) && $dep['optional'] == 'yes')) {
continue;
}
 
$dname = $reg->parsedPackageNameToString(
array(
'channel' => 'pear.php.net',
'package' => strtolower($dep['name']),
));
if (isset($nodes[$dname]))
{
 
if (isset($nodes[$dname])) {
if (!isset($deplinks[$dname])) {
$deplinks[$dname] = array();
}
 
$deplinks[$dname][$package] = 1;
// dependency is in installed packages
continue;
}
 
$dname = $reg->parsedPackageNameToString(
array(
'channel' => 'pecl.php.net',
'package' => strtolower($dep['name']),
));
if (isset($nodes[$dname]))
{
 
if (isset($nodes[$dname])) {
if (!isset($deplinks[$dname])) {
$deplinks[$dname] = array();
}
 
$deplinks[$dname][$package] = 1;
// dependency is in installed packages
continue;
1245,12 → 1281,15
if (!isset($t[0])) {
$t = array($t);
}
 
$this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
}
 
if (isset($pdeps['group'])) {
if (!isset($pdeps['group'][0])) {
$pdeps['group'] = array($pdeps['group']);
}
 
foreach ($pdeps['group'] as $group) {
if (isset($group['subpackage'])) {
$t = $group['subpackage'];
1257,28 → 1296,35
if (!isset($t[0])) {
$t = array($t);
}
 
$this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
}
}
}
 
if (isset($pdeps['optional']['subpackage'])) {
$t = $pdeps['optional']['subpackage'];
if (!isset($t[0])) {
$t = array($t);
}
 
$this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
}
 
if (isset($pdeps['required']['package'])) {
$t = $pdeps['required']['package'];
if (!isset($t[0])) {
$t = array($t);
}
 
$this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
}
 
if (isset($pdeps['group'])) {
if (!isset($pdeps['group'][0])) {
$pdeps['group'] = array($pdeps['group']);
}
 
foreach ($pdeps['group'] as $group) {
if (isset($group['package'])) {
$t = $group['package'];
1285,6 → 1331,7
if (!isset($t[0])) {
$t = array($t);
}
 
$this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
}
}
1291,6 → 1338,7
}
}
}
 
$this->_detectDepCycle($deplinks);
foreach ($deplinks as $dependent => $parents) {
foreach ($parents as $parent => $unused) {
1297,9 → 1345,10
$nodes[$dependent]->connectTo($nodes[$parent]);
}
}
 
$installOrder = Structures_Graph_Manipulator_TopologicalSorter::sort($depgraph);
$ret = array();
for ($i = 0; $i < count($installOrder); $i++) {
for ($i = 0, $count = count($installOrder); $i < $count; $i++) {
foreach ($installOrder[$i] as $index => $sortedpackage) {
$data = &$installOrder[$i][$index]->getData();
$ret[] = &$nodes[$reg->parsedPackageNameToString(
1309,6 → 1358,7
))]->getData();
}
}
 
$packages = $ret;
return;
}
1333,6 → 1383,7
if (count($deplinks[$dep]) == 0) {
unset($deplinks[$dep]);
}
 
continue 3;
}
}
1347,19 → 1398,23
$visited = array();
return;
}
 
// this happens when a parent has a dep cycle on another dependency
// but the child is not part of the cycle
if (isset($visited[$dep])) {
return false;
}
 
$visited[$dep] = 1;
if ($test == $dep) {
return true;
}
 
if (isset($deplinks[$dep])) {
if (in_array($test, array_keys($deplinks[$dep]), true)) {
return true;
}
 
foreach ($deplinks[$dep] as $parent => $unused) {
if ($this->_testCycle($test, $deplinks, $parent)) {
return true;
1366,6 → 1421,7
}
}
}
 
return false;
}
 
1382,15 → 1438,14
function _setupGraph($t, $reg, &$deplinks, &$nodes, $package)
{
foreach ($t as $dep) {
$depchannel = !isset($dep['channel']) ?
'__uri': $dep['channel'];
$depchannel = !isset($dep['channel']) ? '__uri': $dep['channel'];
$dname = $reg->parsedPackageNameToString(
array(
'channel' => $depchannel,
'package' => strtolower($dep['name']),
));
if (isset($nodes[$dname]))
{
 
if (isset($nodes[$dname])) {
if (!isset($deplinks[$dname])) {
$deplinks[$dname] = array();
}
1401,8 → 1456,7
 
function _dependsOn($a, $b)
{
return $this->_checkDepTree(strtolower($a->getChannel()), strtolower($a->getPackage()),
$b);
return $this->_checkDepTree(strtolower($a->getChannel()), strtolower($a->getPackage()), $b);
}
 
function _checkDepTree($channel, $package, $b, $checked = array())
1411,10 → 1465,12
if (!isset($this->_depTree[$channel][$package])) {
return false;
}
 
if (isset($this->_depTree[$channel][$package][strtolower($b->getChannel())]
[strtolower($b->getPackage())])) {
return true;
}
 
foreach ($this->_depTree[$channel][$package] as $ch => $packages) {
foreach ($packages as $pa => $true) {
if ($this->_checkDepTree($ch, $pa, $b, $checked)) {
1422,6 → 1478,7
}
}
}
 
return false;
}
 
1484,43 → 1541,51
* @param false|string|array $lastmodified header values to check against for caching
* use false to return the header values from this download
* @param false|array $accept Accept headers to send
* @return string|array Returns the full path of the downloaded file or a PEAR
* error on failure. If the error is caused by
* socket-related errors, the error object will
* have the fsockopen error code available through
* getCode(). If caching is requested, then return the header
* values.
* @param false|string $channel Channel to use for retrieving authentication
* @return mixed Returns the full path of the downloaded file or a PEAR
* error on failure. If the error is caused by
* socket-related errors, the error object will
* have the fsockopen error code available through
* getCode(). If caching is requested, then return the header
* values.
* If $lastmodified was given and the there are no changes,
* boolean false is returned.
*
* @access public
*/
function downloadHttp($url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null,
$accept = false)
{
public static function _downloadHttp(
$object, $url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null,
$accept = false, $channel = false
) {
static $redirect = 0;
// allways reset , so we are clean case of error
// always reset , so we are clean case of error
$wasredirect = $redirect;
$redirect = 0;
if ($callback) {
call_user_func($callback, 'setup', array(&$ui));
}
 
$info = parse_url($url);
if (!isset($info['scheme']) || !in_array($info['scheme'], array('http', 'https'))) {
return PEAR::raiseError('Cannot download non-http URL "' . $url . '"');
}
 
if (!isset($info['host'])) {
return PEAR::raiseError('Cannot download from non-URL "' . $url . '"');
} else {
$host = isset($info['host']) ? $info['host'] : null;
$port = isset($info['port']) ? $info['port'] : null;
$path = isset($info['path']) ? $info['path'] : null;
}
if (isset($this)) {
$config = &$this->config;
 
$host = isset($info['host']) ? $info['host'] : null;
$port = isset($info['port']) ? $info['port'] : null;
$path = isset($info['path']) ? $info['path'] : null;
 
if ($object !== null) {
$config = $object->config;
} else {
$config = &PEAR_Config::singleton();
}
 
$proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
if ($config->get('http_proxy') &&
if ($config->get('http_proxy') &&
$proxy = parse_url($config->get('http_proxy'))) {
$proxy_host = isset($proxy['host']) ? $proxy['host'] : null;
if (isset($proxy['scheme']) && $proxy['scheme'] == 'https') {
1534,13 → 1599,13
call_user_func($callback, 'message', "Using HTTP proxy $host:$port");
}
}
 
if (empty($port)) {
if (isset($info['scheme']) && $info['scheme'] == 'https') {
$port = 443;
} else {
$port = 80;
}
$port = (isset($info['scheme']) && $info['scheme'] == 'https') ? 443 : 80;
}
 
$scheme = (isset($info['scheme']) && $info['scheme'] == 'https') ? 'https' : 'http';
 
if ($proxy_host != '') {
$fp = @fsockopen($proxy_host, $proxy_port, $errno, $errstr);
if (!$fp) {
1550,16 → 1615,21
}
return PEAR::raiseError("Connection to `$proxy_host:$proxy_port' failed: $errstr", $errno);
}
 
if ($lastmodified === false || $lastmodified) {
$request = "GET $url HTTP/1.1\r\n";
$request = "GET $url HTTP/1.1\r\n";
$request .= "Host: $host\r\n";
} else {
$request = "GET $url HTTP/1.0\r\n";
$request = "GET $url HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
}
} else {
$network_host = $host;
if (isset($info['scheme']) && $info['scheme'] == 'https') {
$host = 'ssl://' . $host;
$network_host = 'ssl://' . $host;
}
$fp = @fsockopen($host, $port, $errno, $errstr);
 
$fp = @fsockopen($network_host, $port, $errno, $errstr);
if (!$fp) {
if ($callback) {
call_user_func($callback, 'connfailed', array($host, $port,
1567,19 → 1637,22
}
return PEAR::raiseError("Connection to `$host:$port' failed: $errstr", $errno);
}
 
if ($lastmodified === false || $lastmodified) {
$request = "GET $path HTTP/1.1\r\n";
$request .= "Host: $host:$port\r\n";
$request .= "Host: $host\r\n";
} else {
$request = "GET $path HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
}
}
 
$ifmodifiedsince = '';
if (is_array($lastmodified)) {
if (isset($lastmodified['Last-Modified'])) {
$ifmodifiedsince = 'If-Modified-Since: ' . $lastmodified['Last-Modified'] . "\r\n";
}
 
if (isset($lastmodified['ETag'])) {
$ifmodifiedsince .= "If-None-Match: $lastmodified[ETag]\r\n";
}
1586,23 → 1659,28
} else {
$ifmodifiedsince = ($lastmodified ? "If-Modified-Since: $lastmodified\r\n" : '');
}
$request .= $ifmodifiedsince . "User-Agent: PEAR/1.5.1/PHP/" .
PHP_VERSION . "\r\n";
if (isset($this)) { // only pass in authentication for non-static calls
$username = $config->get('username');
$password = $config->get('password');
 
$request .= $ifmodifiedsince .
"User-Agent: PEAR/1.10.1/PHP/" . PHP_VERSION . "\r\n";
 
if ($object !== null) { // only pass in authentication for non-static calls
$username = $config->get('username', null, $channel);
$password = $config->get('password', null, $channel);
if ($username && $password) {
$tmp = base64_encode("$username:$password");
$request .= "Authorization: Basic $tmp\r\n";
}
}
 
if ($proxy_host != '' && $proxy_user != '') {
$request .= 'Proxy-Authorization: Basic ' .
base64_encode($proxy_user . ':' . $proxy_pass) . "\r\n";
}
 
if ($accept) {
$request .= 'Accept: ' . implode(', ', $accept) . "\r\n";
}
 
$request .= "Connection: close\r\n";
$request .= "\r\n";
fwrite($fp, $request);
1609,37 → 1687,41
$headers = array();
$reply = 0;
while (trim($line = fgets($fp, 1024))) {
if (preg_match('/^([^:]+):\s+(.*)\s*$/', $line, $matches)) {
if (preg_match('/^([^:]+):\s+(.*)\s*\\z/', $line, $matches)) {
$headers[strtolower($matches[1])] = trim($matches[2]);
} elseif (preg_match('|^HTTP/1.[01] ([0-9]{3}) |', $line, $matches)) {
$reply = (int) $matches[1];
$reply = (int)$matches[1];
if ($reply == 304 && ($lastmodified || ($lastmodified === false))) {
return false;
}
if (! in_array($reply, array(200, 301, 302, 303, 305, 307))) {
return PEAR::raiseError("File http://$host:$port$path not valid (received: $line)");
 
if (!in_array($reply, array(200, 301, 302, 303, 305, 307))) {
return PEAR::raiseError("File $scheme://$host:$port$path not valid (received: $line)");
}
}
}
 
if ($reply != 200) {
if (isset($headers['location'])) {
if ($wasredirect < 5) {
$redirect = $wasredirect + 1;
return $this->downloadHttp($headers['location'],
$ui, $save_dir, $callback, $lastmodified, $accept);
} else {
return PEAR::raiseError("File http://$host:$port$path not valid (redirection looped more than 5 times)");
}
} else {
return PEAR::raiseError("File http://$host:$port$path not valid (redirected but no location)");
if (!isset($headers['location'])) {
return PEAR::raiseError("File $scheme://$host:$port$path not valid (redirected but no location)");
}
 
if ($wasredirect > 4) {
return PEAR::raiseError("File $scheme://$host:$port$path not valid (redirection looped more than 5 times)");
}
 
$redirect = $wasredirect + 1;
return static::_downloadHttp($object, $headers['location'],
$ui, $save_dir, $callback, $lastmodified, $accept);
}
 
if (isset($headers['content-disposition']) &&
preg_match('/\sfilename=\"([^;]*\S)\"\s*(;|$)/', $headers['content-disposition'], $matches)) {
preg_match('/\sfilename=\"([^;]*\S)\"\s*(;|\\z)/', $headers['content-disposition'], $matches)) {
$save_as = basename($matches[1]);
} else {
$save_as = basename($url);
}
 
if ($callback) {
$tmp = call_user_func($callback, 'saveas', $save_as);
if ($tmp) {
1646,7 → 1728,12
$save_as = $tmp;
}
}
 
$dest_file = $save_dir . DIRECTORY_SEPARATOR . $save_as;
if (is_link($dest_file)) {
return PEAR::raiseError('SECURITY ERROR: Will not write to ' . $dest_file . ' as it is symlinked to ' . readlink($dest_file) . ' - Possible symlink attack');
}
 
if (!$wp = @fopen($dest_file, 'wb')) {
fclose($fp);
if ($callback) {
1654,15 → 1741,14
}
return PEAR::raiseError("could not open $dest_file for writing");
}
if (isset($headers['content-length'])) {
$length = $headers['content-length'];
} else {
$length = -1;
}
 
$length = isset($headers['content-length']) ? $headers['content-length'] : -1;
 
$bytes = 0;
if ($callback) {
call_user_func($callback, 'start', array(basename($dest_file), $length));
}
 
while ($data = fread($fp, 1024)) {
$bytes += strlen($data);
if ($callback) {
1676,15 → 1762,18
return PEAR::raiseError("$dest_file: write failed ($php_errormsg)");
}
}
 
fclose($fp);
fclose($wp);
if ($callback) {
call_user_func($callback, 'done', $bytes);
}
 
if ($lastmodified === false || $lastmodified) {
if (isset($headers['etag'])) {
$lastmodified = array('ETag' => $headers['etag']);
}
 
if (isset($headers['last-modified'])) {
if (is_array($lastmodified)) {
$lastmodified['Last-Modified'] = $headers['last-modified'];
1697,6 → 1786,3
return $dest_file;
}
}
// }}}
 
?>
/trunk/bibliotheque/pear/PEAR/Autoloader.php
3,19 → 3,13
* Class auto-loader
*
* PHP versions 4
 
*
* 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 Stig Bakken <ssb@php.net>
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: Autoloader.php,v 1.13 2006/01/06 04:47:36 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/manual/en/core.ppm.php#core.ppm.pear-autoloader
* @since File available since Release 0.1
* @deprecated File deprecated in Release 1.4.0a1
48,9 → 42,9
* @category pear
* @package PEAR
* @author Stig Bakken <ssb@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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/manual/en/core.ppm.php#core.ppm.pear-autoloader
* @since File available since Release 0.1
* @deprecated File deprecated in Release 1.4.0a1
149,7 → 143,7
$include_file = preg_replace('/[^a-z0-9]/i', '_', $classname);
include_once $include_file;
}
$obj =& new $classname;
$obj = new $classname;
$methods = get_class_methods($classname);
foreach ($methods as $method) {
// don't import priviate methods and constructors
/trunk/bibliotheque/pear/PEAR/Validator/PECL.php
8,8 → 8,7
* @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: PECL.php,v 1.8 2006/05/12 02:38:58 cellog Exp $
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a5
*/
22,9 → 21,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a5
*/
/trunk/bibliotheque/pear/PEAR/Dependency2.php
4,18 → 4,11
*
* 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: Dependency2.php,v 1.54 2007/02/13 04:16:25 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
35,9 → 28,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
49,32 → 42,39
* @var integer
*/
var $_state;
 
/**
* Command-line options to install/upgrade/uninstall commands
* @param array
*/
var $_options;
 
/**
* @var OS_Guess
*/
var $_os;
 
/**
* @var PEAR_Registry
*/
var $_registry;
 
/**
* @var PEAR_Config
*/
var $_config;
 
/**
* @var PEAR_DependencyDB
*/
var $_dependencydb;
 
/**
* Output of PEAR_Registry::parsedPackageName()
* @var array
*/
var $_currentPackage;
 
/**
* @param PEAR_Config
* @param array installation options
81,7 → 81,7
* @param array format of PEAR_Registry::parsedPackageName()
* @param int installation state (one of PEAR_VALIDATE_*)
*/
function PEAR_Dependency2(&$config, $installoptions, $package,
function __construct(&$config, $installoptions, $package,
$state = PEAR_VALIDATE_INSTALLING)
{
$this->_config = &$config;
88,20 → 88,24
if (!class_exists('PEAR_DependencyDB')) {
require_once 'PEAR/DependencyDB.php';
}
 
if (isset($installoptions['packagingroot'])) {
// make sure depdb is in the right location
$config->setInstallRoot($installoptions['packagingroot']);
}
 
$this->_registry = &$config->getRegistry();
$this->_dependencydb = &PEAR_DependencyDB::singleton($config);
if (isset($installoptions['packagingroot'])) {
$config->setInstallRoot(false);
}
 
$this->_options = $installoptions;
$this->_state = $state;
if (!class_exists('OS_Guess')) {
require_once 'OS/Guess.php';
}
 
$this->_os = new OS_Guess;
$this->_currentPackage = $package;
}
112,6 → 116,7
if (isset($dep['uri'])) {
return '';
}
 
if (isset($dep['recommended'])) {
$extra .= 'recommended version ' . $dep['recommended'];
} else {
118,6 → 123,7
if (isset($dep['min'])) {
$extra .= 'version >= ' . $dep['min'];
}
 
if (isset($dep['max'])) {
if ($extra != ' (') {
$extra .= ', ';
124,13 → 130,16
}
$extra .= 'version <= ' . $dep['max'];
}
 
if (isset($dep['exclude'])) {
if (!is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
}
 
if ($extra != ' (') {
$extra .= ', ';
}
 
$extra .= 'excluded versions: ';
foreach ($dep['exclude'] as $i => $exclude) {
if ($i) {
140,10 → 149,12
}
}
}
 
$extra .= ')';
if ($extra == ' ()') {
$extra = '';
}
 
return $extra;
}
 
171,37 → 182,32
*/
function validateOsDependency($dep)
{
if ($this->_state != PEAR_VALIDATE_INSTALLING &&
$this->_state != PEAR_VALIDATE_DOWNLOADING) {
if ($this->_state != PEAR_VALIDATE_INSTALLING && $this->_state != PEAR_VALIDATE_DOWNLOADING) {
return true;
}
if (isset($dep['conflicts'])) {
$not = true;
} else {
$not = false;
}
 
if ($dep['name'] == '*') {
return true;
}
 
$not = isset($dep['conflicts']) ? true : false;
switch (strtolower($dep['name'])) {
case 'windows' :
if ($not) {
if (strtolower(substr($this->getPHP_OS(), 0, 3)) == 'win') {
if (!isset($this->_options['nodeps']) &&
!isset($this->_options['force'])) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError("Cannot install %s on Windows");
} else {
return $this->warning("warning: Cannot install %s on Windows");
}
 
return $this->warning("warning: Cannot install %s on Windows");
}
} else {
if (strtolower(substr($this->getPHP_OS(), 0, 3)) != 'win') {
if (!isset($this->_options['nodeps']) &&
!isset($this->_options['force'])) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError("Can only install %s on Windows");
} else {
return $this->warning("warning: Can only install %s on Windows");
}
 
return $this->warning("warning: Can only install %s on Windows");
}
}
break;
209,23 → 215,19
$unices = array('linux', 'freebsd', 'darwin', 'sunos', 'irix', 'hpux', 'aix');
if ($not) {
if (in_array($this->getSysname(), $unices)) {
if (!isset($this->_options['nodeps']) &&
!isset($this->_options['force'])) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError("Cannot install %s on any Unix system");
} else {
return $this->warning(
"warning: Cannot install %s on any Unix system");
}
 
return $this->warning( "warning: Cannot install %s on any Unix system");
}
} else {
if (!in_array($this->getSysname(), $unices)) {
if (!isset($this->_options['nodeps']) &&
!isset($this->_options['force'])) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError("Can only install %s on a Unix system");
} else {
return $this->warning(
"warning: Can only install %s on a Unix system");
}
 
return $this->warning("warning: Can only install %s on a Unix system");
}
}
break;
236,23 → 238,22
!isset($this->_options['force'])) {
return $this->raiseError('Cannot install %s on ' . $dep['name'] .
' operating system');
} else {
return $this->warning('warning: Cannot install %s on ' .
$dep['name'] . ' operating system');
}
 
return $this->warning('warning: Cannot install %s on ' .
$dep['name'] . ' operating system');
}
} else {
if (strtolower($dep['name']) != strtolower($this->getSysname())) {
if (!isset($this->_options['nodeps']) &&
!isset($this->_options['force'])) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('Cannot install %s on ' .
$this->getSysname() .
' operating system, can only install on ' . $dep['name']);
} else {
return $this->warning('warning: Cannot install %s on ' .
$this->getSysname() .
' operating system, can only install on ' . $dep['name']);
}
 
return $this->warning('warning: Cannot install %s on ' .
$this->getSysname() .
' operating system, can only install on ' . $dep['name']);
}
}
}
279,34 → 280,33
if ($this->_state != PEAR_VALIDATE_INSTALLING) {
return true;
}
if (isset($dep['conflicts'])) {
$not = true;
} else {
$not = false;
}
 
$not = isset($dep['conflicts']) ? true : false;
if (!$this->matchSignature($dep['pattern'])) {
if (!$not) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s Architecture dependency failed, does not ' .
'match "' . $dep['pattern'] . '"');
} else {
return $this->warning('warning: %s Architecture dependency failed, does ' .
'not match "' . $dep['pattern'] . '"');
}
 
return $this->warning('warning: %s Architecture dependency failed, does ' .
'not match "' . $dep['pattern'] . '"');
}
 
return true;
} else {
if ($not) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s Architecture dependency failed, required "' .
$dep['pattern'] . '"');
} else {
return $this->warning('warning: %s Architecture dependency failed, ' .
'required "' . $dep['pattern'] . '"');
}
}
 
if ($not) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s Architecture dependency failed, required "' .
$dep['pattern'] . '"');
}
return true;
 
return $this->warning('warning: %s Architecture dependency failed, ' .
'required "' . $dep['pattern'] . '"');
}
 
return true;
}
 
/**
324,9 → 324,9
{
if ($name !== null) {
return phpversion($name);
} else {
return phpversion();
}
 
return phpversion();
}
 
function validateExtensionDependency($dep, $required = true)
335,92 → 335,101
$this->_state != PEAR_VALIDATE_DOWNLOADING) {
return true;
}
 
$loaded = $this->extension_loaded($dep['name']);
$extra = $this->_getExtraString($dep);
$extra = $this->_getExtraString($dep);
if (isset($dep['exclude'])) {
if (!is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
}
}
 
if (!isset($dep['min']) && !isset($dep['max']) &&
!isset($dep['recommended']) && !isset($dep['exclude'])) {
!isset($dep['recommended']) && !isset($dep['exclude'])
) {
if ($loaded) {
if (isset($dep['conflicts'])) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s conflicts with PHP extension "' .
$dep['name'] . '"' . $extra);
} else {
return $this->warning('warning: %s conflicts with PHP extension "' .
$dep['name'] . '"' . $extra);
}
 
return $this->warning('warning: %s conflicts with PHP extension "' .
$dep['name'] . '"' . $extra);
}
 
return true;
} else {
if (isset($dep['conflicts'])) {
return true;
}
if ($required) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires PHP extension "' .
$dep['name'] . '"' . $extra);
} else {
return $this->warning('warning: %s requires PHP extension "' .
$dep['name'] . '"' . $extra);
}
} else {
return $this->warning('%s can optionally use PHP extension "' .
}
 
if (isset($dep['conflicts'])) {
return true;
}
 
if ($required) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires PHP extension "' .
$dep['name'] . '"' . $extra);
}
 
return $this->warning('warning: %s requires PHP extension "' .
$dep['name'] . '"' . $extra);
}
 
return $this->warning('%s can optionally use PHP extension "' .
$dep['name'] . '"' . $extra);
}
 
if (!$loaded) {
if (isset($dep['conflicts'])) {
return true;
}
 
if (!$required) {
return $this->warning('%s can optionally use PHP extension "' .
$dep['name'] . '"' . $extra);
} else {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires PHP extension "' . $dep['name'] .
'"' . $extra);
}
return $this->warning('warning: %s requires PHP extension "' . $dep['name'] .
'"' . $extra);
}
 
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires PHP extension "' . $dep['name'] .
'"' . $extra);
}
 
return $this->warning('warning: %s requires PHP extension "' . $dep['name'] .
'"' . $extra);
}
 
$version = (string) $this->phpversion($dep['name']);
if (empty($version)) {
$version = '0';
}
 
$fail = false;
if (isset($dep['min'])) {
if (!version_compare($version, $dep['min'], '>=')) {
$fail = true;
}
if (isset($dep['min']) && !version_compare($version, $dep['min'], '>=')) {
$fail = true;
}
if (isset($dep['max'])) {
if (!version_compare($version, $dep['max'], '<=')) {
$fail = true;
}
 
if (isset($dep['max']) && !version_compare($version, $dep['max'], '<=')) {
$fail = true;
}
 
if ($fail && !isset($dep['conflicts'])) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires PHP extension "' . $dep['name'] .
'"' . $extra . ', installed version is ' . $version);
} else {
return $this->warning('warning: %s requires PHP extension "' . $dep['name'] .
'"' . $extra . ', installed version is ' . $version);
}
 
return $this->warning('warning: %s requires PHP extension "' . $dep['name'] .
'"' . $extra . ', installed version is ' . $version);
} elseif ((isset($dep['min']) || isset($dep['max'])) && !$fail && isset($dep['conflicts'])) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s conflicts with PHP extension "' .
$dep['name'] . '"' . $extra . ', installed version is ' . $version);
} else {
return $this->warning('warning: %s conflicts with PHP extension "' .
$dep['name'] . '"' . $extra . ', installed version is ' . $version);
}
 
return $this->warning('warning: %s conflicts with PHP extension "' .
$dep['name'] . '"' . $extra . ', installed version is ' . $version);
}
 
if (isset($dep['exclude'])) {
foreach ($dep['exclude'] as $exclude) {
if (version_compare($version, $exclude, '==')) {
427,43 → 436,45
if (isset($dep['conflicts'])) {
continue;
}
if (!isset($this->_options['nodeps']) &&
!isset($this->_options['force'])) {
 
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s is not compatible with PHP extension "' .
$dep['name'] . '" version ' .
$exclude);
} else {
return $this->warning('warning: %s is not compatible with PHP extension "' .
$dep['name'] . '" version ' .
$exclude);
}
 
return $this->warning('warning: %s is not compatible with PHP extension "' .
$dep['name'] . '" version ' .
$exclude);
} elseif (version_compare($version, $exclude, '!=') && isset($dep['conflicts'])) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s conflicts with PHP extension "' .
$dep['name'] . '"' . $extra . ', installed version is ' . $version);
} else {
return $this->warning('warning: %s conflicts with PHP extension "' .
$dep['name'] . '"' . $extra . ', installed version is ' . $version);
}
 
return $this->warning('warning: %s conflicts with PHP extension "' .
$dep['name'] . '"' . $extra . ', installed version is ' . $version);
}
}
}
 
if (isset($dep['recommended'])) {
if (version_compare($version, $dep['recommended'], '==')) {
return true;
} else {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s dependency: PHP extension ' . $dep['name'] .
' version "' . $version . '"' .
' is not the recommended version "' . $dep['recommended'] .
'", but may be compatible, use --force to install');
} else {
return $this->warning('warning: %s dependency: PHP extension ' .
$dep['name'] . ' version "' . $version . '"' .
' is not the recommended version "' . $dep['recommended'].'"');
}
}
 
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s dependency: PHP extension ' . $dep['name'] .
' version "' . $version . '"' .
' is not the recommended version "' . $dep['recommended'] .
'", but may be compatible, use --force to install');
}
 
return $this->warning('warning: %s dependency: PHP extension ' .
$dep['name'] . ' version "' . $version . '"' .
' is not the recommended version "' . $dep['recommended'].'"');
}
 
return true;
}
 
473,50 → 484,54
$this->_state != PEAR_VALIDATE_DOWNLOADING) {
return true;
}
 
$version = $this->phpversion();
$extra = $this->_getExtraString($dep);
$extra = $this->_getExtraString($dep);
if (isset($dep['exclude'])) {
if (!is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
}
}
 
if (isset($dep['min'])) {
if (!version_compare($version, $dep['min'], '>=')) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires PHP' .
$extra . ', installed version is ' . $version);
} else {
return $this->warning('warning: %s requires PHP' .
$extra . ', installed version is ' . $version);
}
 
return $this->warning('warning: %s requires PHP' .
$extra . ', installed version is ' . $version);
}
}
 
if (isset($dep['max'])) {
if (!version_compare($version, $dep['max'], '<=')) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires PHP' .
$extra . ', installed version is ' . $version);
} else {
return $this->warning('warning: %s requires PHP' .
$extra . ', installed version is ' . $version);
}
 
return $this->warning('warning: %s requires PHP' .
$extra . ', installed version is ' . $version);
}
}
 
if (isset($dep['exclude'])) {
foreach ($dep['exclude'] as $exclude) {
if (version_compare($version, $exclude, '==')) {
if (!isset($this->_options['nodeps']) &&
!isset($this->_options['force'])) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s is not compatible with PHP version ' .
$exclude);
} else {
return $this->warning(
'warning: %s is not compatible with PHP version ' .
$exclude);
}
 
return $this->warning(
'warning: %s is not compatible with PHP version ' .
$exclude);
}
}
}
 
return true;
}
 
525,7 → 540,7
*/
function getPEARVersion()
{
return '1.5.1';
return '1.10.1';
}
 
function validatePearinstallerDependency($dep)
537,42 → 552,47
$dep['exclude'] = array($dep['exclude']);
}
}
 
if (version_compare($pearversion, $dep['min'], '<')) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires PEAR Installer' . $extra .
', installed version is ' . $pearversion);
} else {
return $this->warning('warning: %s requires PEAR Installer' . $extra .
', installed version is ' . $pearversion);
}
 
return $this->warning('warning: %s requires PEAR Installer' . $extra .
', installed version is ' . $pearversion);
}
 
if (isset($dep['max'])) {
if (version_compare($pearversion, $dep['max'], '>')) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires PEAR Installer' . $extra .
', installed version is ' . $pearversion);
} else {
return $this->warning('warning: %s requires PEAR Installer' . $extra .
', installed version is ' . $pearversion);
}
 
return $this->warning('warning: %s requires PEAR Installer' . $extra .
', installed version is ' . $pearversion);
}
}
 
if (isset($dep['exclude'])) {
if (!isset($dep['exclude'][0])) {
$dep['exclude'] = array($dep['exclude']);
}
 
foreach ($dep['exclude'] as $exclude) {
if (version_compare($exclude, $pearversion, '==')) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s is not compatible with PEAR Installer ' .
'version ' . $exclude);
} else {
return $this->warning('warning: %s is not compatible with PEAR ' .
'Installer version ' . $exclude);
}
 
return $this->warning('warning: %s is not compatible with PEAR ' .
'Installer version ' . $exclude);
}
}
}
 
return true;
}
 
586,7 → 606,7
* @param boolean whether this is a required dependency
* @param array a list of downloaded packages to be installed, if any
* @param boolean if true, then deps on pear.php.net that fail will also check
* against pecl.php.net packages to accomodate extensions that have
* against pecl.php.net packages to accommodate extensions that have
* moved to pecl.php.net from pear.php.net
*/
function validatePackageDependency($dep, $required, $params, $depv1 = false)
595,6 → 615,7
$this->_state != PEAR_VALIDATE_DOWNLOADING) {
return true;
}
 
if (isset($dep['providesextension'])) {
if ($this->extension_loaded($dep['providesextension'])) {
$save = $dep;
608,9 → 629,11
}
}
}
 
if ($this->_state == PEAR_VALIDATE_INSTALLING) {
return $this->_validatePackageInstall($dep, $required, $depv1);
}
 
if ($this->_state == PEAR_VALIDATE_DOWNLOADING) {
return $this->_validatePackageDownload($dep, $required, $params, $depv1);
}
622,6 → 645,7
if (isset($dep['uri'])) {
$dep['channel'] = '__uri';
}
 
$depname = $this->_registry->parsedPackageNameToString($dep, true);
$found = false;
foreach ($params as $param) {
631,6 → 655,7
$found = true;
break;
}
 
if ($depv1 && $dep['channel'] == 'pear.php.net') {
if ($param->isEqual(
array('package' => $dep['name'],
640,6 → 665,7
}
}
}
 
if (!$found && isset($dep['providesextension'])) {
foreach ($params as $param) {
if ($param->isExtension($dep['providesextension'])) {
648,6 → 674,7
}
}
}
 
if ($found) {
$version = $param->getVersion();
$installed = false;
672,77 → 699,73
}
}
}
 
$extra = $this->_getExtraString($dep);
if (isset($dep['exclude'])) {
if (!is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
}
if (isset($dep['exclude']) && !is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
}
 
if (!isset($dep['min']) && !isset($dep['max']) &&
!isset($dep['recommended']) && !isset($dep['exclude'])) {
!isset($dep['recommended']) && !isset($dep['exclude'])
) {
if ($installed || $downloaded) {
$installed = $installed ? 'installed' : 'downloaded';
if (isset($dep['conflicts'])) {
$rest = '';
if ($version) {
$rest = ", $installed version is " . $version;
} else {
$rest = '';
}
 
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s conflicts with package "' . $depname . '"' .
$extra . $rest);
} else {
return $this->warning('warning: %s conflicts with package "' . $depname . '"' .
$extra . $rest);
return $this->raiseError('%s conflicts with package "' . $depname . '"' . $extra . $rest);
}
 
return $this->warning('warning: %s conflicts with package "' . $depname . '"' . $extra . $rest);
}
 
return true;
} else {
if (isset($dep['conflicts'])) {
return true;
}
 
if (isset($dep['conflicts'])) {
return true;
}
 
if ($required) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires package "' . $depname . '"' . $extra);
}
if ($required) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires package "' . $depname . '"' .
$extra);
} else {
return $this->warning('warning: %s requires package "' . $depname . '"' .
$extra);
}
} else {
return $this->warning('%s can optionally use package "' . $depname . '"' .
$extra);
}
 
return $this->warning('warning: %s requires package "' . $depname . '"' . $extra);
}
 
return $this->warning('%s can optionally use package "' . $depname . '"' . $extra);
}
 
if (!$installed && !$downloaded) {
if (isset($dep['conflicts'])) {
return true;
}
 
if ($required) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires package "' . $depname . '"' .
$extra);
} else {
return $this->warning('warning: %s requires package "' . $depname . '"' .
$extra);
return $this->raiseError('%s requires package "' . $depname . '"' . $extra);
}
} else {
return $this->warning('%s can optionally use package "' . $depname . '"' .
$extra);
 
return $this->warning('warning: %s requires package "' . $depname . '"' . $extra);
}
 
return $this->warning('%s can optionally use package "' . $depname . '"' . $extra);
}
 
$fail = false;
if (isset($dep['min'])) {
if (version_compare($version, $dep['min'], '<')) {
$fail = true;
}
if (isset($dep['min']) && version_compare($version, $dep['min'], '<')) {
$fail = true;
}
if (isset($dep['max'])) {
if (version_compare($version, $dep['max'], '>')) {
$fail = true;
}
 
if (isset($dep['max']) && version_compare($version, $dep['max'], '>')) {
$fail = true;
}
 
if ($fail && !isset($dep['conflicts'])) {
$installed = $installed ? 'installed' : 'downloaded';
$dep['package'] = $dep['name'];
750,10 → 773,10
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires package "' . $depname . '"' .
$extra . ", $installed version is " . $version);
} else {
return $this->warning('warning: %s requires package "' . $depname . '"' .
$extra . ", $installed version is " . $version);
}
 
return $this->warning('warning: %s requires package "' . $depname . '"' .
$extra . ", $installed version is " . $version);
} elseif ((isset($dep['min']) || isset($dep['max'])) && !$fail &&
isset($dep['conflicts']) && !isset($dep['exclude'])) {
$installed = $installed ? 'installed' : 'downloaded';
760,82 → 783,88
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s conflicts with package "' . $depname . '"' . $extra .
", $installed version is " . $version);
} else {
return $this->warning('warning: %s conflicts with package "' . $depname . '"' .
$extra . ", $installed version is " . $version);
}
 
return $this->warning('warning: %s conflicts with package "' . $depname . '"' .
$extra . ", $installed version is " . $version);
}
 
if (isset($dep['exclude'])) {
$installed = $installed ? 'installed' : 'downloaded';
foreach ($dep['exclude'] as $exclude) {
if (version_compare($version, $exclude, '==') && !isset($dep['conflicts'])) {
if (!isset($this->_options['nodeps']) &&
!isset($this->_options['force'])) {
!isset($this->_options['force'])
) {
return $this->raiseError('%s is not compatible with ' .
$installed . ' package "' .
$depname . '" version ' .
$exclude);
} else {
return $this->warning('warning: %s is not compatible with ' .
$installed . ' package "' .
$depname . '" version ' .
$exclude);
}
 
return $this->warning('warning: %s is not compatible with ' .
$installed . ' package "' .
$depname . '" version ' .
$exclude);
} elseif (version_compare($version, $exclude, '!=') && isset($dep['conflicts'])) {
$installed = $installed ? 'installed' : 'downloaded';
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s conflicts with package "' . $depname . '"' .
$extra . ", $installed version is " . $version);
} else {
return $this->warning('warning: %s conflicts with package "' . $depname . '"' .
$extra . ", $installed version is " . $version);
}
 
return $this->warning('warning: %s conflicts with package "' . $depname . '"' .
$extra . ", $installed version is " . $version);
}
}
}
 
if (isset($dep['recommended'])) {
$installed = $installed ? 'installed' : 'downloaded';
if (version_compare($version, $dep['recommended'], '==')) {
return true;
} else {
if (!$found && $installed) {
$param = $this->_registry->getPackage($dep['name'], $dep['channel']);
}
 
if (!$found && $installed) {
$param = $this->_registry->getPackage($dep['name'], $dep['channel']);
}
 
if ($param) {
$found = false;
foreach ($params as $parent) {
if ($parent->isEqual($this->_currentPackage)) {
$found = true;
break;
}
}
if ($param) {
$found = false;
foreach ($params as $parent) {
if ($parent->isEqual($this->_currentPackage)) {
$found = true;
break;
}
 
if ($found) {
if ($param->isCompatible($parent)) {
return true;
}
if ($found) {
if ($param->isCompatible($parent)) {
return true;
}
} else { // this is for validPackage() calls
$parent = $this->_registry->getPackage($this->_currentPackage['package'],
$this->_currentPackage['channel']);
if ($parent !== null) {
if ($param->isCompatible($parent)) {
return true;
}
}
} else { // this is for validPackage() calls
$parent = $this->_registry->getPackage($this->_currentPackage['package'],
$this->_currentPackage['channel']);
if ($parent !== null && $param->isCompatible($parent)) {
return true;
}
}
if (!isset($this->_options['nodeps']) && !isset($this->_options['force']) &&
!isset($this->_options['loose'])) {
return $this->raiseError('%s dependency package "' . $depname .
'" ' . $installed . ' version ' . $version .
' is not the recommended version ' . $dep['recommended'] .
', but may be compatible, use --force to install');
} else {
return $this->warning('warning: %s dependency package "' . $depname .
'" ' . $installed . ' version ' . $version .
' is not the recommended version ' . $dep['recommended']);
}
}
 
if (!isset($this->_options['nodeps']) && !isset($this->_options['force']) &&
!isset($this->_options['loose'])
) {
return $this->raiseError('%s dependency package "' . $depname .
'" ' . $installed . ' version ' . $version .
' is not the recommended version ' . $dep['recommended'] .
', but may be compatible, use --force to install');
}
 
return $this->warning('warning: %s dependency package "' . $depname .
'" ' . $installed . ' version ' . $version .
' is not the recommended version ' . $dep['recommended']);
}
 
return true;
}
 
855,6 → 884,7
if (PEAR::isError($this->_dependencydb)) {
return $this->_dependencydb;
}
 
$params = array();
// construct an array of "downloaded" packages to fool the package dependency checker
// into using these to validate uninstalls of circular dependencies
863,10 → 893,11
if (!class_exists('PEAR_Downloader_Package')) {
require_once 'PEAR/Downloader/Package.php';
}
$dp = &new PEAR_Downloader_Package($dl);
$dp = new PEAR_Downloader_Package($dl);
$dp->setPackageFile($downloaded[$i]);
$params[$i] = &$dp;
$params[$i] = $dp;
}
 
// check cache
$memyselfandI = strtolower($this->_currentPackage['channel']) . '/' .
strtolower($this->_currentPackage['package']);
877,27 → 908,38
$dl->log(0, $warning[0]);
}
}
 
if (isset($badpackages[$memyselfandI]['errors'])) {
foreach ($badpackages[$memyselfandI]['errors'] as $error) {
$dl->log(0, $error->getMessage());
if (is_array($error)) {
$dl->log(0, $error[0]);
} else {
$dl->log(0, $error->getMessage());
}
}
 
if (isset($this->_options['nodeps']) || isset($this->_options['force'])) {
return $this->warning(
'warning: %s should not be uninstalled, other installed packages depend ' .
'on this package');
} else {
return $this->raiseError(
'%s cannot be uninstalled, other installed packages depend on this package');
}
 
return $this->raiseError(
'%s cannot be uninstalled, other installed packages depend on this package');
}
 
return true;
}
 
// first, list the immediate parents of each package to be uninstalled
$perpackagelist = array();
$allparents = array();
foreach ($params as $i => $param) {
$a = array('channel' => strtolower($param->getChannel()),
'package' => strtolower($param->getPackage()));
$a = array(
'channel' => strtolower($param->getChannel()),
'package' => strtolower($param->getPackage())
);
 
$deps = $this->_dependencydb->getDependentPackages($a);
if ($deps) {
foreach ($deps as $d) {
924,6 → 966,7
}
}
}
 
// next, remove any packages from the parents list that are not installed
$remove = array();
foreach ($allparents as $parent => $d1) {
934,6 → 977,7
$remove[$parent] = true;
}
}
 
// next remove any packages from the parents list that are not passed in for
// uninstallation
foreach ($allparents as $parent => $d1) {
948,6 → 992,7
$remove[$parent] = true;
}
}
 
// remove all packages whose dependencies fail
// save which ones failed for error reporting
$badchildren = array();
957,6 → 1002,7
if (!isset($allparents[$package])) {
continue;
}
 
foreach ($allparents[$package] as $kid => $d1) {
foreach ($d1 as $depinfo) {
if ($depinfo[1]['type'] != 'optional') {
976,6 → 1022,7
}
}
} while ($fail);
 
// next, construct the list of packages that can't be uninstalled
$badpackages = array();
$save = $this->_currentPackage;
984,6 → 1031,7
if (!isset($remove[$parent[0]])) {
continue;
}
 
$packagename = $this->_registry->parsePackageName($parent[0]);
$packagename['channel'] = $this->_registry->channelAlias($packagename['channel']);
$pa = $this->_registry->getPackage($packagename['package'], $packagename['channel']);
1009,7 → 1057,8
}
}
}
$this->_currentPackage = $save;
 
$this->_currentPackage = $save;
$dl->___uninstall_package_cache = $badpackages;
if (isset($badpackages[$memyselfandI])) {
if (isset($badpackages[$memyselfandI]['warnings'])) {
1017,20 → 1066,27
$dl->log(0, $warning[0]);
}
}
 
if (isset($badpackages[$memyselfandI]['errors'])) {
foreach ($badpackages[$memyselfandI]['errors'] as $error) {
$dl->log(0, $error->getMessage());
if (is_array($error)) {
$dl->log(0, $error[0]);
} else {
$dl->log(0, $error->getMessage());
}
}
 
if (isset($this->_options['nodeps']) || isset($this->_options['force'])) {
return $this->warning(
'warning: %s should not be uninstalled, other installed packages depend ' .
'on this package');
} else {
return $this->raiseError(
'%s cannot be uninstalled, other installed packages depend on this package');
}
 
return $this->raiseError(
'%s cannot be uninstalled, other installed packages depend on this package');
}
}
 
return true;
}
 
1037,65 → 1093,63
function _validatePackageUninstall($dep, $required, $dl)
{
$depname = $this->_registry->parsedPackageNameToString($dep, true);
$version = $this->_registry->packageinfo($dep['package'], 'version',
$dep['channel']);
$version = $this->_registry->packageinfo($dep['package'], 'version', $dep['channel']);
if (!$version) {
return true;
}
 
$extra = $this->_getExtraString($dep);
if (isset($dep['exclude'])) {
if (!is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
}
if (isset($dep['exclude']) && !is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
}
 
if (isset($dep['conflicts'])) {
return true; // uninstall OK - these packages conflict (probably installed with --force)
}
 
if (!isset($dep['min']) && !isset($dep['max'])) {
if ($required) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('"' . $depname . '" is required by ' .
'installed package %s' . $extra);
} else {
return $this->warning('warning: "' . $depname . '" is required by ' .
'installed package %s' . $extra);
}
} else {
if (!$required) {
return $this->warning('"' . $depname . '" can be optionally used by ' .
'installed package %s' . $extra);
}
 
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('"' . $depname . '" is required by ' .
'installed package %s' . $extra);
}
 
return $this->warning('warning: "' . $depname . '" is required by ' .
'installed package %s' . $extra);
}
 
$fail = false;
if (isset($dep['min'])) {
if (version_compare($version, $dep['min'], '>=')) {
$fail = true;
}
if (isset($dep['min']) && version_compare($version, $dep['min'], '>=')) {
$fail = true;
}
if (isset($dep['max'])) {
if (version_compare($version, $dep['max'], '<=')) {
$fail = true;
}
 
if (isset($dep['max']) && version_compare($version, $dep['max'], '<=')) {
$fail = true;
}
 
// we re-use this variable, preserve the original value
$saverequired = $required;
if ($required) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError($depname . $extra . ' is required by installed package' .
' "%s"');
} else {
return $this->raiseError('warning: ' . $depname . $extra .
' is required by installed package "%s"');
}
} else {
if (!$required) {
return $this->warning($depname . $extra . ' can be optionally used by installed package' .
' "%s"');
}
return true;
 
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError($depname . $extra . ' is required by installed package' .
' "%s"');
}
 
return $this->raiseError('warning: ' . $depname . $extra .
' is required by installed package "%s"');
}
 
/**
* validate a downloaded package against installed packages
*
*
* As of PEAR 1.4.3, this will only validate
*
* @param array|PEAR_Downloader_Package|PEAR_PackageFile_v1|PEAR_PackageFile_v2
1113,17 → 1167,20
} else {
$deps = $this->_dependencydb->getDependentPackageDependencies($pkg);
}
 
$fail = false;
if ($deps) {
if (!class_exists('PEAR_Downloader_Package')) {
require_once 'PEAR/Downloader/Package.php';
}
$dp = &new PEAR_Downloader_Package($dl);
 
$dp = new PEAR_Downloader_Package($dl);
if (is_object($pkg)) {
$dp->setPackageFile($pkg);
} else {
$dp->setDownloadURL($pkg);
}
 
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
foreach ($deps as $channel => $info) {
foreach ($info as $package => $ds) {
1139,8 → 1196,9
continue 2; // jump to next package
}
}
 
foreach ($ds as $d) {
$checker = &new PEAR_Dependency2($this->_config, $this->_options,
$checker = new PEAR_Dependency2($this->_config, $this->_options,
array('channel' => $channel, 'package' => $package), $this->_state);
$dep = $d['dep'];
$required = $d['type'] == 'required';
1156,10 → 1214,12
}
PEAR::popErrorHandling();
}
 
if ($fail) {
return $this->raiseError(
'%s cannot be installed, conflicts with installed packages');
}
 
return true;
}
 
1171,10 → 1231,12
if (!isset($dep['optional'])) {
$dep['optional'] = 'no';
}
 
list($newdep, $type) = $this->normalizeDep($dep);
if (!$newdep) {
return $this->raiseError("Invalid Dependency");
}
 
if (method_exists($this, "validate{$type}Dependency")) {
return $this->{"validate{$type}Dependency"}($newdep, $dep['optional'] == 'no',
$params, true);
1192,11 → 1254,13
'os' => 'Os',
'php' => 'Php'
);
if (isset($types[$dep['type']])) {
$type = $types[$dep['type']];
} else {
 
if (!isset($types[$dep['type']])) {
return array(false, false);
}
 
$type = $types[$dep['type']];
 
$newdep = array();
switch ($type) {
case 'Package' :
1206,6 → 1270,7
$newdep['name'] = $dep['name'];
break;
}
 
$dep['rel'] = PEAR_Dependency2::signOperator($dep['rel']);
switch ($dep['rel']) {
case 'has' :
1241,8 → 1306,9
}
if ($type == 'Php') {
if (!isset($newdep['min'])) {
$newdep['min'] = '4.2.0';
$newdep['min'] = '4.4.0';
}
 
if (!isset($newdep['max'])) {
$newdep['max'] = '6.0.0';
}
1278,6 → 1344,7
if (isset($this->_options['ignore-errors'])) {
return $this->warning($msg);
}
 
return PEAR::raiseError(sprintf($msg, $this->_registry->parsedPackageNameToString(
$this->_currentPackage, true)));
}
1288,4 → 1355,3
$this->_currentPackage, true)));
}
}
?>
/trunk/bibliotheque/pear/PEAR/RunTest.php
4,19 → 4,12
*
* 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 Tomas V.V.Cox <cox@idecnet.com>
* @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: RunTest.php,v 1.34 2007/02/17 19:57:56 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.3.3
*/
42,28 → 35,37
* @package PEAR
* @author Tomas V.V.Cox <cox@idecnet.com>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.3.3
*/
class PEAR_RunTest
{
var $_headers = array();
var $_logger;
var $_options;
var $_php;
var $tests_count;
var $xdebug_loaded;
/**
* Saved value of php executable, used to reset $_php when we
* have a test that uses cgi
*
* @var unknown_type
*/
var $_savephp;
var $ini_overwrites = array(
'output_handler=',
'open_basedir=',
'safe_mode=0',
'disable_functions=',
'output_buffering=Off',
'error_reporting=E_ALL',
'display_errors=1',
'log_errors=0',
'html_errors=0',
'track_errors=1',
'report_memleaks=1',
'report_memleaks=0',
'report_zend_debug=0',
'docref_root=',
'docref_ext=.html',
71,22 → 73,32
'error_append_string=',
'auto_prepend_file=',
'auto_append_file=',
'magic_quotes_runtime=0',
'xdebug.default_enable=0',
'allow_url_fopen=1',
);
 
 
/**
* An object that supports the PEAR_Common->log() signature, or null
* @param PEAR_Common|null
*/
function PEAR_RunTest($logger = null, $options = array())
function __construct($logger = null, $options = array())
{
if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 0);
}
if (!defined('E_STRICT')) {
define('E_STRICT', 0);
}
$this->ini_overwrites[] = 'error_reporting=' . (E_ALL & ~(E_DEPRECATED | E_STRICT));
if (is_null($logger)) {
require_once 'PEAR/Common.php';
$logger = new PEAR_Common;
}
$this->_logger = $logger;
$this->_logger = $logger;
$this->_options = $options;
 
$conf = &PEAR_Config::singleton();
$this->_php = $conf->get('php_bin');
}
 
/**
100,37 → 112,27
function system_with_timeout($commandline, $env = null, $stdin = null)
{
$data = '';
$proc = proc_open($commandline, array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w')
), $pipes, null, $env, array('suppress_errors' => true));
 
if (version_compare(phpversion(), '5.0.0', '<')) {
$proc = proc_open($commandline, array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w')
), $pipes);
} else {
$proc = proc_open($commandline, array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w')
), $pipes, null, $env, array("suppress_errors" => true));
}
if (!$proc) {
return false;
}
 
if (is_string($stdin)) {
fwrite($pipes[0], $stdin);
}
fclose($pipes[0]);
 
while (true) {
/* hide errors from interrupted syscalls */
$r = $pipes;
$w = null;
$e = null;
$e = $w = null;
$n = @stream_select($r, $w, $e, 60);
 
if ($n === 0) {
/* timed out */
$data .= "\n ** ERROR: process timed out **\n";
158,12 → 160,40
return array($code, $data);
}
 
/**
* Turns a PHP INI string into an array
*
* Turns -d "include_path=/foo/bar" into this:
* array(
* 'include_path' => array(
* 'operator' => '-d',
* 'value' => '/foo/bar',
* )
* )
* Works both with quotes and without
*
* @param string an PHP INI string, -d "include_path=/foo/bar"
* @return array
*/
function iniString2array($ini_string)
{
if (!$ini_string) {
return array();
}
$split = preg_split('/[\s]|=/', $ini_string, -1, PREG_SPLIT_NO_EMPTY);
$key = $split[1][0] == '"' ? substr($split[1], 1) : $split[1];
$value = $split[2][strlen($split[2]) - 1] == '"' ? substr($split[2], 0, -1) : $split[2];
// FIXME review if this is really the struct to go with
$array = array($key => array('operator' => $split[0], 'value' => $value));
return $array;
}
 
function settings2array($settings, $ini_settings)
{
foreach ($settings as $setting) {
if (strpos($setting, '=')!==false) {
$setting = explode("=", $setting, 2);
$name = trim(strtolower($setting[0]));
if (strpos($setting, '=') !== false) {
$setting = explode('=', $setting, 2);
$name = trim(strtolower($setting[0]));
$value = trim($setting[1]);
$ini_settings[$name] = $value;
}
170,107 → 200,122
}
return $ini_settings;
}
 
function settings2params($ini_settings)
{
$settings = '';
foreach ($ini_settings as $name => $value) {
if (is_array($value)) {
$operator = $value['operator'];
$value = $value['value'];
} else {
$operator = '-d';
}
$value = addslashes($value);
$settings .= " -d \"$name=$value\"";
$settings .= " $operator \"$name=$value\"";
}
return $settings;
}
 
//
// Run an individual test case.
//
function _preparePhpBin($php, $file, $ini_settings)
{
$file = escapeshellarg($file);
$cmd = $php . $ini_settings . ' -f ' . $file;
 
function run($file, $ini_settings = '')
return $cmd;
}
 
function runPHPUnit($file, $ini_settings = '')
{
$cwd = getcwd();
$conf = &PEAR_Config::singleton();
$php = $conf->get('php_bin');
if (isset($this->_options['phpunit'])) {
$cmd = "$php$ini_settings -f $file";
if (isset($this->_logger)) {
$this->_logger->log(2, 'Running command "' . $cmd . '"');
}
$savedir = getcwd(); // in case the test moves us around
chdir(dirname($file));
echo `$cmd`;
chdir($savedir);
return 'PASSED'; // we have no way of knowing this information so assume passing
if (!file_exists($file) && file_exists(getcwd() . DIRECTORY_SEPARATOR . $file)) {
$file = realpath(getcwd() . DIRECTORY_SEPARATOR . $file);
} elseif (file_exists($file)) {
$file = realpath($file);
}
$pass_options = '';
if (!empty($this->_options['ini'])) {
$pass_options = $this->_options['ini'];
 
$cmd = $this->_preparePhpBin($this->_php, $file, $ini_settings);
if (isset($this->_logger)) {
$this->_logger->log(2, 'Running command "' . $cmd . '"');
}
 
$info_params = '';
$log_format = 'LEOD';
$savedir = getcwd(); // in case the test moves us around
chdir(dirname($file));
echo `$cmd`;
chdir($savedir);
return 'PASSED'; // we have no way of knowing this information so assume passing
}
 
// Load the sections of the test file.
$section_text = array(
'TEST' => '(unnamed test)',
'SKIPIF' => '',
'GET' => '',
'COOKIE' => '',
'POST' => '',
'ARGS' => '',
'INI' => '',
'CLEAN' => '',
);
/**
* Runs an individual test case.
*
* @param string The filename of the test
* @param array|string INI settings to be applied to the test run
* @param integer Number what the current running test is of the
* whole test suite being runned.
*
* @return string|object Returns PASSED, WARNED, FAILED depending on how the
* test came out.
* PEAR Error when the tester it self fails
*/
function run($file, $ini_settings = array(), $test_number = 1)
{
$this->_restorePHPBinary();
 
if (empty($this->_options['cgi'])) {
// try to see if php-cgi is in the path
$res = $this->system_with_timeout('php-cgi -v');
if (false !== $res && !(is_array($res) && in_array($res[0], array(-1, 127)))) {
$this->_options['cgi'] = 'php-cgi';
}
}
if (1 < $len = strlen($this->tests_count)) {
$test_number = str_pad($test_number, $len, ' ', STR_PAD_LEFT);
$test_nr = "[$test_number/$this->tests_count] ";
} else {
$test_nr = '';
}
 
$file = realpath($file);
if (!is_file($file) || !$fp = fopen($file, "r")) {
return PEAR::raiseError("Cannot open test file: $file");
$section_text = $this->_readFile($file);
if (PEAR::isError($section_text)) {
return $section_text;
}
 
$section = '';
while (!feof($fp)) {
$line = fgets($fp);
if (isset($section_text['POST_RAW']) && isset($section_text['UPLOAD'])) {
return PEAR::raiseError("Cannot contain both POST_RAW and UPLOAD in test file: $file");
}
 
// Match the beginning of a section.
if (preg_match('/^--([_A-Z]+)--/', $line, $r)) {
$section = $r[1];
$section_text[$section] = '';
continue;
} elseif (empty($section)) {
fclose($fp);
return PEAR::raiseError("Invalid sections formats in test file: $file");
}
$cwd = getcwd();
 
// Add to the section text.
$section_text[$section] .= $line;
$pass_options = '';
if (!empty($this->_options['ini'])) {
$pass_options = $this->_options['ini'];
}
fclose($fp);
 
if (isset($section_text['POST_RAW']) && isset($section_text['UPLOAD'])) {
return PEAR::raiseError("Cannot contain both POST_RAW and UPLOAD in test file: $file");
if (is_string($ini_settings)) {
$ini_settings = $this->iniString2array($ini_settings);
}
$ini_settings = array();
 
$ini_settings = $this->settings2array($this->ini_overwrites, $ini_settings);
if ($section_text['INI']) {
if (strpos($section_text['INI'], '{PWD}') !== false) {
$section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']);
}
$ini_settings = $this->settings2array(preg_split( "/[\n\r]+/",
$section_text['INI']), $ini_settings);
$ini = preg_split( "/[\n\r]+/", $section_text['INI']);
$ini_settings = $this->settings2array($ini, $ini_settings);
}
$ini_settings = $this->settings2params($ini_settings);
$shortname = str_replace($cwd . DIRECTORY_SEPARATOR, '', $file);
if (!isset($this->_options['simple'])) {
$tested = trim($section_text['TEST']) . "[$shortname]";
} else {
$tested = trim($section_text['TEST']) . ' ';
}
if (!empty($section_text['GET']) || !empty($section_text['POST']) ||
!empty($section_text['POST_RAW']) || !empty($section_text['COOKIE']) ||
!empty($section_text['UPLOAD'])) {
 
$tested = trim($section_text['TEST']);
$tested.= !isset($this->_options['simple']) ? "[$shortname]" : ' ';
 
if (!empty($section_text['POST']) || !empty($section_text['POST_RAW']) ||
!empty($section_text['UPLOAD']) || !empty($section_text['GET']) ||
!empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) {
if (empty($this->_options['cgi'])) {
if (!isset($this->_options['quiet'])) {
$this->_logger->log(0, "SKIP $tested (reason: --cgi option needed for this test, type 'pear help run-tests')");
$this->_logger->log(0, "SKIP $test_nr$tested (reason: --cgi option needed for this test, type 'pear help run-tests')");
}
if (isset($this->_options['tapoutput'])) {
return array('ok', ' # skip --cgi option needed for this test, "pear help run-tests" for info');
277,169 → 322,107
}
return 'SKIPPED';
}
$php = $this->_options['cgi'];
$this->_savePHPBinary();
$this->_php = $this->_options['cgi'];
}
 
$temp_dir = $test_dir = realpath(dirname($file));
$main_file_name = basename($file,'phpt');
$diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'diff';
$log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'log';
$exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'exp';
$output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'out';
$memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'mem';
$temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'php';
$test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'php';
$temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php';
$test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php';
$temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php';
$test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php';
$tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('phpt.');
$temp_dir = realpath(dirname($file));
$main_file_name = basename($file, 'phpt');
$diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'diff';
$log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'log';
$exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'exp';
$output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'out';
$memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'mem';
$temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'php';
$temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php';
$temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php';
$tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('phpt.');
 
// unlink old test results
@unlink($diff_filename);
@unlink($log_filename);
@unlink($exp_filename);
@unlink($output_filename);
@unlink($memcheck_filename);
@unlink($temp_file);
@unlink($test_file);
@unlink($temp_skipif);
@unlink($test_skipif);
@unlink($tmp_post);
@unlink($temp_clean);
@unlink($test_clean);
// unlink old test results
$this->_cleanupOldFiles($file);
 
// Check if test should be skipped.
$info = '';
$warn = false;
if (array_key_exists('SKIPIF', $section_text)) {
if (trim($section_text['SKIPIF'])) {
$this->save_text($temp_skipif, $section_text['SKIPIF']);
$output = $this->system_with_timeout("$php $info_params -f $temp_skipif");
$output = $output[1];
unlink($temp_skipif);
if (!strncasecmp('skip', ltrim($output), 4)) {
$skipreason = "SKIP $tested";
if (preg_match('/^\s*skip\s*(.+)\s*/i', $output, $m)) {
$skipreason .= '(reason: ' . $m[1] . ')';
}
if (!isset($this->_options['quiet'])) {
$this->_logger->log(0, $skipreason);
}
if (isset($this->_options['tapoutput'])) {
return array('ok', ' # skip ' . $reason);
}
return 'SKIPPED';
}
if (!strncasecmp('info', ltrim($output), 4)) {
if (preg_match('/^\s*info\s*(.+)\s*/i', $output, $m)) {
$info = " (info: $m[1])";
}
}
if (!strncasecmp('warn', ltrim($output), 4)) {
if (preg_match('/^\s*warn\s*(.+)\s*/i', $output, $m)) {
$warn = true; /* only if there is a reason */
$info = " (warn: $m[1])";
}
}
}
$res = $this->_runSkipIf($section_text, $temp_skipif, $tested, $ini_settings);
if (count($res) != 2) {
return $res;
}
$info = $res['info'];
$warn = $res['warn'];
 
// We've satisfied the preconditions - run the test!
$this->save_text($temp_file,$section_text['FILE']);
if (isset($this->_options['coverage']) && $this->xdebug_loaded) {
$xdebug_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'xdebug';
$text = "\n" . 'function coverage_shutdown() {' .
"\n" . ' $xdebug = var_export(xdebug_get_code_coverage(), true);';
if (!function_exists('file_put_contents')) {
$text .= "\n" . ' $fh = fopen(\'' . $xdebug_file . '\', "wb");' .
"\n" . ' if ($fh !== false) {' .
"\n" . ' fwrite($fh, $xdebug);' .
"\n" . ' fclose($fh);' .
"\n" . ' }';
} else {
$text .= "\n" . ' file_put_contents(\'' . $xdebug_file . '\', $xdebug);';
}
 
$args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : '';
// Workaround for http://pear.php.net/bugs/bug.php?id=17292
$lines = explode("\n", $section_text['FILE']);
$numLines = count($lines);
$namespace = '';
$coverage_shutdown = 'coverage_shutdown';
 
$cmd = "$php$ini_settings -f $temp_file$args 2>&1";
if (isset($this->_logger)) {
$this->_logger->log(2, 'Running command "' . $cmd . '"');
}
if (
substr($lines[0], 0, 2) == '<?' ||
substr($lines[0], 0, 5) == '<?php'
) {
unset($lines[0]);
}
 
$savedir = getcwd(); // in case the test moves us around
// Reset environment from any previous test.
$env = $_ENV;
$env['REDIRECT_STATUS']='';
$env['QUERY_STRING']='';
$env['PATH_TRANSLATED']='';
$env['SCRIPT_FILENAME']='';
$env['REQUEST_METHOD']='';
$env['CONTENT_TYPE']='';
$env['CONTENT_LENGTH']='';
if (!empty($section_text['ENV'])) {
foreach(explode("\n", trim($section_text['ENV'])) as $e) {
$e = explode('=',trim($e),2);
if (!empty($e[0]) && isset($e[1])) {
$env[$e[0]] = $e[1];
 
for ($i = 0; $i < $numLines; $i++) {
if (isset($lines[$i]) && substr($lines[$i], 0, 9) == 'namespace') {
$namespace = substr($lines[$i], 10, -1);
$coverage_shutdown = $namespace . '\\coverage_shutdown';
$namespace = "namespace " . $namespace . ";\n";
 
unset($lines[$i]);
break;
}
}
}
if (array_key_exists('GET', $section_text)) {
$query_string = trim($section_text['GET']);
 
$text .= "\n xdebug_stop_code_coverage();" .
"\n" . '} // end coverage_shutdown()' .
"\n\n" . 'register_shutdown_function("' . $coverage_shutdown . '");';
$text .= "\n" . 'xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);' . "\n";
 
$this->save_text($temp_file, "<?php\n" . $namespace . $text . "\n" . implode("\n", $lines));
} else {
$query_string = '';
$this->save_text($temp_file, $section_text['FILE']);
}
if (array_key_exists('COOKIE', $section_text)) {
$env['HTTP_COOKIE'] = trim($section_text['COOKIE']);
} else {
$env['HTTP_COOKIE'] = '';
 
$args = $section_text['ARGS'] ? ' -- '.$section_text['ARGS'] : '';
$cmd = $this->_preparePhpBin($this->_php, $temp_file, $ini_settings);
$cmd.= "$args 2>&1";
if (isset($this->_logger)) {
$this->_logger->log(2, 'Running command "' . $cmd . '"');
}
$env['REDIRECT_STATUS'] = '1';
$env['QUERY_STRING'] = $query_string;
$env['PATH_TRANSLATED'] = $test_file;
$env['SCRIPT_FILENAME'] = $test_file;
if (array_key_exists('UPLOAD', $section_text) && !empty($section_text['UPLOAD'])) {
$upload_files = trim($section_text['UPLOAD']);
$upload_files = explode("\n", $upload_files);
 
$request = "Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737\n" .
"-----------------------------20896060251896012921717172737\n";
foreach ($upload_files as $fileinfo) {
$fileinfo = explode('=', $fileinfo);
if (count($fileinfo) != 2) {
return PEAR::raiseError("Invalid UPLOAD section in test file: $file");
}
if (!realpath(dirname($file) . '/' . $fileinfo[1])) {
return PEAR::raiseError("File for upload does not exist: $fileinfo[1] " .
"in test file: $file");
}
$file_contents = file_get_contents(dirname($file) . '/' . $fileinfo[1]);
$fileinfo[1] = basename($fileinfo[1]);
$request .= "Content-Disposition: form-data; name=\"$fileinfo[0]\"; filename=\"$fileinfo[1]\"\n";
$request .= "Content-Type: text/plain\n\n";
$request .= $file_contents . "\n" .
"-----------------------------20896060251896012921717172737\n";
}
if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) {
// encode POST raw
$post = trim($section_text['POST']);
$post = explode('&', $post);
foreach ($post as $i => $post_info) {
$post_info = explode('=', $post_info);
if (count($post_info) != 2) {
return PEAR::raiseError("Invalid POST data in test file: $file");
}
$post_info[0] = rawurldecode($post_info[0]);
$post_info[1] = rawurldecode($post_info[1]);
$post[$i] = $post_info;
}
foreach ($post as $post_info) {
$request .= "Content-Disposition: form-data; name=\"$post_info[0]\"\n\n";
$request .= $post_info[1] . "\n" .
"-----------------------------20896060251896012921717172737\n";
}
unset($section_text['POST']);
}
$section_text['POST_RAW'] = $request;
// Reset environment from any previous test.
$env = $this->_resetEnv($section_text, $temp_file);
 
$section_text = $this->_processUpload($section_text, $file);
if (PEAR::isError($section_text)) {
return $section_text;
}
 
if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) {
$post = trim($section_text['POST_RAW']);
$raw_lines = explode("\n", $post);
 
$request = '';
$started = false;
foreach ($raw_lines as $i => $line) {
if (empty($env['CONTENT_TYPE']) &&
preg_match('/^Content-Type:(.*)/i', $line, $res)) {
preg_match('/^Content-Type:(.*)/i', $line, $res)) {
$env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[1]));
continue;
}
449,32 → 432,28
$started = true;
$request .= $line;
}
 
$env['CONTENT_LENGTH'] = strlen($request);
$env['REQUEST_METHOD'] = 'POST';
 
$this->save_text($tmp_post, $request);
$cmd = "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < $tmp_post";
$cmd = "$this->_php$pass_options$ini_settings \"$temp_file\" 2>&1 < $tmp_post";
} elseif (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) {
$post = trim($section_text['POST']);
$this->save_text($tmp_post, $post);
$content_length = strlen($post);
 
$env['REQUEST_METHOD'] = 'POST';
$env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
$env['CONTENT_LENGTH'] = $content_length;
$cmd = "$php$pass_options$ini_settings -f \"$test_file\" 2>&1 < $tmp_post";
 
$cmd = "$this->_php$pass_options$ini_settings \"$temp_file\" 2>&1 < $tmp_post";
} else {
$env['REQUEST_METHOD'] = 'GET';
$env['CONTENT_TYPE'] = '';
$env['CONTENT_LENGTH'] = '';
$cmd = "$php$pass_options$ini_settings -f \"$test_file\" $args 2>&1";
}
 
if (OS_WINDOWS && isset($section_text['RETURNS'])) {
ob_start();
system($cmd, $return_value);
484,43 → 463,43
$returnfail = ($return_value != $section_text['RETURNS']);
} else {
$returnfail = false;
$out = $this->system_with_timeout($cmd, $env,
isset($section_text['STDIN']) ? $section_text['STDIN'] : null);
$stdin = isset($section_text['STDIN']) ? $section_text['STDIN'] : null;
$out = $this->system_with_timeout($cmd, $env, $stdin);
$return_value = $out[0];
$out = $out[1];
}
if (isset($tmp_post) && realpath($tmp_post)) {
unlink(realpath($tmp_post));
}
chdir($savedir);
 
if ($section_text['CLEAN']) {
// perform test cleanup
$this->save_text($temp_clean, $section_text['CLEAN']);
$this->system_with_timeout("$php $temp_clean");
if (file_exists($temp_clean)) {
unlink($temp_clean);
}
$output = preg_replace('/\r\n/', "\n", trim($out));
 
if (isset($tmp_post) && realpath($tmp_post) && file_exists($tmp_post)) {
@unlink(realpath($tmp_post));
}
// Does the output match what is expected?
$output = trim($out);
$output = preg_replace('/\r\n/', "\n", $output);
chdir($cwd); // in case the test moves us around
 
/* when using CGI, strip the headers from the output */
$headers = "";
if (!empty($this->_options['cgi']) &&
preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) {
$output = trim($match[2]);
$rh = preg_split("/[\n\r]+/",$match[1]);
$headers = array();
foreach ($rh as $line) {
if (strpos($line, ':')!==false) {
$line = explode(':', $line, 2);
$headers[trim($line[0])] = trim($line[1]);
$output = $this->_stripHeadersCGI($output);
 
if (isset($section_text['EXPECTHEADERS'])) {
$testheaders = $this->_processHeaders($section_text['EXPECTHEADERS']);
$missing = array_diff_assoc($testheaders, $this->_headers);
$changed = '';
foreach ($missing as $header => $value) {
if (isset($this->_headers[$header])) {
$changed .= "-$header: $value\n+$header: ";
$changed .= $this->_headers[$header];
} else {
$changed .= "-$header: $value\n";
}
}
if ($missing) {
// tack on failed headers to output:
$output .= "\n====EXPECTHEADERS FAILURE====:\n$changed";
}
}
 
$this->_testCleanup($section_text, $temp_clean);
 
// Does the output match what is expected?
do {
if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) {
if (isset($section_text['EXPECTF'])) {
528,7 → 507,7
} else {
$wanted = trim($section_text['EXPECTREGEX']);
}
$wanted_re = preg_replace('/\r\n/',"\n",$wanted);
$wanted_re = preg_replace('/\r\n/', "\n", $wanted);
if (isset($section_text['EXPECTF'])) {
$wanted_re = preg_quote($wanted_re, '/');
// Stick to basics
540,6 → 519,7
$wanted_re = str_replace("%c", ".", $wanted_re);
// %f allows two points "-.0.0" but that is the best *simple* expression
}
 
/* DEBUG YOUR REGEX HERE
var_dump($wanted_re);
print(str_repeat('=', 80) . "\n");
549,28 → 529,36
if (file_exists($temp_file)) {
unlink($temp_file);
}
 
if (array_key_exists('FAIL', $section_text)) {
break;
}
if (!isset($this->_options['quiet'])) {
$this->_logger->log(0, "PASS $tested$info");
$this->_logger->log(0, "PASS $test_nr$tested$info");
}
if (isset($old_php)) {
$php = $old_php;
}
if (isset($this->_options['tapoutput'])) {
return array('ok', ' - ' . $tested);
}
return 'PASSED';
}
} else {
if (isset($section_text['EXPECTFILE'])) {
$f = $temp_dir . '/' . trim($section_text['EXPECTFILE']);
if (!($fp = @fopen($f, 'rb'))) {
return PEAR::raiseError('--EXPECTFILE-- section file ' .
$f . ' not found');
}
fclose($fp);
$section_text['EXPECT'] = file_get_contents($f);
}
 
} else {
$wanted = trim($section_text['EXPECT']);
$wanted = preg_replace('/\r\n/',"\n",$wanted);
// compare and leave on success
$ok = (0 == strcmp($output,$wanted));
if (!$returnfail && $ok) {
if (isset($section_text['EXPECT'])) {
$wanted = preg_replace('/\r\n/', "\n", trim($section_text['EXPECT']));
} else {
$wanted = '';
}
 
// compare and leave on success
if (!$returnfail && 0 == strcmp($output, $wanted)) {
if (file_exists($temp_file)) {
unlink($temp_file);
}
578,11 → 566,8
break;
}
if (!isset($this->_options['quiet'])) {
$this->_logger->log(0, "PASS $tested$info");
$this->_logger->log(0, "PASS $test_nr$tested$info");
}
if (isset($old_php)) {
$php = $old_php;
}
if (isset($this->_options['tapoutput'])) {
return array('ok', ' - ' . $tested);
}
594,20 → 579,14
if (array_key_exists('FAIL', $section_text)) {
// we expect a particular failure
// this is only used for testing PEAR_RunTest
$faildiff = $this->generate_diff(
$wanted,
$output,
null,
isset($section_text['EXPECTF']) ? $wanted_re : null);
$wanted = preg_replace('/\r/', '', trim($section_text['FAIL']));
$expectf = isset($section_text['EXPECTF']) ? $wanted_re : null;
$faildiff = $this->generate_diff($wanted, $output, null, $expectf);
$faildiff = preg_replace('/\r/', '', $faildiff);
$wanted = preg_replace('/\r/', '', trim($section_text['FAIL']));
if ($faildiff == $wanted) {
if (!isset($this->_options['quiet'])) {
$this->_logger->log(0, "PASS $tested$info");
$this->_logger->log(0, "PASS $test_nr$tested$info");
}
if (isset($old_php)) {
$php = $old_php;
}
if (isset($this->_options['tapoutput'])) {
return array('ok', ' - ' . $tested);
}
622,94 → 601,57
}
 
// Test failed so we need to report details.
if ($warn) {
$this->_logger->log(0, "WARN $tested$info");
} else {
$this->_logger->log(0, "FAIL $tested$info");
}
$txt = $warn ? 'WARN ' : 'FAIL ';
$this->_logger->log(0, $txt . $test_nr . $tested . $info);
 
if (isset($section_text['RETURNS'])) {
$GLOBALS['__PHP_FAILED_TESTS__'][] = array(
'name' => $file,
'test_name' => $tested,
'output' => $log_filename,
'diff' => $diff_filename,
'info' => $info,
'return' => $return_value
);
} else {
$GLOBALS['__PHP_FAILED_TESTS__'][] = array(
'name' => $file,
'test_name' => $tested,
'output' => $output_filename,
'diff' => $diff_filename,
'info' => $info,
);
}
 
// write .exp
if (strpos($log_format,'E') !== FALSE) {
$logname = $exp_filename;
if (!$log = fopen($logname,'w')) {
return PEAR::raiseError("Cannot create test log - $logname");
}
fwrite($log,$wanted);
fclose($log);
$res = $this->_writeLog($exp_filename, $wanted);
if (PEAR::isError($res)) {
return $res;
}
 
// write .out
if (strpos($log_format,'O') !== FALSE) {
$logname = $output_filename;
if (!$log = fopen($logname,'w')) {
return PEAR::raiseError("Cannot create test log - $logname");
}
fwrite($log,$output);
fclose($log);
$res = $this->_writeLog($output_filename, $output);
if (PEAR::isError($res)) {
return $res;
}
 
// write .diff
if (strpos($log_format,'D') !== FALSE) {
$logname = $diff_filename;
if (!$log = fopen($logname,'w')) {
return PEAR::raiseError("Cannot create test log - $logname");
}
fwrite($log, $this->generate_diff(
$wanted,
$output,
isset($section_text['RETURNS']) ?
array(trim($section_text['RETURNS']), $return_value) : null,
isset($section_text['EXPECTF']) ? $wanted_re : null)
);
fclose($log);
$returns = isset($section_text['RETURNS']) ?
array(trim($section_text['RETURNS']), $return_value) : null;
$expectf = isset($section_text['EXPECTF']) ? $wanted_re : null;
$data = $this->generate_diff($wanted, $output, $returns, $expectf);
$res = $this->_writeLog($diff_filename, $data);
if (isset($this->_options['showdiff'])) {
$this->_logger->log(0, "========DIFF========");
$this->_logger->log(0, $data);
$this->_logger->log(0, "========DONE========");
}
if (PEAR::isError($res)) {
return $res;
}
 
// write .log
if (strpos($log_format,'L') !== FALSE) {
$logname = $log_filename;
if (!$log = fopen($logname,'w')) {
return PEAR::raiseError("Cannot create test log - $logname");
}
fwrite($log,"
$data = "
---- EXPECTED OUTPUT
$wanted
---- ACTUAL OUTPUT
$output
---- FAILED
");
if ($returnfail) {
fwrite($log,"
";
 
if ($returnfail) {
$data .= "
---- EXPECTED RETURN
$section_text[RETURNS]
---- ACTUAL RETURN
$return_value
");
}
fclose($log);
//error_report($file,$logname,$tested);
";
}
 
if (isset($old_php)) {
$php = $old_php;
$res = $this->_writeLog($log_filename, $data);
if (PEAR::isError($res)) {
return $res;
}
 
if (isset($this->_options['tapoutput'])) {
722,47 → 664,39
return $warn ? 'WARNED' : 'FAILED';
}
 
function generate_diff($wanted, $output, $return_value, $wanted_re)
function generate_diff($wanted, $output, $rvalue, $wanted_re)
{
$w = explode("\n", $wanted);
$o = explode("\n", $output);
$w = explode("\n", $wanted);
$o = explode("\n", $output);
$wr = explode("\n", $wanted_re);
$w1 = array_diff_assoc($w,$o);
$o1 = array_diff_assoc($o,$w);
$w2 = array();
$o2 = array();
foreach($w1 as $idx => $val) {
$w1 = array_diff_assoc($w, $o);
$o1 = array_diff_assoc($o, $w);
$o2 = $w2 = array();
foreach ($w1 as $idx => $val) {
if (!$wanted_re || !isset($wr[$idx]) || !isset($o1[$idx]) ||
!preg_match('/^' . $wr[$idx] . '$/', $o1[$idx])) {
!preg_match('/^' . $wr[$idx] . '\\z/', $o1[$idx])) {
$w2[sprintf("%03d<", $idx)] = sprintf("%03d- ", $idx + 1) . $val;
}
}
foreach($o1 as $idx => $val) {
foreach ($o1 as $idx => $val) {
if (!$wanted_re || !isset($wr[$idx]) ||
!preg_match('/^' . $wr[$idx] . '$/', $val)) {
!preg_match('/^' . $wr[$idx] . '\\z/', $val)) {
$o2[sprintf("%03d>", $idx)] = sprintf("%03d+ ", $idx + 1) . $val;
}
}
$diff = array_merge($w2, $o2);
ksort($diff);
if ($return_value) {
$extra = "##EXPECTED: $return_value[0]\r\n##RETURNED: $return_value[1]";
} else {
$extra = '';
}
$extra = $rvalue ? "##EXPECTED: $rvalue[0]\r\n##RETURNED: $rvalue[1]" : '';
return implode("\r\n", $diff) . $extra;
}
 
//
// Write the given text to a temporary file, and return the filename.
//
 
function save_text($filename, $text)
{
if (!$fp = fopen($filename, 'w')) {
return PEAR::raiseError("Cannot open file '" . $filename . "' (save_text)");
}
fwrite($fp,$text);
fwrite($fp, $text);
fclose($fp);
if (1 < DETAILED) echo "
FILE $filename {{{
771,5 → 705,268
";
}
 
function _cleanupOldFiles($file)
{
$temp_dir = realpath(dirname($file));
$mainFileName = basename($file, 'phpt');
$diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $mainFileName.'diff';
$log_filename = $temp_dir . DIRECTORY_SEPARATOR . $mainFileName.'log';
$exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $mainFileName.'exp';
$output_filename = $temp_dir . DIRECTORY_SEPARATOR . $mainFileName.'out';
$memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $mainFileName.'mem';
$temp_file = $temp_dir . DIRECTORY_SEPARATOR . $mainFileName.'php';
$temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $mainFileName.'skip.php';
$temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $mainFileName.'clean.php';
$tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('phpt.');
 
// unlink old test results
@unlink($diff_filename);
@unlink($log_filename);
@unlink($exp_filename);
@unlink($output_filename);
@unlink($memcheck_filename);
@unlink($temp_file);
@unlink($temp_skipif);
@unlink($tmp_post);
@unlink($temp_clean);
}
 
function _runSkipIf($section_text, $temp_skipif, $tested, $ini_settings)
{
$info = '';
$warn = false;
if (array_key_exists('SKIPIF', $section_text) && trim($section_text['SKIPIF'])) {
$this->save_text($temp_skipif, $section_text['SKIPIF']);
$output = $this->system_with_timeout("$this->_php$ini_settings -f \"$temp_skipif\"");
$output = $output[1];
$loutput = ltrim($output);
unlink($temp_skipif);
if (!strncasecmp('skip', $loutput, 4)) {
$skipreason = "SKIP $tested";
if (preg_match('/^\s*skip\s*(.+)\s*/i', $output, $m)) {
$skipreason .= '(reason: ' . $m[1] . ')';
}
if (!isset($this->_options['quiet'])) {
$this->_logger->log(0, $skipreason);
}
if (isset($this->_options['tapoutput'])) {
return array('ok', ' # skip ' . $reason);
}
return 'SKIPPED';
}
 
if (!strncasecmp('info', $loutput, 4)
&& preg_match('/^\s*info\s*(.+)\s*/i', $output, $m)) {
$info = " (info: $m[1])";
}
 
if (!strncasecmp('warn', $loutput, 4)
&& preg_match('/^\s*warn\s*(.+)\s*/i', $output, $m)) {
$warn = true; /* only if there is a reason */
$info = " (warn: $m[1])";
}
}
 
return array('warn' => $warn, 'info' => $info);
}
 
function _stripHeadersCGI($output)
{
$this->headers = array();
if (!empty($this->_options['cgi']) &&
$this->_php == $this->_options['cgi'] &&
preg_match("/^(.*?)(?:\n\n(.*)|\\z)/s", $output, $match)) {
$output = isset($match[2]) ? trim($match[2]) : '';
$this->_headers = $this->_processHeaders($match[1]);
}
 
return $output;
}
 
/**
* Return an array that can be used with array_diff() to compare headers
*
* @param string $text
*/
function _processHeaders($text)
{
$headers = array();
$rh = preg_split("/[\n\r]+/", $text);
foreach ($rh as $line) {
if (strpos($line, ':')!== false) {
$line = explode(':', $line, 2);
$headers[trim($line[0])] = trim($line[1]);
}
}
return $headers;
}
 
function _readFile($file)
{
// Load the sections of the test file.
$section_text = array(
'TEST' => '(unnamed test)',
'SKIPIF' => '',
'GET' => '',
'COOKIE' => '',
'POST' => '',
'ARGS' => '',
'INI' => '',
'CLEAN' => '',
);
 
if (!is_file($file) || !$fp = fopen($file, "r")) {
return PEAR::raiseError("Cannot open test file: $file");
}
 
$section = '';
while (!feof($fp)) {
$line = fgets($fp);
 
// Match the beginning of a section.
if (preg_match('/^--([_A-Z]+)--/', $line, $r)) {
$section = $r[1];
$section_text[$section] = '';
continue;
} elseif (empty($section)) {
fclose($fp);
return PEAR::raiseError("Invalid sections formats in test file: $file");
}
 
// Add to the section text.
$section_text[$section] .= $line;
}
fclose($fp);
 
return $section_text;
}
 
function _writeLog($logname, $data)
{
if (!$log = fopen($logname, 'w')) {
return PEAR::raiseError("Cannot create test log - $logname");
}
fwrite($log, $data);
fclose($log);
}
 
function _resetEnv($section_text, $temp_file)
{
$env = $_ENV;
$env['REDIRECT_STATUS'] = '';
$env['QUERY_STRING'] = '';
$env['PATH_TRANSLATED'] = '';
$env['SCRIPT_FILENAME'] = '';
$env['REQUEST_METHOD'] = '';
$env['CONTENT_TYPE'] = '';
$env['CONTENT_LENGTH'] = '';
if (!empty($section_text['ENV'])) {
if (strpos($section_text['ENV'], '{PWD}') !== false) {
$section_text['ENV'] = str_replace('{PWD}', dirname($temp_file), $section_text['ENV']);
}
foreach (explode("\n", trim($section_text['ENV'])) as $e) {
$e = explode('=', trim($e), 2);
if (!empty($e[0]) && isset($e[1])) {
$env[$e[0]] = $e[1];
}
}
}
if (array_key_exists('GET', $section_text)) {
$env['QUERY_STRING'] = trim($section_text['GET']);
} else {
$env['QUERY_STRING'] = '';
}
if (array_key_exists('COOKIE', $section_text)) {
$env['HTTP_COOKIE'] = trim($section_text['COOKIE']);
} else {
$env['HTTP_COOKIE'] = '';
}
$env['REDIRECT_STATUS'] = '1';
$env['PATH_TRANSLATED'] = $temp_file;
$env['SCRIPT_FILENAME'] = $temp_file;
 
return $env;
}
 
function _processUpload($section_text, $file)
{
if (array_key_exists('UPLOAD', $section_text) && !empty($section_text['UPLOAD'])) {
$upload_files = trim($section_text['UPLOAD']);
$upload_files = explode("\n", $upload_files);
 
$request = "Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737\n" .
"-----------------------------20896060251896012921717172737\n";
foreach ($upload_files as $fileinfo) {
$fileinfo = explode('=', $fileinfo);
if (count($fileinfo) != 2) {
return PEAR::raiseError("Invalid UPLOAD section in test file: $file");
}
if (!realpath(dirname($file) . '/' . $fileinfo[1])) {
return PEAR::raiseError("File for upload does not exist: $fileinfo[1] " .
"in test file: $file");
}
$file_contents = file_get_contents(dirname($file) . '/' . $fileinfo[1]);
$fileinfo[1] = basename($fileinfo[1]);
$request .= "Content-Disposition: form-data; name=\"$fileinfo[0]\"; filename=\"$fileinfo[1]\"\n";
$request .= "Content-Type: text/plain\n\n";
$request .= $file_contents . "\n" .
"-----------------------------20896060251896012921717172737\n";
}
 
if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) {
// encode POST raw
$post = trim($section_text['POST']);
$post = explode('&', $post);
foreach ($post as $i => $post_info) {
$post_info = explode('=', $post_info);
if (count($post_info) != 2) {
return PEAR::raiseError("Invalid POST data in test file: $file");
}
$post_info[0] = rawurldecode($post_info[0]);
$post_info[1] = rawurldecode($post_info[1]);
$post[$i] = $post_info;
}
foreach ($post as $post_info) {
$request .= "Content-Disposition: form-data; name=\"$post_info[0]\"\n\n";
$request .= $post_info[1] . "\n" .
"-----------------------------20896060251896012921717172737\n";
}
unset($section_text['POST']);
}
$section_text['POST_RAW'] = $request;
}
 
return $section_text;
}
 
function _testCleanup($section_text, $temp_clean)
{
if ($section_text['CLEAN']) {
$this->_restorePHPBinary();
 
// perform test cleanup
$this->save_text($temp_clean, $section_text['CLEAN']);
$output = $this->system_with_timeout("$this->_php $temp_clean 2>&1");
if (strlen($output[1])) {
echo "BORKED --CLEAN-- section! output:\n", $output[1];
}
if (file_exists($temp_clean)) {
unlink($temp_clean);
}
}
}
 
function _savePHPBinary()
{
$this->_savephp = $this->_php;
}
 
function _restorePHPBinary()
{
if (isset($this->_savephp))
{
$this->_php = $this->_savephp;
unset($this->_savephp);
}
}
}
?>
/trunk/bibliotheque/pear/PEAR/Config.php
4,19 → 4,12
*
* 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 Stig Bakken <ssb@php.net>
* @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: Config.php,v 1.137 2006/11/19 21:33:00 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
28,7 → 21,6
require_once 'PEAR/Registry.php';
require_once 'PEAR/Installer/Role.php';
require_once 'System.php';
require_once 'PEAR/Remote.php';
 
/**
* Last created PEAR_Config instance.
49,8 → 41,11
 
// default channel and preferred mirror is based on whether we are invoked through
// the "pear" or the "pecl" command
if (!defined('PEAR_RUNTYPE')) {
define('PEAR_RUNTYPE', 'pear');
}
 
if (!defined('PEAR_RUNTYPE') || PEAR_RUNTYPE == 'pear') {
if (PEAR_RUNTYPE == 'pear') {
define('PEAR_CONFIG_DEFAULT_CHANNEL', 'pear.php.net');
} else {
define('PEAR_CONFIG_DEFAULT_CHANNEL', 'pecl.php.net');
84,14 → 79,20
if (getenv('PHP_PEAR_INSTALL_DIR')) {
define('PEAR_CONFIG_DEFAULT_PHP_DIR', getenv('PHP_PEAR_INSTALL_DIR'));
} else {
if (file_exists($PEAR_INSTALL_DIR) && is_dir($PEAR_INSTALL_DIR)) {
define('PEAR_CONFIG_DEFAULT_PHP_DIR',
$PEAR_INSTALL_DIR);
if (@file_exists($PEAR_INSTALL_DIR) && is_dir($PEAR_INSTALL_DIR)) {
define('PEAR_CONFIG_DEFAULT_PHP_DIR', $PEAR_INSTALL_DIR);
} else {
define('PEAR_CONFIG_DEFAULT_PHP_DIR', $PEAR_INSTALL_DIR);
}
}
 
// Default for metadata_dir
if (getenv('PHP_PEAR_METADATA_DIR')) {
define('PEAR_CONFIG_DEFAULT_METADATA_DIR', getenv('PHP_PEAR_METADATA_DIR'));
} else {
define('PEAR_CONFIG_DEFAULT_METADATA_DIR', '');
}
 
// Default for ext_dir
if (getenv('PHP_PEAR_EXTENSION_DIR')) {
define('PEAR_CONFIG_DEFAULT_EXT_DIR', getenv('PHP_PEAR_EXTENSION_DIR'));
131,6 → 132,34
$PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'data');
}
 
// Default for cfg_dir
if (getenv('PHP_PEAR_CFG_DIR')) {
define('PEAR_CONFIG_DEFAULT_CFG_DIR', getenv('PHP_PEAR_CFG_DIR'));
} else {
define('PEAR_CONFIG_DEFAULT_CFG_DIR',
$PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'cfg');
}
 
// Default for www_dir
if (getenv('PHP_PEAR_WWW_DIR')) {
define('PEAR_CONFIG_DEFAULT_WWW_DIR', getenv('PHP_PEAR_WWW_DIR'));
} else {
define('PEAR_CONFIG_DEFAULT_WWW_DIR',
$PEAR_INSTALL_DIR.DIRECTORY_SEPARATOR.'www');
}
 
// Default for man_dir
if (getenv('PHP_PEAR_MAN_DIR')) {
define('PEAR_CONFIG_DEFAULT_MAN_DIR', getenv('PHP_PEAR_MAN_DIR'));
} else {
if (defined('PHP_MANDIR')) { // Added in PHP5.3.7
define('PEAR_CONFIG_DEFAULT_MAN_DIR', PHP_MANDIR);
} else {
define('PEAR_CONFIG_DEFAULT_MAN_DIR', PHP_PREFIX . DIRECTORY_SEPARATOR .
'local' . DIRECTORY_SEPARATOR .'man');
}
}
 
// Default for test_dir
if (getenv('PHP_PEAR_TEST_DIR')) {
define('PEAR_CONFIG_DEFAULT_TEST_DIR', getenv('PHP_PEAR_TEST_DIR'));
233,16 → 262,14
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Config extends PEAR
{
// {{{ properties
 
/**
* Array of config files used.
*
254,7 → 281,7
);
 
var $layers = array();
 
/**
* Configuration data, two-dimensional array where the first
* dimension is the config layer ('user', 'system' and 'default'),
272,7 → 299,7
'system' => array(),
'default' => array(),
);
 
/**
* Configuration values that can be set for a channel
*
281,9 → 308,9
* @access private
*/
var $_channelConfigInfo = array(
'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir',
'test_dir', 'php_bin', 'username', 'password', 'verbose',
'preferred_state', 'umask', 'preferred_mirror',
'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir', 'cfg_dir',
'test_dir', 'www_dir', 'php_bin', 'php_prefix', 'php_suffix', 'username',
'password', 'verbose', 'preferred_state', 'umask', 'preferred_mirror', 'php_ini'
);
 
/**
417,6 → 444,27
'prompt' => 'PEAR data directory',
'group' => 'File Locations (Advanced)',
),
'cfg_dir' => array(
'type' => 'directory',
'default' => PEAR_CONFIG_DEFAULT_CFG_DIR,
'doc' => 'directory where modifiable configuration files are installed',
'prompt' => 'PEAR configuration file directory',
'group' => 'File Locations (Advanced)',
),
'www_dir' => array(
'type' => 'directory',
'default' => PEAR_CONFIG_DEFAULT_WWW_DIR,
'doc' => 'directory where www frontend files (html/js) are installed',
'prompt' => 'PEAR www files directory',
'group' => 'File Locations (Advanced)',
),
'man_dir' => array(
'type' => 'directory',
'default' => PEAR_CONFIG_DEFAULT_MAN_DIR,
'doc' => 'directory where unix manual pages are installed',
'prompt' => 'Systems manpage files directory',
'group' => 'File Locations (Advanced)',
),
'test_dir' => array(
'type' => 'directory',
'default' => PEAR_CONFIG_DEFAULT_TEST_DIR,
427,7 → 475,7
'cache_dir' => array(
'type' => 'directory',
'default' => PEAR_CONFIG_DEFAULT_CACHE_DIR,
'doc' => 'directory which is used for XMLRPC cache',
'doc' => 'directory which is used for web service cache',
'prompt' => 'PEAR Installer cache directory',
'group' => 'File Locations (Advanced)',
),
440,7 → 488,7
),
'download_dir' => array(
'type' => 'directory',
'default' => PEAR_CONFIG_DEFAULT_CACHE_DIR,
'default' => PEAR_CONFIG_DEFAULT_DOWNLOAD_DIR,
'doc' => 'directory which is used for all downloaded files',
'prompt' => 'PEAR Installer download directory',
'group' => 'File Locations (Advanced)',
452,6 → 500,20
'prompt' => 'PHP CLI/CGI binary',
'group' => 'File Locations (Advanced)',
),
'php_prefix' => array(
'type' => 'string',
'default' => '',
'doc' => '--program-prefix for php_bin\'s ./configure, used for pecl installs',
'prompt' => '--program-prefix passed to PHP\'s ./configure',
'group' => 'File Locations (Advanced)',
),
'php_suffix' => array(
'type' => 'string',
'default' => '',
'doc' => '--program-suffix for php_bin\'s ./configure, used for pecl installs',
'prompt' => '--program-suffix passed to PHP\'s ./configure',
'group' => 'File Locations (Advanced)',
),
'php_ini' => array(
'type' => 'file',
'default' => '',
459,6 → 521,13
'prompt' => 'php.ini location',
'group' => 'File Locations (Advanced)',
),
'metadata_dir' => array(
'type' => 'directory',
'default' => PEAR_CONFIG_DEFAULT_METADATA_DIR,
'doc' => 'directory where metadata files are installed (registry, filemap, channels, ...)',
'prompt' => 'PEAR metadata directory',
'group' => 'File Locations (Advanced)',
),
// Maintainers
'username' => array(
'type' => 'string',
541,10 → 610,6
// __channels is reserved - used for channel-specific configuration
);
 
// }}}
 
// {{{ PEAR_Config([file], [defaults_file])
 
/**
* Constructor.
*
559,10 → 624,10
*
* @see PEAR_Config::singleton
*/
function PEAR_Config($user_file = '', $system_file = '', $ftp_file = false,
function __construct($user_file = '', $system_file = '', $ftp_file = false,
$strict = true)
{
$this->PEAR();
parent::__construct();
PEAR_Installer_Role::initializeConfig($this);
$sl = DIRECTORY_SEPARATOR;
if (empty($user_file)) {
572,16 → 637,18
$user_file = getenv('HOME') . $sl . '.pearrc';
}
}
 
if (empty($system_file)) {
$system_file = PEAR_CONFIG_SYSCONFDIR . $sl;
if (OS_WINDOWS) {
$system_file = PEAR_CONFIG_SYSCONFDIR . $sl . 'pearsys.ini';
$system_file .= 'pearsys.ini';
} else {
$system_file = PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.conf';
$system_file .= 'pear.conf';
}
}
 
$this->layers = array_keys($this->configuration);
$this->files['user'] = $user_file;
$this->files['user'] = $user_file;
$this->files['system'] = $system_file;
if ($user_file && file_exists($user_file)) {
$this->pushErrorHandling(PEAR_ERROR_RETURN);
592,7 → 659,7
}
}
 
if ($system_file && file_exists($system_file)) {
if ($system_file && @file_exists($system_file)) {
$this->mergeConfigFile($system_file, false, 'system', $strict);
if ($this->_errorsFound > 0) {
return;
612,15 → 679,33
$this->configuration['default'][$key] = $info['default'];
}
 
$this->_registry['default'] = &new PEAR_Registry($this->configuration['default']['php_dir']);
$this->_registry['default']->setConfig($this);
$this->_registry['default'] = new PEAR_Registry(
$this->configuration['default']['php_dir'], false, false,
$this->configuration['default']['metadata_dir']);
$this->_registry['default']->setConfig($this, false);
$this->_regInitialized['default'] = false;
//$GLOBALS['_PEAR_Config_instance'] = &$this;
}
 
// }}}
// {{{ singleton([file], [defaults_file])
/**
* Return the default locations of user and system configuration files
*/
public static function getDefaultConfigFiles()
{
$sl = DIRECTORY_SEPARATOR;
if (OS_WINDOWS) {
return array(
'user' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.ini',
'system' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pearsys.ini'
);
}
 
return array(
'user' => getenv('HOME') . $sl . '.pearrc',
'system' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.conf'
);
}
 
/**
* Static singleton method. If you want to keep only one instance
* of this class in use, this method will give you a reference to
632,17 → 717,15
*
* @return object an existing or new PEAR_Config instance
*
* @access public
*
* @see PEAR_Config::PEAR_Config
*/
function &singleton($user_file = '', $system_file = '', $strict = true)
public static function &singleton($user_file = '', $system_file = '', $strict = true)
{
if (is_object($GLOBALS['_PEAR_Config_instance'])) {
return $GLOBALS['_PEAR_Config_instance'];
}
 
$t_conf = &new PEAR_Config($user_file, $system_file, false, $strict);
$t_conf = new PEAR_Config($user_file, $system_file, false, $strict);
if ($t_conf->_errorsFound > 0) {
return $t_conf->lastError;
}
651,9 → 734,6
return $GLOBALS['_PEAR_Config_instance'];
}
 
// }}}
// {{{ validConfiguration()
 
/**
* Determine whether any configuration files have been detected, and whether a
* registry object can be retrieved from this configuration.
665,12 → 745,10
if ($this->isDefinedLayer('user') || $this->isDefinedLayer('system')) {
return true;
}
 
return false;
}
 
// }}}
// {{{ readConfigFile([file], [layer])
 
/**
* Reads configuration data from a file. All existing values in
* the config layer are discarded and replaced with data from the
691,26 → 769,26
}
 
$data = $this->_readConfigDataFrom($file);
 
if (PEAR::isError($data)) {
if ($strict) {
$this->_errorsFound++;
$this->lastError = $data;
 
return $data;
} else {
if (!$strict) {
return true;
}
} else {
$this->files[$layer] = $file;
 
$this->_errorsFound++;
$this->lastError = $data;
 
return $data;
}
 
$this->files[$layer] = $file;
$this->_decodeInput($data);
$this->configuration[$layer] = $data;
$this->_setupChannels();
if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) {
$this->_registry[$layer] = &new PEAR_Registry($phpdir);
$this->_registry[$layer]->setConfig($this);
$this->_registry[$layer] = new PEAR_Registry(
$phpdir, false, false,
$this->get('metadata_dir', $layer, 'pear.php.net'));
$this->_registry[$layer]->setConfig($this, false);
$this->_regInitialized[$layer] = false;
} else {
unset($this->_registry[$layer]);
718,8 → 796,6
return true;
}
 
// }}}
 
/**
* @param string url to the remote config file, like ftp://www.example.com/pear/config.ini
* @return true|PEAR_Error
735,61 → 811,64
require_once 'PEAR/FTP.php';
}
}
if (class_exists('PEAR_FTP')) {
$this->_ftp = &new PEAR_FTP;
$this->_ftp->pushErrorHandling(PEAR_ERROR_RETURN);
$e = $this->_ftp->init($path);
if (PEAR::isError($e)) {
$this->_ftp->popErrorHandling();
return $e;
}
$tmp = System::mktemp('-d');
PEAR_Common::addTempFile($tmp);
$e = $this->_ftp->get(basename($path), $tmp . DIRECTORY_SEPARATOR .
'pear.ini', false, FTP_BINARY);
if (PEAR::isError($e)) {
$this->_ftp->popErrorHandling();
return $e;
}
PEAR_Common::addTempFile($tmp . DIRECTORY_SEPARATOR . 'pear.ini');
$this->_ftp->disconnect();
 
if (!class_exists('PEAR_FTP')) {
return PEAR::raiseError('PEAR_RemoteInstaller must be installed to use remote config');
}
 
$this->_ftp = new PEAR_FTP;
$this->_ftp->pushErrorHandling(PEAR_ERROR_RETURN);
$e = $this->_ftp->init($path);
if (PEAR::isError($e)) {
$this->_ftp->popErrorHandling();
$this->files['ftp'] = $tmp . DIRECTORY_SEPARATOR . 'pear.ini';
$e = $this->readConfigFile(null, 'ftp');
if (PEAR::isError($e)) {
return $e;
}
$fail = array();
foreach ($this->configuration_info as $key => $val) {
if (in_array($this->getGroup($key),
array('File Locations', 'File Locations (Advanced)')) &&
$this->getType($key) == 'directory') {
// any directory configs must be set for this to work
if (!isset($this->configuration['ftp'][$key])) {
$fail[] = $key;
}
return $e;
}
 
$tmp = System::mktemp('-d');
PEAR_Common::addTempFile($tmp);
$e = $this->_ftp->get(basename($path), $tmp . DIRECTORY_SEPARATOR .
'pear.ini', false, FTP_BINARY);
if (PEAR::isError($e)) {
$this->_ftp->popErrorHandling();
return $e;
}
 
PEAR_Common::addTempFile($tmp . DIRECTORY_SEPARATOR . 'pear.ini');
$this->_ftp->disconnect();
$this->_ftp->popErrorHandling();
$this->files['ftp'] = $tmp . DIRECTORY_SEPARATOR . 'pear.ini';
$e = $this->readConfigFile(null, 'ftp');
if (PEAR::isError($e)) {
return $e;
}
 
$fail = array();
foreach ($this->configuration_info as $key => $val) {
if (in_array($this->getGroup($key),
array('File Locations', 'File Locations (Advanced)')) &&
$this->getType($key) == 'directory') {
// any directory configs must be set for this to work
if (!isset($this->configuration['ftp'][$key])) {
$fail[] = $key;
}
}
if (count($fail)) {
$fail = '"' . implode('", "', $fail) . '"';
unset($this->files['ftp']);
unset($this->configuration['ftp']);
return PEAR::raiseError('ERROR: Ftp configuration file must set all ' .
'directory configuration variables. These variables were not set: ' .
$fail);
} else {
return true;
}
} else {
return PEAR::raiseError('PEAR_RemoteInstaller must be installed to use remote config');
}
 
if (!count($fail)) {
return true;
}
 
$fail = '"' . implode('", "', $fail) . '"';
unset($this->files['ftp']);
unset($this->configuration['ftp']);
return PEAR::raiseError('ERROR: Ftp configuration file must set all ' .
'directory configuration variables. These variables were not set: ' .
$fail);
} while (false); // poor man's catch
unset($this->files['ftp']);
return PEAR::raiseError('no remote host specified');
}
 
// {{{ _setupChannels()
/**
* Reads the existing configurations and creates the _channels array from it
*/
808,26 → 887,20
$this->setChannels($this->_channels);
}
 
// }}}
// {{{ deleteChannel(channel)
 
function deleteChannel($channel)
{
$ch = strtolower($channel);
foreach ($this->configuration as $layer => $data) {
if (isset($data['__channels'])) {
if (isset($data['__channels'][strtolower($channel)])) {
unset($this->configuration[$layer]['__channels'][strtolower($channel)]);
}
if (isset($data['__channels']) && isset($data['__channels'][$ch])) {
unset($this->configuration[$layer]['__channels'][$ch]);
}
}
 
$this->_channels = array_flip($this->_channels);
unset($this->_channels[strtolower($channel)]);
unset($this->_channels[$ch]);
$this->_channels = array_flip($this->_channels);
}
 
// }}}
// {{{ mergeConfigFile(file, [override], [layer])
 
/**
* Merges data into a config layer from a file. Does the same
* thing as readConfigFile, except it does not replace all
843,20 → 916,23
if (empty($this->files[$layer])) {
return $this->raiseError("unknown config layer `$layer'");
}
 
if ($file === null) {
$file = $this->files[$layer];
}
 
$data = $this->_readConfigDataFrom($file);
if (PEAR::isError($data)) {
if ($strict) {
$this->_errorsFound++;
$this->lastError = $data;
 
return $data;
} else {
if (!$strict) {
return true;
}
 
$this->_errorsFound++;
$this->lastError = $data;
 
return $data;
}
 
$this->_decodeInput($data);
if ($override) {
$this->configuration[$layer] =
865,10 → 941,13
$this->configuration[$layer] =
PEAR_Config::arrayMergeRecursive($data, $this->configuration[$layer]);
}
 
$this->_setupChannels();
if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) {
$this->_registry[$layer] = &new PEAR_Registry($phpdir);
$this->_registry[$layer]->setConfig($this);
$this->_registry[$layer] = new PEAR_Registry(
$phpdir, false, false,
$this->get('metadata_dir', $layer, 'pear.php.net'));
$this->_registry[$layer]->setConfig($this, false);
$this->_regInitialized[$layer] = false;
} else {
unset($this->_registry[$layer]);
876,15 → 955,12
return true;
}
 
// }}}
// {{{ arrayMergeRecursive($arr2, $arr1)
/**
* @param array
* @param array
* @return array
* @static
*/
function arrayMergeRecursive($arr2, $arr1)
public static function arrayMergeRecursive($arr2, $arr1)
{
$ret = array();
foreach ($arr2 as $key => $data) {
903,12 → 979,10
unset($arr1[$key]);
}
}
 
return array_merge($ret, $arr1);
}
 
// }}}
// {{{ writeConfigFile([file], [layer])
 
/**
* Writes data into a config layer from a file.
*
930,12 → 1004,15
}
return true;
}
 
if (empty($this->files[$layer])) {
return $this->raiseError("unknown config file type `$layer'");
}
 
if ($file === null) {
$file = $this->files[$layer];
}
 
$data = ($data === null) ? $this->configuration[$layer] : $data;
$this->_encodeOutput($data);
$opt = array('-p', dirname($file));
942,13 → 1019,16
if (!@System::mkDir($opt)) {
return $this->raiseError("could not create directory: " . dirname($file));
}
 
if (file_exists($file) && is_file($file) && !is_writeable($file)) {
return $this->raiseError("no write access to $file!");
}
 
$fp = @fopen($file, "w");
if (!$fp) {
return $this->raiseError("PEAR_Config::writeConfigFile fopen('$file','w') failed ($php_errormsg)");
}
 
$contents = "#PEAR_Config 0.9\n" . serialize($data);
if (!@fwrite($fp, $contents)) {
return $this->raiseError("PEAR_Config::writeConfigFile: fwrite failed ($php_errormsg)");
956,17 → 1036,12
return true;
}
 
// }}}
// {{{ _readConfigDataFrom(file)
 
/**
* Reads configuration data from a file and returns the parsed data
* in an array.
*
* @param string file to read from
*
* @return array configuration data or a PEAR error on failure
*
* @access private
*/
function _readConfigDataFrom($file)
975,19 → 1050,17
if (file_exists($file)) {
$fp = @fopen($file, "r");
}
 
if (!$fp) {
return $this->raiseError("PEAR_Config::readConfigFile fopen('$file','r') failed");
}
 
$size = filesize($file);
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
fclose($fp);
$contents = file_get_contents($file);
if (empty($contents)) {
return $this->raiseError('Configuration file "' . $file . '" is empty');
}
set_magic_quotes_runtime($rt);
 
$version = false;
if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) {
999,8 → 1072,8
$version = '0.1';
}
}
 
if ($version && version_compare("$version", '1', '<')) {
 
// no '@', it is possible that unserialize
// raises a notice but it seems to block IO to
// STDOUT if a '@' is used and a notice is raise
1019,116 → 1092,124
$error = "PEAR_Config: bad data in $file";
$err = $this->raiseError($error);
return $err;
} else {
$data = array();
}
 
$data = array();
}
// add parsing of newer formats here...
} else {
$err = $this->raiseError("$file: unknown version `$version'");
return $err;
return $err;
}
 
return $data;
}
 
// }}}
// {{{ getConfFile(layer)
/**
* Gets the file used for storing the config for a layer
*
* @param string $layer 'user' or 'system'
*/
 
function getConfFile($layer)
{
return $this->files[$layer];
}
 
// }}}
 
/**
* @param string Configuration class name, used for detecting duplicate calls
* @param array information on a role as parsed from its xml file
* @return true|PEAR_Error
* @access private
*/
function _addConfigVars($vars)
function _addConfigVars($class, $vars)
{
static $called = array();
if (isset($called[$class])) {
return;
}
 
$called[$class] = 1;
if (count($vars) > 3) {
return $this->raiseError('Roles can only define 3 new config variables or less');
}
 
foreach ($vars as $name => $var) {
if (!is_array($var)) {
return $this->raiseError('Configuration information must be an array');
}
 
if (!isset($var['type'])) {
return $this->raiseError('Configuration information must contain a type');
} else {
if (!in_array($var['type'],
array('string', 'mask', 'password', 'directory', 'file', 'set'))) {
return $this->raiseError(
'Configuration type must be one of directory, file, string, ' .
'mask, set, or password');
}
} elseif (!in_array($var['type'],
array('string', 'mask', 'password', 'directory', 'file', 'set'))) {
return $this->raiseError(
'Configuration type must be one of directory, file, string, ' .
'mask, set, or password');
}
if (!isset($var['default'])) {
return $this->raiseError(
'Configuration information must contain a default value ("default" index)');
} else {
if (is_array($var['default'])) {
$real_default = '';
foreach ($var['default'] as $config_var => $val) {
if (strpos($config_var, 'text') === 0) {
$real_default .= $val;
} elseif (strpos($config_var, 'constant') === 0) {
if (defined($val)) {
$real_default .= constant($val);
} else {
return $this->raiseError(
'Unknown constant "' . $val . '" requested in ' .
'default value for configuration variable "' .
$name . '"');
}
} elseif (isset($this->configuration_info[$config_var])) {
$real_default .=
$this->configuration_info[$config_var]['default'];
} else {
}
 
if (is_array($var['default'])) {
$real_default = '';
foreach ($var['default'] as $config_var => $val) {
if (strpos($config_var, 'text') === 0) {
$real_default .= $val;
} elseif (strpos($config_var, 'constant') === 0) {
if (!defined($val)) {
return $this->raiseError(
'Unknown request for "' . $config_var . '" value in ' .
'Unknown constant "' . $val . '" requested in ' .
'default value for configuration variable "' .
$name . '"');
}
 
$real_default .= constant($val);
} elseif (isset($this->configuration_info[$config_var])) {
$real_default .=
$this->configuration_info[$config_var]['default'];
} else {
return $this->raiseError(
'Unknown request for "' . $config_var . '" value in ' .
'default value for configuration variable "' .
$name . '"');
}
$var['default'] = $real_default;
}
if ($var['type'] == 'integer') {
$var['default'] = (integer) $var['default'];
}
$var['default'] = $real_default;
}
 
if ($var['type'] == 'integer') {
$var['default'] = (integer) $var['default'];
}
 
if (!isset($var['doc'])) {
return $this->raiseError(
'Configuration information must contain a summary ("doc" index)');
}
 
if (!isset($var['prompt'])) {
return $this->raiseError(
'Configuration information must contain a simple prompt ("prompt" index)');
}
 
if (!isset($var['group'])) {
return $this->raiseError(
'Configuration information must contain a simple group ("group" index)');
}
 
if (isset($this->configuration_info[$name])) {
return $this->raiseError('Configuration variable "' . $name .
'" already exists');
}
 
$this->configuration_info[$name] = $var;
// fix bug #7351: setting custom config variable in a channel fails
$this->_channelConfigInfo[] = $name;
}
 
return true;
}
 
// {{{ _encodeOutput(&data)
 
/**
* Encodes/scrambles configuration data before writing to files.
* Currently, 'password' values will be base64-encoded as to avoid
1135,9 → 1216,7
* that people spot cleartext passwords by accident.
*
* @param array (reference) array to encode values in
*
* @return bool TRUE on success
*
* @access private
*/
function _encodeOutput(&$data)
1148,9 → 1227,11
$this->_encodeOutput($data['__channels'][$channel]);
}
}
 
if (!isset($this->configuration_info[$key])) {
continue;
}
 
$type = $this->configuration_info[$key]['type'];
switch ($type) {
// we base64-encode passwords so they are at least
1165,19 → 1246,15
}
}
}
 
return true;
}
 
// }}}
// {{{ _decodeInput(&data)
 
/**
* Decodes/unscrambles configuration data after reading from files.
*
* @param array (reference) array to encode values in
*
* @return bool TRUE on success
*
* @access private
*
* @see PEAR_Config::_encodeOutput
1187,6 → 1264,7
if (!is_array($data)) {
return true;
}
 
foreach ($data as $key => $value) {
if ($key == '__channels') {
foreach ($data['__channels'] as $channel => $blah) {
1193,9 → 1271,11
$this->_decodeInput($data['__channels'][$channel]);
}
}
 
if (!isset($this->configuration_info[$key])) {
continue;
}
 
$type = $this->configuration_info[$key]['type'];
switch ($type) {
case 'password': {
1208,11 → 1288,10
}
}
}
 
return true;
}
 
// }}}
// {{{ getDefaultChannel([layer])
/**
* Retrieve the default channel.
*
1234,27 → 1313,28
} elseif (isset($this->configuration[$layer]['default_channel'])) {
$ret = $this->configuration[$layer]['default_channel'];
}
 
if ($ret == 'pear.php.net' && defined('PEAR_RUNTYPE') && PEAR_RUNTYPE == 'pecl') {
$ret = 'pecl.php.net';
}
 
if ($ret) {
if ($ret != 'pear.php.net') {
$this->_lazyChannelSetup();
}
 
return $ret;
}
 
return PEAR_CONFIG_DEFAULT_CHANNEL;
}
 
// {{{ get(key, [layer])
/**
* Returns a configuration value, prioritizing layers as per the
* layers property.
*
* @param string config key
*
* @return mixed the config value, or NULL if not found
*
* @access public
*/
function get($key, $layer = null, $channel = false)
1262,12 → 1342,15
if (!isset($this->configuration_info[$key])) {
return null;
}
 
if ($key == '__channels') {
return null;
}
 
if ($key == 'default_channel') {
return $this->getDefaultChannel($layer);
}
 
if (!$channel) {
$channel = $this->getDefaultChannel();
} elseif ($channel != 'pear.php.net') {
1274,7 → 1357,7
$this->_lazyChannelSetup();
}
$channel = strtolower($channel);
 
$test = (in_array($key, $this->_channelConfigInfo)) ?
$this->_getChannelValue($key, $layer, $channel) :
null;
1288,6 → 1371,7
}
return $test;
}
 
if ($layer === null) {
foreach ($this->layers as $layer) {
if (isset($this->configuration[$layer][$key])) {
1299,13 → 1383,15
return $this->_prependPath($test, $this->_installRoot);
}
}
 
if ($key == 'preferred_mirror') {
$reg = &$this->getRegistry();
if (is_object($reg)) {
$chan = &$reg->getChannel($channel);
$chan = $reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $channel;
}
 
if (!$chan->getMirror($test) && $chan->getName() != $test) {
return $channel; // mirror does not exist
}
1323,33 → 1409,33
return $this->_prependPath($test, $this->_installRoot);
}
}
 
if ($key == 'preferred_mirror') {
$reg = &$this->getRegistry();
if (is_object($reg)) {
$chan = &$reg->getChannel($channel);
$chan = $reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $channel;
}
 
if (!$chan->getMirror($test) && $chan->getName() != $test) {
return $channel; // mirror does not exist
}
}
}
 
return $test;
}
 
return null;
}
 
// }}}
// {{{ _getChannelValue(key, value, [layer])
/**
* Returns a channel-specific configuration value, prioritizing layers as per the
* layers property.
*
* @param string config key
*
* @return mixed the config value, or NULL if not found
*
* @access private
*/
function _getChannelValue($key, $layer, $channel)
1357,6 → 1443,7
if ($key == '__channels' || $channel == 'pear.php.net') {
return null;
}
 
$ret = null;
if ($layer === null) {
foreach ($this->layers as $ilayer) {
1368,33 → 1455,35
} elseif (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
$ret = $this->configuration[$layer]['__channels'][$channel][$key];
}
if ($key == 'preferred_mirror') {
if ($ret !== null) {
$reg = &$this->getRegistry($layer);
if (is_object($reg)) {
$chan = &$reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $channel;
}
if (!$chan->getMirror($ret) && $chan->getName() != $ret) {
return $channel; // mirror does not exist
}
 
if ($key != 'preferred_mirror') {
return $ret;
}
 
 
if ($ret !== null) {
$reg = &$this->getRegistry($layer);
if (is_object($reg)) {
$chan = $reg->getChannel($channel);
if (PEAR::isError($chan)) {
return $channel;
}
return $ret;
 
if (!$chan->getMirror($ret) && $chan->getName() != $ret) {
return $channel; // mirror does not exist
}
}
if ($channel != $this->getDefaultChannel($layer)) {
return $channel; // we must use the channel name as the preferred mirror
// if the user has not chosen an alternate
} else {
return $this->getDefaultChannel($layer);
}
 
return $ret;
}
return $ret;
}
 
if ($channel != $this->getDefaultChannel($layer)) {
return $channel; // we must use the channel name as the preferred mirror
// if the user has not chosen an alternate
}
 
// }}}
// {{{ set(key, value, [layer])
return $this->getDefaultChannel($layer);
}
 
/**
* Set a config value in a specific layer (defaults to 'user').
1413,9 → 1502,11
if ($key == '__channels') {
return false;
}
 
if (!isset($this->configuration[$layer])) {
return false;
}
 
if ($key == 'default_channel') {
// can only set this value globally
$channel = 'pear.php.net';
1423,24 → 1514,29
$this->_lazyChannelSetup($layer);
}
}
 
if ($key == 'preferred_mirror') {
if ($channel == '__uri') {
return false; // can't set the __uri pseudo-channel's mirror
}
 
$reg = &$this->getRegistry($layer);
if (is_object($reg)) {
$chan = &$reg->getChannel($channel ? $channel : 'pear.php.net');
$chan = $reg->getChannel($channel ? $channel : 'pear.php.net');
if (PEAR::isError($chan)) {
return false;
}
 
if (!$chan->getMirror($value) && $chan->getName() != $value) {
return false; // mirror does not exist
}
}
}
if (empty($this->configuration_info[$key])) {
 
if (!isset($this->configuration_info[$key])) {
return false;
}
 
extract($this->configuration_info[$key]);
switch ($type) {
case 'integer':
1461,9 → 1557,11
break;
}
}
 
if (!$channel) {
$channel = $this->get('default_channel', null, 'pear.php.net');
}
 
if (!in_array($channel, $this->_channels)) {
$this->_lazyChannelSetup($layer);
$reg = &$this->getRegistry($layer);
1470,56 → 1568,63
if ($reg) {
$channel = $reg->channelName($channel);
}
 
if (!in_array($channel, $this->_channels)) {
return false;
}
}
 
if ($channel != 'pear.php.net') {
if (in_array($key, $this->_channelConfigInfo)) {
$this->configuration[$layer]['__channels'][$channel][$key] = $value;
return true;
} else {
return false;
}
} else {
if ($key == 'default_channel') {
if (!isset($reg)) {
$reg = &$this->getRegistry($layer);
if (!$reg) {
$reg = &$this->getRegistry();
}
 
return false;
}
 
if ($key == 'default_channel') {
if (!isset($reg)) {
$reg = &$this->getRegistry($layer);
if (!$reg) {
$reg = &$this->getRegistry();
}
if ($reg) {
$value = $reg->channelName($value);
}
if (!$value) {
return false;
}
}
 
if ($reg) {
$value = $reg->channelName($value);
}
 
if (!$value) {
return false;
}
}
 
$this->configuration[$layer][$key] = $value;
if ($key == 'php_dir' && !$this->_noRegistry) {
if (!isset($this->_registry[$layer]) ||
$value != $this->_registry[$layer]->install_dir) {
$this->_registry[$layer] = &new PEAR_Registry($value);
$this->_registry[$layer] = new PEAR_Registry($value);
$this->_regInitialized[$layer] = false;
$this->_registry[$layer]->setConfig($this);
$this->_registry[$layer]->setConfig($this, false);
}
}
 
return true;
}
 
// }}}
function _lazyChannelSetup($uselayer = false)
{
if ($this->_noRegistry) {
return;
}
 
$merge = false;
foreach ($this->_registry as $layer => $p) {
if ($uselayer && $uselayer != $layer) {
continue;
}
 
if (!$this->_regInitialized[$layer]) {
if ($layer == 'default' && isset($this->_registry['user']) ||
isset($this->_registry['system'])) {
1526,10 → 1631,13
// only use the default registry if there are no alternatives
continue;
}
 
if (!is_object($this->_registry[$layer])) {
if ($phpdir = $this->get('php_dir', $layer, 'pear.php.net')) {
$this->_registry[$layer] = &new PEAR_Registry($phpdir);
$this->_registry[$layer]->setConfig($this);
$this->_registry[$layer] = new PEAR_Registry(
$phpdir, false, false,
$this->get('metadata_dir', $layer, 'pear.php.net'));
$this->_registry[$layer]->setConfig($this, false);
$this->_regInitialized[$layer] = false;
} else {
unset($this->_registry[$layer]);
1536,6 → 1644,7
return;
}
}
 
$this->setChannels($this->_registry[$layer]->listChannels(), $merge);
$this->_regInitialized[$layer] = true;
$merge = true;
1542,8 → 1651,7
}
}
}
// {{{ setChannels()
 
/**
* Set the list of channels.
*
1557,16 → 1665,19
if (!is_array($channels)) {
return false;
}
 
if ($merge) {
$this->_channels = array_merge($this->_channels, $channels);
} else {
$this->_channels = $channels;
}
 
foreach ($channels as $channel) {
$channel = strtolower($channel);
if ($channel == 'pear.php.net') {
continue;
}
 
foreach ($this->layers as $layer) {
if (!isset($this->configuration[$layer]['__channels'])) {
$this->configuration[$layer]['__channels'] = array();
1577,12 → 1688,10
}
}
}
 
return true;
}
 
// }}}
// {{{ getType(key)
 
/**
* Get the type of a config value.
*
1602,14 → 1711,10
return false;
}
 
// }}}
// {{{ getDocs(key)
 
/**
* Get the documentation for a config value.
*
* @param string config key
*
* @return string documentation string
*
* @access public
1620,16 → 1725,14
if (isset($this->configuration_info[$key])) {
return $this->configuration_info[$key]['doc'];
}
 
return false;
}
// }}}
// {{{ getPrompt(key)
 
/**
* Get the short documentation for a config value.
*
* @param string config key
*
* @return string short documentation string
*
* @access public
1640,16 → 1743,14
if (isset($this->configuration_info[$key])) {
return $this->configuration_info[$key]['prompt'];
}
 
return false;
}
// }}}
// {{{ getGroup(key)
 
/**
* Get the parameter group for a config key.
*
* @param string config key
*
* @return string parameter group
*
* @access public
1660,12 → 1761,10
if (isset($this->configuration_info[$key])) {
return $this->configuration_info[$key]['group'];
}
 
return false;
}
 
// }}}
// {{{ getGroups()
 
/**
* Get the list of parameter groups.
*
1680,17 → 1779,14
foreach ($this->configuration_info as $key => $info) {
$tmp[$info['group']] = 1;
}
 
return array_keys($tmp);
}
 
// }}}
// {{{ getGroupKeys()
 
/**
* Get the list of the parameters in a group.
*
* @param string $group parameter group
*
* @return array list of parameters in $group
*
* @access public
1704,18 → 1800,15
$keys[] = $key;
}
}
 
return $keys;
}
 
// }}}
// {{{ getSetValues(key)
 
/**
* Get the list of allowed set values for a config value. Returns
* NULL for config values that are not sets.
*
* @param string config key
*
* @return array enumerated array of set values, or NULL if the
* config key is unknown or not a set
*
1733,14 → 1826,13
if (key($valid_set) === 0) {
return $valid_set;
}
 
return array_keys($valid_set);
}
 
return null;
}
 
// }}}
// {{{ getKeys()
 
/**
* Get all the current config keys.
*
1758,29 → 1850,30
$keys = array_merge($keys, $configs);
}
}
 
unset($test['__channels']);
$keys = array_merge($keys, $test);
 
}
return array_keys($keys);
}
 
// }}}
// {{{ remove(key, [layer])
 
/**
* Remove the a config key from a specific config layer.
*
* @param string config key
*
* @param string (optional) config layer
*
* @param string (optional) channel (defaults to default channel)
* @return bool TRUE on success, FALSE on failure
*
* @access public
*/
function remove($key, $layer = 'user')
function remove($key, $layer = 'user', $channel = null)
{
$channel = $this->getDefaultChannel();
if ($channel === null) {
$channel = $this->getDefaultChannel();
}
 
if ($channel !== 'pear.php.net') {
if (isset($this->configuration[$layer]['__channels'][$channel][$key])) {
unset($this->configuration[$layer]['__channels'][$channel][$key]);
1787,23 → 1880,20
return true;
}
}
 
if (isset($this->configuration[$layer][$key])) {
unset($this->configuration[$layer][$key]);
return true;
}
 
return false;
}
 
// }}}
// {{{ removeLayer(layer)
 
/**
* Temporarily remove an entire config layer. USE WITH CARE!
*
* @param string config key
*
* @param string (optional) config layer
*
* @return bool TRUE on success, FALSE on failure
*
* @access public
1814,17 → 1904,14
$this->configuration[$layer] = array();
return true;
}
 
return false;
}
 
// }}}
// {{{ store([layer])
 
/**
* Stores configuration data in a layer.
*
* @param string config layer to store
*
* @return bool TRUE on success, or PEAR error on failure
*
* @access public
1834,29 → 1921,7
return $this->writeConfigFile(null, $layer, $data);
}
 
// }}}
// {{{ toDefault(key)
 
/**
* Unset the user-defined value of a config key, reverting the
* value to the system-defined one.
*
* @param string config key
*
* @return bool TRUE on success, FALSE on failure
*
* @access public
*/
function toDefault($key)
{
trigger_error("PEAR_Config::toDefault() deprecated, use PEAR_Config::remove() instead", E_USER_NOTICE);
return $this->remove($key, 'user');
}
 
// }}}
// {{{ definedBy(key)
 
/**
* Tells what config layer that gets to define a key.
*
* @param string config key
1881,6 → 1946,7
return $layer;
}
}
 
if (isset($this->configuration[$layer][$key])) {
if ($returnchannel) {
return array('layer' => $layer, 'channel' => 'pear.php.net');
1888,37 → 1954,14
return $layer;
}
}
 
return '';
}
 
// }}}
// {{{ isDefaulted(key)
 
/**
* Tells whether a config value has a system-defined value.
*
* @param string config key
*
* @return bool
*
* @access public
*
* @deprecated
*/
function isDefaulted($key)
{
trigger_error("PEAR_Config::isDefaulted() deprecated, use PEAR_Config::definedBy() instead", E_USER_NOTICE);
return $this->definedBy($key) == 'system';
}
 
// }}}
// {{{ isDefined(key)
 
/**
* Tells whether a given key exists as a config value.
*
* @param string config key
*
* @return bool whether <config key> exists in this object
*
* @access public
1930,17 → 1973,14
return true;
}
}
 
return false;
}
 
// }}}
// {{{ isDefinedLayer(key)
 
/**
* Tells whether a given config layer exists.
*
* @param string config layer
*
* @return bool whether <config layer> exists in this object
*
* @access public
1950,9 → 1990,6
return isset($this->configuration[$layer]);
}
 
// }}}
// {{{ getLayers()
 
/**
* Returns the layers defined (except the 'default' one)
*
1965,13 → 2002,10
return array_keys($cf);
}
 
// }}}
// {{{ apiVersion()
function apiVersion()
{
return '1.1';
}
// }}}
 
/**
* @return PEAR_Registry
1978,11 → 2012,7
*/
function &getRegistry($use = null)
{
if ($use === null) {
$layer = 'user';
} else {
$layer = $use;
}
$layer = $use === null ? 'user' : $use;
if (isset($this->_registry[$layer])) {
return $this->_registry[$layer];
} elseif ($use === null && isset($this->_registry['system'])) {
1992,12 → 2022,13
} elseif ($use) {
$a = false;
return $a;
} else {
// only go here if null was passed in
echo "CRITICAL ERROR: Registry could not be initialized from any value";
exit(1);
}
 
// only go here if null was passed in
echo "CRITICAL ERROR: Registry could not be initialized from any value";
exit(1);
}
 
/**
* This is to allow customization like the use of installroot
* @param PEAR_Registry
2008,13 → 2039,16
if ($this->_noRegistry) {
return false;
}
 
if (!in_array($layer, array('user', 'system'))) {
return false;
}
 
$this->_registry[$layer] = &$reg;
if (is_object($reg)) {
$this->_registry[$layer]->setConfig($this);
$this->_registry[$layer]->setConfig($this, false);
}
 
return true;
}
 
2024,15 → 2058,6
}
 
/**
* @return PEAR_Remote
*/
function &getRemote()
{
$remote = &new PEAR_Remote($this);
return $remote;
}
 
/**
* @return PEAR_REST
*/
function &getREST($version, $options = array())
2041,7 → 2066,8
if (!class_exists($class = 'PEAR_REST_' . $version)) {
require_once 'PEAR/REST/' . $version . '.php';
}
$remote = &new $class($this, $options);
 
$remote = new $class($this, $options);
return $remote;
}
 
2054,14 → 2080,12
{
if (isset($this->_ftp)) {
return $this->_ftp;
} else {
$a = false;
return $a;
}
 
$a = false;
return $a;
}
 
// {{{ _prependPath($path, $prepend)
 
function _prependPath($path, $prepend)
{
if (strlen($prepend) > 0) {
2078,7 → 2102,6
}
return $path;
}
// }}}
 
/**
* @param string|false installation directory to prepend to all _dir variables, or false to
2097,12 → 2120,12
continue;
}
$this->_registry[$layer] =
&new PEAR_Registry($this->get('php_dir', $layer, 'pear.php.net'));
$this->_registry[$layer]->setConfig($this);
new PEAR_Registry(
$this->get('php_dir', $layer, 'pear.php.net'), false, false,
$this->get('metadata_dir', $layer, 'pear.php.net'));
$this->_registry[$layer]->setConfig($this, false);
$this->_regInitialized[$layer] = false;
}
}
}
}
 
?>
/trunk/bibliotheque/pear/PEAR/PackageFile/Parser/v1.php
4,18 → 4,11
*
* 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: v1.php,v 1.22 2006/03/27 05:25:48 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
28,8 → 21,8
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @PEAR-VER@
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
66,7 → 59,7
* @param string contents of package.xml file, version 1.0
* @return bool success of parsing
*/
function parse($data, $file, $archive = false)
function &parse($data, $file, $archive = false)
{
if (!extension_loaded('xml')) {
return PEAR::raiseError('Cannot create xml parser for parsing package.xml, no xml extension');
73,7 → 66,8
}
$xp = xml_parser_create();
if (!$xp) {
return PEAR::raiseError('Cannot create xml parser for parsing package.xml');
$a = &PEAR::raiseError('Cannot create xml parser for parsing package.xml');
return $a;
}
xml_set_object($xp, $this);
xml_set_element_handler($xp, '_element_start_1_0', '_element_end_1_0');
96,8 → 90,9
$code = xml_get_error_code($xp);
$line = xml_get_current_line_number($xp);
xml_parser_free($xp);
return PEAR::raiseError(sprintf("XML error: %s at line %d",
$a = PEAR::raiseError(sprintf("XML error: %s at line %d",
$str = xml_error_string($code), $line), 2);
return $a;
}
 
xml_parser_free($xp);
132,6 → 127,8
foreach (explode("\n", $str) as $line) {
if (substr($line, 0, $indent_len) == $indent) {
$data .= substr($line, $indent_len) . "\n";
} elseif (trim(substr($line, 0, $indent_len))) {
$data .= ltrim($line);
}
}
return $data;
167,7 → 164,7
if (array_key_exists('name', $attribs) && $attribs['name'] != '/') {
$attribs['name'] = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'),
$attribs['name']);
if (strrpos($attribs['name'], '/') == strlen($attribs['name']) - 1) {
if (strrpos($attribs['name'], '/') === strlen($attribs['name']) - 1) {
$attribs['name'] = substr($attribs['name'], 0,
strlen($attribs['name']) - 1);
}
333,7 → 330,6
$this->current_maintainer['role'] = $data;
break;
case 'version':
//$data = ereg_replace ('[^a-zA-Z0-9._\-]', '_', $data);
if ($this->in_changelog) {
$this->current_release['version'] = $data;
} else {
350,7 → 346,8
case 'notes':
// try to "de-indent" release notes in case someone
// has been over-indenting their xml ;-)
$data = $this->_unIndent($this->cdata);
// Trim only on the right side
$data = rtrim($this->_unIndent($this->cdata));
if ($this->in_changelog) {
$this->current_release['release_notes'] = $data;
} else {
/trunk/bibliotheque/pear/PEAR/PackageFile/Parser/v2.php
4,18 → 4,11
*
* 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: v2.php,v 1.19 2006/01/23 17:39:52 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
29,8 → 22,8
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @PEAR-VER@
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
70,6 → 63,8
foreach (explode("\n", $str) as $line) {
if (substr($line, 0, $indent_len) == $indent) {
$data .= substr($line, $indent_len) . "\n";
} else {
$data .= $line . "\n";
}
}
return $data;
97,19 → 92,21
* a subclass
* @return PEAR_PackageFile_v2
*/
function &parse($data, $file, $archive = false, $class = 'PEAR_PackageFile_v2')
function parse($data, $file = null, $archive = false, $class = 'PEAR_PackageFile_v2')
{
if (PEAR::isError($err = parent::parse($data, $file))) {
if (PEAR::isError($err = parent::parse($data))) {
return $err;
}
 
$ret = new $class;
$ret->encoding = $this->encoding;
$ret->setConfig($this->_config);
if (isset($this->_logger)) {
$ret->setLogger($this->_logger);
}
 
$ret->fromArray($this->_unserializedData);
$ret->setPackagefile($file, $archive);
return $ret;
}
}
?>
}
/trunk/bibliotheque/pear/PEAR/PackageFile/v1.php
4,18 → 4,11
*
* 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: v1.php,v 1.72 2006/10/31 02:54:41 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
279,9 → 272,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
352,9 → 345,9
* @param bool determines whether to return a PEAR_Error object, or use the PEAR_ErrorStack
* @param string Name of Error Stack class to use.
*/
function PEAR_PackageFile_v1()
function __construct()
{
$this->_stack = &new PEAR_ErrorStack('PEAR_PackageFile_v1');
$this->_stack = new PEAR_ErrorStack('PEAR_PackageFile_v1');
$this->_stack->setErrorMessageTemplate($this->_getErrorMessage());
$this->_isValid = 0;
}
1200,10 → 1193,25
$this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE,
array('file' => $file, 'role' => $fa['role'], 'roles' => PEAR_Common::getFileRoles()));
}
if ($file{0} == '.' && $file{1} == '/') {
if (preg_match('~/\.\.?(/|\\z)|^\.\.?/~', str_replace('\\', '/', $file))) {
// file contains .. parent directory or . cur directory references
$this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME,
array('file' => $file));
}
if (isset($fa['install-as']) &&
preg_match('~/\.\.?(/|\\z)|^\.\.?/~',
str_replace('\\', '/', $fa['install-as']))) {
// install-as contains .. parent directory or . cur directory references
$this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME,
array('file' => $file . ' [installed as ' . $fa['install-as'] . ']'));
}
if (isset($fa['baseinstalldir']) &&
preg_match('~/\.\.?(/|\\z)|^\.\.?/~',
str_replace('\\', '/', $fa['baseinstalldir']))) {
// install-as contains .. parent directory or . cur directory references
$this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME,
array('file' => $file . ' [baseinstalldir ' . $fa['baseinstalldir'] . ']'));
}
}
}
if (isset($this->_registry) && $this->_isValid) {
1299,7 → 1307,7
if (!class_exists('PEAR_PackageFile_Generator_v1')) {
require_once 'PEAR/PackageFile/Generator/v1.php';
}
$a = &new PEAR_PackageFile_Generator_v1($this);
$a = new PEAR_PackageFile_Generator_v1($this);
return $a;
}
 
1322,7 → 1330,7
if (!class_exists('Archive_Tar')) {
require_once 'Archive/Tar.php';
}
$tar = &new Archive_Tar($this->_archiveFile);
$tar = new Archive_Tar($this->_archiveFile);
$tar->pushErrorHandling(PEAR_ERROR_RETURN);
if ($file != 'package.xml' && $file != 'package2.xml') {
$file = $this->getPackage() . '-' . $this->getVersion() . '/' . $file;
1457,15 → 1465,6
$look_for = $token;
continue 2;
case T_STRING:
if (version_compare(zend_version(), '2.0', '<')) {
if (in_array(strtolower($data),
array('public', 'private', 'protected', 'abstract',
'interface', 'implements', 'throw')
)) {
$this->_validateWarning(PEAR_PACKAGEFILE_ERROR_PHP5,
array($file));
}
}
if ($look_for == T_CLASS) {
$current_class = $data;
$current_class_level = $brace_level;
/trunk/bibliotheque/pear/PEAR/PackageFile/v2.php
4,18 → 4,11
*
* 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: v2.php,v 1.136 2007/02/20 00:16:12 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
27,9 → 20,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
121,7 → 114,7
*
* - package name
* - channel name
* - dependencies
* - dependencies
* @var boolean
* @access private
*/
135,7 → 128,7
/**
* The constructor merely sets up the private error stack
*/
function PEAR_PackageFile_v2()
function __construct()
{
$this->_stack = new PEAR_ErrorStack('PEAR_PackageFile_v2', false, null);
$this->_isValid = false;
142,6 → 135,15
}
 
/**
* PHP 4 style constructor for backwards compatibility.
* Used by PEAR_PackageFileManager2
*/
public function PEAR_PackageFile_v2()
{
$this->__construct();
}
 
/**
* To make unit-testing easier
* @param PEAR_Frontend_*
* @param array options
151,7 → 153,7
*/
function &getPEARDownloader(&$i, $o, &$c)
{
$z = &new PEAR_Downloader($i, $o, $c);
$z = new PEAR_Downloader($i, $o, $c);
return $z;
}
 
169,7 → 171,7
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
$z = &new PEAR_Dependency2($c, $o, $p, $s);
$z = new PEAR_Dependency2($c, $o, $p, $s);
return $z;
}
 
473,6 → 475,9
*/
function setRawState($state)
{
if (!isset($this->_packageInfo['stability'])) {
$this->_packageInfo['stability'] = array();
}
$this->_packageInfo['stability']['release'] = $state;
}
 
567,7 → 572,7
$atts = $filelist[$name];
foreach ($tasks as $tag => $raw) {
$task = $this->getTask($tag);
$task = &new $task($this->_config, $common, PEAR_TASK_INSTALL);
$task = new $task($this->_config, $common, PEAR_TASK_INSTALL);
if ($task->isScript()) {
$ret[] = $filelist[$name]['installed_as'];
}
613,7 → 618,7
$atts = $filelist[$name];
foreach ($tasks as $tag => $raw) {
$taskname = $this->getTask($tag);
$task = &new $taskname($this->_config, $common, PEAR_TASK_INSTALL);
$task = new $taskname($this->_config, $common, PEAR_TASK_INSTALL);
if (!$task->isScript()) {
continue; // scripts are only handled after installation
}
802,6 → 807,10
{
unset($pinfo['old']);
unset($pinfo['xsdversion']);
// If the changelog isn't an array then it was passed in as an empty tag
if (isset($pinfo['changelog']) && !is_array($pinfo['changelog'])) {
unset($pinfo['changelog']);
}
$this->_incomplete = false;
$this->_packageInfo = $pinfo;
}
1169,10 → 1178,16
$this->flattenFilelist();
if ($contents = $this->getContents()) {
$ret = array();
if (!isset($contents['dir'])) {
return false;
}
if (!isset($contents['dir']['file'][0])) {
$contents['dir']['file'] = array($contents['dir']['file']);
}
foreach ($contents['dir']['file'] as $file) {
if (!isset($file['attribs']['name'])) {
continue;
}
$name = $file['attribs']['name'];
if (!$preserve) {
$file = $file['attribs'];
1197,19 → 1212,24
if ($this->getPackageType() != 'extsrc' && $this->getPackageType() != 'zendextsrc') {
return false;
}
 
$releases = $this->getReleases();
if (isset($releases[0])) {
$releases = $releases[0];
}
 
if (isset($releases['configureoption'])) {
if (!isset($releases['configureoption'][0])) {
$releases['configureoption'] = array($releases['configureoption']);
}
 
for ($i = 0; $i < count($releases['configureoption']); $i++) {
$releases['configureoption'][$i] = $releases['configureoption'][$i]['attribs'];
}
 
return $releases['configureoption'];
}
 
return false;
}
 
1563,7 → 1583,7
if (strtolower($dep['name']) == strtolower($package) &&
$depchannel == $channel) {
return true;
}
}
}
}
}
1581,7 → 1601,7
if (strtolower($dep['name']) == strtolower($package) &&
$depchannel == $channel) {
return true;
}
}
}
}
}
1641,7 → 1661,8
);
foreach (array('required', 'optional') as $type) {
$optional = ($type == 'optional') ? 'yes' : 'no';
if (!isset($this->_packageInfo['dependencies'][$type])) {
if (!isset($this->_packageInfo['dependencies'][$type])
|| empty($this->_packageInfo['dependencies'][$type])) {
continue;
}
foreach ($this->_packageInfo['dependencies'][$type] as $dtype => $deps) {
1844,7 → 1865,7
return implode('', file($file));
}
} else { // tgz
$tar = &new Archive_Tar($this->_archiveFile);
$tar = new Archive_Tar($this->_archiveFile);
$tar->pushErrorHandling(PEAR_ERROR_RETURN);
if ($file != 'package.xml' && $file != 'package2.xml') {
$file = $this->getPackage() . '-' . $this->getVersion() . '/' . $file;
1883,7 → 1904,7
if (!class_exists('PEAR_PackageFile_Generator_v2')) {
require_once 'PEAR/PackageFile/Generator/v2.php';
}
$a = &new PEAR_PackageFile_Generator_v2($this);
$a = new PEAR_PackageFile_Generator_v2($this);
return $a;
}
 
1947,17 → 1968,17
$this->getTasksNs();
// transform all '-' to '/' and 'tasks:' to '' so tasks:replace becomes replace
$task = str_replace(array($this->_tasksNs . ':', '-'), array('', ' '), $task);
$task = str_replace(' ', '/', ucwords($task));
$ps = (strtolower(substr(PHP_OS, 0, 3)) == 'win') ? ';' : ':';
foreach (explode($ps, ini_get('include_path')) as $path) {
if (file_exists($path . "/PEAR/Task/$task.php")) {
include_once "PEAR/Task/$task.php";
$task = str_replace('/', '_', $task);
if (class_exists("PEAR_Task_$task")) {
return "PEAR_Task_$task";
}
}
$taskfile = str_replace(' ', '/', ucwords($task));
$task = str_replace(array(' ', '/'), '_', ucwords($task));
if (class_exists("PEAR_Task_$task")) {
return "PEAR_Task_$task";
}
$fp = @fopen("PEAR/Task/$taskfile.php", 'r', true);
if ($fp) {
fclose($fp);
require_once "PEAR/Task/$taskfile.php";
return "PEAR_Task_$task";
}
return false;
}
 
/trunk/bibliotheque/pear/PEAR/PackageFile/Generator/v1.php
4,18 → 4,11
*
* 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: v1.php,v 1.72 2006/05/10 02:56:19 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
33,9 → 26,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
45,7 → 38,7
* @var PEAR_PackageFile_v1
*/
var $_packagefile;
function PEAR_PackageFile_Generator_v1(&$packagefile)
function __construct(&$packagefile)
{
$this->_packagefile = &$packagefile;
}
52,7 → 45,7
 
function getPackagerVersion()
{
return '1.5.1';
return '1.10.1';
}
 
/**
115,7 → 108,7
// }}}
$packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true);
if ($packagexml) {
$tar =& new Archive_Tar($dest_package, $compress);
$tar = new Archive_Tar($dest_package, $compress);
$tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
// ----- Creates with the package.xml file
$ok = $tar->createModify(array($packagexml), '', $where);
174,9 → 167,6
*/
function _fixXmlEncoding($string)
{
if (version_compare(phpversion(), '5.0.0', 'lt')) {
$string = utf8_encode($string);
}
return strtr($string, array(
'&' => '&amp;',
'>' => '&gt;',
206,7 → 196,7
);
$ret = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
$ret .= "<!DOCTYPE package SYSTEM \"http://pear.php.net/dtd/package-1.0\">\n";
$ret .= "<package version=\"1.0\" packagerversion=\"1.5.1\">\n" .
$ret .= "<package version=\"1.0\" packagerversion=\"1.10.1\">\n" .
" <name>$pkginfo[package]</name>";
if (isset($pkginfo['extends'])) {
$ret .= "\n<extends>$pkginfo[extends]</extends>";
521,6 → 511,7
return $a;
}
}
 
$arr = array(
'attribs' => array(
'version' => '2.0',
550,6 → 541,7
);
$arr['lead'][] = $new;
}
 
if (!isset($arr['lead'])) { // some people... you know?
$arr['lead'] = array(
'name' => 'unknown',
558,9 → 550,11
'active' => 'no',
);
}
 
if (count($arr['lead']) == 1) {
$arr['lead'] = $arr['lead'][0];
}
 
foreach ($maintainers as $maintainer) {
if ($maintainer['role'] == 'lead') {
continue;
573,15 → 567,19
);
$arr[$maintainer['role']][] = $new;
}
 
if (isset($arr['developer']) && count($arr['developer']) == 1) {
$arr['developer'] = $arr['developer'][0];
}
 
if (isset($arr['contributor']) && count($arr['contributor']) == 1) {
$arr['contributor'] = $arr['contributor'][0];
}
 
if (isset($arr['helper']) && count($arr['helper']) == 1) {
$arr['helper'] = $arr['helper'][0];
}
 
$arr['date'] = $this->_packagefile->getDate();
$arr['version'] =
array(
605,6 → 603,7
'gpl' => 'http://www.gnu.org/copyleft/gpl.html',
'apache' => 'http://www.opensource.org/licenses/apache2.0.php'
);
 
if (isset($licensemap[strtolower($this->_packagefile->getLicense())])) {
$arr['license'] = array(
'attribs' => array('uri' =>
615,6 → 614,7
// don't use bogus uri
$arr['license'] = $this->_packagefile->getLicense();
}
 
$arr['notes'] = $this->_packagefile->getNotes();
$temp = array();
$arr['contents'] = $this->_convertFilelist2_0($temp);
625,6 → 625,7
$arr['channel'] = 'pecl.php.net';
$arr['providesextension'] = $arr['name']; // assumption
}
 
$arr[$release] = array();
if ($this->_packagefile->getConfigureOptions()) {
$arr[$release]['configureoption'] = $this->_packagefile->getConfigureOptions();
635,11 → 636,13
$arr[$release]['configureoption'] = $arr[$release]['configureoption'][0];
}
}
 
$this->_convertRelease2_0($arr[$release], $temp);
if ($release == 'extsrcrelease' && count($arr[$release]) > 1) {
// multiple extsrcrelease tags added in PEAR 1.4.1
$arr['dependencies']['required']['pearinstaller']['min'] = '1.4.1';
}
 
if ($cl = $this->_packagefile->getChangelog()) {
foreach ($cl as $release) {
$rel = array();
651,6 → 654,7
if (!isset($release['release_state'])) {
$release['release_state'] = 'stable';
}
 
$rel['stability'] =
array(
'release' => $release['release_state'],
661,6 → 665,7
} else {
$rel['date'] = date('Y-m-d');
}
 
if (isset($release['release_license'])) {
if (isset($licensemap[strtolower($release['release_license'])])) {
$uri = $licensemap[strtolower($release['release_license'])];
674,18 → 679,22
} else {
$rel['license'] = $arr['license'];
}
 
if (!isset($release['release_notes'])) {
$release['release_notes'] = 'no release notes';
}
 
$rel['notes'] = $release['release_notes'];
$arr['changelog']['release'][] = $rel;
}
}
 
$ret = new $class;
$ret->setConfig($this->_packagefile->_config);
if (isset($this->_packagefile->_logger) && is_object($this->_packagefile->_logger)) {
$ret->setLogger($this->_packagefile->_logger);
}
 
$ret->fromArray($arr);
return $ret;
}
700,7 → 709,7
$peardep = array('pearinstaller' =>
array('min' => '1.4.0b1')); // this is a lot safer
$required = $optional = array();
$release['dependencies'] = array();
$release['dependencies'] = array('required' => array());
if ($this->_packagefile->hasDeps()) {
foreach ($this->_packagefile->getDeps() as $dep) {
if (!isset($dep['optional']) || $dep['optional'] == 'no') {
831,9 → 840,9
/**
* Post-process special files with install-as/platform attributes and
* make the release tag.
*
*
* This complex method follows this work-flow to create the release tags:
*
*
* <pre>
* - if any install-as/platform exist, create a generic release and fill it with
* o <install as=..> tags for <file name=... install-as=...>
849,10 → 858,10
* o <ignore> tags for <file name=... platform=other platform install-as=..>
* o <ignore> tags for <file name=... platform=!this platform install-as=..>
* </pre>
*
*
* It does this by accessing the $package parameter, which contains an array with
* indices:
*
*
* - platform: mapping of file => OS the file should be installed on
* - install-as: mapping of file => installed name
* - osmap: mapping of OS => list of files that should be installed
866,7 → 875,7
*/
function _convertRelease2_0(&$release, $package)
{
//- if any install-as/platform exist, create a generic release and fill it with
//- if any install-as/platform exist, create a generic release and fill it with
if (count($package['platform']) || count($package['install-as'])) {
$generic = array();
$genericIgnore = array();
1165,13 → 1174,15
}
if (count($min)) {
// get the highest minimum
$min = array_pop($a = array_flip($min));
$a = array_flip($min);
$min = array_pop($a);
} else {
$min = false;
}
if (count($max)) {
// get the lowest maximum
$max = array_shift($a = array_flip($max));
$a = array_flip($max);
$max = array_shift($a);
} else {
$max = false;
}
1202,16 → 1213,15
*/
function _processMultipleDepsName($deps)
{
$tests = array();
$ret = $tests = array();
foreach ($deps as $name => $dep) {
foreach ($dep as $d) {
$tests[$name][] = $this->_processDep($d);
}
}
 
foreach ($tests as $name => $test) {
$php = array();
$min = array();
$max = array();
$max = $min = $php = array();
$php['name'] = $name;
foreach ($test as $dep) {
if (!$dep) {
1238,13 → 1248,15
}
if (count($min)) {
// get the highest minimum
$min = array_pop($a = array_flip($min));
$a = array_flip($min);
$min = array_pop($a);
} else {
$min = false;
}
if (count($max)) {
// get the lowest maximum
$max = array_shift($a = array_flip($max));
$a = array_flip($max);
$max = array_shift($a);
} else {
$max = false;
}
1269,4 → 1281,4
return $ret;
}
}
?>
?>
/trunk/bibliotheque/pear/PEAR/PackageFile/Generator/v2.php
4,19 → 4,12
*
* 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>
* @author Stephan Schmidt (original XML_Serializer code)
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: v2.php,v 1.35 2006/03/25 21:09:08 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
24,6 → 17,8
* file/dir manipulation routines
*/
require_once 'System.php';
require_once 'XML/Util.php';
 
/**
* This class converts a PEAR_PackageFile_v2 object into any output format.
*
33,9 → 28,9
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @author Stephan Schmidt (original XML_Serializer code)
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.5.1
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
47,37 → 42,37
* @var array $_defaultOptions
*/
var $_defaultOptions = array(
'indent' => ' ', // string used for indentation
'linebreak' => "\n", // string used for newlines
'typeHints' => false, // automatically add type hin attributes
'addDecl' => true, // add an XML declaration
'defaultTagName' => 'XML_Serializer_Tag', // tag used for indexed arrays or invalid names
'classAsTagName' => false, // use classname for objects in indexed arrays
'keyAttribute' => '_originalKey', // attribute where original key is stored
'typeAttribute' => '_type', // attribute for type (only if typeHints => true)
'classAttribute' => '_class', // attribute for class of objects (only if typeHints => true)
'scalarAsAttributes' => false, // scalar values (strings, ints,..) will be serialized as attribute
'prependAttributes' => '', // prepend string for attributes
'indentAttributes' => false, // indent the attributes, if set to '_auto', it will indent attributes so they all start at the same column
'mode' => 'simplexml', // use 'simplexml' to use parent name as tagname if transforming an indexed array
'addDoctype' => false, // add a doctype declaration
'doctype' => null, // supply a string or an array with id and uri ({@see PEAR_PackageFile_Generator_v2_PEAR_PackageFile_Generator_v2_XML_Util::getDoctypeDeclaration()}
'rootName' => 'package', // name of the root tag
'rootAttributes' => array(
'version' => '2.0',
'xmlns' => 'http://pear.php.net/dtd/package-2.0',
'xmlns:tasks' => 'http://pear.php.net/dtd/tasks-1.0',
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation' => 'http://pear.php.net/dtd/tasks-1.0
'indent' => ' ', // string used for indentation
'linebreak' => "\n", // string used for newlines
'typeHints' => false, // automatically add type hin attributes
'addDecl' => true, // add an XML declaration
'defaultTagName' => 'XML_Serializer_Tag', // tag used for indexed arrays or invalid names
'classAsTagName' => false, // use classname for objects in indexed arrays
'keyAttribute' => '_originalKey', // attribute where original key is stored
'typeAttribute' => '_type', // attribute for type (only if typeHints => true)
'classAttribute' => '_class', // attribute for class of objects (only if typeHints => true)
'scalarAsAttributes' => false, // scalar values (strings, ints,..) will be serialized as attribute
'prependAttributes' => '', // prepend string for attributes
'indentAttributes' => false, // indent the attributes, if set to '_auto', it will indent attributes so they all start at the same column
'mode' => 'simplexml', // use 'simplexml' to use parent name as tagname if transforming an indexed array
'addDoctype' => false, // add a doctype declaration
'doctype' => null, // supply a string or an array with id and uri ({@see XML_Util::getDoctypeDeclaration()}
'rootName' => 'package', // name of the root tag
'rootAttributes' => array(
'version' => '2.0',
'xmlns' => 'http://pear.php.net/dtd/package-2.0',
'xmlns:tasks' => 'http://pear.php.net/dtd/tasks-1.0',
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation' => 'http://pear.php.net/dtd/tasks-1.0
http://pear.php.net/dtd/tasks-1.0.xsd
http://pear.php.net/dtd/package-2.0
http://pear.php.net/dtd/package-2.0.xsd',
), // attributes of the root tag
'attributesArray' => 'attribs', // all values in this key will be treated as attributes
'contentName' => '_content', // this value will be used directly as content, instead of creating a new tag, may only be used in conjuction with attributesArray
'beautifyFilelist' => false,
'encoding' => 'UTF-8',
);
), // attributes of the root tag
'attributesArray' => 'attribs', // all values in this key will be treated as attributes
'contentName' => '_content', // this value will be used directly as content, instead of creating a new tag, may only be used in conjunction with attributesArray
'beautifyFilelist' => false,
'encoding' => 'UTF-8',
);
 
/**
* options for the serialization
104,9 → 99,12
/**
* @param PEAR_PackageFile_v2
*/
function PEAR_PackageFile_Generator_v2(&$packagefile)
function __construct(&$packagefile)
{
$this->_packagefile = &$packagefile;
if (isset($this->_packagefile->encoding)) {
$this->_defaultOptions['encoding'] = $this->_packagefile->encoding;
}
}
 
/**
114,7 → 112,7
*/
function getPackagerVersion()
{
return '1.5.1';
return '1.10.1';
}
 
/**
144,6 → 142,7
'" is not equivalent to "' . basename($this->_packagefile->getPackageFile())
. '"');
}
 
if ($where === null) {
if (!($where = System::mktemp(array('-d')))) {
return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: mktemp failed');
152,29 → 151,34
return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: "' . $where . '" could' .
' not be created');
}
if (file_exists($where . DIRECTORY_SEPARATOR . 'package.xml') &&
!is_file($where . DIRECTORY_SEPARATOR . 'package.xml')) {
 
$file = $where . DIRECTORY_SEPARATOR . 'package.xml';
if (file_exists($file) && !is_file($file)) {
return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: unable to save package.xml as' .
' "' . $where . DIRECTORY_SEPARATOR . 'package.xml"');
' "' . $file .'"');
}
 
if (!$this->_packagefile->validate(PEAR_VALIDATE_PACKAGING)) {
return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: invalid package.xml');
}
 
$ext = $compress ? '.tgz' : '.tar';
$pkgver = $this->_packagefile->getPackage() . '-' . $this->_packagefile->getVersion();
$dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext;
if (file_exists(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext) &&
!is_file(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext)) {
if (file_exists($dest_package) && !is_file($dest_package)) {
return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: cannot create tgz file "' .
getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext . '"');
$dest_package . '"');
}
if ($pkgfile = $this->_packagefile->getPackageFile()) {
$pkgdir = dirname(realpath($pkgfile));
$pkgfile = basename($pkgfile);
} else {
 
$pkgfile = $this->_packagefile->getPackageFile();
if (!$pkgfile) {
return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: package file object must ' .
'be created from a real file');
}
 
$pkgdir = dirname(realpath($pkgfile));
$pkgfile = basename($pkgfile);
 
// {{{ Create the package file list
$filelist = array();
$i = 0;
185,6 → 189,7
if (!isset($contents[0])) {
$contents = array($contents);
}
 
$packageDir = $where;
foreach ($contents as $i => $package) {
$fname = $package;
192,6 → 197,7
if (!file_exists($file)) {
return $packager->raiseError("File does not exist: $fname");
}
 
$tfile = $packageDir . DIRECTORY_SEPARATOR . $fname;
System::mkdir(array('-p', dirname($tfile)));
copy($file, $tfile);
203,7 → 209,7
if (!isset($contents[0])) {
$contents = array($contents);
}
 
$packageDir = $where;
foreach ($contents as $i => $file) {
$fname = $file['attribs']['name'];
212,52 → 218,57
$file = $pkgdir . DIRECTORY_SEPARATOR . $fname;
if (!file_exists($file)) {
return $packager->raiseError("File does not exist: $fname");
} else {
$tfile = $packageDir . DIRECTORY_SEPARATOR . $fname;
unset($orig['attribs']);
if (count($orig)) { // file with tasks
// run any package-time tasks
$contents = file_get_contents($file);
foreach ($orig as $tag => $raw) {
$tag = str_replace($this->_packagefile->getTasksNs() . ':', '', $tag);
$task = "PEAR_Task_$tag";
$task = &new $task($this->_packagefile->_config,
$this->_packagefile->_logger,
PEAR_TASK_PACKAGE);
$task->init($raw, $atts, null);
$res = $task->startSession($this->_packagefile, $contents, $tfile);
if (!$res) {
continue; // skip this task
}
if (PEAR::isError($res)) {
return $res;
}
$contents = $res; // save changes
System::mkdir(array('-p', dirname($tfile)));
$wp = fopen($tfile, "wb");
fwrite($wp, $contents);
fclose($wp);
}
 
$origperms = fileperms($file);
$tfile = $packageDir . DIRECTORY_SEPARATOR . $fname;
unset($orig['attribs']);
if (count($orig)) { // file with tasks
// run any package-time tasks
$contents = file_get_contents($file);
foreach ($orig as $tag => $raw) {
$tag = str_replace(
array($this->_packagefile->getTasksNs() . ':', '-'),
array('', '_'), $tag);
$task = "PEAR_Task_$tag";
$task = new $task($this->_packagefile->_config,
$this->_packagefile->_logger,
PEAR_TASK_PACKAGE);
$task->init($raw, $atts, null);
$res = $task->startSession($this->_packagefile, $contents, $tfile);
if (!$res) {
continue; // skip this task
}
}
if (!file_exists($tfile)) {
 
if (PEAR::isError($res)) {
return $res;
}
 
$contents = $res; // save changes
System::mkdir(array('-p', dirname($tfile)));
copy($file, $tfile);
$wp = fopen($tfile, "wb");
fwrite($wp, $contents);
fclose($wp);
}
$filelist[$i++] = $tfile;
$this->_packagefile->setFileAttribute($fname, 'md5sum', md5_file($tfile), $i - 1);
$packager->log(2, "Adding file $fname");
}
 
if (!file_exists($tfile)) {
System::mkdir(array('-p', dirname($tfile)));
copy($file, $tfile);
}
 
chmod($tfile, $origperms);
$filelist[$i++] = $tfile;
$this->_packagefile->setFileAttribute($fname, 'md5sum', md5_file($tfile), $i - 1);
$packager->log(2, "Adding file $fname");
}
}
// }}}
if ($pf1 !== null) {
$name = 'package2.xml';
} else {
$name = 'package.xml';
}
 
$name = $pf1 !== null ? 'package2.xml' : 'package.xml';
$packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name);
if ($packagexml) {
$tar =& new Archive_Tar($dest_package, $compress);
$tar = new Archive_Tar($dest_package, $compress);
$tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
// ----- Creates with the package.xml file
$ok = $tar->createModify(array($packagexml), '', $where);
267,21 → 278,23
return $packager->raiseError('PEAR_Packagefile_v2::toTgz(): adding ' . $name .
' failed');
}
 
// ----- Add the content of the package
if (!$tar->addModify($filelist, $pkgver, $where)) {
return $packager->raiseError(
'PEAR_Packagefile_v2::toTgz(): tarball creation failed');
}
 
// add the package.xml version 1.0
if ($pf1 !== null) {
$pfgen = &$pf1->getDefaultGenerator();
$packagexml1 = $pfgen->toPackageFile($where, PEAR_VALIDATE_PACKAGING,
'package.xml', true);
$packagexml1 = $pfgen->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true);
if (!$tar->addModify(array($packagexml1), '', $where)) {
return $packager->raiseError(
'PEAR_Packagefile_v2::toTgz(): adding package.xml failed');
}
}
 
return $dest_package;
}
}
292,6 → 305,7
return PEAR::raiseError('PEAR_Packagefile_v2::toPackageFile: invalid package.xml',
null, null, null, $this->_packagefile->getValidationWarnings());
}
 
if ($where === null) {
if (!($where = System::mktemp(array('-d')))) {
return PEAR::raiseError('PEAR_Packagefile_v2::toPackageFile: mktemp failed');
300,6 → 314,7
return PEAR::raiseError('PEAR_Packagefile_v2::toPackageFile: "' . $where . '" could' .
' not be created');
}
 
$newpkgfile = $where . DIRECTORY_SEPARATOR . $name;
$np = @fopen($newpkgfile, 'wb');
if (!$np) {
329,18 → 344,47
if (!$this->_packagefile->validate($state)) {
return false;
}
 
if (is_array($options)) {
$this->options = array_merge($this->_defaultOptions, $options);
} else {
$this->options = $this->_defaultOptions;
}
 
$arr = $this->_packagefile->getArray();
if (isset($arr['filelist'])) {
unset($arr['filelist']);
}
 
if (isset($arr['_lastversion'])) {
unset($arr['_lastversion']);
}
 
// Fix the notes a little bit
if (isset($arr['notes'])) {
// This trims out the indenting, needs fixing
$arr['notes'] = "\n" . trim($arr['notes']) . "\n";
}
 
if (isset($arr['changelog']) && !empty($arr['changelog'])) {
// Fix for inconsistency how the array is filled depending on the changelog release amount
if (!isset($arr['changelog']['release'][0])) {
$release = $arr['changelog']['release'];
unset($arr['changelog']['release']);
 
$arr['changelog']['release'] = array();
$arr['changelog']['release'][0] = $release;
}
 
foreach (array_keys($arr['changelog']['release']) as $key) {
$c =& $arr['changelog']['release'][$key];
if (isset($c['notes'])) {
// This trims out the indenting, needs fixing
$c['notes'] = "\n" . trim($c['notes']) . "\n";
}
}
}
 
if ($state ^ PEAR_VALIDATE_PACKAGING && !isset($arr['bundle'])) {
$use = $this->_recursiveXmlFilelist($arr['contents']['dir']['file']);
unset($arr['contents']['dir']['file']);
352,10 → 396,12
}
$this->options['beautifyFilelist'] = true;
}
$arr['attribs']['packagerversion'] = '1.5.1';
 
$arr['attribs']['packagerversion'] = '1.10.1';
if ($this->serialize($arr, $options)) {
return $this->_serializedData . "\n";
}
 
return false;
}
 
477,7 → 523,7
{
$this->options[$name] = $value;
}
 
/**
* sets several options at once
*
509,29 → 555,22
} else {
$this->options = array_merge($this->options, $options);
}
}
else {
} else {
$optionsBak = null;
}
 
// start depth is zero
$this->_tagDepth = 0;
 
$this->_serializedData = '';
// serialize an array
if (is_array($data)) {
if (isset($this->options['rootName'])) {
$tagName = $this->options['rootName'];
} else {
$tagName = 'array';
}
 
$tagName = isset($this->options['rootName']) ? $this->options['rootName'] : 'array';
$this->_serializedData .= $this->_serializeArray($data, $tagName, $this->options['rootAttributes']);
}
 
// add doctype declaration
if ($this->options['addDoctype'] === true) {
$this->_serializedData = PEAR_PackageFile_Generator_v2_XML_Util::getDoctypeDeclaration($tagName, $this->options['doctype'])
$this->_serializedData = XML_Util::getDoctypeDeclaration($tagName, $this->options['doctype'])
. $this->options['linebreak']
. $this->_serializedData;
}
539,21 → 578,17
// build xml declaration
if ($this->options['addDecl']) {
$atts = array();
if (isset($this->options['encoding']) ) {
$encoding = $this->options['encoding'];
} else {
$encoding = null;
}
$this->_serializedData = PEAR_PackageFile_Generator_v2_XML_Util::getXMLDeclaration('1.0', $encoding)
$encoding = isset($this->options['encoding']) ? $this->options['encoding'] : null;
$this->_serializedData = XML_Util::getXMLDeclaration('1.0', $encoding)
. $this->options['linebreak']
. $this->_serializedData;
}
if ($optionsBak !== null) {
$this->options = $optionsBak;
}
 
 
if ($optionsBak !== null) {
$this->options = $optionsBak;
}
 
return true;
}
 
565,12 → 600,12
*/
function getSerializedData()
{
if ($this->_serializedData == null ) {
if ($this->_serializedData === null) {
return $this->raiseError('No serialized data available. Use XML_Serializer::serialize() first.', XML_SERIALIZER_ERROR_NO_SERIALIZATION);
}
return $this->_serializedData;
}
 
/**
* serialize any value
*
598,7 → 633,7
}
return $xml;
}
 
/**
* serialize an array
*
607,12 → 642,12
* @param string $tagName name of the root tag
* @param array $attributes attributes for the root tag
* @return string $string serialized data
* @uses PEAR_PackageFile_Generator_v2_XML_Util::isValidName() to check, whether key has to be substituted
* @uses XML_Util::isValidName() to check, whether key has to be substituted
*/
function _serializeArray(&$array, $tagName = null, $attributes = array())
{
$_content = null;
 
/**
* check for special attributes
*/
676,10 → 711,10
$this->_curdir = $savedir;
}
}
 
$string .= $this->options['linebreak'];
// do indentation
if ($this->options['indent']!==null && $this->_tagDepth>0) {
// do indentation
if ($this->options['indent'] !== null && $this->_tagDepth > 0) {
$string .= str_repeat($this->options['indent'], $this->_tagDepth);
}
}
686,16 → 721,16
return rtrim($string);
}
}
if ($this->options['scalarAsAttributes'] === true) {
foreach ($array as $key => $value) {
if (is_scalar($value) && (PEAR_PackageFile_Generator_v2_XML_Util::isValidName($key) === true)) {
unset($array[$key]);
$attributes[$this->options['prependAttributes'].$key] = $value;
}
}
}
 
if ($this->options['scalarAsAttributes'] === true) {
foreach ($array as $key => $value) {
if (is_scalar($value) && (XML_Util::isValidName($key) === true)) {
unset($array[$key]);
$attributes[$this->options['prependAttributes'].$key] = $value;
}
}
}
 
// check for empty array => create empty tag
if (empty($array)) {
$tag = array(
708,29 → 743,29
$this->_tagDepth++;
$tmp = $this->options['linebreak'];
foreach ($array as $key => $value) {
// do indentation
if ($this->options['indent']!==null && $this->_tagDepth>0) {
// do indentation
if ($this->options['indent'] !== null && $this->_tagDepth > 0) {
$tmp .= str_repeat($this->options['indent'], $this->_tagDepth);
}
// copy key
$origKey = $key;
// key cannot be used as tagname => use default tag
$valid = PEAR_PackageFile_Generator_v2_XML_Util::isValidName($key);
if (PEAR::isError($valid)) {
if ($this->options['classAsTagName'] && is_object($value)) {
$key = get_class($value);
} else {
$key = $this->options['defaultTagName'];
}
}
 
// copy key
$origKey = $key;
// key cannot be used as tagname => use default tag
$valid = XML_Util::isValidName($key);
if (PEAR::isError($valid)) {
if ($this->options['classAsTagName'] && is_object($value)) {
$key = get_class($value);
} else {
$key = $this->options['defaultTagName'];
}
}
$atts = array();
if ($this->options['typeHints'] === true) {
$atts[$this->options['typeAttribute']] = gettype($value);
if ($key !== $origKey) {
$atts[$this->options['keyAttribute']] = (string)$origKey;
}
if ($key !== $origKey) {
$atts[$this->options['keyAttribute']] = (string)$origKey;
}
 
}
if ($this->options['beautifyFilelist'] && $key == 'dir') {
if (!isset($this->_curdir)) {
766,21 → 801,21
}
$tmp .= $this->options['linebreak'];
}
 
$this->_tagDepth--;
if ($this->options['indent']!==null && $this->_tagDepth>0) {
$tmp .= str_repeat($this->options['indent'], $this->_tagDepth);
}
if (trim($tmp) === '') {
$tmp = null;
}
 
if (trim($tmp) === '') {
$tmp = null;
}
 
$tag = array(
'qname' => $tagName,
'content' => $tmp,
'attributes' => $attributes
);
'qname' => $tagName,
'content' => $tmp,
'attributes' => $attributes
);
}
if ($this->options['typeHints'] === true) {
if (!isset($tag['attributes'][$this->options['typeAttribute']])) {
791,7 → 826,7
$string = $this->_createXMLTag($tag, false);
return $string;
}
 
/**
* create a tag from an array
* this method awaits an array in the following format
808,7 → 843,7
* @param boolean $replaceEntities whether to replace XML entities in content or not
* @return string $string XML tag
*/
function _createXMLTag( $tag, $replaceEntities = true )
function _createXMLTag($tag, $replaceEntities = true)
{
if ($this->options['indentAttributes'] !== false) {
$multiline = true;
821,707 → 856,31
$indent .= $this->options['indentAttributes'];
}
} else {
$multiline = false;
$indent = false;
$indent = $multiline = false;
}
 
if (is_array($tag['content'])) {
if (empty($tag['content'])) {
$tag['content'] = '';
$tag['content'] = '';
}
} elseif(is_scalar($tag['content']) && (string)$tag['content'] == '') {
$tag['content'] = '';
$tag['content'] = '';
}
 
if (is_scalar($tag['content']) || is_null($tag['content'])) {
if ($this->options['encoding'] == 'UTF-8' &&
version_compare(phpversion(), '5.0.0', 'lt')) {
$encoding = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_UTF8_XML;
} else {
$encoding = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML;
if ($replaceEntities === true) {
$replaceEntities = XML_UTIL_ENTITIES_XML;
}
$tag = PEAR_PackageFile_Generator_v2_XML_Util::createTagFromArray($tag, $replaceEntities, $multiline, $indent, $this->options['linebreak'], $encoding);
 
$tag = XML_Util::createTagFromArray($tag, $replaceEntities, $multiline, $indent, $this->options['linebreak']);
} elseif (is_array($tag['content'])) {
$tag = $this->_serializeArray($tag['content'], $tag['qname'], $tag['attributes']);
$tag = $this->_serializeArray($tag['content'], $tag['qname'], $tag['attributes']);
} elseif (is_object($tag['content'])) {
$tag = $this->_serializeObject($tag['content'], $tag['qname'], $tag['attributes']);
$tag = $this->_serializeObject($tag['content'], $tag['qname'], $tag['attributes']);
} elseif (is_resource($tag['content'])) {
settype($tag['content'], 'string');
$tag = PEAR_PackageFile_Generator_v2_XML_Util::createTagFromArray($tag, $replaceEntities);
$tag = XML_Util::createTagFromArray($tag, $replaceEntities);
}
return $tag;
}
}
 
// well, it's one way to do things without extra deps ...
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Stephan Schmidt <schst@php-tools.net> |
// +----------------------------------------------------------------------+
//
// $Id: v2.php,v 1.35 2006/03/25 21:09:08 cellog Exp $
 
/**
* error code for invalid chars in XML name
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_ERROR_INVALID_CHARS", 51);
 
/**
* error code for invalid chars in XML name
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_ERROR_INVALID_START", 52);
 
/**
* error code for non-scalar tag content
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_ERROR_NON_SCALAR_CONTENT", 60);
/**
* error code for missing tag name
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_ERROR_NO_TAG_NAME", 61);
/**
* replace XML entities
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_REPLACE_ENTITIES", 1);
 
/**
* embedd content in a CData Section
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_CDATA_SECTION", 2);
 
/**
* do not replace entitites
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_NONE", 0);
 
/**
* replace all XML entitites
* This setting will replace <, >, ", ' and &
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML", 1);
 
/**
* replace only required XML entitites
* This setting will replace <, " and &
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML_REQUIRED", 2);
 
/**
* replace HTML entitites
* @link http://www.php.net/htmlentities
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_HTML", 3);
 
/**
* replace all XML entitites, and encode from ISO-8859-1 to UTF-8
* This setting will replace <, >, ", ' and &
*/
define("PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_UTF8_XML", 4);
 
/**
* utility class for working with XML documents
*
* customized version of XML_Util 0.6.0
*
* @category XML
* @package PEAR
* @version 0.6.0
* @author Stephan Schmidt <schst@php.net>
* @author Gregory Beaver <cellog@php.net>
*/
class PEAR_PackageFile_Generator_v2_XML_Util {
 
/**
* return API version
*
* @access public
* @static
* @return string $version API version
*/
function apiVersion()
{
return "0.6";
}
 
/**
* replace XML entities
*
* With the optional second parameter, you may select, which
* entities should be replaced.
*
* <code>
* require_once 'XML/Util.php';
*
* // replace XML entites:
* $string = PEAR_PackageFile_Generator_v2_XML_Util::replaceEntities("This string contains < & >.");
* </code>
*
* @access public
* @static
* @param string string where XML special chars should be replaced
* @param integer setting for entities in attribute values (one of PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML, PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML_REQUIRED, PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_HTML)
* @return string string with replaced chars
*/
function replaceEntities($string, $replaceEntities = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML)
{
switch ($replaceEntities) {
case PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_UTF8_XML:
return strtr(utf8_encode($string),array(
'&' => '&amp;',
'>' => '&gt;',
'<' => '&lt;',
'"' => '&quot;',
'\'' => '&apos;' ));
break;
case PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML:
return strtr($string,array(
'&' => '&amp;',
'>' => '&gt;',
'<' => '&lt;',
'"' => '&quot;',
'\'' => '&apos;' ));
break;
case PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML_REQUIRED:
return strtr($string,array(
'&' => '&amp;',
'<' => '&lt;',
'"' => '&quot;' ));
break;
case PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_HTML:
return htmlspecialchars($string);
break;
}
return $string;
}
 
/**
* build an xml declaration
*
* <code>
* require_once 'XML/Util.php';
*
* // get an XML declaration:
* $xmlDecl = PEAR_PackageFile_Generator_v2_XML_Util::getXMLDeclaration("1.0", "UTF-8", true);
* </code>
*
* @access public
* @static
* @param string $version xml version
* @param string $encoding character encoding
* @param boolean $standAlone document is standalone (or not)
* @return string $decl xml declaration
* @uses PEAR_PackageFile_Generator_v2_XML_Util::attributesToString() to serialize the attributes of the XML declaration
*/
function getXMLDeclaration($version = "1.0", $encoding = null, $standalone = null)
{
$attributes = array(
"version" => $version,
);
// add encoding
if ($encoding !== null) {
$attributes["encoding"] = $encoding;
}
// add standalone, if specified
if ($standalone !== null) {
$attributes["standalone"] = $standalone ? "yes" : "no";
}
return sprintf("<?xml%s?>", PEAR_PackageFile_Generator_v2_XML_Util::attributesToString($attributes, false));
}
 
/**
* build a document type declaration
*
* <code>
* require_once 'XML/Util.php';
*
* // get a doctype declaration:
* $xmlDecl = PEAR_PackageFile_Generator_v2_XML_Util::getDocTypeDeclaration("rootTag","myDocType.dtd");
* </code>
*
* @access public
* @static
* @param string $root name of the root tag
* @param string $uri uri of the doctype definition (or array with uri and public id)
* @param string $internalDtd internal dtd entries
* @return string $decl doctype declaration
* @since 0.2
*/
function getDocTypeDeclaration($root, $uri = null, $internalDtd = null)
{
if (is_array($uri)) {
$ref = sprintf( ' PUBLIC "%s" "%s"', $uri["id"], $uri["uri"] );
} elseif (!empty($uri)) {
$ref = sprintf( ' SYSTEM "%s"', $uri );
} else {
$ref = "";
}
 
if (empty($internalDtd)) {
return sprintf("<!DOCTYPE %s%s>", $root, $ref);
} else {
return sprintf("<!DOCTYPE %s%s [\n%s\n]>", $root, $ref, $internalDtd);
}
}
 
/**
* create string representation of an attribute list
*
* <code>
* require_once 'XML/Util.php';
*
* // build an attribute string
* $att = array(
* "foo" => "bar",
* "argh" => "tomato"
* );
*
* $attList = PEAR_PackageFile_Generator_v2_XML_Util::attributesToString($att);
* </code>
*
* @access public
* @static
* @param array $attributes attribute array
* @param boolean|array $sort sort attribute list alphabetically, may also be an assoc array containing the keys 'sort', 'multiline', 'indent', 'linebreak' and 'entities'
* @param boolean $multiline use linebreaks, if more than one attribute is given
* @param string $indent string used for indentation of multiline attributes
* @param string $linebreak string used for linebreaks of multiline attributes
* @param integer $entities setting for entities in attribute values (one of PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_NONE, PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML, PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML_REQUIRED, PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_HTML)
* @return string string representation of the attributes
* @uses PEAR_PackageFile_Generator_v2_XML_Util::replaceEntities() to replace XML entities in attribute values
* @todo allow sort also to be an options array
*/
function attributesToString($attributes, $sort = true, $multiline = false, $indent = ' ', $linebreak = "\n", $entities = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML)
{
/**
* second parameter may be an array
*/
if (is_array($sort)) {
if (isset($sort['multiline'])) {
$multiline = $sort['multiline'];
}
if (isset($sort['indent'])) {
$indent = $sort['indent'];
}
if (isset($sort['linebreak'])) {
$multiline = $sort['linebreak'];
}
if (isset($sort['entities'])) {
$entities = $sort['entities'];
}
if (isset($sort['sort'])) {
$sort = $sort['sort'];
} else {
$sort = true;
}
}
$string = '';
if (is_array($attributes) && !empty($attributes)) {
if ($sort) {
ksort($attributes);
}
if( !$multiline || count($attributes) == 1) {
foreach ($attributes as $key => $value) {
if ($entities != PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_NONE) {
$value = PEAR_PackageFile_Generator_v2_XML_Util::replaceEntities($value, $entities);
}
$string .= ' '.$key.'="'.$value.'"';
}
} else {
$first = true;
foreach ($attributes as $key => $value) {
if ($entities != PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_NONE) {
$value = PEAR_PackageFile_Generator_v2_XML_Util::replaceEntities($value, $entities);
}
if ($first) {
$string .= " ".$key.'="'.$value.'"';
$first = false;
} else {
$string .= $linebreak.$indent.$key.'="'.$value.'"';
}
}
}
}
return $string;
}
 
/**
* create a tag
*
* This method will call PEAR_PackageFile_Generator_v2_XML_Util::createTagFromArray(), which
* is more flexible.
*
* <code>
* require_once 'XML/Util.php';
*
* // create an XML tag:
* $tag = PEAR_PackageFile_Generator_v2_XML_Util::createTag("myNs:myTag", array("foo" => "bar"), "This is inside the tag", "http://www.w3c.org/myNs#");
* </code>
*
* @access public
* @static
* @param string $qname qualified tagname (including namespace)
* @param array $attributes array containg attributes
* @param mixed $content
* @param string $namespaceUri URI of the namespace
* @param integer $replaceEntities whether to replace XML special chars in content, embedd it in a CData section or none of both
* @param boolean $multiline whether to create a multiline tag where each attribute gets written to a single line
* @param string $indent string used to indent attributes (_auto indents attributes so they start at the same column)
* @param string $linebreak string used for linebreaks
* @param string $encoding encoding that should be used to translate content
* @return string $string XML tag
* @see PEAR_PackageFile_Generator_v2_XML_Util::createTagFromArray()
* @uses PEAR_PackageFile_Generator_v2_XML_Util::createTagFromArray() to create the tag
*/
function createTag($qname, $attributes = array(), $content = null, $namespaceUri = null, $replaceEntities = PEAR_PackageFile_Generator_v2_XML_Util_REPLACE_ENTITIES, $multiline = false, $indent = "_auto", $linebreak = "\n", $encoding = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML)
{
$tag = array(
"qname" => $qname,
"attributes" => $attributes
);
 
// add tag content
if ($content !== null) {
$tag["content"] = $content;
}
// add namespace Uri
if ($namespaceUri !== null) {
$tag["namespaceUri"] = $namespaceUri;
}
 
return PEAR_PackageFile_Generator_v2_XML_Util::createTagFromArray($tag, $replaceEntities, $multiline, $indent, $linebreak, $encoding);
}
 
/**
* create a tag from an array
* this method awaits an array in the following format
* <pre>
* array(
* "qname" => $qname // qualified name of the tag
* "namespace" => $namespace // namespace prefix (optional, if qname is specified or no namespace)
* "localpart" => $localpart, // local part of the tagname (optional, if qname is specified)
* "attributes" => array(), // array containing all attributes (optional)
* "content" => $content, // tag content (optional)
* "namespaceUri" => $namespaceUri // namespaceUri for the given namespace (optional)
* )
* </pre>
*
* <code>
* require_once 'XML/Util.php';
*
* $tag = array(
* "qname" => "foo:bar",
* "namespaceUri" => "http://foo.com",
* "attributes" => array( "key" => "value", "argh" => "fruit&vegetable" ),
* "content" => "I'm inside the tag",
* );
* // creating a tag with qualified name and namespaceUri
* $string = PEAR_PackageFile_Generator_v2_XML_Util::createTagFromArray($tag);
* </code>
*
* @access public
* @static
* @param array $tag tag definition
* @param integer $replaceEntities whether to replace XML special chars in content, embedd it in a CData section or none of both
* @param boolean $multiline whether to create a multiline tag where each attribute gets written to a single line
* @param string $indent string used to indent attributes (_auto indents attributes so they start at the same column)
* @param string $linebreak string used for linebreaks
* @return string $string XML tag
* @see PEAR_PackageFile_Generator_v2_XML_Util::createTag()
* @uses PEAR_PackageFile_Generator_v2_XML_Util::attributesToString() to serialize the attributes of the tag
* @uses PEAR_PackageFile_Generator_v2_XML_Util::splitQualifiedName() to get local part and namespace of a qualified name
*/
function createTagFromArray($tag, $replaceEntities = PEAR_PackageFile_Generator_v2_XML_Util_REPLACE_ENTITIES, $multiline = false, $indent = "_auto", $linebreak = "\n", $encoding = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML)
{
if (isset($tag["content"]) && !is_scalar($tag["content"])) {
return PEAR_PackageFile_Generator_v2_XML_Util::raiseError( "Supplied non-scalar value as tag content", PEAR_PackageFile_Generator_v2_XML_Util_ERROR_NON_SCALAR_CONTENT );
}
 
if (!isset($tag['qname']) && !isset($tag['localPart'])) {
return PEAR_PackageFile_Generator_v2_XML_Util::raiseError( 'You must either supply a qualified name (qname) or local tag name (localPart).', PEAR_PackageFile_Generator_v2_XML_Util_ERROR_NO_TAG_NAME );
}
 
// if no attributes hav been set, use empty attributes
if (!isset($tag["attributes"]) || !is_array($tag["attributes"])) {
$tag["attributes"] = array();
}
// qualified name is not given
if (!isset($tag["qname"])) {
// check for namespace
if (isset($tag["namespace"]) && !empty($tag["namespace"])) {
$tag["qname"] = $tag["namespace"].":".$tag["localPart"];
} else {
$tag["qname"] = $tag["localPart"];
}
// namespace URI is set, but no namespace
} elseif (isset($tag["namespaceUri"]) && !isset($tag["namespace"])) {
$parts = PEAR_PackageFile_Generator_v2_XML_Util::splitQualifiedName($tag["qname"]);
$tag["localPart"] = $parts["localPart"];
if (isset($parts["namespace"])) {
$tag["namespace"] = $parts["namespace"];
}
}
 
if (isset($tag["namespaceUri"]) && !empty($tag["namespaceUri"])) {
// is a namespace given
if (isset($tag["namespace"]) && !empty($tag["namespace"])) {
$tag["attributes"]["xmlns:".$tag["namespace"]] = $tag["namespaceUri"];
} else {
// define this Uri as the default namespace
$tag["attributes"]["xmlns"] = $tag["namespaceUri"];
}
}
 
// check for multiline attributes
if ($multiline === true) {
if ($indent === "_auto") {
$indent = str_repeat(" ", (strlen($tag["qname"])+2));
}
}
// create attribute list
$attList = PEAR_PackageFile_Generator_v2_XML_Util::attributesToString($tag["attributes"], true, $multiline, $indent, $linebreak );
if (!isset($tag["content"]) || (string)$tag["content"] == '') {
$tag = sprintf("<%s%s />", $tag["qname"], $attList);
} else {
if ($replaceEntities == PEAR_PackageFile_Generator_v2_XML_Util_REPLACE_ENTITIES) {
$tag["content"] = PEAR_PackageFile_Generator_v2_XML_Util::replaceEntities($tag["content"], $encoding);
} elseif ($replaceEntities == PEAR_PackageFile_Generator_v2_XML_Util_CDATA_SECTION) {
$tag["content"] = PEAR_PackageFile_Generator_v2_XML_Util::createCDataSection($tag["content"]);
}
$tag = sprintf("<%s%s>%s</%s>", $tag["qname"], $attList, $tag["content"], $tag["qname"] );
}
return $tag;
}
 
/**
* create a start element
*
* <code>
* require_once 'XML/Util.php';
*
* // create an XML start element:
* $tag = PEAR_PackageFile_Generator_v2_XML_Util::createStartElement("myNs:myTag", array("foo" => "bar") ,"http://www.w3c.org/myNs#");
* </code>
*
* @access public
* @static
* @param string $qname qualified tagname (including namespace)
* @param array $attributes array containg attributes
* @param string $namespaceUri URI of the namespace
* @param boolean $multiline whether to create a multiline tag where each attribute gets written to a single line
* @param string $indent string used to indent attributes (_auto indents attributes so they start at the same column)
* @param string $linebreak string used for linebreaks
* @return string $string XML start element
* @see PEAR_PackageFile_Generator_v2_XML_Util::createEndElement(), PEAR_PackageFile_Generator_v2_XML_Util::createTag()
*/
function createStartElement($qname, $attributes = array(), $namespaceUri = null, $multiline = false, $indent = '_auto', $linebreak = "\n")
{
// if no attributes hav been set, use empty attributes
if (!isset($attributes) || !is_array($attributes)) {
$attributes = array();
}
if ($namespaceUri != null) {
$parts = PEAR_PackageFile_Generator_v2_XML_Util::splitQualifiedName($qname);
}
 
// check for multiline attributes
if ($multiline === true) {
if ($indent === "_auto") {
$indent = str_repeat(" ", (strlen($qname)+2));
}
}
 
if ($namespaceUri != null) {
// is a namespace given
if (isset($parts["namespace"]) && !empty($parts["namespace"])) {
$attributes["xmlns:".$parts["namespace"]] = $namespaceUri;
} else {
// define this Uri as the default namespace
$attributes["xmlns"] = $namespaceUri;
}
}
 
// create attribute list
$attList = PEAR_PackageFile_Generator_v2_XML_Util::attributesToString($attributes, true, $multiline, $indent, $linebreak);
$element = sprintf("<%s%s>", $qname, $attList);
return $element;
}
 
/**
* create an end element
*
* <code>
* require_once 'XML/Util.php';
*
* // create an XML start element:
* $tag = PEAR_PackageFile_Generator_v2_XML_Util::createEndElement("myNs:myTag");
* </code>
*
* @access public
* @static
* @param string $qname qualified tagname (including namespace)
* @return string $string XML end element
* @see PEAR_PackageFile_Generator_v2_XML_Util::createStartElement(), PEAR_PackageFile_Generator_v2_XML_Util::createTag()
*/
function createEndElement($qname)
{
$element = sprintf("</%s>", $qname);
return $element;
}
/**
* create an XML comment
*
* <code>
* require_once 'XML/Util.php';
*
* // create an XML start element:
* $tag = PEAR_PackageFile_Generator_v2_XML_Util::createComment("I am a comment");
* </code>
*
* @access public
* @static
* @param string $content content of the comment
* @return string $comment XML comment
*/
function createComment($content)
{
$comment = sprintf("<!-- %s -->", $content);
return $comment;
}
/**
* create a CData section
*
* <code>
* require_once 'XML/Util.php';
*
* // create a CData section
* $tag = PEAR_PackageFile_Generator_v2_XML_Util::createCDataSection("I am content.");
* </code>
*
* @access public
* @static
* @param string $data data of the CData section
* @return string $string CData section with content
*/
function createCDataSection($data)
{
return sprintf("<![CDATA[%s]]>", $data);
}
 
/**
* split qualified name and return namespace and local part
*
* <code>
* require_once 'XML/Util.php';
*
* // split qualified tag
* $parts = PEAR_PackageFile_Generator_v2_XML_Util::splitQualifiedName("xslt:stylesheet");
* </code>
* the returned array will contain two elements:
* <pre>
* array(
* "namespace" => "xslt",
* "localPart" => "stylesheet"
* );
* </pre>
*
* @access public
* @static
* @param string $qname qualified tag name
* @param string $defaultNs default namespace (optional)
* @return array $parts array containing namespace and local part
*/
function splitQualifiedName($qname, $defaultNs = null)
{
if (strstr($qname, ':')) {
$tmp = explode(":", $qname);
return array(
"namespace" => $tmp[0],
"localPart" => $tmp[1]
);
}
return array(
"namespace" => $defaultNs,
"localPart" => $qname
);
}
 
/**
* check, whether string is valid XML name
*
* <p>XML names are used for tagname, attribute names and various
* other, lesser known entities.</p>
* <p>An XML name may only consist of alphanumeric characters,
* dashes, undescores and periods, and has to start with a letter
* or an underscore.
* </p>
*
* <code>
* require_once 'XML/Util.php';
*
* // verify tag name
* $result = PEAR_PackageFile_Generator_v2_XML_Util::isValidName("invalidTag?");
* if (PEAR_PackageFile_Generator_v2_XML_Util::isError($result)) {
* print "Invalid XML name: " . $result->getMessage();
* }
* </code>
*
* @access public
* @static
* @param string $string string that should be checked
* @return mixed $valid true, if string is a valid XML name, PEAR error otherwise
* @todo support for other charsets
*/
function isValidName($string)
{
// check for invalid chars
if (!preg_match("/^[[:alnum:]_\-.]$/", $string{0})) {
return PEAR_PackageFile_Generator_v2_XML_Util::raiseError( "XML names may only start with letter or underscore", PEAR_PackageFile_Generator_v2_XML_Util_ERROR_INVALID_START );
}
// check for invalid chars
if (!preg_match("/^([a-zA-Z_]([a-zA-Z0-9_\-\.]*)?:)?[a-zA-Z_]([a-zA-Z0-9_\-\.]+)?$/", $string)) {
return PEAR_PackageFile_Generator_v2_XML_Util::raiseError( "XML names may only contain alphanumeric chars, period, hyphen, colon and underscores", PEAR_PackageFile_Generator_v2_XML_Util_ERROR_INVALID_CHARS );
}
// XML name is valid
return true;
}
 
/**
* replacement for PEAR_PackageFile_Generator_v2_XML_Util::raiseError
*
* Avoids the necessity to always require
* PEAR.php
*
* @access public
* @param string error message
* @param integer error code
* @return object PEAR_Error
*/
function raiseError($msg, $code)
{
require_once 'PEAR.php';
return PEAR::raiseError($msg, $code);
}
}
?>
/trunk/bibliotheque/pear/PEAR/PackageFile/v2/Validator.php
1,27 → 1,28
<?php
//
// +----------------------------------------------------------------------+
// | PHP Version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | 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 world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Greg Beaver <cellog@php.net> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: Validator.php,v 1.97 2007/02/10 05:56:18 cellog Exp $
/**
* PEAR_PackageFile_v2, package.xml version 2.0, read/write version
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a8
*/
/**
* Private validation class used by PEAR_PackageFile_v2 - do not use directly, its
* sole purpose is to split up the PEAR/PackageFile/v2.php file to make it smaller
* @author Greg Beaver <cellog@php.net>
* @category pear
* @package PEAR
* @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.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a8
* @access private
*/
class PEAR_PackageFile_v2_Validator
71,7 → 72,8
}
if (!isset($this->_packageInfo['attribs']['version']) ||
($this->_packageInfo['attribs']['version'] != '2.0' &&
$this->_packageInfo['attribs']['version'] != '2.1')) {
$this->_packageInfo['attribs']['version'] != '2.1')
) {
$this->_noPackageVersion();
}
$structure =
109,8 → 111,10
isset($test['dependencies']['required']) &&
isset($test['dependencies']['required']['pearinstaller']) &&
isset($test['dependencies']['required']['pearinstaller']['min']) &&
version_compare('1.5.1',
$test['dependencies']['required']['pearinstaller']['min'], '<')) {
'1.10.1' != '@package' . '_version@' &&
version_compare('1.10.1',
$test['dependencies']['required']['pearinstaller']['min'], '<')
) {
$this->_pearVersionTooLow($test['dependencies']['required']['pearinstaller']['min']);
return false;
}
130,18 → 134,13
if (array_key_exists('_lastversion', $test)) {
unset($test['_lastversion']);
}
if (!$this->_stupidSchemaValidate($structure,
$test, '<package>')) {
if (!$this->_stupidSchemaValidate($structure, $test, '<package>')) {
return false;
}
if (empty($this->_packageInfo['name'])) {
$this->_tagCannotBeEmpty('name');
}
if (isset($this->_packageInfo['uri'])) {
$test = 'uri';
} else {
$test = 'channel';
}
$test = isset($this->_packageInfo['uri']) ? 'uri' :'channel';
if (empty($this->_packageInfo[$test])) {
$this->_tagCannotBeEmpty($test);
}
233,14 → 232,17
}
}
}
 
if ($fail) {
return false;
}
 
$list = $this->_packageInfo['contents'];
if (isset($list['dir']) && is_array($list['dir']) && isset($list['dir'][0])) {
$this->_multipleToplevelDirNotAllowed();
return $this->_isValid = 0;
}
 
$this->_validateFilelist();
$this->_validateRelease();
if (!$this->_stack->hasErrors()) {
254,11 → 256,10
$validator = $chan->getValidationObject($this->_pf->getPackage());
if (!$validator) {
$this->_stack->push(__FUNCTION__, 'error',
array_merge(
array('channel' => $chan->getName(),
'package' => $this->_pf->getPackage()),
$valpack
),
array('channel' => $chan->getName(),
'package' => $this->_pf->getPackage(),
'name' => $valpack['_content'],
'version' => $valpack['attribs']['version']),
'package "%channel%/%package%" cannot be properly validated without ' .
'validation package "%channel%/%name%-%version%"');
return $this->_isValid = 0;
276,6 → 277,7
}
}
}
 
$this->_pf->_isValid = $this->_isValid = !$this->_stack->hasErrors('error');
if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$this->_filesValid) {
if ($this->_pf->getPackageType() == 'bundle') {
292,9 → 294,11
}
}
}
 
if ($this->_isValid) {
return $this->_pf->_isValid = $this->_isValid = $state;
}
 
return $this->_pf->_isValid = $this->_isValid = 0;
}
 
466,21 → 470,21
$a = $this->_stupidSchemaValidate($structure, $this->_packageInfo['version'], '<version>');
$a &= $this->_stupidSchemaValidate($structure, $this->_packageInfo['stability'], '<stability>');
if ($a) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$this->_packageInfo['version']['release'])) {
$this->_invalidVersion('release', $this->_packageInfo['version']['release']);
}
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$this->_packageInfo['version']['api'])) {
$this->_invalidVersion('api', $this->_packageInfo['version']['api']);
}
if (!in_array($this->_packageInfo['stability']['release'],
array('snapshot', 'devel', 'alpha', 'beta', 'stable'))) {
$this->_invalidState('release', $this->_packageinfo['stability']['release']);
$this->_invalidState('release', $this->_packageInfo['stability']['release']);
}
if (!in_array($this->_packageInfo['stability']['api'],
array('devel', 'alpha', 'beta', 'stable'))) {
$this->_invalidState('api', $this->_packageinfo['stability']['api']);
$this->_invalidState('api', $this->_packageInfo['stability']['api']);
}
}
}
519,13 → 523,13
$type = $installcondition ? '<installcondition><php>' : '<dependencies><required><php>';
$this->_stupidSchemaValidate($structure, $dep, $type);
if (isset($dep['min'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?\\z/',
$dep['min'])) {
$this->_invalidVersion($type . '<min>', $dep['min']);
}
}
if (isset($dep['max'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?\\z/',
$dep['max'])) {
$this->_invalidVersion($type . '<max>', $dep['max']);
}
536,7 → 540,7
}
foreach ($dep['exclude'] as $exclude) {
if (!preg_match(
'/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?$/',
'/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?\\z/',
$exclude)) {
$this->_invalidVersion($type . '<exclude>', $exclude);
}
554,7 → 558,7
);
$this->_stupidSchemaValidate($structure, $dep, '<dependencies><required><pearinstaller>');
if (isset($dep['min'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$dep['min'])) {
$this->_invalidVersion('<dependencies><required><pearinstaller><min>',
$dep['min']);
561,7 → 565,7
}
}
if (isset($dep['max'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$dep['max'])) {
$this->_invalidVersion('<dependencies><required><pearinstaller><max>',
$dep['max']);
568,7 → 572,7
}
}
if (isset($dep['recommended'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$dep['recommended'])) {
$this->_invalidVersion('<dependencies><required><pearinstaller><recommended>',
$dep['recommended']);
579,7 → 583,7
$dep['exclude'] = array($dep['exclude']);
}
foreach ($dep['exclude'] as $exclude) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$exclude)) {
$this->_invalidVersion('<dependencies><required><pearinstaller><exclude>',
$exclude);
641,19 → 645,19
$this->_DepchannelCannotBeUri('<dependencies>' . $group . $type);
}
if (isset($dep['min'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$dep['min'])) {
$this->_invalidVersion('<dependencies>' . $group . $type . '<min>', $dep['min']);
}
}
if (isset($dep['max'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$dep['max'])) {
$this->_invalidVersion('<dependencies>' . $group . $type . '<max>', $dep['max']);
}
}
if (isset($dep['recommended'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$dep['recommended'])) {
$this->_invalidVersion('<dependencies>' . $group . $type . '<recommended>',
$dep['recommended']);
664,7 → 668,7
$dep['exclude'] = array($dep['exclude']);
}
foreach ($dep['exclude'] as $exclude) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$exclude)) {
$this->_invalidVersion('<dependencies>' . $group . $type . '<exclude>',
$exclude);
713,19 → 717,19
}
$this->_stupidSchemaValidate($structure, $dep, $type);
if (isset($dep['min'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$dep['min'])) {
$this->_invalidVersion(substr($type, 1) . '<min', $dep['min']);
}
}
if (isset($dep['max'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$dep['max'])) {
$this->_invalidVersion(substr($type, 1) . '<max', $dep['max']);
}
}
if (isset($dep['recommended'])) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$dep['recommended'])) {
$this->_invalidVersion(substr($type, 1) . '<recommended', $dep['recommended']);
}
735,7 → 739,7
$dep['exclude'] = array($dep['exclude']);
}
foreach ($dep['exclude'] as $exclude) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$exclude)) {
$this->_invalidVersion(substr($type, 1) . '<exclude', $exclude);
}
932,13 → 936,13
}
$this->_stupidSchemaValidate($required, $package, $type);
if (is_array($package) && array_key_exists('min', $package)) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$package['min'])) {
$this->_invalidVersion(substr($type, 1) . '<min', $package['min']);
}
}
if (is_array($package) && array_key_exists('max', $package)) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$package['max'])) {
$this->_invalidVersion(substr($type, 1) . '<max', $package['max']);
}
948,7 → 952,7
$package['exclude'] = array($package['exclude']);
}
foreach ($package['exclude'] as $exclude) {
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
$exclude)) {
$this->_invalidVersion(substr($type, 1) . '<exclude', $exclude);
}
1007,6 → 1011,11
$dirname = $iscontents ? '<contents>' : $unknown;
} else {
$dirname = '<dir name="' . $list['attribs']['name'] . '">';
if (preg_match('~/\.\.?(/|\\z)|^\.\.?/~',
str_replace('\\', '/', $list['attribs']['name']))) {
// file contains .. parent directory or . cur directory
$this->_invalidDirName($list['attribs']['name']);
}
}
$res = $this->_stupidSchemaValidate($struc, $list, $dirname);
if ($allowignore && $res) {
1036,6 → 1045,12
$ignored_or_installed[$file['attribs']['name']] = array();
}
$ignored_or_installed[$file['attribs']['name']][] = 1;
if (preg_match('~/\.\.?(/|\\z)|^\.\.?/~',
str_replace('\\', '/', $file['attribs']['as']))) {
// file contains .. parent directory or . cur directory references
$this->_invalidFileInstallAs($file['attribs']['name'],
$file['attribs']['as']);
}
}
}
if (isset($list['ignore'])) {
1054,6 → 1069,10
}
}
if (!$allowignore && isset($list['file'])) {
if (is_string($list['file'])) {
$this->_oldStyleFileNotAllowed();
return false;
}
if (!isset($list['file'][0])) {
// single file
$list['file'] = array($list['file']);
1060,11 → 1079,17
}
foreach ($list['file'] as $i => $file)
{
if (isset($file['attribs']) && isset($file['attribs']['name']) &&
$file['attribs']['name']{0} == '.' &&
$file['attribs']['name']{1} == '/') {
// name is something like "./doc/whatever.txt"
$this->_invalidFileName($file['attribs']['name']);
if (isset($file['attribs']) && isset($file['attribs']['name'])) {
if ($file['attribs']['name']{0} == '.' &&
$file['attribs']['name']{1} == '/') {
// name is something like "./doc/whatever.txt"
$this->_invalidFileName($file['attribs']['name'], $dirname);
}
if (preg_match('~/\.\.?(/|\\z)|^\.\.?/~',
str_replace('\\', '/', $file['attribs']['name']))) {
// file contains .. parent directory or . cur directory
$this->_invalidFileName($file['attribs']['name'], $dirname);
}
}
if (isset($file['attribs']) && isset($file['attribs']['role'])) {
if (!$this->_validateRole($file['attribs']['role'])) {
1304,7 → 1329,7
}
if (is_array($rel) && array_key_exists('filelist', $rel)) {
if ($rel['filelist']) {
 
$this->_validateFilelist($rel['filelist'], true);
}
}
1325,7 → 1350,7
$this->_stack->push(__FUNCTION__, 'error',
array('version' => $version),
'This package.xml requires PEAR version %version% to parse properly, we are ' .
'version 1.5.1');
'version 1.10.1');
}
 
function _invalidTagOrder($oktags, $actual, $root)
1349,6 → 1374,13
'<contents>, use <ignore> and <install> only');
}
 
function _oldStyleFileNotAllowed()
{
$this->_stack->push(__FUNCTION__, 'error', array(),
'Old-style <file>name</file> is not allowed. Use' .
'<file name="name" role="role"/>');
}
 
function _tagMissingAttribute($tag, $attr, $context)
{
$this->_stack->push(__FUNCTION__, 'error', array('tag' => $tag,
1381,9 → 1413,23
{
$this->_stack->push(__FUNCTION__, 'error', array(
'file' => $file),
'File "%file%" cannot begin with "."');
'File "%file%" in directory "%dir%" cannot begin with "./" or contain ".."');
}
 
function _invalidFileInstallAs($file, $as)
{
$this->_stack->push(__FUNCTION__, 'error', array(
'file' => $file, 'as' => $as),
'File "%file%" <install as="%as%"/> cannot contain "./" or contain ".."');
}
 
function _invalidDirName($dir)
{
$this->_stack->push(__FUNCTION__, 'error', array(
'dir' => $file),
'Directory "%dir%" cannot begin with "./" or contain ".."');
}
 
function _filelistCannotContainFile($filelist)
{
$this->_stack->push(__FUNCTION__, 'error', array('tag' => $filelist),
1625,13 → 1671,13
function _usesroletaskMustHaveChannelOrUri($role, $tag)
{
$this->_stack->push(__FUNCTION__, 'error', array('role' => $role, 'tag' => $tag),
'<%tag%> must contain either <uri>, or <channel> and <package>');
'<%tag%> for role "%role%" must contain either <uri>, or <channel> and <package>');
}
 
function _usesroletaskMustHavePackage($role, $tag)
{
$this->_stack->push(__FUNCTION__, 'error', array('role' => $role, 'tag' => $tag),
'<%tag%> must contain <package>');
'<%tag%> for role "%role%" must contain <package>');
}
 
function _usesroletaskMustHaveRoleTask($tag, $type)
1648,7 → 1694,7
 
function _invalidDepGroupName($name)
{
$this->_stack->push(__FUNCTION__, 'error', array('group' => $name),
$this->_stack->push(__FUNCTION__, 'error', array('name' => $name),
'Invalid dependency group name "%name%"');
}
 
1683,14 → 1729,15
return false;
}
$dir_prefix = dirname($this->_pf->_packageFile);
$common = new PEAR_Common;
$log = isset($this->_pf->_logger) ? array(&$this->_pf->_logger, 'log') :
array('PEAR_Common', 'log');
array($common, 'log');
$info = $this->_pf->getContents();
$info = $info['bundledpackage'];
if (!is_array($info)) {
$info = array($info);
}
$pkg = &new PEAR_PackageFile($this->_pf->_config);
$pkg = new PEAR_PackageFile($this->_pf->_config);
foreach ($info as $package) {
if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $package)) {
$this->_fileNotFound($dir_prefix . DIRECTORY_SEPARATOR . $package);
1798,15 → 1845,19
'Parser error: token_get_all() function must exist to analyze source code, PHP may have been compiled with --disable-tokenizer');
return false;
}
 
if (!defined('T_DOC_COMMENT')) {
define('T_DOC_COMMENT', T_COMMENT);
}
 
if (!defined('T_INTERFACE')) {
define('T_INTERFACE', -1);
}
 
if (!defined('T_IMPLEMENTS')) {
define('T_IMPLEMENTS', -1);
}
 
if ($string) {
$contents = $file;
} else {
1816,7 → 1867,18
fclose($fp);
$contents = file_get_contents($file);
}
$tokens = token_get_all($contents);
 
// Silence this function so we can catch PHP Warnings and show our own custom message
$tokens = @token_get_all($contents);
if (isset($php_errormsg)) {
if (isset($this->_stack)) {
$pn = $this->_pf->getPackage();
$this->_stack->push(__FUNCTION__, 'warning',
array('file' => $file, 'package' => $pn),
'in %file%: Could not process file for unknown reasons,' .
' possibly a PHP parse error in %file% from %package%');
}
}
/*
for ($i = 0; $i < sizeof($tokens); $i++) {
@list($token, $data) = $tokens[$i];
1856,6 → 1918,7
$token = $tokens[$i];
$data = '';
}
 
if ($inquote) {
if ($token != '"' && $token != T_END_HEREDOC) {
continue;
1864,6 → 1927,7
continue;
}
}
 
switch ($token) {
case T_WHITESPACE :
continue;
1899,8 → 1963,14
$interface = true;
case T_CLASS:
if (($current_class_level != -1) || ($current_function_level != -1)) {
$this->_stack->push(__FUNCTION__, 'error', array('file' => $file),
'Parser error: invalid PHP found in file "%file%"');
if (isset($this->_stack)) {
$this->_stack->push(__FUNCTION__, 'error', array('file' => $file),
'Parser error: invalid PHP found in file "%file%"');
} else {
PEAR::raiseError("Parser error: invalid PHP found in file \"$file\"",
PEAR_COMMON_ERROR_INVALIDPHP);
}
 
return false;
}
case T_FUNCTION:
1910,17 → 1980,6
$look_for = $token;
continue 2;
case T_STRING:
if (version_compare(zend_version(), '2.0', '<')) {
if (in_array(strtolower($data),
array('public', 'private', 'protected', 'abstract',
'interface', 'implements', 'throw')
)) {
$this->_stack->push(__FUNCTION__, 'warning', array(
'file' => $file),
'Error, PHP5 token encountered in %file%,' .
' analysis should be in PHP5');
}
}
if ($look_for == T_CLASS) {
$current_class = $data;
$current_class_level = $brace_level;
1944,11 → 2003,13
$current_function = $data;
$declared_functions[] = $current_function;
}
 
$current_function_level = $brace_level;
$m = array();
} elseif ($look_for == T_NEW) {
$used_classes[$data] = true;
}
 
$look_for = 0;
continue 2;
case T_VARIABLE:
1964,18 → 2025,28
}
continue 2;
case T_DOUBLE_COLON:
if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
$this->_stack->push(__FUNCTION__, 'warning', array('file' => $file),
'Parser error: invalid PHP found in file "%file%"');
$token = $tokens[$i - 1][0];
if (!($token == T_WHITESPACE || $token == T_STRING || $token == T_STATIC || $token == T_VARIABLE)) {
if (isset($this->_stack)) {
$this->_stack->push(__FUNCTION__, 'warning', array('file' => $file),
'Parser error: invalid PHP found in file "%file%"');
} else {
PEAR::raiseError("Parser error: invalid PHP found in file \"$file\"",
PEAR_COMMON_ERROR_INVALIDPHP);
}
 
return false;
}
 
$class = $tokens[$i - 1][1];
if (strtolower($class) != 'parent') {
$used_classes[$class] = true;
}
 
continue 2;
}
}
 
return array(
"source_file" => $file,
"declared_classes" => $declared_classes,
1985,7 → 2056,7
"used_classes" => array_diff(array_keys($used_classes), $nodeps),
"inheritance" => $extends,
"implements" => $implements,
);
);
}
 
/**
2012,15 → 2083,17
if (!$this->_isValid) {
return array();
}
 
$providesret = array();
$file = basename($srcinfo['source_file']);
$pn = $this->_pf->getPackage();
$pnl = strlen($pn);
$file = basename($srcinfo['source_file']);
$pn = isset($this->_pf) ? $this->_pf->getPackage() : '';
$pnl = strlen($pn);
foreach ($srcinfo['declared_classes'] as $class) {
$key = "class;$class";
if (isset($providesret[$key])) {
continue;
}
 
$providesret[$key] =
array('file'=> $file, 'type' => 'class', 'name' => $class);
if (isset($srcinfo['inheritance'][$class])) {
2028,6 → 2101,7
$srcinfo['inheritance'][$class];
}
}
 
foreach ($srcinfo['declared_methods'] as $class => $methods) {
foreach ($methods as $method) {
$function = "$class::$method";
2036,6 → 2110,7
isset($providesret[$key])) {
continue;
}
 
$providesret[$key] =
array('file'=> $file, 'type' => 'function', 'name' => $function);
}
2046,13 → 2121,15
if ($function{0} == '_' || isset($providesret[$key])) {
continue;
}
 
if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {
$warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";
}
 
$providesret[$key] =
array('file'=> $file, 'type' => 'function', 'name' => $function);
}
 
return $providesret;
}
}
?>
/trunk/bibliotheque/pear/PEAR/PackageFile/v2/rw.php
4,18 → 4,11
*
* 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.19 2006/10/30 04:12:02 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a8
*/
27,9 → 20,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a8
*/
108,7 → 101,7
$this->_isValid = 0;
if (!isset($this->_packageInfo['uri'])) {
// ensure that the uri tag is set up in the right location
$this->_packageInfo = $this->_insertBefore($this->_packageInfo,
$this->_packageInfo = $this->_insertBefore($this->_packageInfo,
array('extends', 'summary', 'description', 'lead',
'developer', 'contributor', 'helper', 'date', 'time', 'version',
'stability', 'license', 'notes', 'contents', 'compatible',
248,7 → 241,7
}
}
foreach ($info as $i => $maintainer) {
if ($maintainer['user'] == $handle) {
if (is_array($maintainer) && $maintainer['user'] == $handle) {
$found = $i;
break 2;
}
458,11 → 451,13
'bundle', 'changelog'), array(), 'contents');
}
if ($this->getPackageType() != 'bundle') {
$this->_packageInfo['contents'] =
$this->_packageInfo['contents'] =
array('dir' => array('attribs' => array('name' => '/')));
if ($baseinstall) {
$this->_packageInfo['contents']['dir']['attribs']['baseinstalldir'] = $baseinstall;
}
} else {
$this->_packageInfo['contents'] = array('bundledpackage' => array());
}
}
 
1225,21 → 1220,26
'zendextbin', 'bundle'))) {
return false;
}
 
if (in_array($type, array('zendextsrc', 'zendextbin'))) {
$this->_setPackageVersion2_1();
}
 
if ($type != 'bundle') {
$type .= 'release';
}
 
foreach (array('phprelease', 'extbinrelease', 'extsrcrelease',
'zendextsrcrelease', 'zendextbinrelease', 'bundle') as $test) {
unset($this->_packageInfo[$test]);
}
 
if (!isset($this->_packageInfo[$type])) {
// ensure that the release tag is set up
$this->_packageInfo = $this->_insertBefore($this->_packageInfo, array('changelog'),
array(), $type);
}
 
$this->_packageInfo[$type] = array();
return true;
}
1359,14 → 1359,17
if ($this->getPackageType() != 'extsrc' && $this->getPackageType() != 'zendextsrc') {
return false;
}
 
$r = &$this->_getCurrentRelease(false);
if ($r === null) {
return false;
}
 
$opt = array('attribs' => array('name' => $name, 'prompt' => $prompt));
if ($default !== null) {
$opt['default'] = $default;
$opt['attribs']['default'] = $default;
}
 
$this->_isValid = 0;
$r = $this->_mergeTag($r, $opt,
array(
1544,7 → 1547,7
function generateChangeLogEntry($notes = false)
{
return array(
'version' =>
'version' =>
array(
'release' => $this->getVersion('release'),
'api' => $this->getVersion('api'),
1597,5 → 1600,4
{
unset($this->_packageInfo['changelog']);
}
}
?>
}
/trunk/bibliotheque/pear/PEAR/Installer/Role/Www.xml
New file
0,0 → 1,15
<role version="1.0">
<releasetypes>php</releasetypes>
<releasetypes>extsrc</releasetypes>
<releasetypes>extbin</releasetypes>
<releasetypes>zendextsrc</releasetypes>
<releasetypes>zendextbin</releasetypes>
<installable>1</installable>
<locationconfig>www_dir</locationconfig>
<honorsbaseinstall>1</honorsbaseinstall>
<unusualbaseinstall />
<phpfile />
<executable />
<phpextension />
<config_vars />
</role>
/trunk/bibliotheque/pear/PEAR/Installer/Role/Cfg.php
New file
0,0 → 1,105
<?php
/**
* PEAR_Installer_Role_Cfg
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 2007-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.7.0
*/
 
/**
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 2007-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.7.0
*/
class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common
{
/**
* @var PEAR_Installer
*/
var $installer;
 
/**
* the md5 of the original file
*
* @var unknown_type
*/
var $md5 = null;
 
/**
* Do any unusual setup here
* @param PEAR_Installer
* @param PEAR_PackageFile_v2
* @param array file attributes
* @param string file name
*/
function setup(&$installer, $pkg, $atts, $file)
{
$this->installer = &$installer;
$reg = &$this->installer->config->getRegistry();
$package = $reg->getPackage($pkg->getPackage(), $pkg->getChannel());
if ($package) {
$filelist = $package->getFilelist();
if (isset($filelist[$file]) && isset($filelist[$file]['md5sum'])) {
$this->md5 = $filelist[$file]['md5sum'];
}
}
}
 
function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
{
$test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer);
if (@file_exists($test[2]) && @file_exists($test[3])) {
$md5 = md5_file($test[2]);
// configuration has already been installed, check for mods
if ($md5 !== $this->md5 && $md5 !== md5_file($test[3])) {
// configuration has been modified, so save our version as
// configfile-version
$old = $test[2];
$test[2] .= '.new-' . $pkg->getVersion();
// backup original and re-install it
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$tmpcfg = $this->config->get('temp_dir');
$newloc = System::mkdir(array('-p', $tmpcfg));
if (!$newloc) {
// try temp_dir
$newloc = System::mktemp(array('-d'));
if (!$newloc || PEAR::isError($newloc)) {
PEAR::popErrorHandling();
return PEAR::raiseError('Could not save existing configuration file '.
$old . ', unable to install. Please set temp_dir ' .
'configuration variable to a writeable location and try again');
}
} else {
$newloc = $tmpcfg;
}
 
$temp_file = $newloc . DIRECTORY_SEPARATOR . uniqid('savefile');
if (!@copy($old, $temp_file)) {
PEAR::popErrorHandling();
return PEAR::raiseError('Could not save existing configuration file '.
$old . ', unable to install. Please set temp_dir ' .
'configuration variable to a writeable location and try again');
}
 
PEAR::popErrorHandling();
$this->installer->log(0, "WARNING: configuration file $old is being installed as $test[2], you should manually merge in changes to the existing configuration file");
$this->installer->addFileOperation('rename', array($temp_file, $old, false));
$this->installer->addFileOperation('delete', array($temp_file));
}
}
 
return $test;
}
}
/trunk/bibliotheque/pear/PEAR/Installer/Role/Ext.php
4,18 → 4,11
*
* 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: Ext.php,v 1.6 2006/01/06 04:47:37 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
24,9 → 17,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
/trunk/bibliotheque/pear/PEAR/Installer/Role/Src.xml
1,8 → 1,8
<role version="1.0">
<releasetypes>extsrc</releasetypes>
<releasetypes>zendextsrc</releasetypes>
<installable />
<locationconfig />
<installable>1</installable>
<locationconfig>temp_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall />
<phpfile />
/trunk/bibliotheque/pear/PEAR/Installer/Role/Script.php
4,18 → 4,11
*
* 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: Script.php,v 1.6 2006/01/06 04:47:37 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
24,9 → 17,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
/trunk/bibliotheque/pear/PEAR/Installer/Role/Doc.php
4,18 → 4,11
*
* 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: Doc.php,v 1.6 2006/01/06 04:47:37 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
24,9 → 17,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
/trunk/bibliotheque/pear/PEAR/Installer/Role/Cfg.xml
New file
0,0 → 1,15
<role version="1.0">
<releasetypes>php</releasetypes>
<releasetypes>extsrc</releasetypes>
<releasetypes>extbin</releasetypes>
<releasetypes>zendextsrc</releasetypes>
<releasetypes>zendextbin</releasetypes>
<installable>1</installable>
<locationconfig>cfg_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
<phpfile />
<executable />
<phpextension />
<config_vars />
</role>
/trunk/bibliotheque/pear/PEAR/Installer/Role/Data.php
4,18 → 4,11
*
* 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: Data.php,v 1.6 2006/01/06 04:47:37 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
24,9 → 17,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
/trunk/bibliotheque/pear/PEAR/Installer/Role/Man.php
New file
0,0 → 1,28
<?php
/**
* PEAR_Installer_Role_Man
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Hannes Magnusson <bjori@php.net>
* @copyright 2011 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version SVN: $Id: $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.10.0
*/
 
/**
* @category pear
* @package PEAR
* @author Hannes Magnusson <bjori@php.net>
* @copyright 2011 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.10.0
*/
class PEAR_Installer_Role_Man extends PEAR_Installer_Role_Common {}
?>
/trunk/bibliotheque/pear/PEAR/Installer/Role/Test.php
4,18 → 4,11
*
* 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: Test.php,v 1.6 2006/01/06 04:47:37 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
24,9 → 17,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
/trunk/bibliotheque/pear/PEAR/Installer/Role/Www.php
New file
0,0 → 1,27
<?php
/**
* PEAR_Installer_Role_Www
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 2007-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.7.0
*/
 
/**
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 2007-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.7.0
*/
class PEAR_Installer_Role_Www extends PEAR_Installer_Role_Common {}
?>
/trunk/bibliotheque/pear/PEAR/Installer/Role/Man.xml
New file
0,0 → 1,15
<role version="1.0">
<releasetypes>php</releasetypes>
<releasetypes>extsrc</releasetypes>
<releasetypes>extbin</releasetypes>
<releasetypes>zendextsrc</releasetypes>
<releasetypes>zendextbin</releasetypes>
<installable>1</installable>
<locationconfig>man_dir</locationconfig>
<honorsbaseinstall>1</honorsbaseinstall>
<unusualbaseinstall />
<phpfile />
<executable />
<phpextension />
<config_vars />
</role>
/trunk/bibliotheque/pear/PEAR/Installer/Role/Php.php
4,18 → 4,11
*
* 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: Php.php,v 1.7 2006/01/06 04:47:37 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
24,9 → 17,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
/trunk/bibliotheque/pear/PEAR/Installer/Role/Src.php
4,18 → 4,11
*
* 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: Src.php,v 1.6 2006/01/06 04:47:37 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
24,9 → 17,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
/trunk/bibliotheque/pear/PEAR/Installer/Role/Common.php
4,18 → 4,11
*
* 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.12 2006/10/19 23:55:32 cellog Exp $
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
29,8 → 22,8
* @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
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
45,7 → 38,7
/**
* @param PEAR_Config
*/
function PEAR_Installer_Role_Common(&$config)
function __construct(&$config)
{
$this->config = $config;
}
177,4 → 170,4
return $roleInfo['phpextension'];
}
}
?>
?>
/trunk/bibliotheque/pear/PEAR/Installer/Role.php
4,18 → 4,11
*
* 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: Role.php,v 1.16 2006/10/31 02:54:41 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
29,9 → 22,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
42,19 → 35,19
*
* Never call this directly, it is called by the PEAR_Config constructor
* @param PEAR_Config
* @access private
* @static
*/
function initializeConfig(&$config)
public static function initializeConfig(&$config)
{
if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
PEAR_Installer_Role::registerRoles();
}
 
foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $class => $info) {
if (!$info['config_vars']) {
continue;
}
$config->_addConfigVars($info['config_vars']);
 
$config->_addConfigVars($class, $info['config_vars']);
}
}
 
63,21 → 56,23
* @param string role name
* @param PEAR_Config
* @return PEAR_Installer_Role_Common
* @static
*/
function &factory($pkg, $role, &$config)
public static function &factory($pkg, $role, &$config)
{
if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
PEAR_Installer_Role::registerRoles();
}
 
if (!in_array($role, PEAR_Installer_Role::getValidRoles($pkg->getPackageType()))) {
$a = false;
return $a;
}
 
$a = 'PEAR_Installer_Role_' . ucfirst($role);
if (!class_exists($a)) {
require_once str_replace('_', '/', $a) . '.php';
}
 
$b = new $a($config);
return $b;
}
89,20 → 84,22
* @param string
* @param bool clear cache
* @return array
* @static
*/
function getValidRoles($release, $clear = false)
public static function getValidRoles($release, $clear = false)
{
if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
PEAR_Installer_Role::registerRoles();
}
 
static $ret = array();
if ($clear) {
$ret = array();
}
 
if (isset($ret[$release])) {
return $ret[$release];
}
 
$ret[$release] = array();
foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
if (in_array($release, $okreleases['releasetypes'])) {
109,6 → 106,7
$ret[$release][] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
}
}
 
return $ret[$release];
}
 
120,25 → 118,29
* roles are actually fully bundled releases of a package
* @param bool clear cache
* @return array
* @static
*/
function getInstallableRoles($clear = false)
public static function getInstallableRoles($clear = false)
{
if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
PEAR_Installer_Role::registerRoles();
}
 
static $ret;
if ($clear) {
unset($ret);
}
if (!isset($ret)) {
$ret = array();
foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
if ($okreleases['installable']) {
$ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
}
 
if (isset($ret)) {
return $ret;
}
 
$ret = array();
foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
if ($okreleases['installable']) {
$ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
}
}
 
return $ret;
}
 
150,25 → 152,29
* so a tests file tests/file.phpt is installed into PackageName/tests/filepath.php
* @param bool clear cache
* @return array
* @static
*/
function getBaseinstallRoles($clear = false)
public static function getBaseinstallRoles($clear = false)
{
if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
PEAR_Installer_Role::registerRoles();
}
 
static $ret;
if ($clear) {
unset($ret);
}
if (!isset($ret)) {
$ret = array();
foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
if ($okreleases['honorsbaseinstall']) {
$ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
}
 
if (isset($ret)) {
return $ret;
}
 
$ret = array();
foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
if ($okreleases['honorsbaseinstall']) {
$ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
}
}
 
return $ret;
}
 
177,25 → 183,29
* like the "php" role.
* @param bool clear cache
* @return array
* @static
*/
function getPhpRoles($clear = false)
public static function getPhpRoles($clear = false)
{
if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
PEAR_Installer_Role::registerRoles();
}
 
static $ret;
if ($clear) {
unset($ret);
}
if (!isset($ret)) {
$ret = array();
foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
if ($okreleases['phpfile']) {
$ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
}
 
if (isset($ret)) {
return $ret;
}
 
$ret = array();
foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
if ($okreleases['phpfile']) {
$ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
}
}
 
return $ret;
}
 
208,10 → 218,8
* included.
*
* @return bool TRUE on success, a PEAR error on failure
* @access public
* @static
*/
function registerRoles($dir = null)
public static function registerRoles($dir = null)
{
$GLOBALS['_PEAR_INSTALLER_ROLES'] = array();
$parser = new PEAR_XMLParser;
218,17 → 226,21
if ($dir === null) {
$dir = dirname(__FILE__) . '/Role';
}
 
if (!file_exists($dir) || !is_dir($dir)) {
return PEAR::raiseError("registerRoles: opendir($dir) failed");
return PEAR::raiseError("registerRoles: opendir($dir) failed: does not exist/is not directory");
}
 
$dp = @opendir($dir);
if (empty($dp)) {
return PEAR::raiseError("registerRoles: opendir($dir) failed");
return PEAR::raiseError("registerRoles: opendir($dir) failed: $php_errmsg");
}
 
while ($entry = readdir($dp)) {
if ($entry{0} == '.' || substr($entry, -4) != '.xml') {
continue;
}
 
$class = "PEAR_Installer_Role_".substr($entry, 0, -4);
// List of roles
if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'][$class])) {
238,9 → 250,11
if (!is_array($data['releasetypes'])) {
$data['releasetypes'] = array($data['releasetypes']);
}
 
$GLOBALS['_PEAR_INSTALLER_ROLES'][$class] = $data;
}
}
 
closedir($dp);
ksort($GLOBALS['_PEAR_INSTALLER_ROLES']);
PEAR_Installer_Role::getBaseinstallRoles(true);
249,5 → 263,4
PEAR_Installer_Role::getValidRoles('****', true);
return true;
}
}
?>
}
/trunk/bibliotheque/pear/PEAR/Downloader/Package.php
4,21 → 4,15
*
* 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: Package.php,v 1.104 2007/01/14 21:11:54 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
 
/**
* Error code when parameter initialization fails because no releases
* exist within preferred_state, but releases do exist
25,6 → 19,12
*/
define('PEAR_DOWNLOADER_PACKAGE_STATE', -1003);
/**
* Error code when parameter initialization fails because no releases
* exist that will work with the existing PHP version
*/
define('PEAR_DOWNLOADER_PACKAGE_PHPVERSION', -1004);
 
/**
* Coordinates download parameters and manages their dependencies
* prior to downloading them.
*
47,9 → 47,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
110,7 → 110,7
*/
var $_explicitGroup = false;
/**
* Package type local|url|xmlrpc
* Package type local|url
* @var string
*/
var $_type;
129,7 → 129,7
/**
* @param PEAR_Downloader
*/
function PEAR_Downloader_Package(&$downloader)
function __construct(&$downloader)
{
$this->_downloader = &$downloader;
$this->_config = &$this->_downloader->config;
157,67 → 157,87
function initialize($param)
{
$origErr = $this->_fromFile($param);
if (!$this->_valid) {
$options = $this->_downloader->getOptions();
if (isset($options['offline'])) {
if (PEAR::isError($origErr)) {
if (!isset($options['soft'])) {
$this->_downloader->log(0, $origErr->getMessage());
if ($this->_valid) {
return true;
}
 
$options = $this->_downloader->getOptions();
if (isset($options['offline'])) {
if (PEAR::isError($origErr) && !isset($options['soft'])) {
foreach ($origErr->getUserInfo() as $userInfo) {
if (isset($userInfo['message'])) {
$this->_downloader->log(0, $userInfo['message']);
}
}
return PEAR::raiseError('Cannot download non-local package "' . $param . '"');
 
$this->_downloader->log(0, $origErr->getMessage());
}
$err = $this->_fromUrl($param);
 
return PEAR::raiseError('Cannot download non-local package "' . $param . '"');
}
 
$err = $this->_fromUrl($param);
if (PEAR::isError($err) || !$this->_valid) {
if ($this->_type == 'url') {
if (PEAR::isError($err) && !isset($options['soft'])) {
$this->_downloader->log(0, $err->getMessage());
}
 
return PEAR::raiseError("Invalid or missing remote package file");
}
 
$err = $this->_fromString($param);
if (PEAR::isError($err) || !$this->_valid) {
if ($this->_type == 'url') {
if (PEAR::isError($err)) {
if (!isset($options['soft'])) {
$this->_downloader->log(0, $err->getMessage());
}
}
return PEAR::raiseError("Invalid or missing remote package file");
if (PEAR::isError($err) && $err->getCode() == PEAR_DOWNLOADER_PACKAGE_STATE) {
return false; // instruct the downloader to silently skip
}
$err = $this->_fromString($param);
if (PEAR::isError($err) || !$this->_valid) {
if (PEAR::isError($err) &&
$err->getCode() == PEAR_DOWNLOADER_PACKAGE_STATE) {
return false; // instruct the downloader to silently skip
}
if (isset($this->_type) && $this->_type == 'local' &&
PEAR::isError($origErr)) {
if (is_array($origErr->getUserInfo())) {
foreach ($origErr->getUserInfo() as $err) {
if (is_array($err)) {
$err = $err['message'];
}
if (!isset($options['soft'])) {
$this->_downloader->log(0, $err);
}
 
if (isset($this->_type) && $this->_type == 'local' && PEAR::isError($origErr)) {
if (is_array($origErr->getUserInfo())) {
foreach ($origErr->getUserInfo() as $err) {
if (is_array($err)) {
$err = $err['message'];
}
 
if (!isset($options['soft'])) {
$this->_downloader->log(0, $err);
}
}
if (!isset($options['soft'])) {
$this->_downloader->log(0, $origErr->getMessage());
}
if (is_array($param)) {
$param = $this->_registry->parsedPackageNameToString($param,
true);
}
return PEAR::raiseError(
"Cannot initialize '$param', invalid or missing package file");
}
if (PEAR::isError($err)) {
if (!isset($options['soft'])) {
$this->_downloader->log(0, $err->getMessage());
}
 
if (!isset($options['soft'])) {
$this->_downloader->log(0, $origErr->getMessage());
}
 
if (is_array($param)) {
$param = $this->_registry->parsedPackageNameToString($param, true);
}
return PEAR::raiseError(
"Cannot initialize '$param', invalid or missing package file");
 
if (!isset($options['soft'])) {
$this->_downloader->log(2, "Cannot initialize '$param', invalid or missing package file");
}
 
// Passing no message back - already logged above
return PEAR::raiseError();
}
 
if (PEAR::isError($err) && !isset($options['soft'])) {
$this->_downloader->log(0, $err->getMessage());
}
 
if (is_array($param)) {
$param = $this->_registry->parsedPackageNameToString($param, true);
}
 
if (!isset($options['soft'])) {
$this->_downloader->log(2, "Cannot initialize '$param', invalid or missing package file");
}
 
// Passing no message back - already logged above
return PEAR::raiseError();
}
}
 
return true;
}
 
230,6 → 250,7
if (isset($this->_packagefile)) {
return $this->_packagefile;
}
 
if (isset($this->_downloadURL['url'])) {
$this->_isvalid = false;
$info = $this->getParsedPackage();
236,6 → 257,7
foreach ($info as $i => $p) {
$info[$i] = strtolower($p);
}
 
$err = $this->_fromUrl($this->_downloadURL['url'],
$this->_registry->parsedPackageNameToString($this->_parsedname, true));
$newinfo = $this->getParsedPackage();
242,15 → 264,24
foreach ($newinfo as $i => $p) {
$newinfo[$i] = strtolower($p);
}
 
if ($info != $newinfo) {
do {
if ($info['package'] == 'pecl.php.net' && $newinfo['package'] == 'pear.php.net') {
$info['package'] = 'pear.php.net';
if ($info['channel'] == 'pecl.php.net' && $newinfo['channel'] == 'pear.php.net') {
$info['channel'] = 'pear.php.net';
if ($info == $newinfo) {
// skip the channel check if a pecl package says it's a PEAR package
break;
}
}
if ($info['channel'] == 'pear.php.net' && $newinfo['channel'] == 'pecl.php.net') {
$info['channel'] = 'pecl.php.net';
if ($info == $newinfo) {
// skip the channel check if a pecl package says it's a PEAR package
break;
}
}
 
return PEAR::raiseError('CRITICAL ERROR: We are ' .
$this->_registry->parsedPackageNameToString($info) . ', but the file ' .
'downloaded claims to be ' .
257,10 → 288,12
$this->_registry->parsedPackageNameToString($this->getParsedPackage()));
} while (false);
}
 
if (PEAR::isError($err) || !$this->_valid) {
return $err;
}
}
 
$this->_type = 'local';
return $this->_packagefile;
}
275,7 → 308,7
return $this->_downloader;
}
 
function getType()
function getType()
{
return $this->_type;
}
293,6 → 326,7
} else {
$ext = '.tgz';
}
 
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$err = $this->_fromUrl($dep['uri'] . $ext);
PEAR::popErrorHandling();
300,6 → 334,7
if (!isset($options['soft'])) {
$this->_downloader->log(0, $err->getMessage());
}
 
return PEAR::raiseError('Invalid uri dependency "' . $dep['uri'] . $ext . '", ' .
'cannot download');
}
314,6 → 349,7
$this->_parsedname['group'] = 'default'; // download the default dependency group
$this->_explicitGroup = false;
}
 
$this->_rawpackagefile = $dep['raw'];
}
}
324,23 → 360,27
if (isset($options['downloadonly'])) {
return;
}
 
if (isset($options['offline'])) {
$this->_downloader->log(3, 'Skipping dependency download check, --offline specified');
return;
}
 
$pname = $this->getParsedPackage();
if (!$pname) {
return;
}
 
$deps = $this->getDeps();
if (!$deps) {
return;
}
 
if (isset($deps['required'])) { // package.xml 2.0
return $this->_detect2($deps, $pname, $options, $params);
} else {
return $this->_detect1($deps, $pname, $options, $params);
}
 
return $this->_detect1($deps, $pname, $options, $params);
}
 
function setValidated()
356,22 → 396,24
/**
* Remove packages to be downloaded that are already installed
* @param array of PEAR_Downloader_Package objects
* @static
*/
function removeInstalled(&$params)
public static function removeInstalled(&$params)
{
if (!isset($params[0])) {
return;
}
 
$options = $params[0]->_downloader->getOptions();
if (!isset($options['downloadonly'])) {
foreach ($params as $i => $param) {
$package = $param->getPackage();
$channel = $param->getChannel();
// remove self if already installed with this version
// this does not need any pecl magic - we only remove exact matches
if ($param->_installRegistry->packageExists($param->getPackage(), $param->getChannel())) {
if (version_compare($param->_installRegistry->packageInfo($param->getPackage(), 'version',
$param->getChannel()), $param->getVersion(), '==')) {
if (!isset($options['force'])) {
if ($param->_installRegistry->packageExists($package, $channel)) {
$packageVersion = $param->_installRegistry->packageInfo($package, 'version', $channel);
if (version_compare($packageVersion, $param->getVersion(), '==')) {
if (!isset($options['force']) && !isset($options['packagingroot'])) {
$info = $param->getParsedPackage();
unset($info['version']);
unset($info['state']);
378,25 → 420,22
if (!isset($options['soft'])) {
$param->_downloader->log(1, 'Skipping package "' .
$param->getShortName() .
'", already installed as version ' .
$param->_installRegistry->packageInfo($param->getPackage(),
'version', $param->getChannel()));
'", already installed as version ' . $packageVersion);
}
$params[$i] = false;
}
} elseif (!isset($options['force']) && !isset($options['upgrade']) &&
!isset($options['soft'])) {
!isset($options['soft']) && !isset($options['packagingroot'])) {
$info = $param->getParsedPackage();
$param->_downloader->log(1, 'Skipping package "' .
$param->getShortName() .
'", already installed as version ' .
$param->_installRegistry->packageInfo($param->getPackage(), 'version',
$param->getChannel()));
'", already installed as version ' . $packageVersion);
$params[$i] = false;
}
}
}
}
 
PEAR_Downloader_Package::removeDuplicates($params);
}
 
416,6 → 455,8
$ret = $this->_detect2Dep($dep, $pname, 'required', $params);
if (is_array($ret)) {
$this->_downloadDeps[] = $ret;
} elseif (PEAR::isError($ret) && !isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
}
} else {
425,10 → 466,13
$ret = $this->_detect2Dep($dep, $pname, 'required', $params);
if (is_array($ret)) {
$this->_downloadDeps[] = $ret;
} elseif (PEAR::isError($ret) && !isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
}
}
}
 
// get optional dependency group, if any
if (isset($deps['optional'][$packagetype])) {
$skipnames = array();
435,6 → 479,7
if (!isset($deps['optional'][$packagetype][0])) {
$deps['optional'][$packagetype] = array($deps['optional'][$packagetype]);
}
 
foreach ($deps['optional'][$packagetype] as $dep) {
$skip = false;
if (!isset($options['alldeps'])) {
451,7 → 496,13
$skip = true;
unset($dep['package']);
}
if (!($ret = $this->_detect2Dep($dep, $pname, 'optional', $params))) {
 
$ret = $this->_detect2Dep($dep, $pname, 'optional', $params);
if (PEAR::isError($ret) && !isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
 
if (!$ret) {
$dep['package'] = $dep['name'];
$skip = count($skipnames) ?
$skipnames[count($skipnames) - 1] : '';
460,10 → 511,12
array_pop($skipnames);
}
}
 
if (!$skip && is_array($ret)) {
$this->_downloadDeps[] = $ret;
}
}
 
if (count($skipnames)) {
if (!isset($options['soft'])) {
$this->_downloader->log(1, 'Did not download optional dependencies: ' .
472,19 → 525,22
}
}
}
 
// get requested dependency group, if any
$groupname = $this->getGroup();
$explicit = $this->_explicitGroup;
$explicit = $this->_explicitGroup;
if (!$groupname) {
if ($this->canDefault()) {
$groupname = 'default'; // try the default dependency group
} else {
if (!$this->canDefault()) {
continue;
}
 
$groupname = 'default'; // try the default dependency group
}
 
if ($groupnotfound) {
continue;
}
 
if (isset($deps['group'])) {
if (isset($deps['group']['attribs'])) {
if (strtolower($deps['group']['attribs']['name']) == strtolower($groupname)) {
495,6 → 551,7
$this->_registry->parsedPackageNameToString($pname, true) .
'" has no dependency ' . 'group named "' . $groupname . '"');
}
 
$groupnotfound = true;
continue;
}
506,6 → 563,7
break;
}
}
 
if (!$found) {
if ($explicit) {
if (!isset($options['soft'])) {
514,29 → 572,33
'" has no dependency ' . 'group named "' . $groupname . '"');
}
}
 
$groupnotfound = true;
continue;
}
}
}
if (isset($group)) {
if (isset($group[$packagetype])) {
if (isset($group[$packagetype][0])) {
foreach ($group[$packagetype] as $dep) {
$ret = $this->_detect2Dep($dep, $pname, 'dependency group "' .
$group['attribs']['name'] . '"', $params);
if (is_array($ret)) {
$this->_downloadDeps[] = $ret;
}
}
} else {
$ret = $this->_detect2Dep($group[$packagetype], $pname,
'dependency group "' .
 
if (isset($group) && isset($group[$packagetype])) {
if (isset($group[$packagetype][0])) {
foreach ($group[$packagetype] as $dep) {
$ret = $this->_detect2Dep($dep, $pname, 'dependency group "' .
$group['attribs']['name'] . '"', $params);
if (is_array($ret)) {
$this->_downloadDeps[] = $ret;
} elseif (PEAR::isError($ret) && !isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
}
} else {
$ret = $this->_detect2Dep($group[$packagetype], $pname,
'dependency group "' .
$group['attribs']['name'] . '"', $params);
if (is_array($ret)) {
$this->_downloadDeps[] = $ret;
} elseif (PEAR::isError($ret) && !isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
}
}
}
547,10 → 609,12
if (isset($dep['conflicts'])) {
return true;
}
 
$options = $this->_downloader->getOptions();
if (isset($dep['uri'])) {
return array('uri' => $dep['uri'], 'dep' => $dep);;
}
 
$testdep = $dep;
$testdep['package'] = $dep['name'];
if (PEAR_Downloader_Package::willDownload($testdep, $params)) {
563,17 → 627,19
}
return false;
}
 
$options = $this->_downloader->getOptions();
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
if ($this->_explicitState) {
$pname['state'] = $this->_explicitState;
}
$url =
$this->_downloader->_getDepPackageDownloadUrl($dep, $pname);
 
$url = $this->_downloader->_getDepPackageDownloadUrl($dep, $pname);
if (PEAR::isError($url)) {
PEAR::popErrorHandling();
return $url;
}
 
$dep['package'] = $dep['name'];
$ret = $this->_analyzeDownloadURL($url, 'dependency', $dep, $params, $group == 'optional' &&
!isset($options['alldeps']), true);
582,34 → 648,38
if (!isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
 
return false;
}
 
// check to see if a dep is already installed and is the same or newer
if (!isset($dep['min']) && !isset($dep['max']) && !isset($dep['recommended'])) {
$oper = 'has';
} else {
// check to see if a dep is already installed and is the same or newer
if (!isset($dep['min']) && !isset($dep['max']) && !isset($dep['recommended'])) {
$oper = 'has';
} else {
$oper = 'gt';
$oper = 'gt';
}
 
// do not try to move this before getDepPackageDownloadURL
// we can't determine whether upgrade is necessary until we know what
// version would be downloaded
if (!isset($options['force']) && $this->isInstalled($ret, $oper)) {
$version = $this->_installRegistry->packageInfo($dep['name'], 'version', $dep['channel']);
$dep['package'] = $dep['name'];
if (!isset($options['soft'])) {
$this->_downloader->log(3, $this->getShortName() . ': Skipping ' . $group .
' dependency "' .
$this->_registry->parsedPackageNameToString($dep, true) .
'" version ' . $url['version'] . ', already installed as version ' .
$version);
}
// do not try to move this before getDepPackageDownloadURL
// we can't determine whether upgrade is necessary until we know what
// version would be downloaded
if (!isset($options['force']) && $this->isInstalled($ret, $oper)) {
$version = $this->_installRegistry->packageInfo($dep['name'], 'version',
$dep['channel']);
$dep['package'] = $dep['name'];
if (!isset($options['soft'])) {
$this->_downloader->log(3, $this->getShortName() . ': Skipping ' . $group .
' dependency "' .
$this->_registry->parsedPackageNameToString($dep, true) .
'" version ' . $url['version'] . ', already installed as version ' .
$version);
}
return false;
}
 
return false;
}
 
if (isset($dep['nodefault'])) {
$ret['nodefault'] = true;
}
 
return $ret;
}
 
619,7 → 689,7
$skipnames = array();
foreach ($deps as $dep) {
$nodownload = false;
if ($dep['type'] == 'pkg') {
if (isset ($dep['type']) && $dep['type'] === 'pkg') {
$dep['channel'] = 'pear.php.net';
$dep['package'] = $dep['name'];
switch ($dep['rel']) {
651,12 → 721,13
continue 2;
}
}
 
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
if ($this->_explicitState) {
$pname['state'] = $this->_explicitState;
}
$url =
$this->_downloader->_getDepPackageDownloadUrl($dep, $pname);
 
$url = $this->_downloader->_getDepPackageDownloadUrl($dep, $pname);
$chan = 'pear.php.net';
if (PEAR::isError($url)) {
// check to see if this is a pecl package that has jumped
664,12 → 735,12
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
 
$newdep = PEAR_Dependency2::normalizeDep($dep);
$newdep = $newdep[0];
$newdep['channel'] = 'pecl.php.net';
$chan = 'pecl.php.net';
$url =
$this->_downloader->_getDepPackageDownloadUrl($newdep, $pname);
$url = $this->_downloader->_getDepPackageDownloadUrl($newdep, $pname);
$obj = &$this->_installRegistry->getPackage($dep['name']);
if (PEAR::isError($url)) {
PEAR::popErrorHandling();
694,8 → 765,7
} else {
if (isset($dep['optional']) && $dep['optional'] == 'yes') {
$this->_downloader->log(2, $this->getShortName() .
': Skipping ' . $group
. ' dependency "' .
': Skipping optional dependency "' .
$this->_registry->parsedPackageNameToString($dep, true) .
'", no releases exist');
continue;
705,6 → 775,7
}
}
}
 
PEAR::popErrorHandling();
if (!isset($options['alldeps'])) {
if (isset($dep['optional']) && $dep['optional'] == 'yes') {
723,6 → 794,7
$nodownload = true;
}
}
 
if (!isset($options['alldeps']) && !isset($options['onlyreqdeps'])) {
if (!isset($dep['optional']) || $dep['optional'] == 'no') {
if (!isset($options['soft'])) {
740,6 → 812,7
$nodownload = true;
}
}
 
// check to see if a dep is already installed
// do not try to move this before getDepPackageDownloadURL
// we can't determine whether upgrade is necessary until we know what
751,11 → 824,11
'optional';
$dep['package'] = $dep['name'];
if (isset($newdep)) {
$version = $this->_installRegistry->packageInfo($newdep['name'], 'version',
$newdep['channel']);
$version = $this->_installRegistry->packageInfo($newdep['name'], 'version', $newdep['channel']);
} else {
$version = $this->_installRegistry->packageInfo($dep['name'], 'version');
}
 
$dep['version'] = $url['version'];
if (!isset($options['soft'])) {
$this->_downloader->log(3, $this->getShortName() . ': Skipping ' . $group .
763,6 → 836,7
$this->_registry->parsedPackageNameToString($dep, true) .
'", already installed as version ' . $version);
}
 
$skip = count($skipnames) ?
$skipnames[count($skipnames) - 1] : '';
if ($skip ==
769,15 → 843,19
$this->_registry->parsedPackageNameToString($dep, true)) {
array_pop($skipnames);
}
 
continue;
}
 
if ($nodownload) {
continue;
}
 
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
if (isset($newdep)) {
$dep = $newdep;
}
 
$dep['package'] = $dep['name'];
$ret = $this->_analyzeDownloadURL($url, 'dependency', $dep, $params,
isset($dep['optional']) && $dep['optional'] == 'yes' &&
789,9 → 867,11
}
continue;
}
 
$this->_downloadDeps[] = $ret;
}
}
 
if (count($skipnames)) {
if (!isset($options['soft'])) {
$this->_downloader->log(1, 'Did not download dependencies: ' .
823,12 → 903,13
}
 
function getParsedPackage()
{
{
if (isset($this->_packagefile) || isset($this->_parsedname)) {
return array('channel' => $this->getChannel(),
'package' => $this->getPackage(),
'version' => $this->getVersion());
}
 
return false;
}
 
839,11 → 920,10
 
function canDefault()
{
if (isset($this->_downloadURL)) {
if (isset($this->_downloadURL['nodefault'])) {
return false;
}
if (isset($this->_downloadURL) && isset($this->_downloadURL['nodefault'])) {
return false;
}
 
return true;
}
 
853,9 → 933,9
return $this->_packagefile->getPackage();
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->getPackage();
} else {
return false;
}
 
return false;
}
 
/**
867,9 → 947,9
return $this->_packagefile->isSubpackage($pf);
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->isSubpackage($pf);
} else {
return false;
}
 
return false;
}
 
function getPackageType()
878,9 → 958,9
return $this->_packagefile->getPackageType();
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->getPackageType();
} else {
return false;
}
 
return false;
}
 
function isBundle()
887,9 → 967,9
{
if (isset($this->_packagefile)) {
return $this->_packagefile->getPackageType() == 'bundle';
} else {
return false;
}
 
return false;
}
 
function getPackageXmlVersion()
898,9 → 978,9
return $this->_packagefile->getPackagexmlVersion();
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->getPackagexmlVersion();
} else {
return '1.0';
}
 
return '1.0';
}
 
function getChannel()
909,9 → 989,9
return $this->_packagefile->getChannel();
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->getChannel();
} else {
return false;
}
 
return false;
}
 
function getURI()
920,9 → 1000,9
return $this->_packagefile->getURI();
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->getURI();
} else {
return false;
}
 
return false;
}
 
function getVersion()
931,9 → 1011,9
return $this->_packagefile->getVersion();
} elseif (isset($this->_downloadURL['version'])) {
return $this->_downloadURL['version'];
} else {
return false;
}
 
return false;
}
 
function isCompatible($pf)
942,9 → 1022,9
return $this->_packagefile->isCompatible($pf);
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->isCompatible($pf);
} else {
return true;
}
 
return true;
}
 
function setGroup($group)
956,9 → 1036,9
{
if (isset($this->_parsedname['group'])) {
return $this->_parsedname['group'];
} else {
return '';
}
 
return '';
}
 
function isExtension($name)
966,14 → 1046,14
if (isset($this->_packagefile)) {
return $this->_packagefile->isExtension($name);
} elseif (isset($this->_downloadURL['info'])) {
if ($this->_downloadURL['info']->getPackagexmlVersion() == '2.0') {
return $this->_downloadURL['info']->getProvidesExtension() == $name;
} else {
return false;
}
} else {
if ($this->_downloadURL['info']->getPackagexmlVersion() == '2.0') {
return $this->_downloadURL['info']->getProvidesExtension() == $name;
}
 
return false;
}
 
return false;
}
 
function getDeps()
982,19 → 1062,19
$ver = $this->_packagefile->getPackagexmlVersion();
if (version_compare($ver, '2.0', '>=')) {
return $this->_packagefile->getDeps(true);
} else {
return $this->_packagefile->getDeps();
}
 
return $this->_packagefile->getDeps();
} elseif (isset($this->_downloadURL['info'])) {
$ver = $this->_downloadURL['info']->getPackagexmlVersion();
if (version_compare($ver, '2.0', '>=')) {
return $this->_downloadURL['info']->getDeps(true);
} else {
return $this->_downloadURL['info']->getDeps();
}
} else {
return array();
 
return $this->_downloadURL['info']->getDeps();
}
 
return array();
}
 
/**
1027,14 → 1107,14
}
return $param['uri'] == $this->getURI();
}
$package = isset($param['package']) ? $param['package'] :
$param['info']->getPackage();
$channel = isset($param['channel']) ? $param['channel'] :
$param['info']->getChannel();
 
$package = isset($param['package']) ? $param['package'] : $param['info']->getPackage();
$channel = isset($param['channel']) ? $param['channel'] : $param['info']->getChannel();
if (isset($param['rel'])) {
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
 
$newdep = PEAR_Dependency2::normalizeDep($param);
$newdep = $newdep[0];
} elseif (isset($param['min'])) {
1041,13 → 1121,16
$newdep = $param;
}
}
 
if (isset($newdep)) {
if (!isset($newdep['min'])) {
$newdep['min'] = '0';
}
 
if (!isset($newdep['max'])) {
$newdep['max'] = '100000000000000000000';
}
 
// use magic to support pecl packages suddenly jumping to the pecl channel
// we need to support both dependency possibilities
if ($channel == 'pear.php.net' && $this->getChannel() == 'pecl.php.net') {
1060,11 → 1143,13
$channel = 'pear.php.net';
}
}
 
return (strtolower($package) == strtolower($this->getPackage()) &&
$channel == $this->getChannel() &&
version_compare($newdep['min'], $this->getVersion(), '<=') &&
version_compare($newdep['max'], $this->getVersion(), '>='));
}
 
// use magic to support pecl packages suddenly jumping to the pecl channel
if ($channel == 'pecl.php.net' && $this->getChannel() == 'pear.php.net') {
if (strtolower($package) == strtolower($this->getPackage())) {
1071,14 → 1156,15
$channel = 'pear.php.net';
}
}
 
if (isset($param['version'])) {
return (strtolower($package) == strtolower($this->getPackage()) &&
$channel == $this->getChannel() &&
$param['version'] == $this->getVersion());
} else {
return strtolower($package) == strtolower($this->getPackage()) &&
$channel == $this->getChannel();
}
 
return strtolower($package) == strtolower($this->getPackage()) &&
$channel == $this->getChannel();
}
 
function isInstalled($dep, $oper = '==')
1086,9 → 1172,11
if (!$dep) {
return false;
}
 
if ($oper != 'ge' && $oper != 'gt' && $oper != 'has' && $oper != '==') {
return false;
}
 
if (is_object($dep)) {
$package = $dep->getPackage();
$channel = $dep->getChannel();
1111,13 → 1199,15
$package = $dep['info']->getPackage();
}
}
 
$options = $this->_downloader->getOptions();
$test = $this->_installRegistry->packageExists($package, $channel);
$test = $this->_installRegistry->packageExists($package, $channel);
if (!$test && $channel == 'pecl.php.net') {
// do magic to allow upgrading from old pecl packages to new ones
$test = $this->_installRegistry->packageExists($package, 'pear.php.net');
$channel = 'pear.php.net';
}
 
if ($test) {
if (isset($dep['uri'])) {
if ($this->_installRegistry->packageInfo($package, 'uri', '__uri') == $dep['uri']) {
1124,35 → 1214,73
return true;
}
}
 
if (isset($options['upgrade'])) {
if ($oper == 'has') {
if (version_compare($this->_installRegistry->packageInfo(
$package, 'version', $channel),
$dep['version'], '>=')) {
return true;
} else {
return false;
}
} else {
if (version_compare($this->_installRegistry->packageInfo(
$package, 'version', $channel),
$dep['version'], '>=')) {
return true;
}
return false;
$packageVersion = $this->_installRegistry->packageInfo($package, 'version', $channel);
if (version_compare($packageVersion, $dep['version'], '>=')) {
return true;
}
 
return false;
}
 
return true;
}
 
return false;
}
 
/**
* Detect duplicate package names with differing versions
*
* If a user requests to install Date 1.4.6 and Date 1.4.7,
* for instance, this is a logic error. This method
* detects this situation.
*
* @param array $params array of PEAR_Downloader_Package objects
* @param array $errorparams empty array
* @return array array of stupid duplicated packages in PEAR_Downloader_Package obejcts
*/
public static function detectStupidDuplicates($params, &$errorparams)
{
$existing = array();
foreach ($params as $i => $param) {
$package = $param->getPackage();
$channel = $param->getChannel();
$group = $param->getGroup();
if (!isset($existing[$channel . '/' . $package])) {
$existing[$channel . '/' . $package] = array();
}
 
if (!isset($existing[$channel . '/' . $package][$group])) {
$existing[$channel . '/' . $package][$group] = array();
}
 
$existing[$channel . '/' . $package][$group][] = $i;
}
 
$indices = array();
foreach ($existing as $package => $groups) {
foreach ($groups as $group => $dupes) {
if (count($dupes) > 1) {
$indices = $indices + $dupes;
}
}
}
 
$indices = array_unique($indices);
foreach ($indices as $index) {
$errorparams[] = $params[$index];
}
 
return count($errorparams);
}
 
/**
* @param array
* @param bool ignore install groups - for final removal of dupe packages
* @static
*/
function removeDuplicates(&$params, $ignoreGroups = false)
public static function removeDuplicates(&$params, $ignoreGroups = false)
{
$pnames = array();
foreach ($params as $i => $param) {
1159,45 → 1287,44
if (!$param) {
continue;
}
 
if ($param->getPackage()) {
if ($ignoreGroups) {
$group = '';
} else {
$group = $param->getGroup();
}
$group = $ignoreGroups ? '' : $param->getGroup();
$pnames[$i] = $param->getChannel() . '/' .
$param->getPackage() . '-' . $param->getVersion() . '#' . $group;
}
}
 
$pnames = array_unique($pnames);
$unset = array_diff(array_keys($params), array_keys($pnames));
$testp = array_flip($pnames);
$unset = array_diff(array_keys($params), array_keys($pnames));
$testp = array_flip($pnames);
foreach ($params as $i => $param) {
if (!$param) {
$unset[] = $i;
continue;
}
 
if (!is_a($param, 'PEAR_Downloader_Package')) {
$unset[] = $i;
continue;
}
if ($ignoreGroups) {
$group = '';
} else {
$group = $param->getGroup();
}
 
$group = $ignoreGroups ? '' : $param->getGroup();
if (!isset($testp[$param->getChannel() . '/' . $param->getPackage() . '-' .
$param->getVersion() . '#' . $group])) {
$unset[] = $i;
}
}
 
foreach ($unset as $i) {
unset($params[$i]);
}
 
$ret = array();
foreach ($params as $i => $param) {
$ret[] = &$params[$i];
}
 
$params = array();
foreach ($ret as $i => $param) {
$params[] = &$ret[$i];
1215,16 → 1342,15
}
 
/**
* @static
*/
function mergeDependencies(&$params)
public static function mergeDependencies(&$params)
{
$newparams = array();
$bundles = array();
$bundles = $newparams = array();
foreach ($params as $i => $param) {
if (!$param->isBundle()) {
continue;
}
 
$bundles[] = $i;
$pf = &$param->getPackageFile();
$newdeps = array();
1232,6 → 1358,7
if (!is_array($contents)) {
$contents = array($contents);
}
 
foreach ($contents as $file) {
$filecontents = $pf->getFileContents($file);
$dl = &$param->getDownloader();
1239,22 → 1366,28
if (PEAR::isError($dir = $dl->getDownloadDir())) {
return $dir;
}
 
$fp = @fopen($dir . DIRECTORY_SEPARATOR . $file, 'wb');
if (!$fp) {
continue;
}
 
// FIXME do symlink check
 
fwrite($fp, $filecontents, strlen($filecontents));
fclose($fp);
if ($s = $params[$i]->explicitState()) {
$obj->setExplicitState($s);
}
$obj = &new PEAR_Downloader_Package($params[$i]->getDownloader());
 
$obj = new PEAR_Downloader_Package($params[$i]->getDownloader());
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
if (PEAR::isError($dir = $dl->getDownloadDir())) {
PEAR::popErrorHandling();
return $dir;
}
$e = $obj->_fromFile($a = $dir . DIRECTORY_SEPARATOR . $file);
$a = $dir . DIRECTORY_SEPARATOR . $file;
$e = $obj->_fromFile($a);
PEAR::popErrorHandling();
if (PEAR::isError($e)) {
if (!isset($options['soft'])) {
1262,16 → 1395,18
}
continue;
}
$j = &$obj;
if (!PEAR_Downloader_Package::willDownload($j,
array_merge($params, $newparams)) && !$param->isInstalled($j)) {
$newparams[] = &$j;
 
if (!PEAR_Downloader_Package::willDownload($obj,
array_merge($params, $newparams)) && !$param->isInstalled($obj)) {
$newparams[] = $obj;
}
}
}
 
foreach ($bundles as $i) {
unset($params[$i]); // remove bundles - only their contents matter for installation
}
 
PEAR_Downloader_Package::removeDuplicates($params); // strip any unset indices
if (count($newparams)) { // add in bundled packages for install
foreach ($newparams as $i => $unused) {
1279,24 → 1414,29
}
$newparams = array();
}
 
foreach ($params as $i => $param) {
$newdeps = array();
foreach ($param->_downloadDeps as $dep) {
if (!PEAR_Downloader_Package::willDownload($dep,
array_merge($params, $newparams)) && !$param->isInstalled($dep)) {
$merge = array_merge($params, $newparams);
if (!PEAR_Downloader_Package::willDownload($dep, $merge)
&& !$param->isInstalled($dep)
) {
$newdeps[] = $dep;
} else {
//var_dump($dep);
// detect versioning conflicts here
}
}
// convert the dependencies into PEAR_Downloader_Package objects for the next time
// around
 
// convert the dependencies into PEAR_Downloader_Package objects for the next time around
$params[$i]->_downloadDeps = array();
foreach ($newdeps as $dep) {
$obj = &new PEAR_Downloader_Package($params[$i]->getDownloader());
$obj = new PEAR_Downloader_Package($params[$i]->getDownloader());
if ($s = $params[$i]->explicitState()) {
$obj->setExplicitState($s);
}
 
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$e = $obj->fromDepURL($dep);
PEAR::popErrorHandling();
1306,6 → 1446,7
}
continue;
}
 
$e = $obj->detectDependencies($params);
if (PEAR::isError($e)) {
if (!isset($options['soft'])) {
1312,34 → 1453,36
$obj->_downloader->log(0, $e->getMessage());
}
}
$j = &$obj;
$newparams[] = &$j;
 
$newparams[] = $obj;
}
}
 
if (count($newparams)) {
foreach ($newparams as $i => $unused) {
$params[] = &$newparams[$i];
}
return true;
} else {
return false;
}
 
return false;
}
 
 
/**
* @static
*/
function willDownload($param, $params)
public static function willDownload($param, $params)
{
if (!is_array($params)) {
return false;
}
 
foreach ($params as $obj) {
if ($obj->isEqual($param)) {
return true;
}
}
 
return false;
}
 
1349,13 → 1492,12
* @param int
* @param string
*/
function &getPackagefileObject(&$c, $d, $t = false)
function &getPackagefileObject(&$c, $d)
{
$a = &new PEAR_PackageFile($c, $d, $t);
$a = new PEAR_PackageFile($c, $d);
return $a;
}
 
 
/**
* This will retrieve from a local file if possible, and parse out
* a group name as well. The original parameter will be modified to reflect this.
1369,25 → 1511,17
if (!@file_exists($param)) {
$test = explode('#', $param);
$group = array_pop($test);
if (file_exists(implode('#', $test))) {
if (@file_exists(implode('#', $test))) {
$this->setGroup($group);
$param = implode('#', $test);
$this->_explicitGroup = true;
}
}
 
if (@is_file($param)) {
$this->_type = 'local';
$options = $this->_downloader->getOptions();
if (isset($options['downloadonly'])) {
$pkg = &$this->getPackagefileObject($this->_config,
$this->_downloader->_debug);
} else {
if (PEAR::isError($dir = $this->_downloader->getDownloadDir())) {
return $dir;
}
$pkg = &$this->getPackagefileObject($this->_config,
$this->_downloader->_debug, $dir);
}
$pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->_debug);
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pf = &$pkg->fromAnyFile($param, PEAR_VALIDATE_INSTALLING);
PEAR::popErrorHandling();
1409,8 → 1543,7
 
function _fromUrl($param, $saveparam = '')
{
if (!is_array($param) &&
(preg_match('#^(http|ftp)://#', $param))) {
if (!is_array($param) && (preg_match('#^(http|https|ftp)://#', $param))) {
$options = $this->_downloader->getOptions();
$this->_type = 'url';
$callback = $this->_downloader->ui ?
1420,8 → 1553,10
$this->_downloader->popErrorHandling();
return $dir;
}
 
$this->_downloader->log(3, 'Downloading "' . $param . '"');
$file = $this->_downloader->downloadHttp($param, $this->_downloader->ui,
$dir, $callback);
$dir, $callback, null, false, $this->getChannel());
$this->_downloader->popErrorHandling();
if (PEAR::isError($file)) {
if (!empty($saveparam)) {
1431,39 → 1566,35
'"' . $saveparam . ' (' . $file->getMessage() . ')');
return $err;
}
 
if ($this->_rawpackagefile) {
require_once 'Archive/Tar.php';
$tar = &new Archive_Tar($file);
$tar = new Archive_Tar($file);
$packagexml = $tar->extractInString('package2.xml');
if (!$packagexml) {
$packagexml = $tar->extractInString('package.xml');
}
 
if (str_replace(array("\n", "\r"), array('',''), $packagexml) !=
str_replace(array("\n", "\r"), array('',''), $this->_rawpackagefile)) {
if ($this->getChannel() == 'pear.php.net') {
// be more lax for the existing PEAR packages that have not-ok
// characters in their package.xml
$this->_downloader->log(0, 'CRITICAL WARNING: The "' .
$this->getPackage() . '" package has invalid characters in its ' .
'package.xml. The next version of PEAR may not be able to install ' .
'this package for security reasons. Please open a bug report at ' .
'http://pear.php.net/package/' . $this->getPackage() . '/bugs');
} else {
if ($this->getChannel() != 'pear.php.net') {
return PEAR::raiseError('CRITICAL ERROR: package.xml downloaded does ' .
'not match value returned from xml-rpc');
}
 
// be more lax for the existing PEAR packages that have not-ok
// characters in their package.xml
$this->_downloader->log(0, 'CRITICAL WARNING: The "' .
$this->getPackage() . '" package has invalid characters in its ' .
'package.xml. The next version of PEAR may not be able to install ' .
'this package for security reasons. Please open a bug report at ' .
'http://pear.php.net/package/' . $this->getPackage() . '/bugs');
}
}
 
// whew, download worked!
if (isset($options['downloadonly'])) {
$pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->debug);
} else {
if (PEAR::isError($dir = $this->_downloader->getDownloadDir())) {
return $dir;
}
$pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->debug,
$dir);
}
$pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->debug);
 
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pf = &$pkg->fromAnyFile($file, PEAR_VALIDATE_INSTALLING);
PEAR::popErrorHandling();
1473,23 → 1604,30
if (is_array($err)) {
$err = $err['message'];
}
 
if (!isset($options['soft'])) {
$this->_downloader->log(0, "Validation Error: $err");
}
}
}
 
if (!isset($options['soft'])) {
$this->_downloader->log(0, $pf->getMessage());
}
$err = PEAR::raiseError('Download of "' . ($saveparam ? $saveparam :
$param) . '" succeeded, but it is not a valid package archive');
 
///FIXME need to pass back some error code that we can use to match with to cancel all further operations
/// At least stop all deps of this package from being installed
$out = $saveparam ? $saveparam : $param;
$err = PEAR::raiseError('Download of "' . $out . '" succeeded, but it is not a valid package archive');
$this->_valid = false;
return $err;
}
 
$this->_packagefile = &$pf;
$this->setGroup('default'); // install the default dependency group
return $this->_valid = true;
}
 
return $this->_valid = false;
}
 
1506,9 → 1644,9
function _fromString($param)
{
$options = $this->_downloader->getOptions();
$channel = $this->_config->get('default_channel');
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pname = $this->_registry->parsePackageName($param,
$this->_config->get('default_channel'));
$pname = $this->_registry->parsePackageName($param, $channel);
PEAR::popErrorHandling();
if (PEAR::isError($pname)) {
if ($pname->getCode() == 'invalid') {
1515,13 → 1653,13
$this->_valid = false;
return false;
}
 
if ($pname->getCode() == 'channel') {
$parsed = $pname->getUserInfo();
if ($this->_downloader->discover($parsed['channel'])) {
if ($this->_config->get('auto_discover')) {
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pname = $this->_registry->parsePackageName($param,
$this->_config->get('default_channel'));
$pname = $this->_registry->parsePackageName($param, $channel);
PEAR::popErrorHandling();
} else {
if (!isset($options['soft'])) {
1532,15 → 1670,17
}
}
}
 
if (PEAR::isError($pname)) {
if (!isset($options['soft'])) {
$this->_downloader->log(0, $pname->getMessage());
}
 
if (is_array($param)) {
$param = $this->_registry->parsedPackageNameToString($param);
}
$err = PEAR::raiseError('invalid package name/package file "' .
$param . '"');
 
$err = PEAR::raiseError('invalid package name/package file "' . $param . '"');
$this->_valid = false;
return $err;
}
1548,26 → 1688,21
if (!isset($options['soft'])) {
$this->_downloader->log(0, $pname->getMessage());
}
$err = PEAR::raiseError('invalid package name/package file "' .
$param . '"');
 
$err = PEAR::raiseError('invalid package name/package file "' . $param . '"');
$this->_valid = false;
return $err;
}
}
 
if (!isset($this->_type)) {
$this->_type = 'xmlrpc';
$this->_type = 'rest';
}
$this->_parsedname = $pname;
if (isset($pname['state'])) {
$this->_explicitState = $pname['state'];
} else {
$this->_explicitState = false;
}
if (isset($pname['group'])) {
$this->_explicitGroup = true;
} else {
$this->_explicitGroup = false;
}
 
$this->_parsedname = $pname;
$this->_explicitState = isset($pname['state']) ? $pname['state'] : false;
$this->_explicitGroup = isset($pname['group']) ? true : false;
 
$info = $this->_downloader->_getPackageDownloadUrl($pname);
if (PEAR::isError($info)) {
if ($info->getCode() != -976 && $pname['channel'] == 'pear.php.net') {
1586,13 → 1721,16
$pname['channel'] = 'pear.php.net';
}
}
 
return $info;
}
 
$this->_rawpackagefile = $info['raw'];
$ret = $this->_analyzeDownloadURL($info, $param, $pname);
if (PEAR::isError($ret)) {
return $ret;
}
 
if ($ret) {
$this->_downloadURL = $ret;
return $this->_valid = (bool) $ret;
1615,16 → 1753,15
if (!is_string($param) && PEAR_Downloader_Package::willDownload($param, $params)) {
return false;
}
if (!$info) {
if (!is_string($param)) {
$saveparam = ", cannot download \"$param\"";
} else {
$saveparam = '';
}
 
if ($info === false) {
$saveparam = !is_string($param) ? ", cannot download \"$param\"" : '';
 
// no releases exist
return PEAR::raiseError('No releases for package "' .
$this->_registry->parsedPackageNameToString($pname, true) . '" exist' . $saveparam);
}
 
if (strtolower($info['info']->getChannel()) != strtolower($pname['channel'])) {
$err = false;
if ($pname['channel'] == 'pecl.php.net') {
1638,6 → 1775,7
} else {
$err = true;
}
 
if ($err) {
return PEAR::raiseError('SECURITY ERROR: package in channel "' . $pname['channel'] .
'" retrieved another channel\'s name for download! ("' .
1644,11 → 1782,13
$info['info']->getChannel() . '")');
}
}
 
$preferred_state = $this->_config->get('preferred_state');
if (!isset($info['url'])) {
$package_version = $this->_registry->packageInfo($info['info']->getPackage(),
'version', $info['info']->getChannel());
if ($this->isInstalled($info)) {
if ($isdependency && version_compare($info['version'],
$this->_registry->packageInfo($info['info']->getPackage(),
'version', $info['info']->getChannel()), '<=')) {
if ($isdependency && version_compare($info['version'], $package_version, '<=')) {
// ignore bogus errors of "failed to download dependency"
// if it is already installed and the one that would be
// downloaded is older or the same version (Bug #7219)
1655,6 → 1795,27
return false;
}
}
 
if ($info['version'] === $package_version) {
if (!isset($options['soft'])) {
$this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] .
'/' . $pname['package'] . '-' . $package_version. ', additionally the suggested version' .
' (' . $package_version . ') is the same as the locally installed one.');
}
 
return false;
}
 
if (version_compare($info['version'], $package_version, '<=')) {
if (!isset($options['soft'])) {
$this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] .
'/' . $pname['package'] . '-' . $package_version . ', additionally the suggested version' .
' (' . $info['version'] . ') is a lower version than the locally installed one (' . $package_version . ').');
}
 
return false;
}
 
$instead = ', will instead download version ' . $info['version'] .
', stability "' . $info['info']->getState() . '"';
// releases exist, but we failed to get any
1667,8 → 1828,9
if (!class_exists('PEAR_Common')) {
require_once 'PEAR/Common.php';
}
 
if (!in_array($info['info']->getState(),
PEAR_Common::betterStates($this->_config->get('preferred_state'), true))) {
PEAR_Common::betterStates($preferred_state, true))) {
if ($optional) {
// don't spit out confusing error message
return $this->_downloader->_getPackageDownloadUrl(
1676,12 → 1838,13
'channel' => $pname['channel'],
'version' => $info['version']));
}
$vs = ' within preferred state "' . $this->_config->get('preferred_state') .
$vs = ' within preferred state "' . $preferred_state .
'"';
} else {
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
 
if ($optional) {
// don't spit out confusing error message
return $this->_downloader->_getPackageDownloadUrl(
1693,13 → 1856,14
$instead = '';
}
} else {
$vs = ' within preferred state "' . $this->_config->get(
'preferred_state') . '"';
$vs = ' within preferred state "' . $preferred_state . '"';
}
 
if (!isset($options['soft'])) {
$this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] .
'/' . $pname['package'] . $vs . $instead);
}
 
// download the latest release
return $this->_downloader->_getPackageDownloadUrl(
array('package' => $pname['package'],
1706,6 → 1870,22
'channel' => $pname['channel'],
'version' => $info['version']));
} else {
if (isset($info['php']) && $info['php']) {
$err = PEAR::raiseError('Failed to download ' .
$this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'],
'package' => $pname['package']),
true) .
', latest release is version ' . $info['php']['v'] .
', but it requires PHP version "' .
$info['php']['m'] . '", use "' .
$this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'], 'package' => $pname['package'],
'version' => $info['php']['v'])) . '" to install',
PEAR_DOWNLOADER_PACKAGE_PHPVERSION);
return $err;
}
 
// construct helpful error message
if (isset($pname['version'])) {
$vs = ', version "' . $pname['version'] . '"';
1715,8 → 1895,9
if (!class_exists('PEAR_Common')) {
require_once 'PEAR/Common.php';
}
 
if (!in_array($info['info']->getState(),
PEAR_Common::betterStates($this->_config->get('preferred_state'), true))) {
PEAR_Common::betterStates($preferred_state, true))) {
if ($optional) {
// don't spit out confusing error message, and don't die on
// optional dep failure!
1725,12 → 1906,12
'channel' => $pname['channel'],
'version' => $info['version']));
}
$vs = ' within preferred state "' . $this->_config->get('preferred_state') .
'"';
$vs = ' within preferred state "' . $preferred_state . '"';
} else {
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
 
if ($optional) {
// don't spit out confusing error message, and don't die on
// optional dep failure!
1742,9 → 1923,9
$vs = PEAR_Dependency2::_getExtraString($pname);
}
} else {
$vs = ' within preferred state "' . $this->_downloader->config->get(
'preferred_state') . '"';
$vs = ' within preferred state "' . $this->_downloader->config->get('preferred_state') . '"';
}
 
$options = $this->_downloader->getOptions();
// this is only set by the "download-all" command
if (isset($options['ignorepreferred_state'])) {
1761,22 → 1942,32
PEAR_DOWNLOADER_PACKAGE_STATE);
return $err;
}
$err = PEAR::raiseError(
'Failed to download ' . $this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'], 'package' => $pname['package']),
true)
. $vs .
', latest release is version ' . $info['version'] .
', stability "' . $info['info']->getState() . '", use "' .
$this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'], 'package' => $pname['package'],
'version' => $info['version'])) . '" to install');
return $err;
 
// Checks if the user has a package installed already and checks the release against
// the state against the installed package, this allows upgrades for packages
// with lower stability than the preferred_state
$stability = $this->_registry->packageInfo($pname['package'], 'stability', $pname['channel']);
if (!$this->isInstalled($info)
|| !in_array($info['info']->getState(), PEAR_Common::betterStates($stability['release'], true))
) {
$err = PEAR::raiseError(
'Failed to download ' . $this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'], 'package' => $pname['package']),
true)
. $vs .
', latest release is version ' . $info['version'] .
', stability "' . $info['info']->getState() . '", use "' .
$this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'], 'package' => $pname['package'],
'version' => $info['version'])) . '" to install');
return $err;
}
}
}
 
if (isset($info['deprecated']) && $info['deprecated']) {
$this->_downloader->log(0,
'WARNING: "' .
'WARNING: "' .
$this->_registry->parsedPackageNameToString(
array('channel' => $info['info']->getChannel(),
'package' => $info['info']->getPackage()), true) .
1784,7 → 1975,7
$this->_registry->parsedPackageNameToString($info['deprecated'], true) .
'"');
}
 
return $info;
}
}
?>
/trunk/bibliotheque/pear/PEAR/ChannelFile.php
4,18 → 4,11
*
* 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: ChannelFile.php,v 1.78 2006/10/31 02:54:40 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
72,11 → 65,11
*/
define('PEAR_CHANNELFILE_ERROR_MULTILINE_SUMMARY', 9);
/**
* Error code when channel server is missing for xmlrpc or soap protocol
* Error code when channel server is missing for protocol
*/
define('PEAR_CHANNELFILE_ERROR_NO_HOST', 10);
/**
* Error code when channel server is invalid for xmlrpc or soap protocol
* Error code when channel server is invalid for protocol
*/
define('PEAR_CHANNELFILE_ERROR_INVALID_HOST', 11);
/**
128,11 → 121,11
* Error code when <baseurl> contains no type attribute in a <rest> protocol definition
*/
define('PEAR_CHANNELFILE_ERROR_NOBASEURLTYPE', 35);
/**
/**
* Error code when a mirror is defined and the channel.xml represents the __uri pseudo-channel
*/
define('PEAR_CHANNELFILE_URI_CANT_MIRROR', 36);
/**
/**
* Error code when ssl attribute is present and is not "yes"
*/
define('PEAR_CHANNELFILE_ERROR_INVALID_SSL', 37);
150,13 → 143,14
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_ChannelFile {
class PEAR_ChannelFile
{
/**
* @access private
* @var PEAR_ErrorStack
163,7 → 157,7
* @access private
*/
var $_stack;
 
/**
* Supported channel.xml versions, for parsing
* @var array
191,7 → 185,7
* @access private
*/
var $_mirrorIndex;
 
/**
* Flag used to determine the validity of parsed content
* @var boolean
199,13 → 193,13
*/
var $_isValid = false;
 
function PEAR_ChannelFile()
function __construct()
{
$this->_stack = &new PEAR_ErrorStack('PEAR_ChannelFile');
$this->_stack = new PEAR_ErrorStack('PEAR_ChannelFile');
$this->_stack->setErrorMessageTemplate($this->_getErrorMessage());
$this->_isValid = false;
}
 
/**
* @return array
* @access protected
284,7 → 278,7
if ($result !== true) {
if ($result->getCode() == 1) {
$this->_stack->push(PEAR_CHANNELFILE_ERROR_NO_XML_EXT, 'error',
array('error' => $error));
array('error' => $result->getMessage()));
} else {
$this->_stack->push(PEAR_CHANNELFILE_ERROR_CANT_MAKE_PARSER, 'error');
}
297,7 → 291,7
return false;
}
}
 
/**
* @return array
*/
308,14 → 302,15
}
return $this->_channelInfo;
}
 
/**
* @param array
* @static
*
* @return PEAR_ChannelFile|false false if invalid
*/
function &fromArray($data, $compatibility = false, $stackClass = 'PEAR_ErrorStack')
{
public static function &fromArray(
$data, $compatibility = false, $stackClass = 'PEAR_ErrorStack'
) {
$a = new PEAR_ChannelFile($compatibility, $stackClass);
$a->_fromArray($data);
if (!$a->validate()) {
327,18 → 322,19
 
/**
* Unlike {@link fromArray()} this does not do any validation
*
* @param array
* @static
*
* @return PEAR_ChannelFile
*/
function &fromArrayWithErrors($data, $compatibility = false,
$stackClass = 'PEAR_ErrorStack')
{
public static function &fromArrayWithErrors(
$data, $compatibility = false, $stackClass = 'PEAR_ErrorStack'
) {
$a = new PEAR_ChannelFile($compatibility, $stackClass);
$a->_fromArray($data);
return $a;
}
 
/**
* @param array
* @access private
347,7 → 343,7
{
$this->_channelInfo = $data;
}
 
/**
* Wrapper to {@link PEAR_ErrorStack::getErrors()}
* @param boolean determines whether to purge the error stack after retrieving
484,15 → 480,9
$ret .= ' port="' . $channelInfo['servers']['primary']['attribs']['port'] . '"';
}
$ret .= ">\n";
if (isset($channelInfo['servers']['primary']['xmlrpc'])) {
$ret .= $this->_makeXmlrpcXml($channelInfo['servers']['primary']['xmlrpc'], ' ');
}
if (isset($channelInfo['servers']['primary']['rest'])) {
$ret .= $this->_makeRestXml($channelInfo['servers']['primary']['rest'], ' ');
}
if (isset($channelInfo['servers']['primary']['soap'])) {
$ret .= $this->_makeSoapXml($channelInfo['servers']['primary']['soap'], ' ');
}
$ret .= " </primary>\n";
if (isset($channelInfo['servers']['mirror'])) {
$ret .= $this->_makeMirrorsXml($channelInfo);
503,38 → 493,6
}
 
/**
* Generate the <xmlrpc> tag
* @access private
*/
function _makeXmlrpcXml($info, $indent)
{
$ret = $indent . "<xmlrpc";
if (isset($info['attribs']['path'])) {
$ret .= ' path="' . htmlspecialchars($info['attribs']['path']) . '"';
}
$ret .= ">\n";
$ret .= $this->_makeFunctionsXml($info['function'], "$indent ");
$ret .= $indent . "</xmlrpc>\n";
return $ret;
}
 
/**
* Generate the <soap> tag
* @access private
*/
function _makeSoapXml($info, $indent)
{
$ret = $indent . "<soap";
if (isset($info['attribs']['path'])) {
$ret .= ' path="' . htmlspecialchars($info['attribs']['path']) . '"';
}
$ret .= ">\n";
$ret .= $this->_makeFunctionsXml($info['function'], "$indent ");
$ret .= $indent . "</soap>\n";
return $ret;
}
 
/**
* Generate the <rest> tag
* @access private
*/
541,12 → 499,15
function _makeRestXml($info, $indent)
{
$ret = $indent . "<rest>\n";
if (!isset($info['baseurl'][0])) {
if (isset($info['baseurl']) && !isset($info['baseurl'][0])) {
$info['baseurl'] = array($info['baseurl']);
}
foreach ($info['baseurl'] as $url) {
$ret .= "$indent <baseurl type=\"" . $url['attribs']['type'] . "\"";
$ret .= ">" . $url['_content'] . "</baseurl>\n";
 
if (isset($info['baseurl'])) {
foreach ($info['baseurl'] as $url) {
$ret .= "$indent <baseurl type=\"" . $url['attribs']['type'] . "\"";
$ret .= ">" . $url['_content'] . "</baseurl>\n";
}
}
$ret .= $indent . "</rest>\n";
return $ret;
571,16 → 532,10
$ret .= ' ssl="' . $mirror['attribs']['ssl'] . '"';
}
$ret .= ">\n";
if (isset($mirror['xmlrpc']) || isset($mirror['soap'])) {
if (isset($mirror['xmlrpc'])) {
$ret .= $this->_makeXmlrpcXml($mirror['xmlrpc'], ' ');
}
if (isset($mirror['rest'])) {
if (isset($mirror['rest'])) {
$ret .= $this->_makeRestXml($mirror['rest'], ' ');
}
if (isset($mirror['soap'])) {
$ret .= $this->_makeSoapXml($mirror['soap'], ' ');
}
$ret .= " </mirror>\n";
} else {
$ret .= "/>\n";
680,12 → 635,14
array('package' => $content));
}
}
if (isset($info['servers']['primary']['attribs']['port']) &&
 
if (isset($info['servers']['primary']['attribs'], $info['servers']['primary']['attribs']['port']) &&
!is_numeric($info['servers']['primary']['attribs']['port'])) {
$this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID_PORT,
array('port' => $info['servers']['primary']['attribs']['port']));
}
if (isset($info['servers']['primary']['attribs']['ssl']) &&
 
if (isset($info['servers']['primary']['attribs'], $info['servers']['primary']['attribs']['ssl']) &&
$info['servers']['primary']['attribs']['ssl'] != 'yes') {
$this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID_SSL,
array('ssl' => $info['servers']['primary']['attribs']['ssl'],
692,14 → 649,6
'server' => $info['name']));
}
 
if (isset($info['servers']['primary']['xmlrpc']) &&
isset($info['servers']['primary']['xmlrpc']['function'])) {
$this->_validateFunctions('xmlrpc', $info['servers']['primary']['xmlrpc']['function']);
}
if (isset($info['servers']['primary']['soap']) &&
isset($info['servers']['primary']['soap']['function'])) {
$this->_validateFunctions('soap', $info['servers']['primary']['soap']['function']);
}
if (isset($info['servers']['primary']['rest']) &&
isset($info['servers']['primary']['rest']['baseurl'])) {
$this->_validateFunctions('rest', $info['servers']['primary']['rest']['baseurl']);
711,7 → 660,6
if (!isset($info['servers']['mirror'][0])) {
$info['servers']['mirror'] = array($info['servers']['mirror']);
}
$i = 0;
foreach ($info['servers']['mirror'] as $mirror) {
if (!isset($mirror['attribs']['host'])) {
$this->_validateError(PEAR_CHANNELFILE_ERROR_NO_HOST,
724,14 → 672,6
$this->_validateError(PEAR_CHANNELFILE_ERROR_INVALID_SSL,
array('ssl' => $info['ssl'], 'server' => $mirror['attribs']['host']));
}
if (isset($mirror['xmlrpc'])) {
$this->_validateFunctions('xmlrpc',
$mirror['xmlrpc']['function'], $mirror['attribs']['host']);
}
if (isset($mirror['soap'])) {
$this->_validateFunctions('soap', $mirror['soap']['function'],
$mirror['attribs']['host']);
}
if (isset($mirror['rest'])) {
$this->_validateFunctions('rest', $mirror['rest']['baseurl'],
$mirror['attribs']['host']);
742,7 → 682,7
}
 
/**
* @param string xmlrpc or soap - protocol name this function applies to
* @param string rest - protocol name this function applies to
* @param array the functions
* @param string the name of the parent element (mirror name, for instance)
*/
751,15 → 691,17
if (!isset($functions[0])) {
$functions = array($functions);
}
 
foreach ($functions as $function) {
if (!isset($function['_content']) || empty($function['_content'])) {
$this->_validateError(PEAR_CHANNELFILE_ERROR_NO_FUNCTIONNAME,
array('parent' => $parent, 'protocol' => $protocol));
}
 
if ($protocol == 'rest') {
if (!isset($function['attribs']['type']) ||
empty($function['attribs']['type'])) {
$this->_validateError(PEAR_CHANNELFILE_ERROR_NO_BASEURLTYPE,
$this->_validateError(PEAR_CHANNELFILE_ERROR_NOBASEURLTYPE,
array('parent' => $parent, 'protocol' => $protocol));
}
} else {
792,9 → 734,9
{
if (isset($this->_channelInfo['name'])) {
return $this->_channelInfo['name'];
} else {
return false;
}
 
return false;
}
 
/**
804,9 → 746,9
{
if (isset($this->_channelInfo['name'])) {
return $this->_channelInfo['name'];
} else {
return false;
}
 
return false;
}
 
/**
818,21 → 760,26
if ($mir = $this->getMirror($mirror)) {
if (isset($mir['attribs']['port'])) {
return $mir['attribs']['port'];
} else {
if ($this->getSSL($mirror)) {
return 443;
}
return 80;
}
 
if ($this->getSSL($mirror)) {
return 443;
}
 
return 80;
}
 
return false;
}
 
if (isset($this->_channelInfo['servers']['primary']['attribs']['port'])) {
return $this->_channelInfo['servers']['primary']['attribs']['port'];
}
 
if ($this->getSSL()) {
return 443;
}
 
return 80;
}
 
845,15 → 792,18
if ($mir = $this->getMirror($mirror)) {
if (isset($mir['attribs']['ssl'])) {
return true;
} else {
return false;
}
 
return false;
}
 
return false;
}
 
if (isset($this->_channelInfo['servers']['primary']['attribs']['ssl'])) {
return true;
}
 
return false;
}
 
864,37 → 814,13
{
if (isset($this->_channelInfo['summary'])) {
return $this->_channelInfo['summary'];
} else {
return false;
}
}
 
/**
* @param string xmlrpc or soap
* @param string|false mirror name or false for primary server
*/
function getPath($protocol, $mirror = false)
{
if (!in_array($protocol, array('xmlrpc', 'soap'))) {
return false;
}
if ($mirror) {
if (!($mir = $this->getMirror($mirror))) {
return false;
}
if (isset($mir[$protocol]['attribs']['path'])) {
return $mir[$protocol]['attribs']['path'];
} else {
return $protocol . '.php';
}
} elseif (isset($this->_channelInfo['servers']['primary'][$protocol]['attribs']['path'])) {
return $this->_channelInfo['servers']['primary'][$protocol]['attribs']['path'];
}
return $protocol . '.php';
return false;
}
 
/**
* @param string protocol type (xmlrpc, soap)
* @param string protocol type
* @param string Mirror name
* @return array|false
*/
903,11 → 829,8
if ($this->getName() == '__uri') {
return false;
}
if ($protocol == 'rest') {
$function = 'baseurl';
} else {
$function = 'function';
}
 
$function = $protocol == 'rest' ? 'baseurl' : 'function';
if ($mirror) {
if ($mir = $this->getMirror($mirror)) {
if (isset($mir[$protocol][$function])) {
914,13 → 837,15
return $mir[$protocol][$function];
}
}
 
return false;
}
 
if (isset($this->_channelInfo['servers']['primary'][$protocol][$function])) {
return $this->_channelInfo['servers']['primary'][$protocol][$function];
} else {
return false;
}
 
return false;
}
 
/**
936,15 → 861,19
if (!$protocols) {
return false;
}
 
foreach ($protocols as $protocol) {
if ($name === null) {
return $protocol;
}
 
if ($protocol['_content'] != $name) {
continue;
}
 
return $protocol;
}
 
return false;
}
 
961,18 → 890,23
if (!$protocols) {
return false;
}
 
foreach ($protocols as $protocol) {
if ($protocol['attribs']['version'] != $version) {
continue;
}
 
if ($name === null) {
return true;
}
 
if ($protocol['_content'] != $name) {
continue;
}
 
return true;
}
 
return false;
}
 
987,12 → 921,15
if ($mirror == $this->_channelInfo['name']) {
$mirror = false;
}
 
if ($mirror) {
if ($mir = $this->getMirror($mirror)) {
return isset($mir['rest']);
}
 
return false;
}
 
return isset($this->_channelInfo['servers']['primary']['rest']);
}
 
1008,25 → 945,28
if ($mirror == $this->_channelInfo['name']) {
$mirror = false;
}
 
if ($mirror) {
if ($mir = $this->getMirror($mirror)) {
$rest = $mir['rest'];
} else {
$mir = $this->getMirror($mirror);
if (!$mir) {
return false;
}
$server = $mirror;
 
$rest = $mir['rest'];
} else {
$rest = $this->_channelInfo['servers']['primary']['rest'];
$server = $this->getServer();
}
 
if (!isset($rest['baseurl'][0])) {
$rest['baseurl'] = array($rest['baseurl']);
}
 
foreach ($rest['baseurl'] as $baseurl) {
if (strtolower($baseurl['attribs']['type']) == strtolower($resourceType)) {
return $baseurl['_content'];
}
}
 
return false;
}
 
1042,7 → 982,7
 
/**
* Empty all protocol definitions
* @param string protocol type (xmlrpc, soap)
* @param string protocol type
* @param string|false mirror name, if any
*/
function resetFunctions($type, $mirror = false)
1053,24 → 993,28
if (!isset($mirrors[0])) {
$mirrors = array($mirrors);
}
 
foreach ($mirrors as $i => $mir) {
if ($mir['attribs']['host'] == $mirror) {
if (isset($this->_channelInfo['servers']['mirror'][$i][$type])) {
unset($this->_channelInfo['servers']['mirror'][$i][$type]);
}
 
return true;
}
}
 
return false;
} else {
return false;
}
} else {
if (isset($this->_channelInfo['servers']['primary'][$type])) {
unset($this->_channelInfo['servers']['primary'][$type]);
}
return true;
 
return false;
}
 
if (isset($this->_channelInfo['servers']['primary'][$type])) {
unset($this->_channelInfo['servers']['primary'][$type]);
}
 
return true;
}
 
/**
1080,19 → 1024,15
{
switch ($version) {
case '1.0' :
$this->resetFunctions('xmlrpc', $mirror);
$this->resetFunctions('soap', $mirror);
$this->resetREST($mirror);
$this->addFunction('xmlrpc', '1.0', 'logintest', $mirror);
$this->addFunction('xmlrpc', '1.0', 'package.listLatestReleases', $mirror);
$this->addFunction('xmlrpc', '1.0', 'package.listAll', $mirror);
$this->addFunction('xmlrpc', '1.0', 'package.info', $mirror);
$this->addFunction('xmlrpc', '1.0', 'package.getDownloadURL', $mirror);
$this->addFunction('xmlrpc', '1.1', 'package.getDownloadURL', $mirror);
$this->addFunction('xmlrpc', '1.0', 'package.getDepDownloadURL', $mirror);
$this->addFunction('xmlrpc', '1.1', 'package.getDepDownloadURL', $mirror);
$this->addFunction('xmlrpc', '1.0', 'package.search', $mirror);
$this->addFunction('xmlrpc', '1.0', 'channel.listAll', $mirror);
 
if (!isset($this->_channelInfo['servers'])) {
$this->_channelInfo['servers'] = array('primary' =>
array('rest' => array()));
} elseif (!isset($this->_channelInfo['servers']['primary'])) {
$this->_channelInfo['servers']['primary'] = array('rest' => array());
}
 
return true;
break;
default :
1100,7 → 1040,7
break;
}
}
 
/**
* @return array
*/
1111,10 → 1051,11
if (!isset($mirrors[0])) {
$mirrors = array($mirrors);
}
 
return $mirrors;
} else {
return array();
}
 
return array();
}
 
/**
1128,6 → 1069,7
return $mirror;
}
}
 
return false;
}
 
1155,7 → 1097,7
array('mirror' => $mirror));
return false;
}
$setmirror = false;
 
if (isset($this->_channelInfo['servers']['mirror'][0])) {
foreach ($this->_channelInfo['servers']['mirror'] as $i => $mir) {
if ($mirror == $mir['attribs']['host']) {
1163,6 → 1105,7
return true;
}
}
 
return false;
} elseif ($this->_channelInfo['servers']['mirror']['attribs']['host'] == $mirror) {
$this->_channelInfo['servers']['mirror']['attribs']['port'] = $port;
1170,6 → 1113,7
return true;
}
}
 
$this->_channelInfo['servers']['primary']['attribs']['port'] = $port;
$this->_isValid = false;
return true;
1188,7 → 1132,7
array('mirror' => $mirror));
return false;
}
$setmirror = false;
 
if (isset($this->_channelInfo['servers']['mirror'][0])) {
foreach ($this->_channelInfo['servers']['mirror'] as $i => $mir) {
if ($mirror == $mir['attribs']['host']) {
1200,9 → 1144,11
} else {
$this->_channelInfo['servers']['mirror'][$i]['attribs']['ssl'] = 'yes';
}
 
return true;
}
}
 
return false;
} elseif ($this->_channelInfo['servers']['mirror']['attribs']['host'] == $mirror) {
if (!$ssl) {
1212,10 → 1158,12
} else {
$this->_channelInfo['servers']['mirror']['attribs']['ssl'] = 'yes';
}
 
$this->_isValid = false;
return true;
}
}
 
if ($ssl) {
$this->_channelInfo['servers']['primary']['attribs']['ssl'] = 'yes';
} else {
1223,45 → 1171,7
unset($this->_channelInfo['servers']['primary']['attribs']['ssl']);
}
}
$this->_isValid = false;
return true;
}
 
/**
* Set the socket number (port) that is used to connect to this channel
* @param integer
* @param string|false name of the mirror server, or false for the primary
*/
function setPath($protocol, $path, $mirror = false)
{
if (!in_array($protocol, array('xmlrpc', 'soap'))) {
return false;
}
if ($mirror) {
if (!isset($this->_channelInfo['servers']['mirror'])) {
$this->_validateError(PEAR_CHANNELFILE_ERROR_MIRROR_NOT_FOUND,
array('mirror' => $mirror));
return false;
}
$setmirror = false;
if (isset($this->_channelInfo['servers']['mirror'][0])) {
foreach ($this->_channelInfo['servers']['mirror'] as $i => $mir) {
if ($mirror == $mir['attribs']['host']) {
$this->_channelInfo['servers']['mirror'][$i][$protocol]['attribs']['path'] =
$path;
return true;
}
}
$this->_validateError(PEAR_CHANNELFILE_ERROR_MIRROR_NOT_FOUND,
array('mirror' => $mirror));
return false;
} elseif ($this->_channelInfo['servers']['mirror']['attribs']['host'] == $mirror) {
$this->_channelInfo['servers']['mirror'][$protocol]['attribs']['path'] = $path;
$this->_isValid = false;
return true;
}
}
$this->_channelInfo['servers']['primary'][$protocol]['attribs']['path'] = $path;
$this->_isValid = false;
return true;
}
1282,6 → 1192,7
array('tag' => 'name', 'name' => $server));
return false;
}
 
if ($mirror) {
$found = false;
foreach ($this->_channelInfo['servers']['mirror'] as $i => $mir) {
1290,14 → 1201,17
break;
}
}
 
if (!$found) {
$this->_validateError(PEAR_CHANNELFILE_ERROR_MIRROR_NOT_FOUND,
array('mirror' => $mirror));
return false;
}
 
$this->_channelInfo['mirror'][$i]['attribs']['host'] = $server;
return true;
}
 
$this->_channelInfo['name'] = $server;
return true;
}
1317,6 → 1231,7
$this->_validateWarning(PEAR_CHANNELFILE_ERROR_MULTILINE_SUMMARY,
array('summary' => $summary));
}
 
$this->_channelInfo['summary'] = $summary;
return true;
}
1333,11 → 1248,13
array('tag' => 'suggestedalias', 'name' => $alias));
return false;
}
 
if ($local) {
$this->_channelInfo['localalias'] = $alias;
} else {
$this->_channelInfo['suggestedalias'] = $alias;
}
 
return true;
}
 
1355,6 → 1272,7
if (isset($this->_channelInfo['name'])) {
return $this->_channelInfo['name'];
}
return '';
}
 
/**
1386,6 → 1304,7
if ($mirror) {
return $this->addMirrorFunction($mirror, $type, $version, $name);
}
 
$set = array('attribs' => array('version' => $version), '_content' => $name);
if (!isset($this->_channelInfo['servers']['primary'][$type]['function'])) {
if (!isset($this->_channelInfo['servers'])) {
1394,6 → 1313,7
} elseif (!isset($this->_channelInfo['servers']['primary'])) {
$this->_channelInfo['servers']['primary'] = array($type => array());
}
 
$this->_channelInfo['servers']['primary'][$type]['function'] = $set;
$this->_isValid = false;
return true;
1401,6 → 1321,7
$this->_channelInfo['servers']['primary'][$type]['function'] = array(
$this->_channelInfo['servers']['primary'][$type]['function']);
}
 
$this->_channelInfo['servers']['primary'][$type]['function'][] = $set;
return true;
}
1413,12 → 1334,12
*/
function addMirrorFunction($mirror, $type, $version, $name = '')
{
$found = false;
if (!isset($this->_channelInfo['servers']['mirror'])) {
$this->_validateError(PEAR_CHANNELFILE_ERROR_MIRROR_NOT_FOUND,
array('mirror' => $mirror));
return false;
}
 
$setmirror = false;
if (isset($this->_channelInfo['servers']['mirror'][0])) {
foreach ($this->_channelInfo['servers']['mirror'] as $i => $mir) {
1432,11 → 1353,13
$setmirror = &$this->_channelInfo['servers']['mirror'];
}
}
 
if (!$setmirror) {
$this->_validateError(PEAR_CHANNELFILE_ERROR_MIRROR_NOT_FOUND,
array('mirror' => $mirror));
return false;
}
 
$set = array('attribs' => array('version' => $version), '_content' => $name);
if (!isset($setmirror[$type]['function'])) {
$setmirror[$type]['function'] = $set;
1445,6 → 1368,7
} elseif (!isset($setmirror[$type]['function'][0])) {
$setmirror[$type]['function'] = array($setmirror[$type]['function']);
}
 
$setmirror[$type]['function'][] = $set;
$this->_isValid = false;
return true;
1458,12 → 1382,12
function setBaseURL($resourceType, $url, $mirror = false)
{
if ($mirror) {
$found = false;
if (!isset($this->_channelInfo['servers']['mirror'])) {
$this->_validateError(PEAR_CHANNELFILE_ERROR_MIRROR_NOT_FOUND,
array('mirror' => $mirror));
return false;
}
 
$setmirror = false;
if (isset($this->_channelInfo['servers']['mirror'][0])) {
foreach ($this->_channelInfo['servers']['mirror'] as $i => $mir) {
1480,10 → 1404,12
} else {
$setmirror = &$this->_channelInfo['servers']['primary'];
}
 
$set = array('attribs' => array('type' => $resourceType), '_content' => $url);
if (!isset($setmirror['rest'])) {
$setmirror['rest'] = array();
}
 
if (!isset($setmirror['rest']['baseurl'])) {
$setmirror['rest']['baseurl'] = $set;
$this->_isValid = false;
1491,6 → 1417,7
} elseif (!isset($setmirror['rest']['baseurl'][0])) {
$setmirror['rest']['baseurl'] = array($setmirror['rest']['baseurl']);
}
 
foreach ($setmirror['rest']['baseurl'] as $i => $url) {
if ($url['attribs']['type'] == $resourceType) {
$this->_isValid = false;
1498,6 → 1425,7
return true;
}
}
 
$setmirror['rest']['baseurl'][] = $set;
$this->_isValid = false;
return true;
1513,19 → 1441,22
if ($this->_channelInfo['name'] == '__uri') {
return false; // the __uri channel cannot have mirrors by definition
}
 
$set = array('attribs' => array('host' => $server));
if (is_numeric($port)) {
$set['attribs']['port'] = $port;
}
 
if (!isset($this->_channelInfo['servers']['mirror'])) {
$this->_channelInfo['servers']['mirror'] = $set;
return true;
} else {
if (!isset($this->_channelInfo['servers']['mirror'][0])) {
$this->_channelInfo['servers']['mirror'] =
array($this->_channelInfo['servers']['mirror']);
}
}
 
if (!isset($this->_channelInfo['servers']['mirror'][0])) {
$this->_channelInfo['servers']['mirror'] =
array($this->_channelInfo['servers']['mirror']);
}
 
$this->_channelInfo['servers']['mirror'][] = $set;
return true;
}
1539,10 → 1470,12
if (!$this->_isValid && !$this->validate()) {
return false;
}
 
if (!isset($this->_channelInfo['validatepackage'])) {
return array('attribs' => array('version' => 'default'),
'_content' => 'PEAR_Validate');
}
 
return $this->_channelInfo['validatepackage'];
}
 
1558,6 → 1491,7
if (!class_exists('PEAR_Validate')) {
require_once 'PEAR/Validate.php';
}
 
if (!$this->_isValid) {
if (!$this->validate()) {
$a = false;
1564,12 → 1498,14
return $a;
}
}
 
if (isset($this->_channelInfo['validatepackage'])) {
if ($package == $this->_channelInfo['validatepackage']) {
// channel validation packages are always validated by PEAR_Validate
$val = &new PEAR_Validate;
$val = new PEAR_Validate;
return $val;
}
 
if (!class_exists(str_replace('.', '_',
$this->_channelInfo['validatepackage']['_content']))) {
if ($this->isIncludeable(str_replace('_', '/',
1578,7 → 1514,7
$this->_channelInfo['validatepackage']['_content']) . '.php';
$vclass = str_replace('.', '_',
$this->_channelInfo['validatepackage']['_content']);
$val = &new $vclass;
$val = new $vclass;
} else {
$a = false;
return $a;
1586,11 → 1522,12
} else {
$vclass = str_replace('.', '_',
$this->_channelInfo['validatepackage']['_content']);
$val = &new $vclass;
$val = new $vclass;
}
} else {
$val = &new PEAR_Validate;
$val = new PEAR_Validate;
}
 
return $val;
}
 
1603,6 → 1540,7
return true;
}
}
 
return false;
}
 
1616,7 → 1554,7
if (isset($this->_channelInfo['_lastmodified'])) {
return $this->_channelInfo['_lastmodified'];
}
 
return time();
}
}
?>
/trunk/bibliotheque/pear/PEAR/Registry.php
4,20 → 4,13
*
* 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 Stig Bakken <ssb@php.net>
* @author Tomas V. V. Cox <cox@idecnet.com>
* @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: Registry.php,v 1.159 2006/12/20 19:34:03 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
28,10 → 21,10
require_once 'PEAR.php';
require_once 'PEAR/DependencyDB.php';
 
define('PEAR_REGISTRY_ERROR_LOCK', -2);
define('PEAR_REGISTRY_ERROR_FORMAT', -3);
define('PEAR_REGISTRY_ERROR_FILE', -4);
define('PEAR_REGISTRY_ERROR_CONFLICT', -5);
define('PEAR_REGISTRY_ERROR_LOCK', -2);
define('PEAR_REGISTRY_ERROR_FORMAT', -3);
define('PEAR_REGISTRY_ERROR_FILE', -4);
define('PEAR_REGISTRY_ERROR_CONFLICT', -5);
define('PEAR_REGISTRY_ERROR_CHANNEL_FILE', -6);
 
/**
41,16 → 34,14
* @author Stig Bakken <ssb@php.net>
* @author Tomas V. V. Cox <cox@idecnet.com>
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_Registry extends PEAR
{
// {{{ properties
 
/**
* File containing all channel information.
* @var string
112,6 → 103,11
var $_peclChannel;
 
/**
* @var false|PEAR_ChannelFile
*/
var $_docChannel;
 
/**
* @var PEAR_DependencyDB
*/
var $_dependencyDB;
120,10 → 116,7
* @var PEAR_Config
*/
var $_config;
// }}}
 
// {{{ constructor
 
/**
* PEAR_Registry constructor.
*
137,43 → 130,61
*
* @access public
*/
function PEAR_Registry($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
$pecl_channel = false)
function __construct($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
$pecl_channel = false, $pear_metadata_dir = '')
{
parent::PEAR();
$ds = DIRECTORY_SEPARATOR;
$this->install_dir = $pear_install_dir;
$this->channelsdir = $pear_install_dir.$ds.'.channels';
$this->statedir = $pear_install_dir.$ds.'.registry';
$this->filemap = $pear_install_dir.$ds.'.filemap';
$this->lockfile = $pear_install_dir.$ds.'.lock';
parent::__construct();
$this->setInstallDir($pear_install_dir, $pear_metadata_dir);
$this->_pearChannel = $pear_channel;
$this->_peclChannel = $pecl_channel;
$this->_config = false;
$this->_config = false;
}
 
function setInstallDir($pear_install_dir = PEAR_INSTALL_DIR, $pear_metadata_dir = '')
{
$ds = DIRECTORY_SEPARATOR;
$this->install_dir = $pear_install_dir;
if (!$pear_metadata_dir) {
$pear_metadata_dir = $pear_install_dir;
}
$this->channelsdir = $pear_metadata_dir.$ds.'.channels';
$this->statedir = $pear_metadata_dir.$ds.'.registry';
$this->filemap = $pear_metadata_dir.$ds.'.filemap';
$this->lockfile = $pear_metadata_dir.$ds.'.lock';
}
 
function hasWriteAccess()
{
if (!file_exists($this->install_dir)) {
$dir = $this->install_dir;
while ($dir && $dir != '.') {
$dir = dirname($dir); // cd ..
$olddir = $dir;
$dir = dirname($dir);
if ($dir != '.' && file_exists($dir)) {
if (is_writeable($dir)) {
return true;
} else {
return false;
}
 
return false;
}
 
if ($dir == $olddir) { // this can happen in safe mode
return @is_writable($dir);
}
}
 
return false;
}
 
return is_writeable($this->install_dir);
}
 
function setConfig(&$config)
function setConfig(&$config, $resetInstallDir = true)
{
$this->_config = &$config;
if ($resetInstallDir) {
$this->setInstallDir($config->get('php_dir'), $config->get('metadata_dir'));
}
}
 
function _initializeChannelDirs()
185,6 → 196,7
if (!is_dir($this->channelsdir) ||
!file_exists($this->channelsdir . $ds . 'pear.php.net.reg') ||
!file_exists($this->channelsdir . $ds . 'pecl.php.net.reg') ||
!file_exists($this->channelsdir . $ds . 'doc.php.net.reg') ||
!file_exists($this->channelsdir . $ds . '__uri.reg')) {
if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
$pear_channel = $this->_pearChannel;
192,8 → 204,8
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setName('pear.php.net');
$pear_channel->setAlias('pear');
$pear_channel->setServer('pear.php.net');
$pear_channel->setSummary('PHP Extension and Application Repository');
200,13 → 212,17
$pear_channel->setDefaultPEARProtocols();
$pear_channel->setBaseURL('REST1.0', 'http://pear.php.net/rest/');
$pear_channel->setBaseURL('REST1.1', 'http://pear.php.net/rest/');
$pear_channel->setBaseURL('REST1.3', 'http://pear.php.net/rest/');
//$pear_channel->setBaseURL('REST1.4', 'http://pear.php.net/rest/');
} else {
$pear_channel->setName('pear.php.net');
$pear_channel->setServer('pear.php.net');
$pear_channel->setAlias('pear');
}
 
$pear_channel->validate();
$this->_addChannel($pear_channel);
}
 
if (!file_exists($this->channelsdir . $ds . 'pecl.php.net.reg')) {
$pecl_channel = $this->_peclChannel;
if (!is_a($pecl_channel, 'PEAR_ChannelFile') || !$pecl_channel->validate()) {
213,8 → 229,8
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$pecl_channel = new PEAR_ChannelFile;
$pecl_channel->setName('pecl.php.net');
$pecl_channel->setAlias('pecl');
$pecl_channel->setServer('pecl.php.net');
$pecl_channel->setSummary('PHP Extension Community Library');
223,24 → 239,53
$pecl_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$pecl_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
} else {
$pecl_channel->setName('pecl.php.net');
$pecl_channel->setServer('pecl.php.net');
$pecl_channel->setAlias('pecl');
}
 
$pecl_channel->validate();
$this->_addChannel($pecl_channel);
}
 
if (!file_exists($this->channelsdir . $ds . 'doc.php.net.reg')) {
$doc_channel = $this->_docChannel;
if (!is_a($doc_channel, 'PEAR_ChannelFile') || !$doc_channel->validate()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$doc_channel = new PEAR_ChannelFile;
$doc_channel->setAlias('phpdocs');
$doc_channel->setServer('doc.php.net');
$doc_channel->setSummary('PHP Documentation Team');
$doc_channel->setDefaultPEARProtocols();
$doc_channel->setBaseURL('REST1.0', 'http://doc.php.net/rest/');
$doc_channel->setBaseURL('REST1.1', 'http://doc.php.net/rest/');
$doc_channel->setBaseURL('REST1.3', 'http://doc.php.net/rest/');
} else {
$doc_channel->setServer('doc.php.net');
$doc_channel->setAlias('doc');
}
 
$doc_channel->validate();
$this->_addChannel($doc_channel);
}
 
if (!file_exists($this->channelsdir . $ds . '__uri.reg')) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$private = new PEAR_ChannelFile;
$private->setName('__uri');
$private->addFunction('xmlrpc', '1.0', '****');
$private->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
$this->_addChannel($private);
}
$this->_rebuildFileMap();
}
 
$running = false;
}
}
254,12 → 299,13
$handle = opendir($this->statedir)) {
$dest = $this->statedir . $ds;
while (false !== ($file = readdir($handle))) {
if (preg_match('/^.*[A-Z].*\.reg$/', $file)) {
if (preg_match('/^.*[A-Z].*\.reg\\z/', $file)) {
rename($dest . $file, $dest . strtolower($file));
}
}
closedir($handle);
}
 
$this->_initializeChannelDirs();
if (!file_exists($this->filemap)) {
$this->_rebuildFileMap();
274,24 → 320,22
if (!$initializing) {
$initializing = true;
if (!$this->_config) { // never used?
if (OS_WINDOWS) {
$file = 'pear.ini';
} else {
$file = '.pearrc';
}
$this->_config = &new PEAR_Config($this->statedir . DIRECTORY_SEPARATOR .
$file = OS_WINDOWS ? 'pear.ini' : '.pearrc';
$this->_config = new PEAR_Config($this->statedir . DIRECTORY_SEPARATOR .
$file);
$this->_config->setRegistry($this);
$this->_config->set('php_dir', $this->install_dir);
}
 
$this->_dependencyDB = &PEAR_DependencyDB::singleton($this->_config);
if (PEAR::isError($this->_dependencyDB)) {
// attempt to recover by removing the dep db
if (file_exists($this->_config->get('php_dir', null, 'pear.php.net') .
if (file_exists($this->_config->get('metadata_dir', null, 'pear.php.net') .
DIRECTORY_SEPARATOR . '.depdb')) {
@unlink($this->_config->get('php_dir', null, 'pear.php.net') .
@unlink($this->_config->get('metadata_dir', null, 'pear.php.net') .
DIRECTORY_SEPARATOR . '.depdb');
}
 
$this->_dependencyDB = &PEAR_DependencyDB::singleton($this->_config);
if (PEAR::isError($this->_dependencyDB)) {
echo $this->_dependencyDB->getMessage();
299,12 → 343,11
exit(1);
}
}
 
$initializing = false;
}
}
}
// }}}
// {{{ destructor
 
/**
* PEAR_Registry destructor. Makes sure no locks are forgotten.
319,10 → 362,6
}
}
 
// }}}
 
// {{{ _assertStateDir()
 
/**
* Make sure the directory where we keep registry files exists.
*
336,11 → 375,13
if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
return $this->_assertChannelStateDir($channel);
}
 
static $init = false;
if (!file_exists($this->statedir)) {
if (!$this->hasWriteAccess()) {
return false;
}
 
require_once 'System.php';
if (!System::mkdir(array('-p', $this->statedir))) {
return $this->raiseError("could not create directory '{$this->statedir}'");
350,10 → 391,12
return $this->raiseError('Cannot create directory ' . $this->statedir . ', ' .
'it already exists and is not a directory');
}
 
$ds = DIRECTORY_SEPARATOR;
if (!file_exists($this->channelsdir)) {
if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg') ||
!file_exists($this->channelsdir . $ds . 'pecl.php.net.reg') ||
!file_exists($this->channelsdir . $ds . 'doc.php.net.reg') ||
!file_exists($this->channelsdir . $ds . '__uri.reg')) {
$init = true;
}
361,6 → 404,7
return $this->raiseError('Cannot create directory ' . $this->channelsdir . ', ' .
'it already exists and is not a directory');
}
 
if ($init) {
static $running = false;
if (!$running) {
372,12 → 416,10
} else {
$this->_initializeDepDB();
}
 
return true;
}
 
// }}}
// {{{ _assertChannelStateDir()
 
/**
* Make sure the directory where we keep registry files exists for a non-standard channel.
*
396,15 → 438,18
}
return $this->_assertStateDir($channel);
}
 
$channelDir = $this->_channelDirectoryName($channel);
if (!is_dir($this->channelsdir) ||
!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
$this->_initializeChannelDirs();
}
 
if (!file_exists($channelDir)) {
if (!$this->hasWriteAccess()) {
return false;
}
 
require_once 'System.php';
if (!System::mkdir(array('-p', $channelDir))) {
return $this->raiseError("could not create directory '" . $channelDir .
414,12 → 459,10
return $this->raiseError("could not create directory '" . $channelDir .
"', already exists and is not a directory");
}
 
return true;
}
 
// }}}
// {{{ _assertChannelDir()
 
/**
* Make sure the directory where we keep registry files for channels exists
*
434,6 → 477,7
if (!$this->hasWriteAccess()) {
return false;
}
 
require_once 'System.php';
if (!System::mkdir(array('-p', $this->channelsdir))) {
return $this->raiseError("could not create directory '{$this->channelsdir}'");
441,12 → 485,13
} elseif (!is_dir($this->channelsdir)) {
return $this->raiseError("could not create directory '{$this->channelsdir}" .
"', it already exists and is not a directory");
}
 
if (!file_exists($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) {
if (!$this->hasWriteAccess()) {
return false;
}
 
require_once 'System.php';
if (!System::mkdir(array('-p', $this->channelsdir . DIRECTORY_SEPARATOR . '.alias'))) {
return $this->raiseError("could not create directory '{$this->channelsdir}/.alias'");
454,14 → 499,11
} elseif (!is_dir($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) {
return $this->raiseError("could not create directory '{$this->channelsdir}" .
"/.alias', it already exists and is not a directory");
}
 
return true;
}
 
// }}}
// {{{ _packageFileName()
 
/**
* Get the name of the file where data for a given package is stored.
*
478,12 → 520,10
return $this->_channelDirectoryName($channel) . DIRECTORY_SEPARATOR .
strtolower($package) . '.reg';
}
 
return $this->statedir . DIRECTORY_SEPARATOR . strtolower($package) . '.reg';
}
 
// }}}
// {{{ _channelFileName()
 
/**
* Get the name of the file where data for a given channel is stored.
* @param string channel name
500,9 → 540,6
strtolower($channel)) . '.reg';
}
 
// }}}
// {{{ getChannelAliasFileName()
 
/**
* @param string
* @return string
513,9 → 550,6
DIRECTORY_SEPARATOR . str_replace('/', '_', strtolower($alias)) . '.txt';
}
 
// }}}
// {{{ _getChannelFromAlias()
 
/**
* Get the name of a channel from its alias
*/
525,25 → 559,31
if ($channel == 'pear.php.net') {
return 'pear.php.net';
}
 
if ($channel == 'pecl.php.net') {
return 'pecl.php.net';
}
 
if ($channel == 'doc.php.net') {
return 'doc.php.net';
}
 
if ($channel == '__uri') {
return '__uri';
}
 
return false;
}
 
$channel = strtolower($channel);
if (file_exists($this->_getChannelAliasFileName($channel))) {
// translate an alias to an actual channel
return implode('', file($this->_getChannelAliasFileName($channel)));
} else {
return $channel;
}
}
// }}}
// {{{ _getChannelFromAlias()
 
return $channel;
}
 
/**
* Get the alias of a channel from its alias or its name
*/
553,19 → 593,25
if ($channel == 'pear.php.net') {
return 'pear';
}
 
if ($channel == 'pecl.php.net') {
return 'pecl';
}
 
if ($channel == 'doc.php.net') {
return 'phpdocs';
}
 
return false;
}
 
$channel = $this->_getChannel($channel);
if (PEAR::isError($channel)) {
return $channel;
}
 
return $channel->getAlias();
}
// }}}
// {{{ _channelDirectoryName()
}
 
/**
* Get the name of the file where data for a given package is stored.
581,84 → 627,79
{
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
return $this->statedir;
} else {
$ch = $this->_getChannelFromAlias($channel);
if (!$ch) {
$ch = $channel;
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
str_replace('/', '_', $ch));
}
 
$ch = $this->_getChannelFromAlias($channel);
if (!$ch) {
$ch = $channel;
}
 
return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
str_replace('/', '_', $ch));
}
 
// }}}
// {{{ _openPackageFile()
 
function _openPackageFile($package, $mode, $channel = false)
{
if (!$this->_assertStateDir($channel)) {
return null;
}
 
if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
return null;
}
 
$file = $this->_packageFileName($package, $channel);
if (!file_exists($file) && $mode == 'r' || $mode == 'rb') {
return null;
}
 
$fp = @fopen($file, $mode);
if (!$fp) {
return null;
}
 
return $fp;
}
 
// }}}
// {{{ _closePackageFile()
 
function _closePackageFile($fp)
{
fclose($fp);
}
 
// }}}
// {{{ _openChannelFile()
 
function _openChannelFile($channel, $mode)
{
if (!$this->_assertChannelDir()) {
return null;
}
 
if (!in_array($mode, array('r', 'rb')) && !$this->hasWriteAccess()) {
return null;
}
 
$file = $this->_channelFileName($channel);
if (!file_exists($file) && $mode == 'r' || $mode == 'rb') {
return null;
}
 
$fp = @fopen($file, $mode);
if (!$fp) {
return null;
}
 
return $fp;
}
 
// }}}
// {{{ _closePackageFile()
 
function _closeChannelFile($fp)
{
fclose($fp);
}
 
// }}}
// {{{ _rebuildFileMap()
 
function _rebuildFileMap()
{
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
 
$channels = $this->_listAllPackages();
$files = array();
foreach ($channels as $channel => $packages) {
668,37 → 709,43
if (!is_array($filelist)) {
continue;
}
 
foreach ($filelist as $name => $attrs) {
if (isset($attrs['attribs'])) {
$attrs = $attrs['attribs'];
}
 
// it is possible for conflicting packages in different channels to
// conflict with data files/doc files
if ($name == 'dirtree') {
continue;
}
 
if (isset($attrs['role']) && !in_array($attrs['role'],
PEAR_Installer_Role::getInstallableRoles())) {
// these are not installed
continue;
}
 
if (isset($attrs['role']) && !in_array($attrs['role'],
PEAR_Installer_Role::getBaseinstallRoles())) {
$attrs['baseinstalldir'] = $package;
}
 
if (isset($attrs['baseinstalldir'])) {
$file = $attrs['baseinstalldir'].DIRECTORY_SEPARATOR.$name;
} else {
$file = $name;
}
 
$file = preg_replace(',^/+,', '', $file);
if ($channel != 'pear.php.net') {
if (!isset($files[$attrs['role']])) {
$files[$attrs['role']] = array();
}
$files[$attrs['role']][$file] = array(strtolower($channel),
strtolower($package));
} else {
if (!is_array($files)) {
$file = array();
}
if (!isset($files[$attrs['role']])) {
$files[$attrs['role']] = array();
}
707,14 → 754,18
}
}
}
 
 
$this->_assertStateDir();
if (!$this->hasWriteAccess()) {
return false;
}
 
$fp = @fopen($this->filemap, 'wb');
if (!$fp) {
return false;
}
 
$this->filemap_cache = $files;
fwrite($fp, serialize($files));
fclose($fp);
721,36 → 772,30
return true;
}
 
// }}}
// {{{ _readFileMap()
 
function _readFileMap()
{
if (!file_exists($this->filemap)) {
return array();
}
 
$fp = @fopen($this->filemap, 'r');
if (!$fp) {
return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $php_errormsg);
}
 
clearstatcache();
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
$fsize = filesize($this->filemap);
fclose($fp);
$data = file_get_contents($this->filemap);
set_magic_quotes_runtime($rt);
$tmp = unserialize($data);
if (!$tmp && $fsize > 7) {
return $this->raiseError('PEAR_Registry: invalid filemap data', PEAR_REGISTRY_ERROR_FORMAT, null, null, $data);
}
 
$this->filemap_cache = $tmp;
return true;
}
 
// }}}
// {{{ _lock()
 
/**
* Lock the registry.
*
765,52 → 810,60
*/
function _lock($mode = LOCK_EX)
{
if (!eregi('Windows 9', php_uname())) {
if ($mode != LOCK_UN && is_resource($this->lock_fp)) {
// XXX does not check type of lock (LOCK_SH/LOCK_EX)
return true;
if (stristr(php_uname(), 'Windows 9')) {
return true;
}
 
if ($mode != LOCK_UN && is_resource($this->lock_fp)) {
// XXX does not check type of lock (LOCK_SH/LOCK_EX)
return true;
}
 
if (!$this->_assertStateDir()) {
if ($mode == LOCK_EX) {
return $this->raiseError('Registry directory is not writeable by the current user');
}
if (!$this->_assertStateDir()) {
if ($mode == LOCK_EX) {
return $this->raiseError('Registry directory is not writeable by the current user');
} else {
return true;
}
 
return true;
}
 
$open_mode = 'w';
// XXX People reported problems with LOCK_SH and 'w'
if ($mode === LOCK_SH || $mode === LOCK_UN) {
if (!file_exists($this->lockfile)) {
touch($this->lockfile);
}
$open_mode = 'w';
// XXX People reported problems with LOCK_SH and 'w'
if ($mode === LOCK_SH || $mode === LOCK_UN) {
if (!file_exists($this->lockfile)) {
touch($this->lockfile);
}
$open_mode = 'r';
}
$open_mode = 'r';
}
 
if (!is_resource($this->lock_fp)) {
$this->lock_fp = @fopen($this->lockfile, $open_mode);
if (!is_resource($this->lock_fp)) {
$this->lock_fp = @fopen($this->lockfile, $open_mode);
}
 
if (!is_resource($this->lock_fp)) {
$this->lock_fp = null;
return $this->raiseError("could not create lock file" .
(isset($php_errormsg) ? ": " . $php_errormsg : ""));
}
 
if (!(int)flock($this->lock_fp, $mode)) {
switch ($mode) {
case LOCK_SH: $str = 'shared'; break;
case LOCK_EX: $str = 'exclusive'; break;
case LOCK_UN: $str = 'unlock'; break;
default: $str = 'unknown'; break;
}
 
if (!is_resource($this->lock_fp)) {
return $this->raiseError("could not create lock file" .
(isset($php_errormsg) ? ": " . $php_errormsg : ""));
}
if (!(int)flock($this->lock_fp, $mode)) {
switch ($mode) {
case LOCK_SH: $str = 'shared'; break;
case LOCK_EX: $str = 'exclusive'; break;
case LOCK_UN: $str = 'unlock'; break;
default: $str = 'unknown'; break;
}
return $this->raiseError("could not acquire $str lock ($this->lockfile)",
PEAR_REGISTRY_ERROR_LOCK);
}
//is resource at this point, close it on error.
fclose($this->lock_fp);
$this->lock_fp = null;
return $this->raiseError("could not acquire $str lock ($this->lockfile)",
PEAR_REGISTRY_ERROR_LOCK);
}
 
return true;
}
 
// }}}
// {{{ _unlock()
 
function _unlock()
{
$ret = $this->_lock(LOCK_UN);
817,23 → 870,19
if (is_resource($this->lock_fp)) {
fclose($this->lock_fp);
}
 
$this->lock_fp = null;
return $ret;
}
 
// }}}
// {{{ _packageExists()
 
function _packageExists($package, $channel = false)
{
return file_exists($this->_packageFileName($package, $channel));
}
 
// }}}
// {{{ _channelExists()
 
/**
* Determine whether a channel exists in the registry
*
* @param string Channel name
* @param bool if true, then aliases will be ignored
* @return boolean
844,15 → 893,42
if (!$a && $channel == 'pear.php.net') {
return true;
}
 
if (!$a && $channel == 'pecl.php.net') {
return true;
}
 
if (!$a && $channel == 'doc.php.net') {
return true;
}
 
return $a;
}
 
// }}}
// {{{ _addChannel()
/**
* Determine whether a mirror exists within the deafult channel in the registry
*
* @param string Channel name
* @param string Mirror name
*
* @return boolean
*/
function _mirrorExists($channel, $mirror)
{
$data = $this->_channelInfo($channel);
if (!isset($data['servers']['mirror'])) {
return false;
}
 
foreach ($data['servers']['mirror'] as $m) {
if ($m['attribs']['host'] == $mirror) {
return true;
}
}
 
return false;
}
 
/**
* @param PEAR_ChannelFile Channel object
* @param donotuse
864,17 → 940,21
if (!is_a($channel, 'PEAR_ChannelFile')) {
return false;
}
 
if (!$channel->validate()) {
return false;
}
 
if (file_exists($this->_channelFileName($channel->getName()))) {
if (!$update) {
return false;
}
 
$checker = $this->_getChannel($channel->getName());
if (PEAR::isError($checker)) {
return $checker;
}
 
if ($channel->getAlias() != $checker->getAlias()) {
if (file_exists($this->_getChannelAliasFileName($checker->getAlias()))) {
@unlink($this->_getChannelAliasFileName($checker->getAlias()));
881,40 → 961,49
}
}
} else {
if ($update && !in_array($channel->getName(), array('pear.php.net', 'pecl.php.net'))) {
if ($update && !in_array($channel->getName(), array('pear.php.net', 'pecl.php.net', 'doc.php.net'))) {
return false;
}
}
 
$ret = $this->_assertChannelDir();
if (PEAR::isError($ret)) {
return $ret;
}
 
$ret = $this->_assertChannelStateDir($channel->getName());
if (PEAR::isError($ret)) {
return $ret;
}
 
if ($channel->getAlias() != $channel->getName()) {
if (file_exists($this->_getChannelAliasFileName($channel->getAlias())) &&
$this->_getChannelFromAlias($channel->getAlias()) != $channel->getName()) {
$channel->setAlias($channel->getName());
}
 
if (!$this->hasWriteAccess()) {
return false;
}
 
$fp = @fopen($this->_getChannelAliasFileName($channel->getAlias()), 'w');
if (!$fp) {
return false;
}
 
fwrite($fp, $channel->getName());
fclose($fp);
}
 
if (!$this->hasWriteAccess()) {
return false;
}
 
$fp = @fopen($this->_channelFileName($channel->getName()), 'wb');
if (!$fp) {
return false;
}
 
$info = $channel->toArray();
if ($lastmodified) {
$info['_lastmodified'] = $lastmodified;
921,14 → 1010,12
} else {
$info['_lastmodified'] = date('r');
}
 
fwrite($fp, serialize($info));
fclose($fp);
return true;
}
 
// }}}
// {{{ _deleteChannel()
 
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
937,39 → 1024,51
function _deleteChannel($channel)
{
if (!is_string($channel)) {
if (is_a($channel, 'PEAR_ChannelFile')) {
if (!$channel->validate()) {
return false;
}
$channel = $channel->getName();
} else {
if (!is_a($channel, 'PEAR_ChannelFile')) {
return false;
}
 
if (!$channel->validate()) {
return false;
}
$channel = $channel->getName();
}
 
if ($this->_getChannelFromAlias($channel) == '__uri') {
return false;
}
 
if ($this->_getChannelFromAlias($channel) == 'pecl.php.net') {
return false;
}
 
if ($this->_getChannelFromAlias($channel) == 'doc.php.net') {
return false;
}
 
if (!$this->_channelExists($channel)) {
return false;
}
 
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
return false;
}
 
$channel = $this->_getChannelFromAlias($channel);
if ($channel == 'pear.php.net') {
return false;
}
 
$test = $this->_listChannelPackages($channel);
if (count($test)) {
return false;
}
 
$test = @rmdir($this->_channelDirectoryName($channel));
if (!$test) {
return false;
}
 
$file = $this->_getChannelAliasFileName($this->_getAlias($channel));
if (file_exists($file)) {
$test = @unlink($file);
977,17 → 1076,16
return false;
}
}
 
$file = $this->_channelFileName($channel);
$ret = true;
if (file_exists($file)) {
$ret = @unlink($file);
}
 
return $ret;
}
 
// }}}
// {{{ _isChannelAlias()
 
/**
* Determine whether a channel exists in the registry
* @param string Channel Alias
998,9 → 1096,6
return file_exists($this->_getChannelAliasFileName($alias));
}
 
// }}}
// {{{ _packageInfo()
 
/**
* @param string|null
* @param string|null
1022,8 → 1117,10
$ret[$channel][] = $this->_packageInfo($package, null, $channel);
}
}
 
return $ret;
}
 
$ps = $this->_listPackages($channel);
if (!count($ps)) {
return array();
1032,33 → 1129,32
$ps, array_fill(0, count($ps), null),
array_fill(0, count($ps), $channel));
}
 
$fp = $this->_openPackageFile($package, 'r', $channel);
if ($fp === null) {
return null;
}
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
 
clearstatcache();
$this->_closePackageFile($fp);
$data = file_get_contents($this->_packageFileName($package, $channel));
set_magic_quotes_runtime($rt);
$data = unserialize($data);
if ($key === null) {
return $data;
}
 
// compatibility for package.xml version 2.0
if (isset($data['old'][$key])) {
return $data['old'][$key];
}
 
if (isset($data[$key])) {
return $data[$key];
}
 
return null;
}
 
// }}}
// {{{ _channelInfo()
 
/**
* @param string Channel name
* @param bool whether to strictly retrieve info of channels, not just aliases
1069,73 → 1165,83
if (!$this->_channelExists($channel, $noaliases)) {
return null;
}
 
$fp = $this->_openChannelFile($channel, 'r');
if ($fp === null) {
return null;
}
$rt = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
 
clearstatcache();
$this->_closeChannelFile($fp);
$data = file_get_contents($this->_channelFileName($channel));
set_magic_quotes_runtime($rt);
$data = unserialize($data);
return $data;
}
 
// }}}
// {{{ _listChannels()
 
function _listChannels()
{
$channellist = array();
if (!file_exists($this->channelsdir) || !is_dir($this->channelsdir)) {
return array('pear.php.net', 'pecl.php.net', '__uri');
return array('pear.php.net', 'pecl.php.net', 'doc.php.net', '__uri');
}
 
$dp = opendir($this->channelsdir);
while ($ent = readdir($dp)) {
if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
continue;
}
 
if ($ent == '__uri.reg') {
$channellist[] = '__uri';
continue;
}
 
$channellist[] = str_replace('_', '/', substr($ent, 0, -4));
}
 
closedir($dp);
if (!in_array('pear.php.net', $channellist)) {
$channellist[] = 'pear.php.net';
}
 
if (!in_array('pecl.php.net', $channellist)) {
$channellist[] = 'pecl.php.net';
}
 
if (!in_array('doc.php.net', $channellist)) {
$channellist[] = 'doc.php.net';
}
 
 
if (!in_array('__uri', $channellist)) {
$channellist[] = '__uri';
}
 
natsort($channellist);
return $channellist;
}
 
// }}}
// {{{ _listPackages()
 
function _listPackages($channel = false)
{
if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
return $this->_listChannelPackages($channel);
}
 
if (!file_exists($this->statedir) || !is_dir($this->statedir)) {
return array();
}
 
$pkglist = array();
$dp = opendir($this->statedir);
if (!$dp) {
return $pkglist;
}
 
while ($ent = readdir($dp)) {
if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
continue;
}
 
$pkglist[] = substr($ent, 0, -4);
}
closedir($dp);
1142,9 → 1248,6
return $pkglist;
}
 
// }}}
// {{{ _listChannelPackages()
 
function _listChannelPackages($channel)
{
$pkglist = array();
1152,10 → 1255,12
!is_dir($this->_channelDirectoryName($channel))) {
return array();
}
 
$dp = opendir($this->_channelDirectoryName($channel));
if (!$dp) {
return $pkglist;
}
 
while ($ent = readdir($dp)) {
if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
continue;
1162,12 → 1267,11
}
$pkglist[] = substr($ent, 0, -4);
}
 
closedir($dp);
return $pkglist;
}
 
// }}}
function _listAllPackages()
{
$ret = array();
1174,6 → 1278,7
foreach ($this->_listChannels() as $channel) {
$ret[$channel] = $this->_listPackages($channel);
}
 
return $ret;
}
 
1189,10 → 1294,12
if ($this->_packageExists($package)) {
return false;
}
 
$fp = $this->_openPackageFile($package, 'wb');
if ($fp === null) {
return false;
}
 
$info['_lastmodified'] = time();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
1199,6 → 1306,7
if (isset($info['filelist'])) {
$this->_rebuildFileMap();
}
 
return true;
}
 
1209,6 → 1317,10
*/
function _addPackage2($info)
{
if (!is_a($info, 'PEAR_PackageFile_v1') && !is_a($info, 'PEAR_PackageFile_v2')) {
return false;
}
 
if (!$info->validate()) {
if (class_exists('PEAR_Common')) {
$ui = PEAR_Frontend::singleton();
1220,6 → 1332,7
}
return false;
}
 
$channel = $info->getChannel();
$package = $info->getPackage();
$save = $info;
1226,17 → 1339,21
if ($this->_packageExists($package, $channel)) {
return false;
}
 
if (!$this->_channelExists($channel, true)) {
return false;
}
 
$info = $info->toArray(true);
if (!$info) {
return false;
}
 
$fp = $this->_openPackageFile($package, 'wb', $channel);
if ($fp === null) {
return false;
}
 
$info['_lastmodified'] = time();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
1256,14 → 1373,17
if (empty($oldinfo)) {
return false;
}
 
$fp = $this->_openPackageFile($package, 'w');
if ($fp === null) {
return false;
}
 
if (is_object($info)) {
$info = $info->toArray();
}
$info['_lastmodified'] = time();
 
$newinfo = $info;
if ($merge) {
$info = array_merge($oldinfo, $info);
1270,11 → 1390,13
} else {
$diff = $info;
}
 
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($newinfo['filelist'])) {
$this->_rebuildFileMap();
}
 
return true;
}
 
1288,10 → 1410,12
if (!$this->_packageExists($info->getPackage(), $info->getChannel())) {
return false;
}
 
$fp = $this->_openPackageFile($info->getPackage(), 'w', $info->getChannel());
if ($fp === null) {
return false;
}
 
$save = $info;
$info = $save->getArray(true);
$info['_lastmodified'] = time();
1313,15 → 1437,18
if ($info === null) {
return $info;
}
 
$a = $this->_config;
if (!$a) {
$this->_config = &new PEAR_Config;
$this->_config = new PEAR_Config;
$this->_config->set('php_dir', $this->statedir);
}
 
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$pkg = &new PEAR_PackageFile($this->_config);
 
$pkg = new PEAR_PackageFile($this->_config);
$pf = &$pkg->fromArray($info);
return $pf;
}
1341,33 → 1468,41
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$ch = &PEAR_ChannelFile::fromArrayWithErrors($chinfo);
}
}
 
if ($ch) {
if ($ch->validate()) {
return $ch;
}
 
foreach ($ch->getErrors(true) as $err) {
$message = $err['message'] . "\n";
}
 
$ch = PEAR::raiseError($message);
return $ch;
}
 
if ($this->_getChannelFromAlias($channel) == 'pear.php.net') {
// the registry is not properly set up, so use defaults
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setName('pear.php.net');
$pear_channel->setServer('pear.php.net');
$pear_channel->setAlias('pear');
$pear_channel->setSummary('PHP Extension and Application Repository');
$pear_channel->setDefaultPEARProtocols();
$pear_channel->setBaseURL('REST1.0', 'http://pear.php.net/rest/');
$pear_channel->setBaseURL('REST1.1', 'http://pear.php.net/rest/');
$pear_channel->setBaseURL('REST1.3', 'http://pear.php.net/rest/');
return $pear_channel;
}
 
if ($this->_getChannelFromAlias($channel) == 'pecl.php.net') {
// the registry is not properly set up, so use defaults
if (!class_exists('PEAR_ChannelFile')) {
1374,7 → 1509,7
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setName('pecl.php.net');
$pear_channel->setServer('pecl.php.net');
$pear_channel->setAlias('pecl');
$pear_channel->setSummary('PHP Extension Community Library');
$pear_channel->setDefaultPEARProtocols();
1383,22 → 1518,42
$pear_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
return $pear_channel;
}
 
if ($this->_getChannelFromAlias($channel) == 'doc.php.net') {
// the registry is not properly set up, so use defaults
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$doc_channel = new PEAR_ChannelFile;
$doc_channel->setServer('doc.php.net');
$doc_channel->setAlias('phpdocs');
$doc_channel->setSummary('PHP Documentation Team');
$doc_channel->setDefaultPEARProtocols();
$doc_channel->setBaseURL('REST1.0', 'http://doc.php.net/rest/');
$doc_channel->setBaseURL('REST1.1', 'http://doc.php.net/rest/');
$doc_channel->setBaseURL('REST1.3', 'http://doc.php.net/rest/');
return $doc_channel;
}
 
 
if ($this->_getChannelFromAlias($channel) == '__uri') {
// the registry is not properly set up, so use defaults
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
 
$private = new PEAR_ChannelFile;
$private->setName('__uri');
$private->addFunction('xmlrpc', '1.0', '****');
$private->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
return $private;
}
 
return $ch;
}
 
// {{{ packageExists()
 
/**
* @param string Package name
* @param string Channel name
1435,6 → 1590,23
 
// }}}
 
/**
* @param string channel name mirror is in
* @param string mirror name
*
* @return bool
*/
function mirrorExists($channel, $mirror)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
 
$ret = $this->_mirrorExists($channel, $mirror);
$this->_unlock();
return $ret;
}
 
// {{{ isAlias()
 
/**
1639,11 → 1811,13
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
 
$ret = $this->_deleteChannel($channel);
$this->_unlock();
if ($ret && is_a($this->_config, 'PEAR_Config')) {
$this->_config->setChannels($this->listChannels());
}
 
return $ret;
}
 
1657,20 → 1831,20
*/
function addChannel($channel, $lastmodified = false, $update = false)
{
if (!is_a($channel, 'PEAR_ChannelFile')) {
if (!is_a($channel, 'PEAR_ChannelFile') || !$channel->validate()) {
return false;
}
if (!$channel->validate()) {
return false;
}
 
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
 
$ret = $this->_addChannel($channel, $update, $lastmodified);
$this->_unlock();
if (!$update && $ret && is_a($this->_config, 'PEAR_Config')) {
$this->_config->setChannels($this->listChannels());
}
 
return $ret;
}
 
1682,12 → 1856,9
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
 
$file = $this->_packageFileName($package, $channel);
if (file_exists($file)) {
$ret = @unlink($file);
} else {
$ret = false;
}
$ret = file_exists($file) ? @unlink($file) : false;
$this->_rebuildFileMap();
$this->_unlock();
$p = array('channel' => $channel, 'package' => $package);
1726,15 → 1897,19
 
function updatePackage2($info)
{
 
if (!is_object($info)) {
return $this->updatePackage($info['package'], $info, $merge);
}
 
if (!$info->validate(PEAR_VALIDATE_DOWNLOADING)) {
return false;
}
 
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
 
$ret = $this->_updatePackage2($info);
$this->_unlock();
if ($ret) {
1741,6 → 1916,7
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
 
return $ret;
}
 
1751,16 → 1927,16
* @param bool whether to strictly return raw channels (no aliases)
* @return PEAR_ChannelFile|PEAR_Error
*/
function &getChannel($channel, $noaliases = false)
function getChannel($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = &$this->_getChannel($channel, $noaliases);
$ret = $this->_getChannel($channel, $noaliases);
$this->_unlock();
if (!$ret) {
return PEAR::raiseError('Unknown channel: ' . $channel);
}
$this->_unlock();
return $ret;
}
 
2149,7 → 2325,7
return PEAR::raiseError('parsePackageName(): "' . $param['version'] .
'" is neither a valid version nor a valid state in "' .
$saveparam . '"', 'version/state', null, null, $param);
}
}
}
}
return $param;
2210,5 → 2386,3
return $ret;
}
}
 
?>
/trunk/bibliotheque/pear/PEAR/Task/Windowseol.php
4,20 → 4,13
*
* 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
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
/**
* Base class
25,33 → 18,35
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
*
* @category pear
* @package PEAR
* @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.10.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;
public $type = 'simple';
public $phase = PEAR_TASK_PACKAGE;
public $_replacements;
 
/**
* Validate the raw xml at parsing-time.
* @param PEAR_PackageFile_v2
* @param array raw, parsed xml
* @param PEAR_Config
* @static
*
* @param PEAR_PackageFile_v2
* @param array raw, parsed xml
* @param PEAR_Config
*/
function validateXml($pkg, $xml, &$config, $fileXml)
public static function validateXml($pkg, $xml, $config, $fileXml)
{
if ($xml != '') {
return array(PEAR_TASK_ERROR_INVALID, 'no attributes allowed');
}
 
return true;
}
 
59,8 → 54,9
* Initialize a task instance with the parameters
* @param array raw, parsed xml
* @param unused
* @param unused
*/
function init($xml, $attribs)
public function init($xml, $attribs, $lastVersion = null)
{
}
 
68,16 → 64,17
* 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)
*
* @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
* (use $this->throwError), otherwise return the new contents
*/
function startSession($pkg, $contents, $dest)
public 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
4,20 → 4,13
*
* 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
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a10
*/
/**
* Base class
28,9 → 21,9
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a10
*/
41,30 → 34,31
*
* @var PEAR_PackageFile_v2_rw
*/
var $_pkg;
public $_pkg;
/**
* Enter description here...
*
* @param PEAR_PackageFile_v2_rw $pkg
* @param PEAR_Config $config
* @param PEAR_Frontend $logger
* @param array $fileXml
* @param PEAR_PackageFile_v2_rw $pkg Package
* @param PEAR_Config $config Config
* @param PEAR_Frontend $logger Logger
* @param array $fileXml XML
*
* @return PEAR_Task_Postinstallscript_rw
*/
function PEAR_Task_Postinstallscript_rw(&$pkg, &$config, &$logger, $fileXml)
function __construct(&$pkg, &$config, &$logger, $fileXml)
{
parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE);
parent::__construct($config, $logger, PEAR_TASK_PACKAGE);
$this->_contents = $fileXml;
$this->_pkg = &$pkg;
$this->_params = array();
}
 
function validate()
public function validate()
{
return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents);
}
 
function getName()
public function getName()
{
return 'postinstallscript';
}
76,14 → 70,15
* 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 $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)
public function addParamGroup($id, $params = false, $instructions = false)
{
if ($params && isset($params[0]) && !isset($params[1])) {
$params = $params[0];
90,19 → 85,19
}
$stuff =
array(
$this->_pkg->getTasksNs() . ':id' => $id,
$this->_pkg->getTasksNs().':id' => $id,
);
if ($instructions) {
$stuff[$this->_pkg->getTasksNs() . ':instructions'] = $instructions;
$stuff[$this->_pkg->getTasksNs().':instructions'] = $instructions;
}
if ($params) {
$stuff[$this->_pkg->getTasksNs() . ':param'] = $params;
$stuff[$this->_pkg->getTasksNs().':param'] = $params;
}
$this->_params[$this->_pkg->getTasksNs() . ':paramgroup'][] = $stuff;
$this->_params[$this->_pkg->getTasksNs().':paramgroup'][] = $stuff;
}
 
/**
* add a complex <paramgroup> to the post-install script with conditions
* Add a complex <paramgroup> to the post-install script with conditions
*
* This inserts a <paramgroup> with
*
110,42 → 105,46
* 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 $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)
{
public 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,
);
$stuff = array(
$this->_pkg->getTasksNs().':id' => $id,
);
if ($instructions) {
$stuff[$this->_pkg->getTasksNs() . ':instructions'] = $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;
$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;
$stuff[$this->_pkg->getTasksNs().':param'] = $params;
}
$this->_params[$this->_pkg->getTasksNs() . ':paramgroup'][] = $stuff;
$this->_params[$this->_pkg->getTasksNs().':paramgroup'][] = $stuff;
}
 
function getXml()
public function getXml()
{
return $this->_params;
}
152,25 → 151,32
 
/**
* Use to set up a param tag for use in creating a paramgroup
* @static
*
* @param mixed $name Name of parameter
* @param mixed $prompt Prompt
* @param string $type Type, defaults to 'string'
* @param mixed $default Default value
*
* @return array
*/
function getParam($name, $prompt, $type = 'string', $default = null)
{
public static function getParam(
$name, $prompt, $type = 'string', $default = null
) {
if ($default !== null) {
return
return
array(
$this->_pkg->getTasksNs() . ':name' => $name,
$this->_pkg->getTasksNs() . ':prompt' => $prompt,
$this->_pkg->getTasksNs() . ':type' => $type,
$this->_pkg->getTasksNs() . ':default' => $default
$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,
$this->_pkg->getTasksNs().':name' => $name,
$this->_pkg->getTasksNs().':prompt' => $prompt,
$this->_pkg->getTasksNs().':type' => $type,
);
}
}
?>
/trunk/bibliotheque/pear/PEAR/Task/Replace.php
4,20 → 4,13
*
* 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
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
/**
* Base class
28,26 → 21,26
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.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;
public $type = 'simple';
public $phase = PEAR_TASK_PACKAGEANDINSTALL;
public $_replacements;
 
/**
* Validate the raw xml at parsing-time.
* @param PEAR_PackageFile_v2
* @param array raw, parsed xml
* @param PEAR_Config
* @static
*
* @param PEAR_PackageFile_v2
* @param array raw, parsed xml
* @param PEAR_Config
*/
function validateXml($pkg, $xml, &$config, $fileXml)
public static function validateXml($pkg, $xml, $config, $fileXml)
{
if (!isset($xml['attribs'])) {
return array(PEAR_TASK_ERROR_NOATTRIBS);
64,7 → 57,7
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());
$config->getKeys(), );
}
} elseif ($xml['attribs']['type'] == 'php-const') {
if (defined($xml['attribs']['to'])) {
71,14 → 64,16
return true;
} else {
return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'],
array('valid PHP constant'));
array('valid PHP constant'), );
}
} elseif ($xml['attribs']['type'] == 'package-info') {
if (in_array($xml['attribs']['to'],
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'))) {
'date', 'time', )
)) {
return true;
} else {
return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'to', $xml['attribs']['to'],
85,12 → 80,13
array('name', 'summary', 'channel', 'notes', 'extends', 'description',
'release_notes', 'license', 'release-license', 'license-uri',
'version', 'api-version', 'state', 'api-state', 'release_date',
'date', 'time'));
'date', 'time', ), );
}
} else {
return array(PEAR_TASK_ERROR_WRONG_ATTRIB_VALUE, 'type', $xml['attribs']['type'],
array('pear-config', 'package-info', 'php-const'));
array('pear-config', 'package-info', 'php-const'), );
}
 
return true;
}
 
98,8 → 94,9
* Initialize a task instance with the parameters
* @param array raw, parsed xml
* @param unused
* @param unused
*/
function init($xml, $attribs)
public function init($xml, $attribs, $lastVersion = null)
{
$this->_replacements = isset($xml['attribs']) ? array($xml) : $xml;
}
108,13 → 105,14
* 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)
*
* @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
* (use $this->throwError), otherwise return the new contents
*/
function startSession($pkg, $contents, $dest)
public function startSession($pkg, $contents, $dest)
{
$subst_from = $subst_to = array();
foreach ($this->_replacements as $a) {
130,6 → 128,7
$to = $chan->getServer();
} else {
$this->logger->log(0, "$dest: invalid pear-config replacement: $a[to]");
 
return false;
}
} else {
146,6 → 145,7
}
if (is_null($to)) {
$this->logger->log(0, "$dest: invalid pear-config replacement: $a[to]");
 
return false;
}
} elseif ($a['type'] == 'php-const') {
156,6 → 156,7
$to = constant($a['to']);
} else {
$this->logger->log(0, "$dest: invalid php-const replacement: $a[to]");
 
return false;
}
} else {
163,6 → 164,7
$to = $t;
} else {
$this->logger->log(0, "$dest: invalid package-info replacement: $a[to]");
 
return false;
}
}
171,12 → 173,14
$subst_to[] = $to;
}
}
$this->logger->log(3, "doing " . sizeof($subst_from) .
" substitution(s) for $dest");
$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
4,20 → 4,13
*
* 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
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a10
*/
/**
* Base class
28,35 → 21,35
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.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)
function __construct(&$pkg, &$config, &$logger, $fileXml)
{
parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE);
parent::__construct($config, $logger, PEAR_TASK_PACKAGE);
$this->_contents = $fileXml;
$this->_pkg = &$pkg;
$this->_params = array();
}
 
function validate()
public function validate()
{
return true;
}
 
function getName()
public function getName()
{
return 'unixeol';
}
 
function getXml()
public function getXml()
{
return '';
}
}
?>
?>
/trunk/bibliotheque/pear/PEAR/Task/Postinstallscript.php
4,20 → 4,13
*
* 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
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
/**
* Base class
28,28 → 21,29
*
* 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
*
* @category pear
* @package PEAR
* @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.10.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;
public $type = 'script';
public $_class;
public $_params;
public $_obj;
/**
*
* @var PEAR_PackageFile_v2
*/
var $_pkg;
var $_contents;
var $phase = PEAR_TASK_INSTALL;
public $_pkg;
public $_contents;
public $phase = PEAR_TASK_INSTALL;
 
/**
* Validate the raw xml at parsing-time.
56,28 → 50,29
*
* 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
*
* @param PEAR_PackageFile_v2
* @param array The XML contents of the <postinstallscript> tag
* @param PEAR_Config
* @param array the entire parsed <file> tag
*/
function validateXml($pkg, $xml, &$config, $fileXml)
public 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"');
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());
 
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!');
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) {
84,29 → 79,37
PEAR::popErrorHandling();
$warnings = '';
foreach ($pkg->getValidationWarnings() as $warn) {
$warnings .= $warn['message'] . "\n";
$warnings .= $warn['message']."\n";
}
return array(PEAR_TASK_ERROR_INVALID, 'Analysis of post-install script "' .
$fileXml['name'] . '" failed: ' . $warnings);
 
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');
 
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') {
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"');
 
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()');
 
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) {
116,129 → 119,137
}
if (count($methods)) {
PEAR::popErrorHandling();
return array(PEAR_TASK_ERROR_INVALID, 'Post-install script "' .
$fileXml['name'] . '" must declare methods init() and run()');
 
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'])) {
$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 (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.'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.'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 (!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 (!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.'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.'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'])) {
if (!isset($param[$tasksNamespace.'param'])) {
continue; // <param> is no longer required
}
$subparams = $param[$tasksNamespace . 'param'];
$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 (!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 (!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.'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');
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'];
$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)
* @param array $xml raw, parsed xml
* @param array $fileattribs attributes from the <file> tag containing
* this task
* @param string|null $lastversion last installed version of this package,
* if any (useful for upgrades)
*/
function init($xml, $fileattribs, $lastversion)
public function init($xml, $fileattribs, $lastversion)
{
$this->_class = str_replace('/', '_', $fileattribs['name']);
$this->_filename = $fileattribs['name'];
$this->_class = str_replace ('.php', '', $this->_class) . '_postinstall';
$this->_class = str_replace('.php', '', $this->_class).'_postinstall';
$this->_params = $xml;
$this->_lastversion = $lastversion;
}
248,7 → 259,7
*
* @access private
*/
function _stripNamespace($params = null)
public function _stripNamespace($params = null)
{
if ($params === null) {
$params = array();
259,7 → 270,7
if (is_array($param)) {
$param = $this->_stripNamespace($param);
}
$params[str_replace($this->_pkg->getTasksNs() . ':', '', $i)] = $param;
$params[str_replace($this->_pkg->getTasksNs().':', '', $i)] = $param;
}
$this->_params = $params;
} else {
268,21 → 279,24
if (is_array($param)) {
$param = $this->_stripNamespace($param);
}
$newparams[str_replace($this->_pkg->getTasksNs() . ':', '', $i)] = $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
* Unlike other tasks, the installed file name is passed in instead of the
* file contents, because this task is handled post-installation
*
* @param mixed $pkg PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @param string $contents file name
*
* @return bool|PEAR_Error false to skip this file, PEAR_Error to fail
* (use $this->throwError)
* (use $this->throwError)
*/
function startSession($pkg, $contents)
public function startSession($pkg, $contents)
{
if ($this->installphase != PEAR_TASK_INSTALL) {
return false;
290,17 → 304,21
// 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');
$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');
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()"');
$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();
307,23 → 325,25
if ($res) {
$this->logger->log(0, 'init succeeded');
} else {
return $this->throwError('init of post-install script "' . $this->_class .
'->init()" failed');
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
*
* @see PEAR_PackageFile_v2::runPostinstallScripts()
* @param array an array of tasks
* @param string install or upgrade
* @access protected
* @static
*/
function run()
public static function run()
{
}
}
?>
/trunk/bibliotheque/pear/PEAR/Task/Unixeol.php
4,20 → 4,13
*
* 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
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
/**
* Base class
28,30 → 21,31
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.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;
public $type = 'simple';
public $phase = PEAR_TASK_PACKAGE;
public $_replacements;
 
/**
* Validate the raw xml at parsing-time.
* @param PEAR_PackageFile_v2
* @param array raw, parsed xml
* @param PEAR_Config
* @static
*
* @param PEAR_PackageFile_v2
* @param array raw, parsed xml
* @param PEAR_Config
*/
function validateXml($pkg, $xml, &$config, $fileXml)
public static function validateXml($pkg, $xml, $config, $fileXml)
{
if ($xml != '') {
return array(PEAR_TASK_ERROR_INVALID, 'no attributes allowed');
}
 
return true;
}
 
59,8 → 53,9
* Initialize a task instance with the parameters
* @param array raw, parsed xml
* @param unused
* @param unused
*/
function init($xml, $attribs)
public function init($xml, $attribs, $lastVersion = null)
{
}
 
68,16 → 63,17
* 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)
*
* @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
* (use $this->throwError), otherwise return the new contents
*/
function startSession($pkg, $contents, $dest)
public 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
4,20 → 4,13
*
* 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
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a10
*/
/**
* Base class
25,38 → 18,39
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
*
* @category pear
* @package PEAR
* @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.10.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)
function __construct(&$pkg, &$config, &$logger, $fileXml)
{
parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE);
parent::__construct($config, $logger, PEAR_TASK_PACKAGE);
$this->_contents = $fileXml;
$this->_pkg = &$pkg;
$this->_params = array();
}
 
function validate()
public function validate()
{
return true;
}
 
function getName()
public function getName()
{
return 'windowseol';
}
 
function getXml()
public function getXml()
{
return '';
}
}
?>
?>
/trunk/bibliotheque/pear/PEAR/Task/Replace/rw.php
4,20 → 4,13
*
* 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
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a10
*/
/**
* Base class
28,40 → 21,39
* @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
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.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)
public function __construct(&$pkg, &$config, &$logger, $fileXml)
{
parent::PEAR_Task_Common($config, $logger, PEAR_TASK_PACKAGE);
parent::__construct($config, $logger, PEAR_TASK_PACKAGE);
$this->_contents = $fileXml;
$this->_pkg = &$pkg;
$this->_params = array();
}
 
function validate()
public function validate()
{
return $this->validateXml($this->_pkg, $this->_params, $this->config, $this->_contents);
}
 
function setInfo($from, $to, $type)
public function setInfo($from, $to, $type)
{
$this->_params = array('attribs' => array('from' => $from, 'to' => $to, 'type' => $type));
}
 
function getName()
public function getName()
{
return 'replace';
}
 
function getXml()
public function getXml()
{
return $this->_params;
}
}
?>
/trunk/bibliotheque/pear/PEAR/Task/Common.php
4,20 → 4,13
*
* 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
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
/**#@+
* Error codes for task validation routines
48,14 → 41,15
* 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
*
* @category pear
* @package PEAR
* @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.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
* @abstract
*/
class PEAR_Task_Common
68,34 → 62,35
* changes directly to disk
*
* Child task classes must override this property.
*
* @access protected
*/
var $type = 'simple';
protected $type = 'simple';
/**
* Determines which install phase this task is executed under
*/
var $phase = PEAR_TASK_INSTALL;
public $phase = PEAR_TASK_INSTALL;
/**
* @access protected
*/
var $config;
protected $config;
/**
* @access protected
*/
var $registry;
protected $registry;
/**
* @access protected
*/
var $logger;
public $logger;
/**
* @access protected
*/
var $installphase;
protected $installphase;
/**
* @param PEAR_Config
* @param PEAR_Common
*/
function PEAR_Task_Common(&$config, &$logger, $phase)
function __construct(&$config, &$logger, $phase)
{
$this->config = &$config;
$this->registry = &$config->getRegistry();
108,86 → 103,90
 
/**
* 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][, ...])
* 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
* 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
*
* @abstract
*/
function validateXml($pkg, $xml, &$config, $fileXml)
public static 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
*
* @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)
public 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
* 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
*
* @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)
public 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
* 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
*/
function run($tasks)
public static function run($tasks)
{
}
 
/**
* @static
* @final
*/
function hasPostinstallTasks()
public static 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']);
/**
* @final
*/
public static 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']);
}
 
/**
194,15 → 193,15
* Determines whether a role is a script
* @return bool
*/
function isScript()
public function isScript()
{
return $this->type == 'script';
return $this->type == 'script';
}
 
function throwError($msg, $code = -1)
public function throwError($msg, $code = -1)
{
include_once 'PEAR.php';
 
return PEAR::raiseError($msg, $code);
}
}
?>
/trunk/bibliotheque/pear/scripts/pecl.bat
New file
0,0 → 1,115
@ECHO OFF
 
REM ----------------------------------------------------------------------
REM PHP version 5
REM ----------------------------------------------------------------------
REM Copyright (c) 1997-2004 The PHP Group
REM ----------------------------------------------------------------------
REM This source file is subject to version 3.0 of the PHP license,
REM that is bundled with this package in the file LICENSE, and is
REM available at through the world-wide-web at
REM http://www.php.net/license/3_0.txt.
REM If you did not receive a copy of the PHP license and are unable to
REM obtain it through the world-wide-web, please send a note to
REM license@php.net so we can mail you a copy immediately.
REM ----------------------------------------------------------------------
REM Authors: Alexander Merz (alexmerz@php.net)
REM ----------------------------------------------------------------------
REM
REM Last updated 02/08/2004 ($Id$ is not replaced if the file is binary)
 
REM change this lines to match the paths of your system
REM -------------------
 
 
REM Test to see if this is a raw pear.bat (uninstalled version)
SET TMPTMPTMPTMPT=@includ
SET PMTPMTPMT=%TMPTMPTMPTMPT%e_path@
FOR %%x IN ("@include_path@") DO (if %%x=="%PMTPMTPMT%" GOTO :NOTINSTALLED)
 
REM Check PEAR global ENV, set them if they do not exist
IF "%PHP_PEAR_INSTALL_DIR%"=="" SET "PHP_PEAR_INSTALL_DIR=@include_path@"
IF "%PHP_PEAR_BIN_DIR%"=="" SET "PHP_PEAR_BIN_DIR=@bin_dir@"
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=@php_bin@"
GOTO :INSTALLED
 
:NOTINSTALLED
ECHO WARNING: This is a raw, uninstalled pear.bat
 
REM Check to see if we can grab the directory of this file (Windows NT+)
IF %~n0 == pear (
FOR %%x IN (cli\php.exe php.exe) DO (if "%%~$PATH:x" NEQ "" (
SET "PHP_PEAR_PHP_BIN=%%~$PATH:x"
echo Using PHP Executable "%PHP_PEAR_PHP_BIN%"
"%PHP_PEAR_PHP_BIN%" -v
GOTO :NEXTTEST
))
GOTO :FAILAUTODETECT
:NEXTTEST
IF "%PHP_PEAR_PHP_BIN%" NEQ "" (
 
REM We can use this PHP to run a temporary php file to get the dirname of pear
 
echo ^<?php $s=getcwd^(^);chdir^($a=dirname^(__FILE__^).'\\'^);if^(stristr^($a,'\\scripts'^)^)$a=dirname^(dirname^($a^)^).'\\';$f=fopen^($s.'\\~a.a','wb'^);echo$s.'\\~a.a';fwrite^($f,$a^);fclose^($f^);chdir^($s^);?^> > ~~getloc.php
"%PHP_PEAR_PHP_BIN%" ~~getloc.php
set /p PHP_PEAR_BIN_DIR=fakeprompt < ~a.a
DEL ~a.a
DEL ~~getloc.php
set "PHP_PEAR_INSTALL_DIR=%PHP_PEAR_BIN_DIR%pear"
 
REM Make sure there is a pearcmd.php at our disposal
 
IF NOT EXIST %PHP_PEAR_INSTALL_DIR%\pearcmd.php (
IF EXIST %PHP_PEAR_INSTALL_DIR%\scripts\pearcmd.php COPY %PHP_PEAR_INSTALL_DIR%\scripts\pearcmd.php %PHP_PEAR_INSTALL_DIR%\pearcmd.php
IF EXIST pearcmd.php COPY pearcmd.php %PHP_PEAR_INSTALL_DIR%\pearcmd.php
IF EXIST %~dp0\scripts\pearcmd.php COPY %~dp0\scripts\pearcmd.php %PHP_PEAR_INSTALL_DIR%\pearcmd.php
)
)
GOTO :INSTALLED
) ELSE (
REM Windows Me/98 cannot succeed, so allow the batch to fail
)
:FAILAUTODETECT
echo WARNING: failed to auto-detect pear information
:INSTALLED
 
REM Check Folders and files
IF NOT EXIST "%PHP_PEAR_INSTALL_DIR%" GOTO PEAR_INSTALL_ERROR
IF NOT EXIST "%PHP_PEAR_INSTALL_DIR%\pearcmd.php" GOTO PEAR_INSTALL_ERROR2
IF NOT EXIST "%PHP_PEAR_BIN_DIR%" GOTO PEAR_BIN_ERROR
IF NOT EXIST "%PHP_PEAR_PHP_BIN%" GOTO PEAR_PHPBIN_ERROR
REM launch pearcmd
GOTO RUN
:PEAR_INSTALL_ERROR
ECHO PHP_PEAR_INSTALL_DIR is not set correctly.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_INSTALL_DIR%
GOTO END
:PEAR_INSTALL_ERROR2
ECHO PHP_PEAR_INSTALL_DIR is not set correctly.
ECHO pearcmd.php could not be found there.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_INSTALL_DIR%
GOTO END
:PEAR_BIN_ERROR
ECHO PHP_PEAR_BIN_DIR is not set correctly.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_BIN_DIR%
GOTO END
:PEAR_PHPBIN_ERROR
ECHO PHP_PEAR_PHP_BIN is not set correctly.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_PHP_BIN%
GOTO END
:RUN
"%PHP_PEAR_PHP_BIN%" -C -n -d date.timezone=UTC -d output_buffering=1 -d safe_mode=0 -d "include_path='%PHP_PEAR_INSTALL_DIR%'" -d register_argc_argv="On" -d variables_order=EGPCS -f "%PHP_PEAR_INSTALL_DIR%\peclcmd.php" -- %1 %2 %3 %4 %5 %6 %7 %8 %9
:END
@ECHO ON
/trunk/bibliotheque/pear/scripts/peardev.bat
New file
0,0 → 1,115
@ECHO OFF
 
REM ----------------------------------------------------------------------
REM PHP version 5
REM ----------------------------------------------------------------------
REM Copyright (c) 1997-2004 The PHP Group
REM ----------------------------------------------------------------------
REM This source file is subject to version 3.0 of the PHP license,
REM that is bundled with this package in the file LICENSE, and is
REM available at through the world-wide-web at
REM http://www.php.net/license/3_0.txt.
REM If you did not receive a copy of the PHP license and are unable to
REM obtain it through the world-wide-web, please send a note to
REM license@php.net so we can mail you a copy immediately.
REM ----------------------------------------------------------------------
REM Authors: Alexander Merz (alexmerz@php.net)
REM ----------------------------------------------------------------------
REM
REM $Id: peardev.bat,v 1.6 2007-09-03 03:00:17 cellog Exp $
 
REM change this lines to match the paths of your system
REM -------------------
 
 
REM Test to see if this is a raw pear.bat (uninstalled version)
SET TMPTMPTMPTMPT=@includ
SET PMTPMTPMT=%TMPTMPTMPTMPT%e_path@
FOR %%x IN ("@include_path@") DO (if %%x=="%PMTPMTPMT%" GOTO :NOTINSTALLED)
 
REM Check PEAR global ENV, set them if they do not exist
IF "%PHP_PEAR_INSTALL_DIR%"=="" SET "PHP_PEAR_INSTALL_DIR=@include_path@"
IF "%PHP_PEAR_BIN_DIR%"=="" SET "PHP_PEAR_BIN_DIR=@bin_dir@"
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=@php_bin@"
GOTO :INSTALLED
 
:NOTINSTALLED
ECHO WARNING: This is a raw, uninstalled pear.bat
 
REM Check to see if we can grab the directory of this file (Windows NT+)
IF %~n0 == pear (
FOR %%x IN (cli\php.exe php.exe) DO (if "%%~$PATH:x" NEQ "" (
SET "PHP_PEAR_PHP_BIN=%%~$PATH:x"
echo Using PHP Executable "%PHP_PEAR_PHP_BIN%"
"%PHP_PEAR_PHP_BIN%" -v
GOTO :NEXTTEST
))
GOTO :FAILAUTODETECT
:NEXTTEST
IF "%PHP_PEAR_PHP_BIN%" NEQ "" (
 
REM We can use this PHP to run a temporary php file to get the dirname of pear
 
echo ^<?php $s=getcwd^(^);chdir^($a=dirname^(__FILE__^).'\\'^);if^(stristr^($a,'\\scripts'^)^)$a=dirname^(dirname^($a^)^).'\\';$f=fopen^($s.'\\~a.a','wb'^);echo$s.'\\~a.a';fwrite^($f,$a^);fclose^($f^);chdir^($s^);?^> > ~~getloc.php
"%PHP_PEAR_PHP_BIN%" ~~getloc.php
set /p PHP_PEAR_BIN_DIR=fakeprompt < ~a.a
DEL ~a.a
DEL ~~getloc.php
set "PHP_PEAR_INSTALL_DIR=%PHP_PEAR_BIN_DIR%pear"
 
REM Make sure there is a pearcmd.php at our disposal
 
IF NOT EXIST %PHP_PEAR_INSTALL_DIR%\pearcmd.php (
IF EXIST %PHP_PEAR_INSTALL_DIR%\scripts\pearcmd.php COPY %PHP_PEAR_INSTALL_DIR%\scripts\pearcmd.php %PHP_PEAR_INSTALL_DIR%\pearcmd.php
IF EXIST pearcmd.php COPY pearcmd.php %PHP_PEAR_INSTALL_DIR%\pearcmd.php
IF EXIST %~dp0\scripts\pearcmd.php COPY %~dp0\scripts\pearcmd.php %PHP_PEAR_INSTALL_DIR%\pearcmd.php
)
)
GOTO :INSTALLED
) ELSE (
REM Windows Me/98 cannot succeed, so allow the batch to fail
)
:FAILAUTODETECT
echo WARNING: failed to auto-detect pear information
:INSTALLED
 
REM Check Folders and files
IF NOT EXIST "%PHP_PEAR_INSTALL_DIR%" GOTO PEAR_INSTALL_ERROR
IF NOT EXIST "%PHP_PEAR_INSTALL_DIR%\pearcmd.php" GOTO PEAR_INSTALL_ERROR2
IF NOT EXIST "%PHP_PEAR_BIN_DIR%" GOTO PEAR_BIN_ERROR
IF NOT EXIST "%PHP_PEAR_PHP_BIN%" GOTO PEAR_PHPBIN_ERROR
REM launch pearcmd
GOTO RUN
:PEAR_INSTALL_ERROR
ECHO PHP_PEAR_INSTALL_DIR is not set correctly.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_INSTALL_DIR%
GOTO END
:PEAR_INSTALL_ERROR2
ECHO PHP_PEAR_INSTALL_DIR is not set correctly.
ECHO pearcmd.php could not be found there.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_INSTALL_DIR%
GOTO END
:PEAR_BIN_ERROR
ECHO PHP_PEAR_BIN_DIR is not set correctly.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_BIN_DIR%
GOTO END
:PEAR_PHPBIN_ERROR
ECHO PHP_PEAR_PHP_BIN is not set correctly.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_PHP_BIN%
GOTO END
:RUN
"%PHP_PEAR_PHP_BIN%" -C -d date.timezone=UTC -d memory_limit="-1" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" -d variables_order=EGPCS -d open_basedir="" -d output_buffering=1 -d "include_path='%PHP_PEAR_INSTALL_DIR%'" -f "%PHP_PEAR_INSTALL_DIR%\pearcmd.php" -- %1 %2 %3 %4 %5 %6 %7 %8 %9
:END
@ECHO ON
/trunk/bibliotheque/pear/scripts/pear.bat
New file
0,0 → 1,111
@ECHO OFF
 
REM ----------------------------------------------------------------------
REM PHP version 5
REM ----------------------------------------------------------------------
REM Copyright (c) 1997-2010 The Authors
REM ----------------------------------------------------------------------
REM http://opensource.org/licenses/bsd-license.php New BSD License
REM ----------------------------------------------------------------------
REM Authors: Alexander Merz (alexmerz@php.net)
REM ----------------------------------------------------------------------
REM
REM Last updated 12/29/2004 ($Id$ is not replaced if the file is binary)
 
REM change this lines to match the paths of your system
REM -------------------
 
 
REM Test to see if this is a raw pear.bat (uninstalled version)
SET TMPTMPTMPTMPT=@includ
SET PMTPMTPMT=%TMPTMPTMPTMPT%e_path@
FOR %%x IN ("@include_path@") DO (if %%x=="%PMTPMTPMT%" GOTO :NOTINSTALLED)
 
REM Check PEAR global ENV, set them if they do not exist
IF "%PHP_PEAR_INSTALL_DIR%"=="" SET "PHP_PEAR_INSTALL_DIR=@include_path@"
IF "%PHP_PEAR_BIN_DIR%"=="" SET "PHP_PEAR_BIN_DIR=@bin_dir@"
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=@php_bin@"
 
GOTO :INSTALLED
 
:NOTINSTALLED
ECHO WARNING: This is a raw, uninstalled pear.bat
 
REM Check to see if we can grab the directory of this file (Windows NT+)
IF %~n0 == pear (
FOR %%x IN (cli\php.exe php.exe) DO (if "%%~$PATH:x" NEQ "" (
SET "PHP_PEAR_PHP_BIN=%%~$PATH:x"
echo Using PHP Executable "%PHP_PEAR_PHP_BIN%"
"%PHP_PEAR_PHP_BIN%" -v
GOTO :NEXTTEST
))
GOTO :FAILAUTODETECT
:NEXTTEST
IF "%PHP_PEAR_PHP_BIN%" NEQ "" (
 
REM We can use this PHP to run a temporary php file to get the dirname of pear
 
echo ^<?php $s=getcwd^(^);chdir^($a=dirname^(__FILE__^).'\\'^);if^(stristr^($a,'\\scripts'^)^)$a=dirname^(dirname^($a^)^).'\\';$f=fopen^($s.'\\~a.a','wb'^);echo$s.'\\~a.a';fwrite^($f,$a^);fclose^($f^);chdir^($s^);?^> > ~~getloc.php
"%PHP_PEAR_PHP_BIN%" ~~getloc.php
set /p PHP_PEAR_BIN_DIR=fakeprompt < ~a.a
DEL ~a.a
DEL ~~getloc.php
set "PHP_PEAR_INSTALL_DIR=%PHP_PEAR_BIN_DIR%pear"
 
REM Make sure there is a pearcmd.php at our disposal
 
IF NOT EXIST %PHP_PEAR_INSTALL_DIR%\pearcmd.php (
IF EXIST %PHP_PEAR_INSTALL_DIR%\scripts\pearcmd.php COPY %PHP_PEAR_INSTALL_DIR%\scripts\pearcmd.php %PHP_PEAR_INSTALL_DIR%\pearcmd.php
IF EXIST pearcmd.php COPY pearcmd.php %PHP_PEAR_INSTALL_DIR%\pearcmd.php
IF EXIST %~dp0\scripts\pearcmd.php COPY %~dp0\scripts\pearcmd.php %PHP_PEAR_INSTALL_DIR%\pearcmd.php
)
)
GOTO :INSTALLED
) ELSE (
REM Windows Me/98 cannot succeed, so allow the batch to fail
)
:FAILAUTODETECT
echo WARNING: failed to auto-detect pear information
:INSTALLED
 
REM Check Folders and files
IF NOT EXIST "%PHP_PEAR_INSTALL_DIR%" GOTO PEAR_INSTALL_ERROR
IF NOT EXIST "%PHP_PEAR_INSTALL_DIR%\pearcmd.php" GOTO PEAR_INSTALL_ERROR2
IF NOT EXIST "%PHP_PEAR_BIN_DIR%" GOTO PEAR_BIN_ERROR
IF NOT EXIST "%PHP_PEAR_PHP_BIN%" GOTO PEAR_PHPBIN_ERROR
 
REM launch pearcmd
GOTO RUN
:PEAR_INSTALL_ERROR
ECHO PHP_PEAR_INSTALL_DIR is not set correctly.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_INSTALL_DIR%
GOTO END
:PEAR_INSTALL_ERROR2
ECHO PHP_PEAR_INSTALL_DIR is not set correctly.
ECHO pearcmd.php could not be found there.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_INSTALL_DIR%
GOTO END
:PEAR_BIN_ERROR
ECHO PHP_PEAR_BIN_DIR is not set correctly.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_BIN_DIR%
GOTO END
:PEAR_PHPBIN_ERROR
ECHO PHP_PEAR_PHP_BIN is not set correctly.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_PHP_BIN%
GOTO END
:RUN
"%PHP_PEAR_PHP_BIN%" -C -d date.timezone=UTC -d output_buffering=1 -d safe_mode=0 -d open_basedir="" -d auto_prepend_file="" -d auto_append_file="" -d variables_order=EGPCS -d register_argc_argv="On" -d "include_path='%PHP_PEAR_INSTALL_DIR%'" -f "%PHP_PEAR_INSTALL_DIR%\pearcmd.php" -- %1 %2 %3 %4 %5 %6 %7 %8 %9
:END
@ECHO ON
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/trunk/bibliotheque/pear/scripts/pecl.sh
New file
0,0 → 1,28
#!/bin/sh
 
# first find which PHP binary to use
if test "x$PHP_PEAR_PHP_BIN" != "x"; then
PHP="$PHP_PEAR_PHP_BIN"
else
if test "@php_bin@" = '@'php_bin'@'; then
PHP=php
else
PHP="@php_bin@"
fi
fi
 
# then look for the right pear include dir
if test "x$PHP_PEAR_INSTALL_DIR" != "x"; then
INCDIR=$PHP_PEAR_INSTALL_DIR
INCARG="-d include_path=$PHP_PEAR_INSTALL_DIR"
else
if test "@php_dir@" = '@'php_dir'@'; then
INCDIR=`dirname $0`
INCARG=""
else
INCDIR="@php_dir@"
INCARG="-d include_path=@php_dir@"
fi
fi
 
exec $PHP -C -n -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d safe_mode=0 -d register_argc_argv="On" $INCDIR/peclcmd.php "$@"
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/trunk/bibliotheque/pear/scripts/peclcmd.php
New file
0,0 → 1,42
<?php
/**
* PEAR, the PHP Extension and Application Repository
*
* Command line interface
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
*/
 
/**
* @nodep Gtk
*/
//the space is needed for windows include paths with trailing backslash
// http://pear.php.net/bugs/bug.php?id=19482
if ('@include_path@ ' != '@'.'include_path'.'@ ') {
ini_set('include_path', trim('@include_path@ '). PATH_SEPARATOR . get_include_path());
$raw = false;
} else {
// this is a raw, uninstalled pear, either a cvs checkout, or php distro
$raw = true;
}
define('PEAR_RUNTYPE', 'pecl');
require_once 'pearcmd.php';
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* mode: php
* End:
*/
// vim600:syn=php
 
?>
/trunk/bibliotheque/pear/scripts/peardev.sh
New file
0,0 → 1,28
#!/bin/sh
 
# first find which PHP binary to use
if test "x$PHP_PEAR_PHP_BIN" != "x"; then
PHP="$PHP_PEAR_PHP_BIN"
else
if test "@php_bin@" = '@'php_bin'@'; then
PHP=php
else
PHP="@php_bin@"
fi
fi
 
# then look for the right pear include dir
if test "x$PHP_PEAR_INSTALL_DIR" != "x"; then
INCDIR=$PHP_PEAR_INSTALL_DIR
INCARG="-d include_path=$PHP_PEAR_INSTALL_DIR"
else
if test "@php_dir@" = '@'php_dir'@'; then
INCDIR=`dirname $0`
INCARG=""
else
INCDIR="@php_dir@"
INCARG="-d include_path=@php_dir@"
fi
fi
 
exec $PHP -d date.timezone=UTC -d memory_limit="-1" -C -q $INCARG -d output_buffering=1 -d open_basedir="" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d variables_order=EGPCS -d auto_append_file="" $INCDIR/pearcmd.php "$@"
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/trunk/bibliotheque/pear/scripts/pear.sh
New file
0,0 → 1,28
#!/bin/sh
 
# first find which PHP binary to use
if test "x$PHP_PEAR_PHP_BIN" != "x"; then
PHP="$PHP_PEAR_PHP_BIN"
else
if test "@php_bin@" = '@'php_bin'@'; then
PHP=php
else
PHP="@php_bin@"
fi
fi
 
# then look for the right pear include dir
if test "x$PHP_PEAR_INSTALL_DIR" != "x"; then
INCDIR=$PHP_PEAR_INSTALL_DIR
INCARG="-d include_path=$PHP_PEAR_INSTALL_DIR"
else
if test "@php_dir@" = '@'php_dir'@'; then
INCDIR=`dirname $0`
INCARG=""
else
INCDIR="@php_dir@"
INCARG="-d include_path=@php_dir@"
fi
fi
 
exec $PHP -C -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d open_basedir="" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" $INCDIR/pearcmd.php "$@"
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/trunk/bibliotheque/pear/scripts/pearcmd.php
New file
0,0 → 1,497
<?php
/**
* PEAR, the PHP Extension and Application Repository
*
* Command line interface
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Stig Bakken <ssb@php.net>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
*/
 
@ob_end_clean();
if (!defined('PEAR_RUNTYPE')) {
// this is defined in peclcmd.php as 'pecl'
define('PEAR_RUNTYPE', 'pear');
}
define('PEAR_IGNORE_BACKTRACE', 1);
/**
* @nodep Gtk
*/
//the space is needed for windows include paths with trailing backslash
// http://pear.php.net/bugs/bug.php?id=19482
if ('@include_path@ ' != '@'.'include_path'.'@ ') {
ini_set('include_path', trim('@include_path@ '). PATH_SEPARATOR . get_include_path());
$raw = false;
} else {
// this is a raw, uninstalled pear, either a cvs checkout, or php distro
$raw = true;
}
@ini_set('allow_url_fopen', true);
@set_time_limit(0);
ob_implicit_flush(true);
@ini_set('track_errors', true);
@ini_set('html_errors', false);
$_PEAR_PHPDIR = '#$%^&*';
set_error_handler('error_handler');
 
$pear_package_version = "@pear_version@";
 
require_once 'PEAR.php';
require_once 'PEAR/Frontend.php';
require_once 'PEAR/Config.php';
require_once 'PEAR/Command.php';
require_once 'Console/Getopt.php';
 
 
PEAR_Command::setFrontendType('CLI');
$all_commands = PEAR_Command::getCommands();
 
// remove this next part when we stop supporting that crap-ass PHP 4.2
if (!isset($_SERVER['argv']) && !isset($argv) && !isset($HTTP_SERVER_VARS['argv'])) {
echo 'ERROR: either use the CLI php executable, ' .
'or set register_argc_argv=On in php.ini';
exit(1);
}
 
$argv = Console_Getopt::readPHPArgv();
// fix CGI sapi oddity - the -- in pear.bat/pear is not removed
if (php_sapi_name() != 'cli' && isset($argv[1]) && $argv[1] == '--') {
unset($argv[1]);
$argv = array_values($argv);
}
$progname = PEAR_RUNTYPE;
array_shift($argv);
$options = Console_Getopt::getopt2($argv, "c:C:d:D:Gh?sSqu:vV");
if (PEAR::isError($options)) {
usage($options);
}
 
$opts = $options[0];
 
$fetype = 'CLI';
if ($progname == 'gpear' || $progname == 'pear-gtk') {
$fetype = 'Gtk2';
} else {
foreach ($opts as $opt) {
if ($opt[0] == 'G') {
$fetype = 'Gtk2';
}
}
}
 
$pear_user_config = '';
$pear_system_config = '';
$store_user_config = false;
$store_system_config = false;
$verbose = 1;
 
foreach ($opts as $opt) {
switch ($opt[0]) {
case 'c':
$pear_user_config = $opt[1];
break;
case 'C':
$pear_system_config = $opt[1];
break;
}
}
 
PEAR_Command::setFrontendType($fetype);
$ui = &PEAR_Command::getFrontendObject();
$config = &PEAR_Config::singleton($pear_user_config, $pear_system_config);
 
if (PEAR::isError($config)) {
$_file = '';
if ($pear_user_config !== false) {
$_file .= $pear_user_config;
}
if ($pear_system_config !== false) {
$_file .= '/' . $pear_system_config;
}
if ($_file == '/') {
$_file = 'The default config file';
}
$config->getMessage();
$ui->outputData("ERROR: $_file is not a valid config file or is corrupted.");
// We stop, we have no idea where we are :)
exit(1);
}
 
// this is used in the error handler to retrieve a relative path
$_PEAR_PHPDIR = $config->get('php_dir');
$ui->setConfig($config);
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError"));
 
$verbose = $config->get("verbose");
$cmdopts = array();
 
if ($raw) {
if (!$config->isDefinedLayer('user') && !$config->isDefinedLayer('system')) {
$found = false;
foreach ($opts as $opt) {
if ($opt[0] == 'd' || $opt[0] == 'D') {
// the user knows what they are doing, and are setting config values
$found = true;
}
}
if (!$found) {
// no prior runs, try to install PEAR
$parent = dirname(__FILE__);
if (strpos($parent, 'scripts')) {
$grandparent = dirname($parent);
$packagexml = $grandparent . DIRECTORY_SEPARATOR . 'package2.xml';
$pearbase = $grandparent;
} else {
$packagexml = $parent . DIRECTORY_SEPARATOR . 'package2.xml';
$pearbase = $parent;
}
if (file_exists($packagexml)) {
$options[1] = array(
'install',
$packagexml
);
$config->set('php_dir', $pearbase . DIRECTORY_SEPARATOR . 'php');
$config->set('data_dir', $pearbase . DIRECTORY_SEPARATOR . 'data');
$config->set('doc_dir', $pearbase . DIRECTORY_SEPARATOR . 'docs');
$config->set('test_dir', $pearbase . DIRECTORY_SEPARATOR . 'tests');
$config->set(
'ext_dir',
$pearbase . DIRECTORY_SEPARATOR . 'extensions'
);
$config->set('bin_dir', $pearbase);
$config->mergeConfigFile($pearbase . 'pear.ini', false);
$config->store();
$config->set('auto_discover', 1);
}
}
}
}
foreach ($opts as $opt) {
$param = !empty($opt[1]) ? $opt[1] : true;
switch ($opt[0]) {
case 'd':
if ($param === true) {
die(
'Invalid usage of "-d" option, expected -d config_value=value, ' .
'received "-d"' . "\n"
);
}
$possible = explode('=', $param);
if (count($possible) != 2) {
die(
'Invalid usage of "-d" option, expected ' .
'-d config_value=value, received "' . $param . '"' . "\n"
);
}
list($key, $value) = explode('=', $param);
$config->set($key, $value, 'user');
break;
case 'D':
if ($param === true) {
die(
'Invalid usage of "-d" option, expected ' .
'-d config_value=value, received "-d"' . "\n"
);
}
$possible = explode('=', $param);
if (count($possible) != 2) {
die(
'Invalid usage of "-d" option, expected ' .
'-d config_value=value, received "' . $param . '"' . "\n"
);
}
list($key, $value) = explode('=', $param);
$config->set($key, $value, 'system');
break;
case 's':
$store_user_config = true;
break;
case 'S':
$store_system_config = true;
break;
case 'u':
$config->remove($param, 'user');
break;
case 'v':
$config->set('verbose', $config->get('verbose') + 1);
break;
case 'q':
$config->set('verbose', $config->get('verbose') - 1);
break;
case 'V':
usage(null, 'version');
case 'c':
case 'C':
break;
default:
// all non pear params goes to the command
$cmdopts[$opt[0]] = $param;
break;
}
}
 
if ($store_system_config) {
$config->store('system');
}
 
if ($store_user_config) {
$config->store('user');
}
 
$command = (isset($options[1][0])) ? $options[1][0] : null;
if (empty($command) && ($store_user_config || $store_system_config)) {
exit;
}
 
if ($fetype == 'Gtk2') {
if (!$config->validConfiguration()) {
PEAR::raiseError(
"CRITICAL ERROR: no existing valid configuration files found in " .
"files '$pear_user_config' or '$pear_system_config', " .
"please copy an existing configuration file to one of these " .
"locations, or use the -c and -s options to create one"
);
}
Gtk::main();
} else {
do {
if ($command == 'help') {
usage(null, isset($options[1][1]) ? $options[1][1] : null);
}
 
if (!$config->validConfiguration()) {
PEAR::raiseError(
"CRITICAL ERROR: no existing valid configuration files found " .
"in files '$pear_user_config' or '$pear_system_config', " .
"please copy an existing configuration file to one of " .
"these locations, or use the -c and -s options to create one"
);
}
 
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$cmd = PEAR_Command::factory($command, $config);
PEAR::popErrorHandling();
if (PEAR::isError($cmd)) {
usage(null, isset($options[1][0]) ? $options[1][0] : null);
}
 
$short_args = $long_args = null;
PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
array_shift($options[1]);
$tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args);
 
if (PEAR::isError($tmp)) {
break;
}
 
list($tmpopt, $params) = $tmp;
$opts = array();
foreach ($tmpopt as $foo => $tmp2) {
list($opt, $value) = $tmp2;
if ($value === null) {
$value = true; // options without args
}
 
if (strlen($opt) == 1) {
$cmdoptions = $cmd->getOptions($command);
foreach ($cmdoptions as $o => $d) {
if (isset($d['shortopt']) && $d['shortopt'] == $opt) {
$opts[$o] = $value;
}
}
} else {
if (substr($opt, 0, 2) == '--') {
$opts[substr($opt, 2)] = $value;
}
}
}
 
$ok = $cmd->run($command, $opts, $params);
if ($ok === false) {
PEAR::raiseError("unknown command `$command'");
}
 
if (PEAR::isError($ok)) {
PEAR::setErrorHandling(
PEAR_ERROR_CALLBACK, array($ui, "displayFatalError")
);
PEAR::raiseError($ok);
}
} while (false);
}
 
// {{{ usage()
 
/**
* Display usage information
*
* @param mixed $error Optional error message
* @param mixed $helpsubject Optional subject/command to display help for
*
* @return void
*/
function usage($error = null, $helpsubject = null)
{
global $progname, $all_commands;
$stdout = fopen('php://stdout', 'w');
if (PEAR::isError($error)) {
fputs($stdout, $error->getMessage() . "\n");
} elseif ($error !== null) {
fputs($stdout, "$error\n");
}
 
if ($helpsubject != null) {
$put = cmdHelp($helpsubject);
} else {
$put = "Commands:\n";
$maxlen = max(array_map("strlen", $all_commands));
$formatstr = "%-{$maxlen}s %s\n";
ksort($all_commands);
foreach ($all_commands as $cmd => $class) {
$put .= sprintf($formatstr, $cmd, PEAR_Command::getDescription($cmd));
}
$put .=
"Usage: $progname [options] command [command-options] <parameters>\n".
"Type \"$progname help options\" to list all options.\n".
"Type \"$progname help shortcuts\" to list all command shortcuts.\n".
"Type \"$progname help version\" or ".
"\"$progname version\" to list version information.\n".
"Type \"$progname help <command>\" to get the help ".
"for the specified command.";
}
fputs($stdout, "$put\n");
fclose($stdout);
 
if ($error === null) {
exit(0);
}
exit(1);
}
 
/**
* Return help string for specified command
*
* @param string $command Command to return help for
*
* @return void
*/
function cmdHelp($command)
{
global $progname, $all_commands, $config;
if ($command == "options") {
return
"Options:\n".
" -v increase verbosity level (default 1)\n".
" -q be quiet, decrease verbosity level\n".
" -c file find user configuration in `file'\n".
" -C file find system configuration in `file'\n".
" -d foo=bar set user config variable `foo' to `bar'\n".
" -D foo=bar set system config variable `foo' to `bar'\n".
" -G start in graphical (Gtk) mode\n".
" -s store user configuration\n".
" -S store system configuration\n".
" -u foo unset `foo' in the user configuration\n".
" -h, -? display help/usage (this message)\n".
" -V version information\n";
} elseif ($command == "shortcuts") {
$sc = PEAR_Command::getShortcuts();
$ret = "Shortcuts:\n";
foreach ($sc as $s => $c) {
$ret .= sprintf(" %-8s %s\n", $s, $c);
}
return $ret;
 
} elseif ($command == "version") {
return "PEAR Version: ".$GLOBALS['pear_package_version'].
"\nPHP Version: ".phpversion().
"\nZend Engine Version: ".zend_version().
"\nRunning on: ".php_uname();
 
} elseif ($help = PEAR_Command::getHelp($command)) {
if (is_string($help)) {
return "$progname $command [options] $help\n";
}
 
if ($help[1] === null) {
return "$progname $command $help[0]";
}
 
return "$progname $command [options] $help[0]\n$help[1]";
}
 
return "Command '$command' is not valid, try '$progname help'";
}
 
// }}}
 
/**
* error_handler
*
* @param mixed $errno Error number
* @param mixed $errmsg Message
* @param mixed $file Filename
* @param mixed $line Line number
* @param mixed $vars Variables
*
* @access public
* @return boolean
*/
function error_handler($errno, $errmsg, $file, $line, $vars)
{
if ($errno & E_STRICT
|| $errno & E_DEPRECATED
|| !error_reporting()
) {
if ($errno & E_STRICT) {
return; // E_STRICT
}
if ($errno & E_DEPRECATED) {
return; // E_DEPRECATED
}
if (!error_reporting() && isset($GLOBALS['config']) && $GLOBALS['config']->get('verbose') < 4) {
return false; // @silenced error, show all if debug is high enough
}
}
$errortype = array (
E_DEPRECATED => 'Deprecated Warning',
E_ERROR => "Error",
E_WARNING => "Warning",
E_PARSE => "Parsing Error",
E_STRICT => 'Strict Warning',
E_NOTICE => "Notice",
E_CORE_ERROR => "Core Error",
E_CORE_WARNING => "Core Warning",
E_COMPILE_ERROR => "Compile Error",
E_COMPILE_WARNING => "Compile Warning",
E_USER_ERROR => "User Error",
E_USER_WARNING => "User Warning",
E_USER_NOTICE => "User Notice"
);
$prefix = $errortype[$errno];
global $_PEAR_PHPDIR;
if (stristr($file, $_PEAR_PHPDIR)) {
$file = substr($file, strlen($_PEAR_PHPDIR) + 1);
} else {
$file = basename($file);
}
print "\n$prefix: $errmsg in $file on line $line\n";
return false;
}
 
 
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* mode: php
* End:
*/
// vim600:syn=php
/trunk/bibliotheque/pear/System.php
New file
0,0 → 1,622
<?php
/**
* File/Directory manipulation
*
* PHP versions 4 and 5
*
* @category pear
* @package System
* @author Tomas V.V.Cox <cox@idecnet.com>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 0.1
*/
 
/**
* base class
*/
require_once 'PEAR.php';
require_once 'Console/Getopt.php';
 
$GLOBALS['_System_temp_files'] = array();
 
/**
* System offers cross plattform compatible system functions
*
* Static functions for different operations. Should work under
* Unix and Windows. The names and usage has been taken from its respectively
* GNU commands. The functions will return (bool) false on error and will
* trigger the error with the PHP trigger_error() function (you can silence
* the error by prefixing a '@' sign after the function call, but this
* is not recommended practice. Instead use an error handler with
* {@link set_error_handler()}).
*
* Documentation on this class you can find in:
* http://pear.php.net/manual/
*
* Example usage:
* if (!@System::rm('-r file1 dir1')) {
* print "could not delete file1 or dir1";
* }
*
* In case you need to to pass file names with spaces,
* pass the params as an array:
*
* System::rm(array('-r', $file1, $dir1));
*
* @category pear
* @package System
* @author Tomas V.V. Cox <cox@idecnet.com>
* @copyright 1997-2006 The PHP Group
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
* @static
*/
class System
{
/**
* returns the commandline arguments of a function
*
* @param string $argv the commandline
* @param string $short_options the allowed option short-tags
* @param string $long_options the allowed option long-tags
* @return array the given options and there values
*/
public static function _parseArgs($argv, $short_options, $long_options = null)
{
if (!is_array($argv) && $argv !== null) {
/*
// Quote all items that are a short option
$av = preg_split('/(\A| )--?[a-z0-9]+[ =]?((?<!\\\\)((,\s*)|((?<!,)\s+))?)/i', $argv, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE);
$offset = 0;
foreach ($av as $a) {
$b = trim($a[0]);
if ($b{0} == '"' || $b{0} == "'") {
continue;
}
 
$escape = escapeshellarg($b);
$pos = $a[1] + $offset;
$argv = substr_replace($argv, $escape, $pos, strlen($b));
$offset += 2;
}
*/
 
// Find all items, quoted or otherwise
preg_match_all("/(?:[\"'])(.*?)(?:['\"])|([^\s]+)/", $argv, $av);
$argv = $av[1];
foreach ($av[2] as $k => $a) {
if (empty($a)) {
continue;
}
$argv[$k] = trim($a) ;
}
}
 
return Console_Getopt::getopt2($argv, $short_options, $long_options);
}
 
/**
* Output errors with PHP trigger_error(). You can silence the errors
* with prefixing a "@" sign to the function call: @System::mkdir(..);
*
* @param mixed $error a PEAR error or a string with the error message
* @return bool false
*/
protected static function raiseError($error)
{
if (PEAR::isError($error)) {
$error = $error->getMessage();
}
trigger_error($error, E_USER_WARNING);
return false;
}
 
/**
* Creates a nested array representing the structure of a directory
*
* System::_dirToStruct('dir1', 0) =>
* Array
* (
* [dirs] => Array
* (
* [0] => dir1
* )
*
* [files] => Array
* (
* [0] => dir1/file2
* [1] => dir1/file3
* )
* )
* @param string $sPath Name of the directory
* @param integer $maxinst max. deep of the lookup
* @param integer $aktinst starting deep of the lookup
* @param bool $silent if true, do not emit errors.
* @return array the structure of the dir
*/
protected static function _dirToStruct($sPath, $maxinst, $aktinst = 0, $silent = false)
{
$struct = array('dirs' => array(), 'files' => array());
if (($dir = @opendir($sPath)) === false) {
if (!$silent) {
System::raiseError("Could not open dir $sPath");
}
return $struct; // XXX could not open error
}
 
$struct['dirs'][] = $sPath = realpath($sPath); // XXX don't add if '.' or '..' ?
$list = array();
while (false !== ($file = readdir($dir))) {
if ($file != '.' && $file != '..') {
$list[] = $file;
}
}
 
closedir($dir);
natsort($list);
if ($aktinst < $maxinst || $maxinst == 0) {
foreach ($list as $val) {
$path = $sPath . DIRECTORY_SEPARATOR . $val;
if (is_dir($path) && !is_link($path)) {
$tmp = System::_dirToStruct($path, $maxinst, $aktinst+1, $silent);
$struct = array_merge_recursive($struct, $tmp);
} else {
$struct['files'][] = $path;
}
}
}
 
return $struct;
}
 
/**
* Creates a nested array representing the structure of a directory and files
*
* @param array $files Array listing files and dirs
* @return array
* @static
* @see System::_dirToStruct()
*/
protected static function _multipleToStruct($files)
{
$struct = array('dirs' => array(), 'files' => array());
settype($files, 'array');
foreach ($files as $file) {
if (is_dir($file) && !is_link($file)) {
$tmp = System::_dirToStruct($file, 0);
$struct = array_merge_recursive($tmp, $struct);
} else {
if (!in_array($file, $struct['files'])) {
$struct['files'][] = $file;
}
}
}
return $struct;
}
 
/**
* The rm command for removing files.
* Supports multiple files and dirs and also recursive deletes
*
* @param string $args the arguments for rm
* @return mixed PEAR_Error or true for success
* @static
* @access public
*/
public static function rm($args)
{
$opts = System::_parseArgs($args, 'rf'); // "f" does nothing but I like it :-)
if (PEAR::isError($opts)) {
return System::raiseError($opts);
}
foreach ($opts[0] as $opt) {
if ($opt[0] == 'r') {
$do_recursive = true;
}
}
$ret = true;
if (isset($do_recursive)) {
$struct = System::_multipleToStruct($opts[1]);
foreach ($struct['files'] as $file) {
if (!@unlink($file)) {
$ret = false;
}
}
 
rsort($struct['dirs']);
foreach ($struct['dirs'] as $dir) {
if (!@rmdir($dir)) {
$ret = false;
}
}
} else {
foreach ($opts[1] as $file) {
$delete = (is_dir($file)) ? 'rmdir' : 'unlink';
if (!@$delete($file)) {
$ret = false;
}
}
}
return $ret;
}
 
/**
* Make directories.
*
* The -p option will create parent directories
* @param string $args the name of the director(y|ies) to create
* @return bool True for success
*/
public static function mkDir($args)
{
$opts = System::_parseArgs($args, 'pm:');
if (PEAR::isError($opts)) {
return System::raiseError($opts);
}
 
$mode = 0777; // default mode
foreach ($opts[0] as $opt) {
if ($opt[0] == 'p') {
$create_parents = true;
} elseif ($opt[0] == 'm') {
// if the mode is clearly an octal number (starts with 0)
// convert it to decimal
if (strlen($opt[1]) && $opt[1]{0} == '0') {
$opt[1] = octdec($opt[1]);
} else {
// convert to int
$opt[1] += 0;
}
$mode = $opt[1];
}
}
 
$ret = true;
if (isset($create_parents)) {
foreach ($opts[1] as $dir) {
$dirstack = array();
while ((!file_exists($dir) || !is_dir($dir)) &&
$dir != DIRECTORY_SEPARATOR) {
array_unshift($dirstack, $dir);
$dir = dirname($dir);
}
 
while ($newdir = array_shift($dirstack)) {
if (!is_writeable(dirname($newdir))) {
$ret = false;
break;
}
 
if (!mkdir($newdir, $mode)) {
$ret = false;
}
}
}
} else {
foreach($opts[1] as $dir) {
if ((@file_exists($dir) || !is_dir($dir)) && !mkdir($dir, $mode)) {
$ret = false;
}
}
}
 
return $ret;
}
 
/**
* Concatenate files
*
* Usage:
* 1) $var = System::cat('sample.txt test.txt');
* 2) System::cat('sample.txt test.txt > final.txt');
* 3) System::cat('sample.txt test.txt >> final.txt');
*
* Note: as the class use fopen, urls should work also (test that)
*
* @param string $args the arguments
* @return boolean true on success
*/
public static function &cat($args)
{
$ret = null;
$files = array();
if (!is_array($args)) {
$args = preg_split('/\s+/', $args, -1, PREG_SPLIT_NO_EMPTY);
}
 
$count_args = count($args);
for ($i = 0; $i < $count_args; $i++) {
if ($args[$i] == '>') {
$mode = 'wb';
$outputfile = $args[$i+1];
break;
} elseif ($args[$i] == '>>') {
$mode = 'ab+';
$outputfile = $args[$i+1];
break;
} else {
$files[] = $args[$i];
}
}
$outputfd = false;
if (isset($mode)) {
if (!$outputfd = fopen($outputfile, $mode)) {
$err = System::raiseError("Could not open $outputfile");
return $err;
}
$ret = true;
}
foreach ($files as $file) {
if (!$fd = fopen($file, 'r')) {
System::raiseError("Could not open $file");
continue;
}
while ($cont = fread($fd, 2048)) {
if (is_resource($outputfd)) {
fwrite($outputfd, $cont);
} else {
$ret .= $cont;
}
}
fclose($fd);
}
if (is_resource($outputfd)) {
fclose($outputfd);
}
return $ret;
}
 
/**
* Creates temporary files or directories. This function will remove
* the created files when the scripts finish its execution.
*
* Usage:
* 1) $tempfile = System::mktemp("prefix");
* 2) $tempdir = System::mktemp("-d prefix");
* 3) $tempfile = System::mktemp();
* 4) $tempfile = System::mktemp("-t /var/tmp prefix");
*
* prefix -> The string that will be prepended to the temp name
* (defaults to "tmp").
* -d -> A temporary dir will be created instead of a file.
* -t -> The target dir where the temporary (file|dir) will be created. If
* this param is missing by default the env vars TMP on Windows or
* TMPDIR in Unix will be used. If these vars are also missing
* c:\windows\temp or /tmp will be used.
*
* @param string $args The arguments
* @return mixed the full path of the created (file|dir) or false
* @see System::tmpdir()
*/
public static function mktemp($args = null)
{
static $first_time = true;
$opts = System::_parseArgs($args, 't:d');
if (PEAR::isError($opts)) {
return System::raiseError($opts);
}
 
foreach ($opts[0] as $opt) {
if ($opt[0] == 'd') {
$tmp_is_dir = true;
} elseif ($opt[0] == 't') {
$tmpdir = $opt[1];
}
}
 
$prefix = (isset($opts[1][0])) ? $opts[1][0] : 'tmp';
if (!isset($tmpdir)) {
$tmpdir = System::tmpdir();
}
 
if (!System::mkDir(array('-p', $tmpdir))) {
return false;
}
 
$tmp = tempnam($tmpdir, $prefix);
if (isset($tmp_is_dir)) {
unlink($tmp); // be careful possible race condition here
if (!mkdir($tmp, 0700)) {
return System::raiseError("Unable to create temporary directory $tmpdir");
}
}
 
$GLOBALS['_System_temp_files'][] = $tmp;
if (isset($tmp_is_dir)) {
//$GLOBALS['_System_temp_files'][] = dirname($tmp);
}
 
if ($first_time) {
PEAR::registerShutdownFunc(array('System', '_removeTmpFiles'));
$first_time = false;
}
 
return $tmp;
}
 
/**
* Remove temporary files created my mkTemp. This function is executed
* at script shutdown time
*/
public static function _removeTmpFiles()
{
if (count($GLOBALS['_System_temp_files'])) {
$delete = $GLOBALS['_System_temp_files'];
array_unshift($delete, '-r');
System::rm($delete);
$GLOBALS['_System_temp_files'] = array();
}
}
 
/**
* Get the path of the temporal directory set in the system
* by looking in its environments variables.
* Note: php.ini-recommended removes the "E" from the variables_order setting,
* making unavaible the $_ENV array, that s why we do tests with _ENV
*
* @return string The temporary directory on the system
*/
public static function tmpdir()
{
if (OS_WINDOWS) {
if ($var = isset($_ENV['TMP']) ? $_ENV['TMP'] : getenv('TMP')) {
return $var;
}
if ($var = isset($_ENV['TEMP']) ? $_ENV['TEMP'] : getenv('TEMP')) {
return $var;
}
if ($var = isset($_ENV['USERPROFILE']) ? $_ENV['USERPROFILE'] : getenv('USERPROFILE')) {
return $var;
}
if ($var = isset($_ENV['windir']) ? $_ENV['windir'] : getenv('windir')) {
return $var;
}
return getenv('SystemRoot') . '\temp';
}
if ($var = isset($_ENV['TMPDIR']) ? $_ENV['TMPDIR'] : getenv('TMPDIR')) {
return $var;
}
return realpath('/tmp');
}
 
/**
* The "which" command (show the full path of a command)
*
* @param string $program The command to search for
* @param mixed $fallback Value to return if $program is not found
*
* @return mixed A string with the full path or false if not found
* @author Stig Bakken <ssb@php.net>
*/
public static function which($program, $fallback = false)
{
// enforce API
if (!is_string($program) || '' == $program) {
return $fallback;
}
 
// full path given
if (basename($program) != $program) {
$path_elements[] = dirname($program);
$program = basename($program);
} else {
$path = getenv('PATH');
if (!$path) {
$path = getenv('Path'); // some OSes are just stupid enough to do this
}
 
$path_elements = explode(PATH_SEPARATOR, $path);
}
 
if (OS_WINDOWS) {
$exe_suffixes = getenv('PATHEXT')
? explode(PATH_SEPARATOR, getenv('PATHEXT'))
: array('.exe','.bat','.cmd','.com');
// allow passing a command.exe param
if (strpos($program, '.') !== false) {
array_unshift($exe_suffixes, '');
}
} else {
$exe_suffixes = array('');
}
 
foreach ($exe_suffixes as $suff) {
foreach ($path_elements as $dir) {
$file = $dir . DIRECTORY_SEPARATOR . $program . $suff;
if (is_executable($file)) {
return $file;
}
}
}
return $fallback;
}
 
/**
* The "find" command
*
* Usage:
*
* System::find($dir);
* System::find("$dir -type d");
* System::find("$dir -type f");
* System::find("$dir -name *.php");
* System::find("$dir -name *.php -name *.htm*");
* System::find("$dir -maxdepth 1");
*
* Params implmented:
* $dir -> Start the search at this directory
* -type d -> return only directories
* -type f -> return only files
* -maxdepth <n> -> max depth of recursion
* -name <pattern> -> search pattern (bash style). Multiple -name param allowed
*
* @param mixed Either array or string with the command line
* @return array Array of found files
*/
public static function find($args)
{
if (!is_array($args)) {
$args = preg_split('/\s+/', $args, -1, PREG_SPLIT_NO_EMPTY);
}
$dir = realpath(array_shift($args));
if (!$dir) {
return array();
}
$patterns = array();
$depth = 0;
$do_files = $do_dirs = true;
$args_count = count($args);
for ($i = 0; $i < $args_count; $i++) {
switch ($args[$i]) {
case '-type':
if (in_array($args[$i+1], array('d', 'f'))) {
if ($args[$i+1] == 'd') {
$do_files = false;
} else {
$do_dirs = false;
}
}
$i++;
break;
case '-name':
$name = preg_quote($args[$i+1], '#');
// our magic characters ? and * have just been escaped,
// so now we change the escaped versions to PCRE operators
$name = strtr($name, array('\?' => '.', '\*' => '.*'));
$patterns[] = '('.$name.')';
$i++;
break;
case '-maxdepth':
$depth = $args[$i+1];
break;
}
}
$path = System::_dirToStruct($dir, $depth, 0, true);
if ($do_files && $do_dirs) {
$files = array_merge($path['files'], $path['dirs']);
} elseif ($do_dirs) {
$files = $path['dirs'];
} else {
$files = $path['files'];
}
if (count($patterns)) {
$dsq = preg_quote(DIRECTORY_SEPARATOR, '#');
$pattern = '#(^|'.$dsq.')'.implode('|', $patterns).'($|'.$dsq.')#';
$ret = array();
$files_count = count($files);
for ($i = 0; $i < $files_count; $i++) {
// only search in the part of the file below the current directory
$filepart = basename($files[$i]);
if (preg_match($pattern, $filepart)) {
$ret[] = $files[$i];
}
}
return $ret;
}
return $files;
}
}
/trunk/bibliotheque/pear/DB.php
5,7 → 5,7
/**
* Database independent query interface
*
* PHP versions 4 and 5
* PHP version 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:
18,9 → 18,9
* @author Stig Bakken <ssb@php.net>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: DB.php,v 1.80 2005/02/16 02:16:00 danielc Exp $
* @version CVS: $Id$
* @link http://pear.php.net/package/DB
*/
 
424,14 → 424,14
* @author Stig Bakken <ssb@php.net>
* @author Tomas V.V.Cox <cox@idecnet.com>
* @author Daniel Convissor <danielc@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB
{
// {{{ &factory()
// {{{ factory()
 
/**
* Create a new DB object for the specified database type but don't
444,7 → 444,7
*
* @see DB_common::setOption()
*/
function &factory($type, $options = false)
public static function factory($type, $options = false)
{
if (!is_array($options)) {
$options = array('persistent' => $options);
467,7 → 467,7
return $tmp;
}
 
@$obj =& new $classname;
@$obj = new $classname;
 
foreach ($options as $option => $value) {
$test = $obj->setOption($option, $value);
480,7 → 480,7
}
 
// }}}
// {{{ &connect()
// {{{ connect()
 
/**
* Create a new DB object including a connection to the specified database
495,7 → 495,7
* 'portability' => DB_PORTABILITY_ALL,
* );
*
* $db =& DB::connect($dsn, $options);
* $db = DB::connect($dsn, $options);
* if (PEAR::isError($db)) {
* die($db->getMessage());
* }
515,7 → 515,7
*
* @uses DB::parseDSN(), DB_common::setOption(), PEAR::isError()
*/
function &connect($dsn, $options = array())
public static function connect($dsn, $options = array())
{
$dsninfo = DB::parseDSN($dsn);
$type = $dsninfo['phptype'];
539,12 → 539,13
if (!class_exists($classname)) {
$tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
"Unable to include the DB/{$type}.php"
. " file for '$dsn'",
. " file for '"
. DB::getDSNString($dsn, true) . "'",
'DB_Error', true);
return $tmp;
}
 
@$obj =& new $classname;
@$obj = new $classname;
 
foreach ($options as $option => $value) {
$test = $obj->setOption($option, $value);
555,7 → 556,11
 
$err = $obj->connect($dsninfo, $obj->getOption('persistent'));
if (DB::isError($err)) {
$err->addUserInfo($dsn);
if (is_array($dsn)) {
$err->addUserInfo(DB::getDSNString($dsn, true));
} else {
$err->addUserInfo($dsn);
}
return $err;
}
 
572,7 → 577,7
*/
function apiVersion()
{
return '1.7.6';
return '1.9.2';
}
 
// }}}
585,9 → 590,9
*
* @return bool whether $value is DB_Error object
*/
function isError($value)
public static function isError($value)
{
return is_a($value, 'DB_Error');
return is_object($value) && is_a($value, 'DB_Error');
}
 
// }}}
600,7 → 605,7
*
* @return bool whether $value is a DB_<driver> object
*/
function isConnection($value)
public static function isConnection($value)
{
return (is_object($value) &&
is_subclass_of($value, 'db_common') &&
621,11 → 626,11
*
* @return boolean whether $query is a data manipulation query
*/
function isManip($query)
public static function isManip($query)
{
$manips = 'INSERT|UPDATE|DELETE|REPLACE|'
. 'CREATE|DROP|'
. 'LOAD DATA|SELECT .* INTO|COPY|'
. 'LOAD DATA|SELECT .* INTO .* FROM|COPY|'
. 'ALTER|GRANT|REVOKE|'
. 'LOCK|UNLOCK';
if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $query)) {
645,7 → 650,7
* @return string the error message or false if the error code was
* not recognized
*/
function errorMessage($value)
public static function errorMessage($value)
{
static $errorMessages;
if (!isset($errorMessages)) {
726,7 → 731,7
* + username: User name for login
* + password: Password for login
*/
function parseDSN($dsn)
public static function parseDSN($dsn)
{
$parsed = array(
'phptype' => false,
808,13 → 813,11
// process the different protocol options
$parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
$proto_opts = rawurldecode($proto_opts);
if (strpos($proto_opts, ':') !== false) {
list($proto_opts, $parsed['port']) = explode(':', $proto_opts);
}
if ($parsed['protocol'] == 'tcp') {
if (strpos($proto_opts, ':') !== false) {
list($parsed['hostspec'],
$parsed['port']) = explode(':', $proto_opts);
} else {
$parsed['hostspec'] = $proto_opts;
}
$parsed['hostspec'] = $proto_opts;
} elseif ($parsed['protocol'] == 'unix') {
$parsed['socket'] = $proto_opts;
}
848,6 → 851,82
}
 
// }}}
// {{{ getDSNString()
 
/**
* Returns the given DSN in a string format suitable for output.
*
* @param array|string the DSN to parse and format
* @param boolean true to hide the password, false to include it
* @return string
*/
public static function getDSNString($dsn, $hidePassword) {
/* Calling parseDSN will ensure that we have all the array elements
* defined, and means that we deal with strings and array in the same
* manner. */
$dsnArray = DB::parseDSN($dsn);
if ($hidePassword) {
$dsnArray['password'] = 'PASSWORD';
}
 
/* Protocol is special-cased, as using the default "tcp" along with an
* Oracle TNS connection string fails. */
if (is_string($dsn) && strpos($dsn, 'tcp') === false && $dsnArray['protocol'] == 'tcp') {
$dsnArray['protocol'] = false;
}
// Now we just have to construct the actual string. This is ugly.
$dsnString = $dsnArray['phptype'];
if ($dsnArray['dbsyntax']) {
$dsnString .= '('.$dsnArray['dbsyntax'].')';
}
$dsnString .= '://'
.$dsnArray['username']
.':'
.$dsnArray['password']
.'@'
.$dsnArray['protocol'];
if ($dsnArray['socket']) {
$dsnString .= '('.$dsnArray['socket'].')';
}
if ($dsnArray['protocol'] && $dsnArray['hostspec']) {
$dsnString .= '+';
}
$dsnString .= $dsnArray['hostspec'];
if ($dsnArray['port']) {
$dsnString .= ':'.$dsnArray['port'];
}
$dsnString .= '/'.$dsnArray['database'];
/* Option handling. Unfortunately, parseDSN simply places options into
* the top-level array, so we'll first get rid of the fields defined by
* DB and see what's left. */
unset($dsnArray['phptype'],
$dsnArray['dbsyntax'],
$dsnArray['username'],
$dsnArray['password'],
$dsnArray['protocol'],
$dsnArray['socket'],
$dsnArray['hostspec'],
$dsnArray['port'],
$dsnArray['database']
);
if (count($dsnArray) > 0) {
$dsnString .= '?';
$i = 0;
foreach ($dsnArray as $key => $value) {
if (++$i > 1) {
$dsnString .= '&';
}
$dsnString .= $key.'='.$value;
}
}
 
return $dsnString;
}
// }}}
}
 
// }}}
860,9 → 939,9
* @category Database
* @package DB
* @author Stig Bakken <ssb@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_Error extends PEAR_Error
880,18 → 959,32
*
* @see PEAR_Error
*/
function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
function __construct($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
$level = E_USER_NOTICE, $debuginfo = null)
{
if (is_int($code)) {
$this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code,
parent::__construct('DB Error: ' . DB::errorMessage($code), $code,
$mode, $level, $debuginfo);
} else {
$this->PEAR_Error("DB Error: $code", DB_ERROR,
parent::__construct("DB Error: $code", DB_ERROR,
$mode, $level, $debuginfo);
}
}
 
/**
* Workaround to both avoid the "Redefining already defined constructor"
* PHP error and provide backward compatibility in case someone is calling
* DB_Error() dynamically
*/
public function __call($method, $arguments)
{
if ($method == 'DB_Error') {
return call_user_func_array(array($this, '__construct'), $arguments);
}
trigger_error(
'Call to undefined method DB_Error::' . $method . '()', E_USER_ERROR
);
}
// }}}
}
 
907,9 → 1000,9
* @category Database
* @package DB
* @author Stig Bakken <ssb@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
*/
class DB_result
1016,7 → 1109,7
*
* @return void
*/
function DB_result(&$dbh, $result, $options = array())
function __construct(&$dbh, $result, $options = array())
{
$this->autofree = $dbh->options['autofree'];
$this->dbh = &$dbh;
1089,7 → 1182,7
$fetchmode = DB_FETCHMODE_ASSOC;
$object_class = $this->fetchmode_object_class;
}
if ($this->limit_from !== null) {
if (is_null($rownum) && $this->limit_from !== null) {
if ($this->row_counter === null) {
$this->row_counter = $this->limit_from;
// Skip rows
1121,7 → 1214,7
if ($object_class == 'stdClass') {
$arr = (object) $arr;
} else {
$arr = &new $object_class($arr);
$arr = new $object_class($arr);
}
}
return $arr;
1171,7 → 1264,7
$fetchmode = DB_FETCHMODE_ASSOC;
$object_class = $this->fetchmode_object_class;
}
if ($this->limit_from !== null) {
if (is_null($rownum) && $this->limit_from !== null) {
if ($this->row_counter === null) {
$this->row_counter = $this->limit_from;
// Skip rows
1253,10 → 1346,33
while ($res->fetchInto($tmp, DB_FETCHMODE_ORDERED)) {
$i++;
}
return $i;
$count = $i;
} else {
return $this->dbh->numRows($this->result);
$count = $this->dbh->numRows($this->result);
}
 
/* fbsql is checked for here because limit queries are implemented
* using a TOP() function, which results in fbsql_num_rows still
* returning the total number of rows that would have been returned,
* rather than the real number. As a result, we'll just do the limit
* calculations for fbsql in the same way as a database with emulated
* limits. Unfortunately, we can't just do this in DB_fbsql::numRows()
* because that only gets the result resource, rather than the full
* DB_Result object. */
if (($this->dbh->features['limit'] === 'emulate'
&& $this->limit_from !== null)
|| $this->dbh->phptype == 'fbsql') {
$limit_count = is_null($this->limit_count) ? $count : $this->limit_count;
if ($count < $this->limit_from) {
$count = 0;
} elseif ($count < ($this->limit_from + $limit_count)) {
$count -= $this->limit_from;
} else {
$count = $limit_count;
}
}
 
return $count;
}
 
// }}}
1349,9 → 1465,9
* @category Database
* @package DB
* @author Stig Bakken <ssb@php.net>
* @copyright 1997-2005 The PHP Group
* @copyright 1997-2007 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.7.6
* @version Release: 1.9.2
* @link http://pear.php.net/package/DB
* @see DB_common::setFetchMode()
*/
1366,7 → 1482,7
*
* @return void
*/
function DB_row(&$arr)
function __construct(&$arr)
{
foreach ($arr as $key => $value) {
$this->$key = &$arr[$key];