home/wwgoat/public_html/blog/wp-includes/SimplePie/src/Registry.php 0000644 00000020766 14720703144 0021477 0 ustar 00
*/
protected $default = [
Cache::class => Cache::class,
Locator::class => Locator::class,
Parser::class => Parser::class,
File::class => File::class,
Sanitize::class => Sanitize::class,
Item::class => Item::class,
Author::class => Author::class,
Category::class => Category::class,
Enclosure::class => Enclosure::class,
Caption::class => Caption::class,
Copyright::class => Copyright::class,
Credit::class => Credit::class,
Rating::class => Rating::class,
Restriction::class => Restriction::class,
Sniffer::class => Sniffer::class,
Source::class => Source::class,
Misc::class => Misc::class,
DeclarationParser::class => DeclarationParser::class,
Date::class => Date::class,
];
/**
* Class mapping
*
* @see register()
* @var array
*/
protected $classes = [];
/**
* Legacy classes
*
* @see register()
* @var array
*/
protected $legacy = [];
/**
* Legacy types
*
* @see register()
* @var array
*/
private $legacyTypes = [
'Cache' => Cache::class,
'Locator' => Locator::class,
'Parser' => Parser::class,
'File' => File::class,
'Sanitize' => Sanitize::class,
'Item' => Item::class,
'Author' => Author::class,
'Category' => Category::class,
'Enclosure' => Enclosure::class,
'Caption' => Caption::class,
'Copyright' => Copyright::class,
'Credit' => Credit::class,
'Rating' => Rating::class,
'Restriction' => Restriction::class,
'Content_Type_Sniffer' => Sniffer::class,
'Source' => Source::class,
'Misc' => Misc::class,
'XML_Declaration_Parser' => DeclarationParser::class,
'Parse_Date' => Date::class,
];
/**
* Constructor
*
* No-op
*/
public function __construct()
{
}
/**
* Register a class
*
* @param string $type See {@see $default} for names
* @param class-string $class Class name, must subclass the corresponding default
* @param bool $legacy Whether to enable legacy support for this class
* @return bool Successfulness
*/
public function register($type, $class, $legacy = false)
{
if (array_key_exists($type, $this->legacyTypes)) {
// trigger_error(sprintf('"%s"(): Using argument #1 ($type) with value "%s" is deprecated since SimplePie 1.8.0, use class-string "%s" instead.', __METHOD__, $type, $this->legacyTypes[$type]), \E_USER_DEPRECATED);
$type = $this->legacyTypes[$type];
}
if (!array_key_exists($type, $this->default)) {
return false;
}
if (!class_exists($class)) {
return false;
}
/** @var string */
$base_class = $this->default[$type];
if (!is_subclass_of($class, $base_class)) {
return false;
}
$this->classes[$type] = $class;
if ($legacy) {
$this->legacy[] = $class;
}
return true;
}
/**
* Get the class registered for a type
*
* Where possible, use {@see create()} or {@see call()} instead
*
* @template T
* @param class-string $type
* @return class-string|null
*/
public function get_class($type)
{
if (array_key_exists($type, $this->legacyTypes)) {
// trigger_error(sprintf('"%s"(): Using argument #1 ($type) with value "%s" is deprecated since SimplePie 1.8.0, use class-string "%s" instead.', __METHOD__, $type, $this->legacyTypes[$type]), \E_USER_DEPRECATED);
$type = $this->legacyTypes[$type];
}
if (!array_key_exists($type, $this->default)) {
return null;
}
$class = $this->default[$type];
if (array_key_exists($type, $this->classes)) {
$class = $this->classes[$type];
}
return $class;
}
/**
* Create a new instance of a given type
*
* @template T class-string $type
* @param class-string $type
* @param array $parameters Parameters to pass to the constructor
* @return T Instance of class
*/
public function &create($type, $parameters = [])
{
$class = $this->get_class($type);
if (!method_exists($class, '__construct')) {
$instance = new $class();
} else {
$reflector = new \ReflectionClass($class);
$instance = $reflector->newInstanceArgs($parameters);
}
if ($instance instanceof RegistryAware) {
$instance->set_registry($this);
} elseif (method_exists($instance, 'set_registry')) {
trigger_error(sprintf('Using the method "set_registry()" without implementing "%s" is deprecated since SimplePie 1.8.0, implement "%s" in "%s".', RegistryAware::class, RegistryAware::class, $class), \E_USER_DEPRECATED);
$instance->set_registry($this);
}
return $instance;
}
/**
* Call a static method for a type
*
* @param class-string $type
* @param string $method
* @param array $parameters
* @return mixed
*/
public function &call($type, $method, $parameters = [])
{
$class = $this->get_class($type);
if (in_array($class, $this->legacy)) {
switch ($type) {
case Cache::class:
// For backwards compatibility with old non-static
// Cache::create() methods in PHP < 8.0.
// No longer supported as of PHP 8.0.
if ($method === 'get_handler') {
$result = @call_user_func_array([$class, 'create'], $parameters);
return $result;
}
break;
}
}
$result = call_user_func_array([$class, $method], $parameters);
return $result;
}
}
class_alias('SimplePie\Registry', 'SimplePie_Registry');
var/softaculous/sitepad/editor/site-inc/SimplePie/Registry.php 0000644 00000013547 14756406255 0020575 0 ustar 00 'SimplePie_Cache',
'Locator' => 'SimplePie_Locator',
'Parser' => 'SimplePie_Parser',
'File' => 'SimplePie_File',
'Sanitize' => 'SimplePie_Sanitize',
'Item' => 'SimplePie_Item',
'Author' => 'SimplePie_Author',
'Category' => 'SimplePie_Category',
'Enclosure' => 'SimplePie_Enclosure',
'Caption' => 'SimplePie_Caption',
'Copyright' => 'SimplePie_Copyright',
'Credit' => 'SimplePie_Credit',
'Rating' => 'SimplePie_Rating',
'Restriction' => 'SimplePie_Restriction',
'Content_Type_Sniffer' => 'SimplePie_Content_Type_Sniffer',
'Source' => 'SimplePie_Source',
'Misc' => 'SimplePie_Misc',
'XML_Declaration_Parser' => 'SimplePie_XML_Declaration_Parser',
'Parse_Date' => 'SimplePie_Parse_Date',
);
/**
* Class mapping
*
* @see register()
* @var array
*/
protected $classes = array();
/**
* Legacy classes
*
* @see register()
* @var array
*/
protected $legacy = array();
/**
* Constructor
*
* No-op
*/
public function __construct() { }
/**
* Register a class
*
* @param string $type See {@see $default} for names
* @param string $class Class name, must subclass the corresponding default
* @param bool $legacy Whether to enable legacy support for this class
* @return bool Successfulness
*/
public function register($type, $class, $legacy = false)
{
if (!is_subclass_of($class, $this->default[$type]))
{
return false;
}
$this->classes[$type] = $class;
if ($legacy)
{
$this->legacy[] = $class;
}
return true;
}
/**
* Get the class registered for a type
*
* Where possible, use {@see create()} or {@see call()} instead
*
* @param string $type
* @return string|null
*/
public function get_class($type)
{
if (!empty($this->classes[$type]))
{
return $this->classes[$type];
}
if (!empty($this->default[$type]))
{
return $this->default[$type];
}
return null;
}
/**
* Create a new instance of a given type
*
* @param string $type
* @param array $parameters Parameters to pass to the constructor
* @return object Instance of class
*/
public function &create($type, $parameters = array())
{
$class = $this->get_class($type);
if (in_array($class, $this->legacy))
{
switch ($type)
{
case 'locator':
// Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
// Specified: file, timeout, useragent, max_checked_feeds
$replacement = array($this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer'));
array_splice($parameters, 3, 1, $replacement);
break;
}
}
if (!method_exists($class, '__construct'))
{
$instance = new $class;
}
else
{
$reflector = new ReflectionClass($class);
$instance = $reflector->newInstanceArgs($parameters);
}
if (method_exists($instance, 'set_registry'))
{
$instance->set_registry($this);
}
return $instance;
}
/**
* Call a static method for a type
*
* @param string $type
* @param string $method
* @param array $parameters
* @return mixed
*/
public function &call($type, $method, $parameters = array())
{
$class = $this->get_class($type);
if (in_array($class, $this->legacy))
{
switch ($type)
{
case 'Cache':
// For backwards compatibility with old non-static
// Cache::create() methods
if ($method === 'get_handler')
{
$result = @call_user_func_array(array($class, 'create'), $parameters);
return $result;
}
break;
}
}
$result = call_user_func_array(array($class, $method), $parameters);
return $result;
}
} opt/cpanel/ea-php74/root/usr/share/pear/PEAR/Registry.php 0000644 00000224270 14756435775 0017070 0 ustar 00
* @author Tomas V. V. Cox
* @author Greg Beaver
* @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
*/
/**
* for PEAR_Error
*/
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_CHANNEL_FILE', -6);
/**
* Administration class used to maintain the installed package database.
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Tomas V. V. Cox
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_Registry extends PEAR
{
/**
* File containing all channel information.
* @var string
*/
var $channels = '';
/** Directory where registry files are stored.
* @var string
*/
var $statedir = '';
/** File where the file map is stored
* @var string
*/
var $filemap = '';
/** Directory where registry files for channels are stored.
* @var string
*/
var $channelsdir = '';
/** Name of file used for locking the registry
* @var string
*/
var $lockfile = '';
/** File descriptor used during locking
* @var resource
*/
var $lock_fp = null;
/** Mode used during locking
* @var int
*/
var $lock_mode = 0; // XXX UNUSED
/** Cache of package information. Structure:
* array(
* 'package' => array('id' => ... ),
* ... )
* @var array
*/
var $pkginfo_cache = array();
/** Cache of file map. Structure:
* array( '/path/to/file' => 'package', ... )
* @var array
*/
var $filemap_cache = array();
/**
* @var false|PEAR_ChannelFile
*/
var $_pearChannel;
/**
* @var false|PEAR_ChannelFile
*/
var $_peclChannel;
/**
* @var false|PEAR_ChannelFile
*/
var $_docChannel;
/**
* @var PEAR_DependencyDB
*/
var $_dependencyDB;
/**
* @var PEAR_Config
*/
var $_config;
/**
* PEAR_Registry constructor.
*
* @param string (optional) PEAR install directory (for .php files)
* @param PEAR_ChannelFile PEAR_ChannelFile object representing the PEAR channel, if
* default values are not desired. Only used the very first time a PEAR
* repository is initialized
* @param PEAR_ChannelFile PEAR_ChannelFile object representing the PECL channel, if
* default values are not desired. Only used the very first time a PEAR
* repository is initialized
*
* @access public
*/
function __construct($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
$pecl_channel = false, $pear_metadata_dir = '')
{
parent::__construct();
$this->setInstallDir($pear_install_dir, $pear_metadata_dir);
$this->_pearChannel = $pear_channel;
$this->_peclChannel = $pecl_channel;
$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 != '.') {
$olddir = $dir;
$dir = dirname($dir);
if ($dir != '.' && file_exists($dir)) {
if (is_writeable($dir)) {
return true;
}
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, $resetInstallDir = true)
{
$this->_config = &$config;
if ($resetInstallDir) {
$this->setInstallDir($config->get('php_dir'), $config->get('metadata_dir'));
}
}
function _initializeChannelDirs()
{
static $running = false;
if (!$running) {
$running = true;
$ds = DIRECTORY_SEPARATOR;
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;
if (!is_a($pear_channel, 'PEAR_ChannelFile') || !$pear_channel->validate()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setAlias('pear');
$pear_channel->setServer('pear.php.net');
$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/');
//$pear_channel->setBaseURL('REST1.4', 'http://pear.php.net/rest/');
} else {
$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()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$pecl_channel = new PEAR_ChannelFile;
$pecl_channel->setAlias('pecl');
$pecl_channel->setServer('pecl.php.net');
$pecl_channel->setSummary('PHP Extension Community Library');
$pecl_channel->setDefaultPEARProtocols();
$pecl_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
$pecl_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$pecl_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
} else {
$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->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
$this->_addChannel($private);
}
$this->_rebuildFileMap();
}
$running = false;
}
}
function _initializeDirs()
{
$ds = DIRECTORY_SEPARATOR;
// XXX Compatibility code should be removed in the future
// rename all registry files if any to lowercase
if (!OS_WINDOWS && file_exists($this->statedir) && is_dir($this->statedir) &&
$handle = opendir($this->statedir)) {
$dest = $this->statedir . $ds;
while (false !== ($file = readdir($handle))) {
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();
}
$this->_initializeDepDB();
}
function _initializeDepDB()
{
if (!isset($this->_dependencyDB)) {
static $initializing = false;
if (!$initializing) {
$initializing = true;
if (!$this->_config) { // never used?
$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('metadata_dir', null, 'pear.php.net') .
DIRECTORY_SEPARATOR . '.depdb')) {
@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();
echo 'Unrecoverable error';
exit(1);
}
}
$initializing = false;
}
}
}
/**
* PEAR_Registry destructor. Makes sure no locks are forgotten.
*
* @access private
*/
function _PEAR_Registry()
{
parent::_PEAR();
if (is_resource($this->lock_fp)) {
$this->_unlock();
}
}
/**
* Make sure the directory where we keep registry files exists.
*
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertStateDir($channel = false)
{
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}'");
}
$init = true;
} elseif (!is_dir($this->statedir)) {
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;
}
} elseif (!is_dir($this->channelsdir)) {
return $this->raiseError('Cannot create directory ' . $this->channelsdir . ', ' .
'it already exists and is not a directory');
}
if ($init) {
static $running = false;
if (!$running) {
$running = true;
$this->_initializeDirs();
$running = false;
$init = false;
}
} else {
$this->_initializeDepDB();
}
return true;
}
/**
* Make sure the directory where we keep registry files exists for a non-standard channel.
*
* @param string channel name
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertChannelStateDir($channel)
{
$ds = DIRECTORY_SEPARATOR;
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
$this->_initializeChannelDirs();
}
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 .
"'");
}
} elseif (!is_dir($channelDir)) {
return $this->raiseError("could not create directory '" . $channelDir .
"', already exists and is not a directory");
}
return true;
}
/**
* Make sure the directory where we keep registry files for channels exists
*
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertChannelDir()
{
if (!file_exists($this->channelsdir)) {
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}'");
}
} 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'");
}
} 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;
}
/**
* Get the name of the file where data for a given package is stored.
*
* @param string channel name, or false if this is a PEAR package
* @param string package name
*
* @return string registry file name
*
* @access public
*/
function _packageFileName($package, $channel = false)
{
if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
return $this->_channelDirectoryName($channel) . DIRECTORY_SEPARATOR .
strtolower($package) . '.reg';
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower($package) . '.reg';
}
/**
* Get the name of the file where data for a given channel is stored.
* @param string channel name
* @return string registry file name
*/
function _channelFileName($channel, $noaliases = false)
{
if (!$noaliases) {
if (file_exists($this->_getChannelAliasFileName($channel))) {
$channel = implode('', file($this->_getChannelAliasFileName($channel)));
}
}
return $this->channelsdir . DIRECTORY_SEPARATOR . str_replace('/', '_',
strtolower($channel)) . '.reg';
}
/**
* @param string
* @return string
*/
function _getChannelAliasFileName($alias)
{
return $this->channelsdir . DIRECTORY_SEPARATOR . '.alias' .
DIRECTORY_SEPARATOR . str_replace('/', '_', strtolower($alias)) . '.txt';
}
/**
* Get the name of a channel from its alias
*/
function _getChannelFromAlias($channel)
{
if (!$this->_channelExists($channel)) {
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)));
}
return $channel;
}
/**
* Get the alias of a channel from its alias or its name
*/
function _getAlias($channel)
{
if (!$this->_channelExists($channel)) {
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();
}
/**
* Get the name of the file where data for a given package is stored.
*
* @param string channel name, or false if this is a PEAR package
* @param string package name
*
* @return string registry file name
*
* @access public
*/
function _channelDirectoryName($channel)
{
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
return $this->statedir;
}
$ch = $this->_getChannelFromAlias($channel);
if (!$ch) {
$ch = $channel;
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
str_replace('/', '_', $ch));
}
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;
}
function _closePackageFile($fp)
{
fclose($fp);
}
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;
}
function _closeChannelFile($fp)
{
fclose($fp);
}
function _rebuildFileMap()
{
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$channels = $this->_listAllPackages();
$files = array();
foreach ($channels as $channel => $packages) {
foreach ($packages as $package) {
$version = $this->_packageInfo($package, 'version', $channel);
$filelist = $this->_packageInfo($package, 'filelist', $channel);
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 (!isset($files[$attrs['role']])) {
$files[$attrs['role']] = array();
}
$files[$attrs['role']][$file] = strtolower($package);
}
}
}
}
$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);
return true;
}
function _readFileMap()
{
if (!file_exists($this->filemap)) {
return array();
}
$fp = @fopen($this->filemap, 'r');
if (!$fp) {
$last_errormsg = '';
$last_error = error_get_last();
if (!empty($last_error['message'])) {
$last_errormsg = $last_error['message'];
}
return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $last_errormsg);
}
clearstatcache();
$fsize = filesize($this->filemap);
fclose($fp);
$data = file_get_contents($this->filemap);
$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 the registry.
*
* @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.
* See flock manual for more information.
*
* @return bool TRUE on success, FALSE if locking failed, or a
* PEAR error if some other error occurs (such as the
* lock file not being writable).
*
* @access private
*/
function _lock($mode = LOCK_EX)
{
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');
}
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 = 'r';
}
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;
}
//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;
}
function _unlock()
{
$ret = $this->_lock(LOCK_UN);
if (is_resource($this->lock_fp)) {
fclose($this->lock_fp);
}
$this->lock_fp = null;
return $ret;
}
function _packageExists($package, $channel = false)
{
return file_exists($this->_packageFileName($package, $channel));
}
/**
* Determine whether a channel exists in the registry
*
* @param string Channel name
* @param bool if true, then aliases will be ignored
* @return boolean
*/
function _channelExists($channel, $noaliases = false)
{
$a = file_exists($this->_channelFileName($channel, $noaliases));
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;
}
/**
* Determine whether a mirror exists within the default 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
* @param string Last-Modified HTTP tag from remote request
* @return boolean|PEAR_Error True on creation, false if it already exists
*/
function _addChannel($channel, $update = false, $lastmodified = false)
{
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()));
}
}
} else {
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;
} else {
$info['_lastmodified'] = self::getSourceDateEpoch();
}
fwrite($fp, serialize($info));
fclose($fp);
return true;
}
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
* @return boolean|PEAR_Error True on deletion, false if it doesn't exist
*/
function _deleteChannel($channel)
{
if (!is_string($channel)) {
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);
if (!$test) {
return false;
}
}
$file = $this->_channelFileName($channel);
$ret = true;
if (file_exists($file)) {
$ret = @unlink($file);
}
return $ret;
}
/**
* Determine whether a channel exists in the registry
* @param string Channel Alias
* @return boolean
*/
function _isChannelAlias($alias)
{
return file_exists($this->_getChannelAliasFileName($alias));
}
/**
* @param string|null
* @param string|null
* @param string|null
* @return array|null
* @access private
*/
function _packageInfo($package = null, $key = null, $channel = 'pear.php.net')
{
if ($package === null) {
if ($channel === null) {
$channels = $this->_listChannels();
$ret = array();
foreach ($channels as $channel) {
$channel = strtolower($channel);
$ret[$channel] = array();
$packages = $this->_listPackages($channel);
foreach ($packages as $package) {
$ret[$channel][] = $this->_packageInfo($package, null, $channel);
}
}
return $ret;
}
$ps = $this->_listPackages($channel);
if (!count($ps)) {
return array();
}
return array_map(array(&$this, '_packageInfo'),
$ps, array_fill(0, count($ps), null),
array_fill(0, count($ps), $channel));
}
$fp = $this->_openPackageFile($package, 'r', $channel);
if ($fp === null) {
return null;
}
clearstatcache();
$this->_closePackageFile($fp);
$data = file_get_contents($this->_packageFileName($package, $channel));
$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;
}
/**
* @param string Channel name
* @param bool whether to strictly retrieve info of channels, not just aliases
* @return array|null
*/
function _channelInfo($channel, $noaliases = false)
{
if (!$this->_channelExists($channel, $noaliases)) {
return null;
}
$fp = $this->_openChannelFile($channel, 'r');
if ($fp === null) {
return null;
}
clearstatcache();
$this->_closeChannelFile($fp);
$data = file_get_contents($this->_channelFileName($channel));
$data = unserialize($data);
return $data;
}
function _listChannels()
{
$channellist = array();
if (!file_exists($this->channelsdir) || !is_dir($this->channelsdir)) {
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;
}
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);
sort($pkglist);
return $pkglist;
}
function _listChannelPackages($channel)
{
$pkglist = array();
if (!file_exists($this->_channelDirectoryName($channel)) ||
!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;
}
$pkglist[] = substr($ent, 0, -4);
}
closedir($dp);
return $pkglist;
}
function _listAllPackages()
{
$ret = array();
foreach ($this->_listChannels() as $channel) {
$ret[$channel] = $this->_listPackages($channel);
}
return $ret;
}
/**
* Add an installed package to the registry
* @param string package name
* @param array package info (parsed by PEAR_Common::infoFrom*() methods)
* @return bool success of saving
* @access private
*/
function _addPackage($package, $info)
{
if ($this->_packageExists($package)) {
return false;
}
$fp = $this->_openPackageFile($package, 'wb');
if ($fp === null) {
return false;
}
$info['_lastmodified'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($info['filelist'])) {
$this->_rebuildFileMap();
}
return true;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @return bool
* @access private
*/
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();
if ($ui) {
foreach ($info->getValidationWarnings() as $err) {
$ui->log($err['message'], true);
}
}
}
return false;
}
$channel = $info->getChannel();
$package = $info->getPackage();
$save = $info;
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'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
$this->_rebuildFileMap();
return true;
}
/**
* @param string Package name
* @param array parsed package.xml 1.0
* @param bool this parameter is only here for BC. Don't use it.
* @access private
*/
function _updatePackage($package, $info, $merge = true)
{
$oldinfo = $this->_packageInfo($package);
if (empty($oldinfo)) {
return false;
}
$fp = $this->_openPackageFile($package, 'w');
if ($fp === null) {
return false;
}
if (is_object($info)) {
$info = $info->toArray();
}
$info['_lastmodified'] = self::getSourceDateEpoch();
$newinfo = $info;
if ($merge) {
$info = array_merge($oldinfo, $info);
} else {
$diff = $info;
}
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($newinfo['filelist'])) {
$this->_rebuildFileMap();
}
return true;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @return bool
* @access private
*/
function _updatePackage2($info)
{
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'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
$this->_rebuildFileMap();
return true;
}
/**
* @param string Package name
* @param string Channel name
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
* @access private
*/
function &_getPackage($package, $channel = 'pear.php.net')
{
$info = $this->_packageInfo($package, null, $channel);
if ($info === null) {
return $info;
}
$a = $this->_config;
if (!$a) {
$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);
$pf = &$pkg->fromArray($info);
return $pf;
}
/**
* @param string channel name
* @param bool whether to strictly retrieve channel names
* @return PEAR_ChannelFile|PEAR_Error
* @access private
*/
function &_getChannel($channel, $noaliases = false)
{
$ch = false;
if ($this->_channelExists($channel, $noaliases)) {
$chinfo = $this->_channelInfo($channel, $noaliases);
if ($chinfo) {
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->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')) {
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setServer('pecl.php.net');
$pear_channel->setAlias('pecl');
$pear_channel->setSummary('PHP Extension Community Library');
$pear_channel->setDefaultPEARProtocols();
$pear_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
$pear_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$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->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
return $private;
}
return $ch;
}
/**
* @param string Package name
* @param string Channel name
* @return bool
*/
function packageExists($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_packageExists($package, $channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ channelExists()
/**
* @param string channel name
* @param bool if true, then aliases will be ignored
* @return bool
*/
function channelExists($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_channelExists($channel, $noaliases);
$this->_unlock();
return $ret;
}
// }}}
/**
* @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()
/**
* Determines whether the parameter is an alias of a channel
* @param string
* @return bool
*/
function isAlias($alias)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_isChannelAlias($alias);
$this->_unlock();
return $ret;
}
// }}}
// {{{ packageInfo()
/**
* @param string|null
* @param string|null
* @param string
* @return array|null
*/
function packageInfo($package = null, $key = null, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_packageInfo($package, $key, $channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ channelInfo()
/**
* Retrieve a raw array of channel data.
*
* Do not use this, instead use {@link getChannel()} for normal
* operations. Array structure is undefined in this method
* @param string channel name
* @param bool whether to strictly retrieve information only on non-aliases
* @return array|null|PEAR_Error
*/
function channelInfo($channel = null, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_channelInfo($channel, $noaliases);
$this->_unlock();
return $ret;
}
// }}}
/**
* @param string
*/
function channelName($channel)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getChannelFromAlias($channel);
$this->_unlock();
return $ret;
}
/**
* @param string
*/
function channelAlias($channel)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getAlias($channel);
$this->_unlock();
return $ret;
}
// {{{ listPackages()
function listPackages($channel = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listPackages($channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ listAllPackages()
function listAllPackages()
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listAllPackages();
$this->_unlock();
return $ret;
}
// }}}
// {{{ listChannel()
function listChannels()
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listChannels();
$this->_unlock();
return $ret;
}
// }}}
// {{{ addPackage()
/**
* Add an installed package to the registry
* @param string|PEAR_PackageFile_v1|PEAR_PackageFile_v2 package name or object
* that will be passed to {@link addPackage2()}
* @param array package info (parsed by PEAR_Common::infoFrom*() methods)
* @return bool success of saving
*/
function addPackage($package, $info)
{
if (is_object($info)) {
return $this->addPackage2($info);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_addPackage($package, $info);
$this->_unlock();
if ($ret) {
if (!class_exists('PEAR_PackageFile_v1')) {
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->_config);
$pf->fromArray($info);
$this->_dependencyDB->uninstallPackage($pf);
$this->_dependencyDB->installPackage($pf);
}
return $ret;
}
// }}}
// {{{ addPackage2()
function addPackage2($info)
{
if (!is_object($info)) {
return $this->addPackage($info['package'], $info);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_addPackage2($info);
$this->_unlock();
if ($ret) {
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
return $ret;
}
// }}}
// {{{ updateChannel()
/**
* For future expandibility purposes, separate this
* @param PEAR_ChannelFile
*/
function updateChannel($channel, $lastmodified = null)
{
if ($channel->getName() == '__uri') {
return false;
}
return $this->addChannel($channel, $lastmodified, true);
}
// }}}
// {{{ deleteChannel()
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
* @return boolean|PEAR_Error True on deletion, false if it doesn't exist
*/
function deleteChannel($channel)
{
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;
}
// }}}
// {{{ addChannel()
/**
* @param PEAR_ChannelFile Channel object
* @param string Last-Modified header from HTTP for caching
* @return boolean|PEAR_Error True on creation, false if it already exists
*/
function addChannel($channel, $lastmodified = false, $update = false)
{
if (!is_a($channel, 'PEAR_ChannelFile') || !$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;
}
// }}}
// {{{ deletePackage()
function deletePackage($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$file = $this->_packageFileName($package, $channel);
$ret = file_exists($file) ? @unlink($file) : false;
$this->_rebuildFileMap();
$this->_unlock();
$p = array('channel' => $channel, 'package' => $package);
$this->_dependencyDB->uninstallPackage($p);
return $ret;
}
// }}}
// {{{ updatePackage()
function updatePackage($package, $info, $merge = true)
{
if (is_object($info)) {
return $this->updatePackage2($info, $merge);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_updatePackage($package, $info, $merge);
$this->_unlock();
if ($ret) {
if (!class_exists('PEAR_PackageFile_v1')) {
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->_config);
$pf->fromArray($this->packageInfo($package));
$this->_dependencyDB->uninstallPackage($pf);
$this->_dependencyDB->installPackage($pf);
}
return $ret;
}
// }}}
// {{{ updatePackage2()
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) {
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
return $ret;
}
// }}}
// {{{ getChannel()
/**
* @param string channel name
* @param bool whether to strictly return raw channels (no aliases)
* @return PEAR_ChannelFile|PEAR_Error
*/
function getChannel($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getChannel($channel, $noaliases);
$this->_unlock();
if (!$ret) {
return PEAR::raiseError('Unknown channel: ' . $channel);
}
return $ret;
}
// }}}
// {{{ getPackage()
/**
* @param string package name
* @param string channel name
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
*/
function &getPackage($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$pf = &$this->_getPackage($package, $channel);
$this->_unlock();
return $pf;
}
// }}}
/**
* Get PEAR_PackageFile_v[1/2] objects representing the contents of
* a dependency group that are installed.
*
* This is used at uninstall-time
* @param array
* @return array|false
*/
function getInstalledGroup($group)
{
$ret = array();
if (isset($group['package'])) {
if (!isset($group['package'][0])) {
$group['package'] = array($group['package']);
}
foreach ($group['package'] as $package) {
$depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
$p = &$this->getPackage($package['name'], $depchannel);
if ($p) {
$save = &$p;
$ret[] = &$save;
}
}
}
if (isset($group['subpackage'])) {
if (!isset($group['subpackage'][0])) {
$group['subpackage'] = array($group['subpackage']);
}
foreach ($group['subpackage'] as $package) {
$depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
$p = &$this->getPackage($package['name'], $depchannel);
if ($p) {
$save = &$p;
$ret[] = &$save;
}
}
}
if (!count($ret)) {
return false;
}
return $ret;
}
// {{{ getChannelValidator()
/**
* @param string channel name
* @return PEAR_Validate|false
*/
function &getChannelValidator($channel)
{
$chan = $this->getChannel($channel);
if (PEAR::isError($chan)) {
return $chan;
}
$val = $chan->getValidationObject();
return $val;
}
// }}}
// {{{ getChannels()
/**
* @param string channel name
* @return array an array of PEAR_ChannelFile objects representing every installed channel
*/
function &getChannels()
{
$ret = array();
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
foreach ($this->_listChannels() as $channel) {
$e = &$this->_getChannel($channel);
if (!$e || PEAR::isError($e)) {
continue;
}
$ret[] = $e;
}
$this->_unlock();
return $ret;
}
// }}}
// {{{ checkFileMap()
/**
* Test whether a file or set of files belongs to a package.
*
* If an array is passed in
* @param string|array file path, absolute or relative to the pear
* install dir
* @param string|array name of PEAR package or array('package' => name, 'channel' =>
* channel) of a package that will be ignored
* @param string API version - 1.1 will exclude any files belonging to a package
* @param array private recursion variable
* @return array|false which package and channel the file belongs to, or an empty
* string if the file does not belong to an installed package,
* or belongs to the second parameter's package
*/
function checkFileMap($path, $package = false, $api = '1.0', $attrs = false)
{
if (is_array($path)) {
static $notempty;
if (empty($notempty)) {
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$notempty = function($a) { return !empty($a); };
}
$package = is_array($package) ? array(strtolower($package[0]), strtolower($package[1]))
: strtolower($package);
$pkgs = array();
foreach ($path as $name => $attrs) {
if (is_array($attrs)) {
if (isset($attrs['install-as'])) {
$name = $attrs['install-as'];
}
if (!in_array($attrs['role'], PEAR_Installer_Role::getInstallableRoles())) {
// these are not installed
continue;
}
if (!in_array($attrs['role'], PEAR_Installer_Role::getBaseinstallRoles())) {
$attrs['baseinstalldir'] = is_array($package) ? $package[1] : $package;
}
if (isset($attrs['baseinstalldir'])) {
$name = $attrs['baseinstalldir'] . DIRECTORY_SEPARATOR . $name;
}
}
$pkgs[$name] = $this->checkFileMap($name, $package, $api, $attrs);
if (PEAR::isError($pkgs[$name])) {
return $pkgs[$name];
}
}
return array_filter($pkgs, $notempty);
}
if (empty($this->filemap_cache)) {
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$err = $this->_readFileMap();
$this->_unlock();
if (PEAR::isError($err)) {
return $err;
}
}
if (!$attrs) {
$attrs = array('role' => 'php'); // any old call would be for PHP role only
}
if (isset($this->filemap_cache[$attrs['role']][$path])) {
if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
return false;
}
return $this->filemap_cache[$attrs['role']][$path];
}
$l = strlen($this->install_dir);
if (substr($path, 0, $l) == $this->install_dir) {
$path = preg_replace('!^'.DIRECTORY_SEPARATOR.'+!', '', substr($path, $l));
}
if (isset($this->filemap_cache[$attrs['role']][$path])) {
if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
return false;
}
return $this->filemap_cache[$attrs['role']][$path];
}
return false;
}
// }}}
// {{{ flush()
/**
* Force a reload of the filemap
* @since 1.5.0RC3
*/
function flushFileMap()
{
$this->filemap_cache = null;
clearstatcache(); // ensure that the next read gets the full, current filemap
}
// }}}
// {{{ apiVersion()
/**
* Get the expected API version. Channels API is version 1.1, as it is backwards
* compatible with 1.0
* @return string
*/
function apiVersion()
{
return '1.1';
}
// }}}
/**
* Parse a package name, or validate a parsed package name array
* @param string|array pass in an array of format
* array(
* 'package' => 'pname',
* ['channel' => 'channame',]
* ['version' => 'version',]
* ['state' => 'state',]
* ['group' => 'groupname'])
* or a string of format
* [channel://][channame/]pname[-version|-state][/group=groupname]
* @return array|PEAR_Error
*/
function parsePackageName($param, $defaultchannel = 'pear.php.net')
{
$saveparam = $param;
if (is_array($param)) {
// convert to string for error messages
$saveparam = $this->parsedPackageNameToString($param);
// process the array
if (!isset($param['package'])) {
return PEAR::raiseError('parsePackageName(): array $param ' .
'must contain a valid package name in index "param"',
'package', null, null, $param);
}
if (!isset($param['uri'])) {
if (!isset($param['channel'])) {
$param['channel'] = $defaultchannel;
}
} else {
$param['channel'] = '__uri';
}
} else {
$components = @parse_url((string) $param);
if (isset($components['scheme'])) {
if ($components['scheme'] == 'http') {
// uri package
$param = array('uri' => $param, 'channel' => '__uri');
} elseif($components['scheme'] != 'channel') {
return PEAR::raiseError('parsePackageName(): only channel:// uris may ' .
'be downloaded, not "' . $param . '"', 'invalid', null, null, $param);
}
}
if (!isset($components['path'])) {
return PEAR::raiseError('parsePackageName(): array $param ' .
'must contain a valid package name in "' . $param . '"',
'package', null, null, $param);
}
if (isset($components['host'])) {
// remove the leading "/"
$components['path'] = substr($components['path'], 1);
}
if (!isset($components['scheme'])) {
if (strpos($components['path'], '/') !== false) {
if ($components['path'][0] == '/') {
return PEAR::raiseError('parsePackageName(): this is not ' .
'a package name, it begins with "/" in "' . $param . '"',
'invalid', null, null, $param);
}
$parts = explode('/', $components['path']);
$components['host'] = array_shift($parts);
if (count($parts) > 1) {
$components['path'] = array_pop($parts);
$components['host'] .= '/' . implode('/', $parts);
} else {
$components['path'] = implode('/', $parts);
}
} else {
$components['host'] = $defaultchannel;
}
} else {
if (strpos($components['path'], '/')) {
$parts = explode('/', $components['path']);
$components['path'] = array_pop($parts);
$components['host'] .= '/' . implode('/', $parts);
}
}
if (is_array($param)) {
$param['package'] = $components['path'];
} else {
$param = array(
'package' => $components['path']
);
if (isset($components['host'])) {
$param['channel'] = $components['host'];
}
}
if (isset($components['fragment'])) {
$param['group'] = $components['fragment'];
}
if (isset($components['user'])) {
$param['user'] = $components['user'];
}
if (isset($components['pass'])) {
$param['pass'] = $components['pass'];
}
if (isset($components['query'])) {
parse_str($components['query'], $param['opts']);
}
// check for extension
$pathinfo = pathinfo($param['package']);
if (isset($pathinfo['extension']) &&
in_array(strtolower($pathinfo['extension']), array('tgz', 'tar'))) {
$param['extension'] = $pathinfo['extension'];
$param['package'] = substr($pathinfo['basename'], 0,
strlen($pathinfo['basename']) - 4);
}
// check for version
if (strpos($param['package'], '-')) {
$test = explode('-', $param['package']);
if (count($test) != 2) {
return PEAR::raiseError('parsePackageName(): only one version/state ' .
'delimiter "-" is allowed in "' . $saveparam . '"',
'version', null, null, $param);
}
list($param['package'], $param['version']) = $test;
}
}
// validation
$info = $this->channelExists($param['channel']);
if (PEAR::isError($info)) {
return $info;
}
if (!$info) {
return PEAR::raiseError('unknown channel "' . $param['channel'] .
'" in "' . $saveparam . '"', 'channel', null, null, $param);
}
$chan = $this->getChannel($param['channel']);
if (PEAR::isError($chan)) {
return $chan;
}
if (!$chan) {
return PEAR::raiseError("Exception: corrupt registry, could not " .
"retrieve channel " . $param['channel'] . " information",
'registry', null, null, $param);
}
$param['channel'] = $chan->getName();
$validate = $chan->getValidationObject();
$vpackage = $chan->getValidationPackage();
// validate package name
if (!$validate->validPackageName($param['package'], $vpackage['_content'])) {
return PEAR::raiseError('parsePackageName(): invalid package name "' .
$param['package'] . '" in "' . $saveparam . '"',
'package', null, null, $param);
}
if (isset($param['group'])) {
if (!PEAR_Validate::validGroupName($param['group'])) {
return PEAR::raiseError('parsePackageName(): dependency group "' . $param['group'] .
'" is not a valid group name in "' . $saveparam . '"', 'group', null, null,
$param);
}
}
if (isset($param['state'])) {
if (!in_array(strtolower($param['state']), $validate->getValidStates())) {
return PEAR::raiseError('parsePackageName(): state "' . $param['state']
. '" is not a valid state in "' . $saveparam . '"',
'state', null, null, $param);
}
}
if (isset($param['version'])) {
if (isset($param['state'])) {
return PEAR::raiseError('parsePackageName(): cannot contain both ' .
'a version and a stability (state) in "' . $saveparam . '"',
'version/state', null, null, $param);
}
// check whether version is actually a state
if (in_array(strtolower($param['version']), $validate->getValidStates())) {
$param['state'] = strtolower($param['version']);
unset($param['version']);
} else {
if (!$validate->validVersion($param['version'])) {
return PEAR::raiseError('parsePackageName(): "' . $param['version'] .
'" is neither a valid version nor a valid state in "' .
$saveparam . '"', 'version/state', null, null, $param);
}
}
}
return $param;
}
/**
* @param array
* @return string
*/
function parsedPackageNameToString($parsed, $brief = false)
{
if (is_string($parsed)) {
return $parsed;
}
if (is_object($parsed)) {
$p = $parsed;
$parsed = array(
'package' => $p->getPackage(),
'channel' => $p->getChannel(),
'version' => $p->getVersion(),
);
}
if (isset($parsed['uri'])) {
return $parsed['uri'];
}
if ($brief) {
if ($channel = $this->channelAlias($parsed['channel'])) {
return $channel . '/' . $parsed['package'];
}
}
$upass = '';
if (isset($parsed['user'])) {
$upass = $parsed['user'];
if (isset($parsed['pass'])) {
$upass .= ':' . $parsed['pass'];
}
$upass = "$upass@";
}
$ret = 'channel://' . $upass . $parsed['channel'] . '/' . $parsed['package'];
if (isset($parsed['version']) || isset($parsed['state'])) {
$ver = isset($parsed['version']) ? $parsed['version'] : '';
$ver .= isset($parsed['state']) ? $parsed['state'] : '';
$ret .= '-' . $ver;
}
if (isset($parsed['extension'])) {
$ret .= '.' . $parsed['extension'];
}
if (isset($parsed['opts'])) {
$ret .= '?';
foreach ($parsed['opts'] as $name => $value) {
$parsed['opts'][$name] = "$name=$value";
}
$ret .= implode('&', $parsed['opts']);
}
if (isset($parsed['group'])) {
$ret .= '#' . $parsed['group'];
}
return $ret;
}
}
opt/cpanel/ea-php74/root/usr/share/pear/PEAR/Command/Registry.php 0000644 00000132315 14756526372 0020436 0 ustar 00
* @author Greg Beaver
* @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/Command/Common.php';
/**
* PEAR commands for registry manipulation
*
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Registry extends PEAR_Command_Common
{
var $commands = array(
'list' => array(
'summary' => 'List Installed Packages In The Default Channel',
'function' => 'doList',
'shortcut' => 'l',
'options' => array(
'channel' => array(
'shortopt' => 'c',
'doc' => 'list installed packages from this channel',
'arg' => 'CHAN',
),
'allchannels' => array(
'shortopt' => 'a',
'doc' => 'list installed packages from all channels',
),
'channelinfo' => array(
'shortopt' => 'i',
'doc' => 'output fully channel-aware data, even on failure',
),
),
'doc' => '
If invoked without parameters, this command lists the PEAR packages
installed in your php_dir ({config php_dir}). With a parameter, it
lists the files in a package.
',
),
'list-files' => array(
'summary' => 'List Files In Installed Package',
'function' => 'doFileList',
'shortcut' => 'fl',
'options' => array(),
'doc' => '
List the files in an installed package.
'
),
'shell-test' => array(
'summary' => 'Shell Script Test',
'function' => 'doShellTest',
'shortcut' => 'st',
'options' => array(),
'doc' => ' [[relation] version]
Tests if a package is installed in the system. Will exit(1) if it is not.
The version comparison operator. One of:
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
The version to compare with
'),
'info' => array(
'summary' => 'Display information about a package',
'function' => 'doInfo',
'shortcut' => 'in',
'options' => array(),
'doc' => '
Displays information about a package. The package argument may be a
local package file, an URL to a package file, or the name of an
installed package.'
)
);
/**
* PEAR_Command_Registry constructor.
*
* @access public
*/
function __construct(&$ui, &$config)
{
parent::__construct($ui, $config);
}
function _sortinfo($a, $b)
{
$apackage = isset($a['package']) ? $a['package'] : $a['name'];
$bpackage = isset($b['package']) ? $b['package'] : $b['name'];
return strcmp($apackage, $bpackage);
}
function doList($command, $options, $params)
{
$reg = &$this->config->getRegistry();
$channelinfo = isset($options['channelinfo']);
if (isset($options['allchannels']) && !$channelinfo) {
return $this->doListAll($command, array(), $params);
}
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'])) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' .
$channel . ':',
'border' => true,
'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);
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) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Package', 'Version', 'State'),
'channel' => $channel
);
foreach ($packages as $package) {
$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);
}
// 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)'), array()),
'channel' => $channel
);
}
$this->ui->outputData($data, $command);
}
return true;
}
function doFileList($command, $options, $params)
{
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 ($fp) {
fclose($fp);
}
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$pkg = new PEAR_PackageFile($this->config, $this->_debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
$headings = array('Package File', 'Install Path');
$installed = false;
} else {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
PEAR::staticPopErrorHandling();
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) {
$caption = 'Installed Files For ' . $params[0];
} else {
$caption = 'Contents of ' . basename($params[0]);
}
$data = array(
'caption' => $caption,
'border' => true,
'headline' => $headings);
if ($info->getPackagexmlVersion() == '1.0' || $installed) {
foreach ($list as $file => $att) {
if ($installed) {
if (empty($att['installed_as'])) {
continue;
}
$data['data'][] = array($att['role'], $att['installed_as']);
} else {
if (isset($att['baseinstalldir']) && !in_array($att['role'],
array('test', 'data', 'doc'))) {
$dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
$file;
} else {
$dest = $file;
}
switch ($att['role']) {
case 'test':
case 'data':
case 'doc':
$role = $att['role'];
if ($role == 'test') {
$role .= 's';
}
$dest = $this->config->get($role . '_dir') . DIRECTORY_SEPARATOR .
$info->getPackage() . DIRECTORY_SEPARATOR . $dest;
break;
case 'php':
default:
$dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
$dest;
}
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
$dest = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
array(DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR),
$dest);
$file = preg_replace('!/+!', '/', $file);
$data['data'][] = array($file, $dest);
}
}
} else { // package.xml 2.0, not installed
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'];
$role = &PEAR_Installer_Role::factory($info, $att['role'], $this->config);
$role->setup($this, $info, $att, $file);
if (!$role->isInstallable()) {
$dest = '(not installable)';
} else {
$dest = $role->processInstallation($info, $att, $file, '');
if (PEAR::isError($dest)) {
$dest = '(Unknown role "' . $att['role'] . ')';
} else {
list(,, $dest) = $dest;
}
}
$data['data'][] = array($file, $dest);
}
}
$this->ui->outputData($data, $command);
return true;
}
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'));
if (PEAR::isError($info)) {
exit(1); // invalid package name
}
$package = $info['package'];
$channel = $info['channel'];
// "pear shell-test Foo"
if (!$reg->packageExists($package, $channel)) {
if ($channel == 'pecl.php.net') {
if ($reg->packageExists($package, 'pear.php.net')) {
$channel = 'pear.php.net'; // magically change channels for extensions
}
}
}
if (count($params) === 1) {
if (!$reg->packageExists($package, $channel)) {
exit(1);
}
// "pear shell-test Foo 1.0"
} 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 (count($params) === 3) {
$v = $reg->packageInfo($package, 'version', $channel);
if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
exit(1);
}
} else {
PEAR::staticPopErrorHandling();
$this->raiseError("$command: expects 1 to 3 parameters");
exit(1);
}
}
function doInfo($command, $options, $params)
{
if (count($params) !== 1) {
return $this->raiseError('pear info expects 1 parameter');
}
$info = $fp = false;
$reg = &$this->config->getRegistry();
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);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
if (PEAR::isError($obj)) {
$uinfo = $obj->getUserInfo();
if (is_array($uinfo)) {
foreach ($uinfo as $message) {
if (is_array($message)) {
$message = $message['message'];
}
$this->ui->outputData($message);
}
}
return $this->raiseError($obj);
}
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);
if (isset($info['old'])) {
$obj = $reg->getPackage($package, $channel);
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']);
if (isset($info['xsdversion'])) {
$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) {
if (is_array($info[$key])) {
switch ($key) {
case 'maintainers': {
$i = 0;
$mstr = '';
foreach ($info[$key] as $m) {
if ($i++ > 0) {
$mstr .= "\n";
}
$mstr .= $m['name'] . " <";
if (isset($m['email'])) {
$mstr .= $m['email'];
} else {
$mstr .= $m['handle'] . '@php.net';
}
$mstr .= "> ($m[role])";
}
$info[$key] = $mstr;
break;
}
case 'release_deps': {
$i = 0;
$dstr = '';
foreach ($info[$key] as $d) {
if (isset($this->_deps_rel_trans[$d['rel']])) {
$rel = $this->_deps_rel_trans[$d['rel']];
} else {
$rel = $d['rel'];
}
if (isset($this->_deps_type_trans[$d['type']])) {
$type = ucfirst($this->_deps_type_trans[$d['type']]);
} else {
$type = $d['type'];
}
if (isset($d['name'])) {
$name = $d['name'] . ' ';
} else {
$name = '';
}
if (isset($d['version'])) {
$version = $d['version'] . ' ';
} else {
$version = '';
}
if (isset($d['optional']) && $d['optional'] == 'yes') {
$optional = ' (optional)';
} else {
$optional = '';
}
$dstr .= "$type $name$rel $version$optional\n";
}
$info[$key] = $dstr;
break;
}
case 'provides' : {
$debug = $this->config->get('verbose');
if ($debug < 2) {
$pstr = 'Classes: ';
} else {
$pstr = '';
}
$i = 0;
foreach ($info[$key] as $p) {
if ($debug < 2 && $p['type'] != "class") {
continue;
}
// Only print classes when verbosity mode is < 2
if ($debug < 2) {
if ($i++ > 0) {
$pstr .= ", ";
}
$pstr .= $p['name'];
} else {
if ($i++ > 0) {
$pstr .= "\n";
}
$pstr .= ucfirst($p['type']) . " " . $p['name'];
if (isset($p['explicit']) && $p['explicit'] == 1) {
$pstr .= " (explicit)";
}
}
}
$info[$key] = $pstr;
break;
}
case 'configure_options' : {
foreach ($info[$key] as $i => $p) {
$info[$key][$i] = array_map(null, array_keys($p), array_values($p));
$info[$key][$i] = array_map(
function($a) { return join(" = ", $a); },
$info[$key][$i]);
$info[$key][$i] = implode(', ', $info[$key][$i]);
}
$info[$key] = implode("\n", $info[$key]);
break;
}
default: {
$info[$key] = implode(", ", $info[$key]);
break;
}
}
}
if ($key == '_lastmodified') {
$hdate = date('Y-m-d', $info[$key]);
unset($info[$key]);
$info['Last Modified'] = $hdate;
} elseif ($key == '_lastversion') {
$info['Previous Installed Version'] = $info[$key] ? $info[$key] : '- None -';
unset($info[$key]);
} else {
$info[$key] = trim($info[$key]);
if (in_array($key, $longtext)) {
$info[$key] = preg_replace('/ +/', ' ', $info[$key]);
}
}
}
$caption = 'About ' . $info['package'] . '-' . $info['version'];
$data = array(
'caption' => $caption,
'border' => true);
foreach ($info as $key => $value) {
$key = ucwords(trim(str_replace('_', ' ', $key)));
$data['data'][] = array($key, $value);
}
$data['raw'] = $info;
$this->ui->outputData($data, 'package-info');
}
/**
* @access private
*/
function _doInfo2($command, $options, $params, &$obj, $installed)
{
$reg = &$this->config->getRegistry();
$caption = 'About ' . $obj->getChannel() . '/' .$obj->getPackage() . '-' .
$obj->getVersion();
$data = array(
'caption' => $caption,
'border' => true);
switch ($obj->getPackageType()) {
case 'php' :
$release = 'PEAR-style PHP-based Package';
break;
case 'extsrc' :
$release = 'PECL-style PHP extension (source code)';
break;
case 'zendextsrc' :
$release = 'PECL-style Zend extension (source code)';
break;
case 'extbin' :
$release = 'PECL-style PHP extension (binary)';
break;
case 'zendextbin' :
$release = 'PECL-style Zend extension (binary)';
break;
case 'bundle' :
$release = 'Package bundle (collection of packages)';
break;
}
$extends = $obj->getExtends();
$extends = $extends ?
$obj->getPackage() . ' (extends ' . $extends . ')' : $obj->getPackage();
if ($src = $obj->getSourcePackage()) {
$extends .= ' (source package ' . $src['channel'] . '/' . $src['package'] . ')';
}
$info = array(
'Release Type' => $release,
'Name' => $extends,
'Channel' => $obj->getChannel(),
'Summary' => preg_replace('/ +/', ' ', $obj->getSummary()),
'Description' => preg_replace('/ +/', ' ', $obj->getDescription()),
);
$info['Maintainers'] = '';
foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
$leads = $obj->{"get{$role}s"}();
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$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();
$uri = $obj->getLicenseLocation();
if ($uri) {
if (isset($uri['uri'])) {
$info['License'] .= ' (' . $uri['uri'] . ')';
} else {
$extra = $obj->getInstalledLocation($info['filesource']);
if ($extra) {
$info['License'] .= ' (' . $uri['filesource'] . ')';
}
}
}
$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['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 {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= $package['channel'] . '/' .
$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";
} else {
$info['Uses Custom Roles'] = '';
}
if (isset($roledata['package'])) {
$rolepackage = $reg->parsedPackageNameToString($roledata, true);
} else {
$rolepackage = $roledata['uri'];
}
$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";
} else {
$info['Uses Custom Tasks'] = '';
}
if (isset($taskdata['package'])) {
$taskpackage = $reg->parsedPackageNameToString($taskdata, true);
} else {
$taskpackage = $taskdata['uri'];
}
$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'])) {
$info['Required Dependencies'] .= '-' . $deps['required']['php']['max'] . "\n";
} else {
$info['Required Dependencies'] .= "\n";
}
if (isset($deps['required']['php']['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['php']['exclude'])) {
$deps['required']['php']['exclude'] =
implode(', ', $deps['required']['php']['exclude']);
}
$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 ' .
$deps['required']['pearinstaller']['min'] . '-' .
$deps['required']['pearinstaller']['max'];
} else {
$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'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['pearinstaller']['exclude'])) {
$deps['required']['pearinstaller']['exclude'] =
implode(', ', $deps['required']['pearinstaller']['exclude']);
}
$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])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Required Dependencies';
$info[$infoindex] .= "\n";
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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 ';
}
$info['Not Compatible with'] .= 'Package ' .
$reg->parsedPackageNameToString($package, true);
$info['Not Compatible with'] .= "\n Versions " . $package['exclude'];
}
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "$os[name] Operating System";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "$os[name] Operating System";
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "OS/Arch matching pattern '/$os[pattern]/'";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "OS/Arch matching pattern '/$os[pattern]/'";
}
}
}
if (isset($deps['optional'])) {
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($deps['optional'][$index])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Optional Dependencies';
if (!isset($info['Optional Dependencies'])) {
$info['Optional Dependencies'] = '';
} else {
$info['Optional Dependencies'] .= "\n";
}
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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'];
}
}
}
}
}
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';
$info[$groupindex] = '';
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($group[$index])) {
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 {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$name = '__uri/' . $package['name'] . ' (static URI)';
}
}
if (isset($package['uri'])) {
if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
$info[$groupindex] .= "Not Compatible with $type $name";
} 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 " .
$package['min'] . '-' . $package['max'];
} elseif (isset($package['min'])) {
$info[$groupindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} else {
$info[$groupindex] .= "Not Compatible with\n";
}
if (is_array($package['exclude'])) {
$package['exclude'] = implode(', ', $package['exclude']);
}
$info[$groupindex] .= " Package $package\n Versions " .
$package['exclude'];
}
}
}
}
}
}
if ($obj->getPackageType() == 'bundle') {
$info['Bundled Packages'] = '';
foreach ($obj->getBundledPackages() as $package) {
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]";
} else {
$info['Bundled Packages'] .= $package['channel'] . '/' . $package['name'];
}
}
}
$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');
}
}
opt/cpanel/ea-php71/root/usr/share/pear/PEAR/Registry.php 0000644 00000224270 14756530447 0017055 0 ustar 00
* @author Tomas V. V. Cox
* @author Greg Beaver
* @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
*/
/**
* for PEAR_Error
*/
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_CHANNEL_FILE', -6);
/**
* Administration class used to maintain the installed package database.
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Tomas V. V. Cox
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_Registry extends PEAR
{
/**
* File containing all channel information.
* @var string
*/
var $channels = '';
/** Directory where registry files are stored.
* @var string
*/
var $statedir = '';
/** File where the file map is stored
* @var string
*/
var $filemap = '';
/** Directory where registry files for channels are stored.
* @var string
*/
var $channelsdir = '';
/** Name of file used for locking the registry
* @var string
*/
var $lockfile = '';
/** File descriptor used during locking
* @var resource
*/
var $lock_fp = null;
/** Mode used during locking
* @var int
*/
var $lock_mode = 0; // XXX UNUSED
/** Cache of package information. Structure:
* array(
* 'package' => array('id' => ... ),
* ... )
* @var array
*/
var $pkginfo_cache = array();
/** Cache of file map. Structure:
* array( '/path/to/file' => 'package', ... )
* @var array
*/
var $filemap_cache = array();
/**
* @var false|PEAR_ChannelFile
*/
var $_pearChannel;
/**
* @var false|PEAR_ChannelFile
*/
var $_peclChannel;
/**
* @var false|PEAR_ChannelFile
*/
var $_docChannel;
/**
* @var PEAR_DependencyDB
*/
var $_dependencyDB;
/**
* @var PEAR_Config
*/
var $_config;
/**
* PEAR_Registry constructor.
*
* @param string (optional) PEAR install directory (for .php files)
* @param PEAR_ChannelFile PEAR_ChannelFile object representing the PEAR channel, if
* default values are not desired. Only used the very first time a PEAR
* repository is initialized
* @param PEAR_ChannelFile PEAR_ChannelFile object representing the PECL channel, if
* default values are not desired. Only used the very first time a PEAR
* repository is initialized
*
* @access public
*/
function __construct($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
$pecl_channel = false, $pear_metadata_dir = '')
{
parent::__construct();
$this->setInstallDir($pear_install_dir, $pear_metadata_dir);
$this->_pearChannel = $pear_channel;
$this->_peclChannel = $pecl_channel;
$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 != '.') {
$olddir = $dir;
$dir = dirname($dir);
if ($dir != '.' && file_exists($dir)) {
if (is_writeable($dir)) {
return true;
}
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, $resetInstallDir = true)
{
$this->_config = &$config;
if ($resetInstallDir) {
$this->setInstallDir($config->get('php_dir'), $config->get('metadata_dir'));
}
}
function _initializeChannelDirs()
{
static $running = false;
if (!$running) {
$running = true;
$ds = DIRECTORY_SEPARATOR;
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;
if (!is_a($pear_channel, 'PEAR_ChannelFile') || !$pear_channel->validate()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setAlias('pear');
$pear_channel->setServer('pear.php.net');
$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/');
//$pear_channel->setBaseURL('REST1.4', 'http://pear.php.net/rest/');
} else {
$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()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$pecl_channel = new PEAR_ChannelFile;
$pecl_channel->setAlias('pecl');
$pecl_channel->setServer('pecl.php.net');
$pecl_channel->setSummary('PHP Extension Community Library');
$pecl_channel->setDefaultPEARProtocols();
$pecl_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
$pecl_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$pecl_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
} else {
$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->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
$this->_addChannel($private);
}
$this->_rebuildFileMap();
}
$running = false;
}
}
function _initializeDirs()
{
$ds = DIRECTORY_SEPARATOR;
// XXX Compatibility code should be removed in the future
// rename all registry files if any to lowercase
if (!OS_WINDOWS && file_exists($this->statedir) && is_dir($this->statedir) &&
$handle = opendir($this->statedir)) {
$dest = $this->statedir . $ds;
while (false !== ($file = readdir($handle))) {
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();
}
$this->_initializeDepDB();
}
function _initializeDepDB()
{
if (!isset($this->_dependencyDB)) {
static $initializing = false;
if (!$initializing) {
$initializing = true;
if (!$this->_config) { // never used?
$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('metadata_dir', null, 'pear.php.net') .
DIRECTORY_SEPARATOR . '.depdb')) {
@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();
echo 'Unrecoverable error';
exit(1);
}
}
$initializing = false;
}
}
}
/**
* PEAR_Registry destructor. Makes sure no locks are forgotten.
*
* @access private
*/
function _PEAR_Registry()
{
parent::_PEAR();
if (is_resource($this->lock_fp)) {
$this->_unlock();
}
}
/**
* Make sure the directory where we keep registry files exists.
*
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertStateDir($channel = false)
{
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}'");
}
$init = true;
} elseif (!is_dir($this->statedir)) {
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;
}
} elseif (!is_dir($this->channelsdir)) {
return $this->raiseError('Cannot create directory ' . $this->channelsdir . ', ' .
'it already exists and is not a directory');
}
if ($init) {
static $running = false;
if (!$running) {
$running = true;
$this->_initializeDirs();
$running = false;
$init = false;
}
} else {
$this->_initializeDepDB();
}
return true;
}
/**
* Make sure the directory where we keep registry files exists for a non-standard channel.
*
* @param string channel name
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertChannelStateDir($channel)
{
$ds = DIRECTORY_SEPARATOR;
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
$this->_initializeChannelDirs();
}
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 .
"'");
}
} elseif (!is_dir($channelDir)) {
return $this->raiseError("could not create directory '" . $channelDir .
"', already exists and is not a directory");
}
return true;
}
/**
* Make sure the directory where we keep registry files for channels exists
*
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertChannelDir()
{
if (!file_exists($this->channelsdir)) {
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}'");
}
} 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'");
}
} 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;
}
/**
* Get the name of the file where data for a given package is stored.
*
* @param string channel name, or false if this is a PEAR package
* @param string package name
*
* @return string registry file name
*
* @access public
*/
function _packageFileName($package, $channel = false)
{
if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
return $this->_channelDirectoryName($channel) . DIRECTORY_SEPARATOR .
strtolower($package) . '.reg';
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower($package) . '.reg';
}
/**
* Get the name of the file where data for a given channel is stored.
* @param string channel name
* @return string registry file name
*/
function _channelFileName($channel, $noaliases = false)
{
if (!$noaliases) {
if (file_exists($this->_getChannelAliasFileName($channel))) {
$channel = implode('', file($this->_getChannelAliasFileName($channel)));
}
}
return $this->channelsdir . DIRECTORY_SEPARATOR . str_replace('/', '_',
strtolower($channel)) . '.reg';
}
/**
* @param string
* @return string
*/
function _getChannelAliasFileName($alias)
{
return $this->channelsdir . DIRECTORY_SEPARATOR . '.alias' .
DIRECTORY_SEPARATOR . str_replace('/', '_', strtolower($alias)) . '.txt';
}
/**
* Get the name of a channel from its alias
*/
function _getChannelFromAlias($channel)
{
if (!$this->_channelExists($channel)) {
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)));
}
return $channel;
}
/**
* Get the alias of a channel from its alias or its name
*/
function _getAlias($channel)
{
if (!$this->_channelExists($channel)) {
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();
}
/**
* Get the name of the file where data for a given package is stored.
*
* @param string channel name, or false if this is a PEAR package
* @param string package name
*
* @return string registry file name
*
* @access public
*/
function _channelDirectoryName($channel)
{
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
return $this->statedir;
}
$ch = $this->_getChannelFromAlias($channel);
if (!$ch) {
$ch = $channel;
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
str_replace('/', '_', $ch));
}
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;
}
function _closePackageFile($fp)
{
fclose($fp);
}
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;
}
function _closeChannelFile($fp)
{
fclose($fp);
}
function _rebuildFileMap()
{
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$channels = $this->_listAllPackages();
$files = array();
foreach ($channels as $channel => $packages) {
foreach ($packages as $package) {
$version = $this->_packageInfo($package, 'version', $channel);
$filelist = $this->_packageInfo($package, 'filelist', $channel);
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 (!isset($files[$attrs['role']])) {
$files[$attrs['role']] = array();
}
$files[$attrs['role']][$file] = strtolower($package);
}
}
}
}
$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);
return true;
}
function _readFileMap()
{
if (!file_exists($this->filemap)) {
return array();
}
$fp = @fopen($this->filemap, 'r');
if (!$fp) {
$last_errormsg = '';
$last_error = error_get_last();
if (!empty($last_error['message'])) {
$last_errormsg = $last_error['message'];
}
return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $last_errormsg);
}
clearstatcache();
$fsize = filesize($this->filemap);
fclose($fp);
$data = file_get_contents($this->filemap);
$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 the registry.
*
* @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.
* See flock manual for more information.
*
* @return bool TRUE on success, FALSE if locking failed, or a
* PEAR error if some other error occurs (such as the
* lock file not being writable).
*
* @access private
*/
function _lock($mode = LOCK_EX)
{
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');
}
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 = 'r';
}
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;
}
//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;
}
function _unlock()
{
$ret = $this->_lock(LOCK_UN);
if (is_resource($this->lock_fp)) {
fclose($this->lock_fp);
}
$this->lock_fp = null;
return $ret;
}
function _packageExists($package, $channel = false)
{
return file_exists($this->_packageFileName($package, $channel));
}
/**
* Determine whether a channel exists in the registry
*
* @param string Channel name
* @param bool if true, then aliases will be ignored
* @return boolean
*/
function _channelExists($channel, $noaliases = false)
{
$a = file_exists($this->_channelFileName($channel, $noaliases));
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;
}
/**
* Determine whether a mirror exists within the default 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
* @param string Last-Modified HTTP tag from remote request
* @return boolean|PEAR_Error True on creation, false if it already exists
*/
function _addChannel($channel, $update = false, $lastmodified = false)
{
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()));
}
}
} else {
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;
} else {
$info['_lastmodified'] = self::getSourceDateEpoch();
}
fwrite($fp, serialize($info));
fclose($fp);
return true;
}
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
* @return boolean|PEAR_Error True on deletion, false if it doesn't exist
*/
function _deleteChannel($channel)
{
if (!is_string($channel)) {
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);
if (!$test) {
return false;
}
}
$file = $this->_channelFileName($channel);
$ret = true;
if (file_exists($file)) {
$ret = @unlink($file);
}
return $ret;
}
/**
* Determine whether a channel exists in the registry
* @param string Channel Alias
* @return boolean
*/
function _isChannelAlias($alias)
{
return file_exists($this->_getChannelAliasFileName($alias));
}
/**
* @param string|null
* @param string|null
* @param string|null
* @return array|null
* @access private
*/
function _packageInfo($package = null, $key = null, $channel = 'pear.php.net')
{
if ($package === null) {
if ($channel === null) {
$channels = $this->_listChannels();
$ret = array();
foreach ($channels as $channel) {
$channel = strtolower($channel);
$ret[$channel] = array();
$packages = $this->_listPackages($channel);
foreach ($packages as $package) {
$ret[$channel][] = $this->_packageInfo($package, null, $channel);
}
}
return $ret;
}
$ps = $this->_listPackages($channel);
if (!count($ps)) {
return array();
}
return array_map(array(&$this, '_packageInfo'),
$ps, array_fill(0, count($ps), null),
array_fill(0, count($ps), $channel));
}
$fp = $this->_openPackageFile($package, 'r', $channel);
if ($fp === null) {
return null;
}
clearstatcache();
$this->_closePackageFile($fp);
$data = file_get_contents($this->_packageFileName($package, $channel));
$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;
}
/**
* @param string Channel name
* @param bool whether to strictly retrieve info of channels, not just aliases
* @return array|null
*/
function _channelInfo($channel, $noaliases = false)
{
if (!$this->_channelExists($channel, $noaliases)) {
return null;
}
$fp = $this->_openChannelFile($channel, 'r');
if ($fp === null) {
return null;
}
clearstatcache();
$this->_closeChannelFile($fp);
$data = file_get_contents($this->_channelFileName($channel));
$data = unserialize($data);
return $data;
}
function _listChannels()
{
$channellist = array();
if (!file_exists($this->channelsdir) || !is_dir($this->channelsdir)) {
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;
}
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);
sort($pkglist);
return $pkglist;
}
function _listChannelPackages($channel)
{
$pkglist = array();
if (!file_exists($this->_channelDirectoryName($channel)) ||
!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;
}
$pkglist[] = substr($ent, 0, -4);
}
closedir($dp);
return $pkglist;
}
function _listAllPackages()
{
$ret = array();
foreach ($this->_listChannels() as $channel) {
$ret[$channel] = $this->_listPackages($channel);
}
return $ret;
}
/**
* Add an installed package to the registry
* @param string package name
* @param array package info (parsed by PEAR_Common::infoFrom*() methods)
* @return bool success of saving
* @access private
*/
function _addPackage($package, $info)
{
if ($this->_packageExists($package)) {
return false;
}
$fp = $this->_openPackageFile($package, 'wb');
if ($fp === null) {
return false;
}
$info['_lastmodified'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($info['filelist'])) {
$this->_rebuildFileMap();
}
return true;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @return bool
* @access private
*/
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();
if ($ui) {
foreach ($info->getValidationWarnings() as $err) {
$ui->log($err['message'], true);
}
}
}
return false;
}
$channel = $info->getChannel();
$package = $info->getPackage();
$save = $info;
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'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
$this->_rebuildFileMap();
return true;
}
/**
* @param string Package name
* @param array parsed package.xml 1.0
* @param bool this parameter is only here for BC. Don't use it.
* @access private
*/
function _updatePackage($package, $info, $merge = true)
{
$oldinfo = $this->_packageInfo($package);
if (empty($oldinfo)) {
return false;
}
$fp = $this->_openPackageFile($package, 'w');
if ($fp === null) {
return false;
}
if (is_object($info)) {
$info = $info->toArray();
}
$info['_lastmodified'] = self::getSourceDateEpoch();
$newinfo = $info;
if ($merge) {
$info = array_merge($oldinfo, $info);
} else {
$diff = $info;
}
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($newinfo['filelist'])) {
$this->_rebuildFileMap();
}
return true;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @return bool
* @access private
*/
function _updatePackage2($info)
{
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'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
$this->_rebuildFileMap();
return true;
}
/**
* @param string Package name
* @param string Channel name
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
* @access private
*/
function &_getPackage($package, $channel = 'pear.php.net')
{
$info = $this->_packageInfo($package, null, $channel);
if ($info === null) {
return $info;
}
$a = $this->_config;
if (!$a) {
$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);
$pf = &$pkg->fromArray($info);
return $pf;
}
/**
* @param string channel name
* @param bool whether to strictly retrieve channel names
* @return PEAR_ChannelFile|PEAR_Error
* @access private
*/
function &_getChannel($channel, $noaliases = false)
{
$ch = false;
if ($this->_channelExists($channel, $noaliases)) {
$chinfo = $this->_channelInfo($channel, $noaliases);
if ($chinfo) {
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->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')) {
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setServer('pecl.php.net');
$pear_channel->setAlias('pecl');
$pear_channel->setSummary('PHP Extension Community Library');
$pear_channel->setDefaultPEARProtocols();
$pear_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
$pear_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$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->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
return $private;
}
return $ch;
}
/**
* @param string Package name
* @param string Channel name
* @return bool
*/
function packageExists($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_packageExists($package, $channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ channelExists()
/**
* @param string channel name
* @param bool if true, then aliases will be ignored
* @return bool
*/
function channelExists($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_channelExists($channel, $noaliases);
$this->_unlock();
return $ret;
}
// }}}
/**
* @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()
/**
* Determines whether the parameter is an alias of a channel
* @param string
* @return bool
*/
function isAlias($alias)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_isChannelAlias($alias);
$this->_unlock();
return $ret;
}
// }}}
// {{{ packageInfo()
/**
* @param string|null
* @param string|null
* @param string
* @return array|null
*/
function packageInfo($package = null, $key = null, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_packageInfo($package, $key, $channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ channelInfo()
/**
* Retrieve a raw array of channel data.
*
* Do not use this, instead use {@link getChannel()} for normal
* operations. Array structure is undefined in this method
* @param string channel name
* @param bool whether to strictly retrieve information only on non-aliases
* @return array|null|PEAR_Error
*/
function channelInfo($channel = null, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_channelInfo($channel, $noaliases);
$this->_unlock();
return $ret;
}
// }}}
/**
* @param string
*/
function channelName($channel)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getChannelFromAlias($channel);
$this->_unlock();
return $ret;
}
/**
* @param string
*/
function channelAlias($channel)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getAlias($channel);
$this->_unlock();
return $ret;
}
// {{{ listPackages()
function listPackages($channel = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listPackages($channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ listAllPackages()
function listAllPackages()
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listAllPackages();
$this->_unlock();
return $ret;
}
// }}}
// {{{ listChannel()
function listChannels()
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listChannels();
$this->_unlock();
return $ret;
}
// }}}
// {{{ addPackage()
/**
* Add an installed package to the registry
* @param string|PEAR_PackageFile_v1|PEAR_PackageFile_v2 package name or object
* that will be passed to {@link addPackage2()}
* @param array package info (parsed by PEAR_Common::infoFrom*() methods)
* @return bool success of saving
*/
function addPackage($package, $info)
{
if (is_object($info)) {
return $this->addPackage2($info);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_addPackage($package, $info);
$this->_unlock();
if ($ret) {
if (!class_exists('PEAR_PackageFile_v1')) {
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->_config);
$pf->fromArray($info);
$this->_dependencyDB->uninstallPackage($pf);
$this->_dependencyDB->installPackage($pf);
}
return $ret;
}
// }}}
// {{{ addPackage2()
function addPackage2($info)
{
if (!is_object($info)) {
return $this->addPackage($info['package'], $info);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_addPackage2($info);
$this->_unlock();
if ($ret) {
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
return $ret;
}
// }}}
// {{{ updateChannel()
/**
* For future expandibility purposes, separate this
* @param PEAR_ChannelFile
*/
function updateChannel($channel, $lastmodified = null)
{
if ($channel->getName() == '__uri') {
return false;
}
return $this->addChannel($channel, $lastmodified, true);
}
// }}}
// {{{ deleteChannel()
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
* @return boolean|PEAR_Error True on deletion, false if it doesn't exist
*/
function deleteChannel($channel)
{
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;
}
// }}}
// {{{ addChannel()
/**
* @param PEAR_ChannelFile Channel object
* @param string Last-Modified header from HTTP for caching
* @return boolean|PEAR_Error True on creation, false if it already exists
*/
function addChannel($channel, $lastmodified = false, $update = false)
{
if (!is_a($channel, 'PEAR_ChannelFile') || !$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;
}
// }}}
// {{{ deletePackage()
function deletePackage($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$file = $this->_packageFileName($package, $channel);
$ret = file_exists($file) ? @unlink($file) : false;
$this->_rebuildFileMap();
$this->_unlock();
$p = array('channel' => $channel, 'package' => $package);
$this->_dependencyDB->uninstallPackage($p);
return $ret;
}
// }}}
// {{{ updatePackage()
function updatePackage($package, $info, $merge = true)
{
if (is_object($info)) {
return $this->updatePackage2($info, $merge);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_updatePackage($package, $info, $merge);
$this->_unlock();
if ($ret) {
if (!class_exists('PEAR_PackageFile_v1')) {
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->_config);
$pf->fromArray($this->packageInfo($package));
$this->_dependencyDB->uninstallPackage($pf);
$this->_dependencyDB->installPackage($pf);
}
return $ret;
}
// }}}
// {{{ updatePackage2()
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) {
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
return $ret;
}
// }}}
// {{{ getChannel()
/**
* @param string channel name
* @param bool whether to strictly return raw channels (no aliases)
* @return PEAR_ChannelFile|PEAR_Error
*/
function getChannel($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getChannel($channel, $noaliases);
$this->_unlock();
if (!$ret) {
return PEAR::raiseError('Unknown channel: ' . $channel);
}
return $ret;
}
// }}}
// {{{ getPackage()
/**
* @param string package name
* @param string channel name
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
*/
function &getPackage($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$pf = &$this->_getPackage($package, $channel);
$this->_unlock();
return $pf;
}
// }}}
/**
* Get PEAR_PackageFile_v[1/2] objects representing the contents of
* a dependency group that are installed.
*
* This is used at uninstall-time
* @param array
* @return array|false
*/
function getInstalledGroup($group)
{
$ret = array();
if (isset($group['package'])) {
if (!isset($group['package'][0])) {
$group['package'] = array($group['package']);
}
foreach ($group['package'] as $package) {
$depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
$p = &$this->getPackage($package['name'], $depchannel);
if ($p) {
$save = &$p;
$ret[] = &$save;
}
}
}
if (isset($group['subpackage'])) {
if (!isset($group['subpackage'][0])) {
$group['subpackage'] = array($group['subpackage']);
}
foreach ($group['subpackage'] as $package) {
$depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
$p = &$this->getPackage($package['name'], $depchannel);
if ($p) {
$save = &$p;
$ret[] = &$save;
}
}
}
if (!count($ret)) {
return false;
}
return $ret;
}
// {{{ getChannelValidator()
/**
* @param string channel name
* @return PEAR_Validate|false
*/
function &getChannelValidator($channel)
{
$chan = $this->getChannel($channel);
if (PEAR::isError($chan)) {
return $chan;
}
$val = $chan->getValidationObject();
return $val;
}
// }}}
// {{{ getChannels()
/**
* @param string channel name
* @return array an array of PEAR_ChannelFile objects representing every installed channel
*/
function &getChannels()
{
$ret = array();
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
foreach ($this->_listChannels() as $channel) {
$e = &$this->_getChannel($channel);
if (!$e || PEAR::isError($e)) {
continue;
}
$ret[] = $e;
}
$this->_unlock();
return $ret;
}
// }}}
// {{{ checkFileMap()
/**
* Test whether a file or set of files belongs to a package.
*
* If an array is passed in
* @param string|array file path, absolute or relative to the pear
* install dir
* @param string|array name of PEAR package or array('package' => name, 'channel' =>
* channel) of a package that will be ignored
* @param string API version - 1.1 will exclude any files belonging to a package
* @param array private recursion variable
* @return array|false which package and channel the file belongs to, or an empty
* string if the file does not belong to an installed package,
* or belongs to the second parameter's package
*/
function checkFileMap($path, $package = false, $api = '1.0', $attrs = false)
{
if (is_array($path)) {
static $notempty;
if (empty($notempty)) {
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$notempty = function($a) { return !empty($a); };
}
$package = is_array($package) ? array(strtolower($package[0]), strtolower($package[1]))
: strtolower($package);
$pkgs = array();
foreach ($path as $name => $attrs) {
if (is_array($attrs)) {
if (isset($attrs['install-as'])) {
$name = $attrs['install-as'];
}
if (!in_array($attrs['role'], PEAR_Installer_Role::getInstallableRoles())) {
// these are not installed
continue;
}
if (!in_array($attrs['role'], PEAR_Installer_Role::getBaseinstallRoles())) {
$attrs['baseinstalldir'] = is_array($package) ? $package[1] : $package;
}
if (isset($attrs['baseinstalldir'])) {
$name = $attrs['baseinstalldir'] . DIRECTORY_SEPARATOR . $name;
}
}
$pkgs[$name] = $this->checkFileMap($name, $package, $api, $attrs);
if (PEAR::isError($pkgs[$name])) {
return $pkgs[$name];
}
}
return array_filter($pkgs, $notempty);
}
if (empty($this->filemap_cache)) {
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$err = $this->_readFileMap();
$this->_unlock();
if (PEAR::isError($err)) {
return $err;
}
}
if (!$attrs) {
$attrs = array('role' => 'php'); // any old call would be for PHP role only
}
if (isset($this->filemap_cache[$attrs['role']][$path])) {
if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
return false;
}
return $this->filemap_cache[$attrs['role']][$path];
}
$l = strlen($this->install_dir);
if (substr($path, 0, $l) == $this->install_dir) {
$path = preg_replace('!^'.DIRECTORY_SEPARATOR.'+!', '', substr($path, $l));
}
if (isset($this->filemap_cache[$attrs['role']][$path])) {
if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
return false;
}
return $this->filemap_cache[$attrs['role']][$path];
}
return false;
}
// }}}
// {{{ flush()
/**
* Force a reload of the filemap
* @since 1.5.0RC3
*/
function flushFileMap()
{
$this->filemap_cache = null;
clearstatcache(); // ensure that the next read gets the full, current filemap
}
// }}}
// {{{ apiVersion()
/**
* Get the expected API version. Channels API is version 1.1, as it is backwards
* compatible with 1.0
* @return string
*/
function apiVersion()
{
return '1.1';
}
// }}}
/**
* Parse a package name, or validate a parsed package name array
* @param string|array pass in an array of format
* array(
* 'package' => 'pname',
* ['channel' => 'channame',]
* ['version' => 'version',]
* ['state' => 'state',]
* ['group' => 'groupname'])
* or a string of format
* [channel://][channame/]pname[-version|-state][/group=groupname]
* @return array|PEAR_Error
*/
function parsePackageName($param, $defaultchannel = 'pear.php.net')
{
$saveparam = $param;
if (is_array($param)) {
// convert to string for error messages
$saveparam = $this->parsedPackageNameToString($param);
// process the array
if (!isset($param['package'])) {
return PEAR::raiseError('parsePackageName(): array $param ' .
'must contain a valid package name in index "param"',
'package', null, null, $param);
}
if (!isset($param['uri'])) {
if (!isset($param['channel'])) {
$param['channel'] = $defaultchannel;
}
} else {
$param['channel'] = '__uri';
}
} else {
$components = @parse_url((string) $param);
if (isset($components['scheme'])) {
if ($components['scheme'] == 'http') {
// uri package
$param = array('uri' => $param, 'channel' => '__uri');
} elseif($components['scheme'] != 'channel') {
return PEAR::raiseError('parsePackageName(): only channel:// uris may ' .
'be downloaded, not "' . $param . '"', 'invalid', null, null, $param);
}
}
if (!isset($components['path'])) {
return PEAR::raiseError('parsePackageName(): array $param ' .
'must contain a valid package name in "' . $param . '"',
'package', null, null, $param);
}
if (isset($components['host'])) {
// remove the leading "/"
$components['path'] = substr($components['path'], 1);
}
if (!isset($components['scheme'])) {
if (strpos($components['path'], '/') !== false) {
if ($components['path'][0] == '/') {
return PEAR::raiseError('parsePackageName(): this is not ' .
'a package name, it begins with "/" in "' . $param . '"',
'invalid', null, null, $param);
}
$parts = explode('/', $components['path']);
$components['host'] = array_shift($parts);
if (count($parts) > 1) {
$components['path'] = array_pop($parts);
$components['host'] .= '/' . implode('/', $parts);
} else {
$components['path'] = implode('/', $parts);
}
} else {
$components['host'] = $defaultchannel;
}
} else {
if (strpos($components['path'], '/')) {
$parts = explode('/', $components['path']);
$components['path'] = array_pop($parts);
$components['host'] .= '/' . implode('/', $parts);
}
}
if (is_array($param)) {
$param['package'] = $components['path'];
} else {
$param = array(
'package' => $components['path']
);
if (isset($components['host'])) {
$param['channel'] = $components['host'];
}
}
if (isset($components['fragment'])) {
$param['group'] = $components['fragment'];
}
if (isset($components['user'])) {
$param['user'] = $components['user'];
}
if (isset($components['pass'])) {
$param['pass'] = $components['pass'];
}
if (isset($components['query'])) {
parse_str($components['query'], $param['opts']);
}
// check for extension
$pathinfo = pathinfo($param['package']);
if (isset($pathinfo['extension']) &&
in_array(strtolower($pathinfo['extension']), array('tgz', 'tar'))) {
$param['extension'] = $pathinfo['extension'];
$param['package'] = substr($pathinfo['basename'], 0,
strlen($pathinfo['basename']) - 4);
}
// check for version
if (strpos($param['package'], '-')) {
$test = explode('-', $param['package']);
if (count($test) != 2) {
return PEAR::raiseError('parsePackageName(): only one version/state ' .
'delimiter "-" is allowed in "' . $saveparam . '"',
'version', null, null, $param);
}
list($param['package'], $param['version']) = $test;
}
}
// validation
$info = $this->channelExists($param['channel']);
if (PEAR::isError($info)) {
return $info;
}
if (!$info) {
return PEAR::raiseError('unknown channel "' . $param['channel'] .
'" in "' . $saveparam . '"', 'channel', null, null, $param);
}
$chan = $this->getChannel($param['channel']);
if (PEAR::isError($chan)) {
return $chan;
}
if (!$chan) {
return PEAR::raiseError("Exception: corrupt registry, could not " .
"retrieve channel " . $param['channel'] . " information",
'registry', null, null, $param);
}
$param['channel'] = $chan->getName();
$validate = $chan->getValidationObject();
$vpackage = $chan->getValidationPackage();
// validate package name
if (!$validate->validPackageName($param['package'], $vpackage['_content'])) {
return PEAR::raiseError('parsePackageName(): invalid package name "' .
$param['package'] . '" in "' . $saveparam . '"',
'package', null, null, $param);
}
if (isset($param['group'])) {
if (!PEAR_Validate::validGroupName($param['group'])) {
return PEAR::raiseError('parsePackageName(): dependency group "' . $param['group'] .
'" is not a valid group name in "' . $saveparam . '"', 'group', null, null,
$param);
}
}
if (isset($param['state'])) {
if (!in_array(strtolower($param['state']), $validate->getValidStates())) {
return PEAR::raiseError('parsePackageName(): state "' . $param['state']
. '" is not a valid state in "' . $saveparam . '"',
'state', null, null, $param);
}
}
if (isset($param['version'])) {
if (isset($param['state'])) {
return PEAR::raiseError('parsePackageName(): cannot contain both ' .
'a version and a stability (state) in "' . $saveparam . '"',
'version/state', null, null, $param);
}
// check whether version is actually a state
if (in_array(strtolower($param['version']), $validate->getValidStates())) {
$param['state'] = strtolower($param['version']);
unset($param['version']);
} else {
if (!$validate->validVersion($param['version'])) {
return PEAR::raiseError('parsePackageName(): "' . $param['version'] .
'" is neither a valid version nor a valid state in "' .
$saveparam . '"', 'version/state', null, null, $param);
}
}
}
return $param;
}
/**
* @param array
* @return string
*/
function parsedPackageNameToString($parsed, $brief = false)
{
if (is_string($parsed)) {
return $parsed;
}
if (is_object($parsed)) {
$p = $parsed;
$parsed = array(
'package' => $p->getPackage(),
'channel' => $p->getChannel(),
'version' => $p->getVersion(),
);
}
if (isset($parsed['uri'])) {
return $parsed['uri'];
}
if ($brief) {
if ($channel = $this->channelAlias($parsed['channel'])) {
return $channel . '/' . $parsed['package'];
}
}
$upass = '';
if (isset($parsed['user'])) {
$upass = $parsed['user'];
if (isset($parsed['pass'])) {
$upass .= ':' . $parsed['pass'];
}
$upass = "$upass@";
}
$ret = 'channel://' . $upass . $parsed['channel'] . '/' . $parsed['package'];
if (isset($parsed['version']) || isset($parsed['state'])) {
$ver = isset($parsed['version']) ? $parsed['version'] : '';
$ver .= isset($parsed['state']) ? $parsed['state'] : '';
$ret .= '-' . $ver;
}
if (isset($parsed['extension'])) {
$ret .= '.' . $parsed['extension'];
}
if (isset($parsed['opts'])) {
$ret .= '?';
foreach ($parsed['opts'] as $name => $value) {
$parsed['opts'][$name] = "$name=$value";
}
$ret .= implode('&', $parsed['opts']);
}
if (isset($parsed['group'])) {
$ret .= '#' . $parsed['group'];
}
return $ret;
}
}
opt/cpanel/ea-php72/root/usr/share/pear/PEAR/Registry.php 0000644 00000224270 14756545623 0017060 0 ustar 00
* @author Tomas V. V. Cox
* @author Greg Beaver
* @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
*/
/**
* for PEAR_Error
*/
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_CHANNEL_FILE', -6);
/**
* Administration class used to maintain the installed package database.
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Tomas V. V. Cox
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_Registry extends PEAR
{
/**
* File containing all channel information.
* @var string
*/
var $channels = '';
/** Directory where registry files are stored.
* @var string
*/
var $statedir = '';
/** File where the file map is stored
* @var string
*/
var $filemap = '';
/** Directory where registry files for channels are stored.
* @var string
*/
var $channelsdir = '';
/** Name of file used for locking the registry
* @var string
*/
var $lockfile = '';
/** File descriptor used during locking
* @var resource
*/
var $lock_fp = null;
/** Mode used during locking
* @var int
*/
var $lock_mode = 0; // XXX UNUSED
/** Cache of package information. Structure:
* array(
* 'package' => array('id' => ... ),
* ... )
* @var array
*/
var $pkginfo_cache = array();
/** Cache of file map. Structure:
* array( '/path/to/file' => 'package', ... )
* @var array
*/
var $filemap_cache = array();
/**
* @var false|PEAR_ChannelFile
*/
var $_pearChannel;
/**
* @var false|PEAR_ChannelFile
*/
var $_peclChannel;
/**
* @var false|PEAR_ChannelFile
*/
var $_docChannel;
/**
* @var PEAR_DependencyDB
*/
var $_dependencyDB;
/**
* @var PEAR_Config
*/
var $_config;
/**
* PEAR_Registry constructor.
*
* @param string (optional) PEAR install directory (for .php files)
* @param PEAR_ChannelFile PEAR_ChannelFile object representing the PEAR channel, if
* default values are not desired. Only used the very first time a PEAR
* repository is initialized
* @param PEAR_ChannelFile PEAR_ChannelFile object representing the PECL channel, if
* default values are not desired. Only used the very first time a PEAR
* repository is initialized
*
* @access public
*/
function __construct($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
$pecl_channel = false, $pear_metadata_dir = '')
{
parent::__construct();
$this->setInstallDir($pear_install_dir, $pear_metadata_dir);
$this->_pearChannel = $pear_channel;
$this->_peclChannel = $pecl_channel;
$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 != '.') {
$olddir = $dir;
$dir = dirname($dir);
if ($dir != '.' && file_exists($dir)) {
if (is_writeable($dir)) {
return true;
}
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, $resetInstallDir = true)
{
$this->_config = &$config;
if ($resetInstallDir) {
$this->setInstallDir($config->get('php_dir'), $config->get('metadata_dir'));
}
}
function _initializeChannelDirs()
{
static $running = false;
if (!$running) {
$running = true;
$ds = DIRECTORY_SEPARATOR;
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;
if (!is_a($pear_channel, 'PEAR_ChannelFile') || !$pear_channel->validate()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setAlias('pear');
$pear_channel->setServer('pear.php.net');
$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/');
//$pear_channel->setBaseURL('REST1.4', 'http://pear.php.net/rest/');
} else {
$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()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$pecl_channel = new PEAR_ChannelFile;
$pecl_channel->setAlias('pecl');
$pecl_channel->setServer('pecl.php.net');
$pecl_channel->setSummary('PHP Extension Community Library');
$pecl_channel->setDefaultPEARProtocols();
$pecl_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
$pecl_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$pecl_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
} else {
$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->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
$this->_addChannel($private);
}
$this->_rebuildFileMap();
}
$running = false;
}
}
function _initializeDirs()
{
$ds = DIRECTORY_SEPARATOR;
// XXX Compatibility code should be removed in the future
// rename all registry files if any to lowercase
if (!OS_WINDOWS && file_exists($this->statedir) && is_dir($this->statedir) &&
$handle = opendir($this->statedir)) {
$dest = $this->statedir . $ds;
while (false !== ($file = readdir($handle))) {
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();
}
$this->_initializeDepDB();
}
function _initializeDepDB()
{
if (!isset($this->_dependencyDB)) {
static $initializing = false;
if (!$initializing) {
$initializing = true;
if (!$this->_config) { // never used?
$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('metadata_dir', null, 'pear.php.net') .
DIRECTORY_SEPARATOR . '.depdb')) {
@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();
echo 'Unrecoverable error';
exit(1);
}
}
$initializing = false;
}
}
}
/**
* PEAR_Registry destructor. Makes sure no locks are forgotten.
*
* @access private
*/
function _PEAR_Registry()
{
parent::_PEAR();
if (is_resource($this->lock_fp)) {
$this->_unlock();
}
}
/**
* Make sure the directory where we keep registry files exists.
*
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertStateDir($channel = false)
{
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}'");
}
$init = true;
} elseif (!is_dir($this->statedir)) {
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;
}
} elseif (!is_dir($this->channelsdir)) {
return $this->raiseError('Cannot create directory ' . $this->channelsdir . ', ' .
'it already exists and is not a directory');
}
if ($init) {
static $running = false;
if (!$running) {
$running = true;
$this->_initializeDirs();
$running = false;
$init = false;
}
} else {
$this->_initializeDepDB();
}
return true;
}
/**
* Make sure the directory where we keep registry files exists for a non-standard channel.
*
* @param string channel name
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertChannelStateDir($channel)
{
$ds = DIRECTORY_SEPARATOR;
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
$this->_initializeChannelDirs();
}
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 .
"'");
}
} elseif (!is_dir($channelDir)) {
return $this->raiseError("could not create directory '" . $channelDir .
"', already exists and is not a directory");
}
return true;
}
/**
* Make sure the directory where we keep registry files for channels exists
*
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertChannelDir()
{
if (!file_exists($this->channelsdir)) {
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}'");
}
} 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'");
}
} 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;
}
/**
* Get the name of the file where data for a given package is stored.
*
* @param string channel name, or false if this is a PEAR package
* @param string package name
*
* @return string registry file name
*
* @access public
*/
function _packageFileName($package, $channel = false)
{
if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
return $this->_channelDirectoryName($channel) . DIRECTORY_SEPARATOR .
strtolower($package) . '.reg';
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower($package) . '.reg';
}
/**
* Get the name of the file where data for a given channel is stored.
* @param string channel name
* @return string registry file name
*/
function _channelFileName($channel, $noaliases = false)
{
if (!$noaliases) {
if (file_exists($this->_getChannelAliasFileName($channel))) {
$channel = implode('', file($this->_getChannelAliasFileName($channel)));
}
}
return $this->channelsdir . DIRECTORY_SEPARATOR . str_replace('/', '_',
strtolower($channel)) . '.reg';
}
/**
* @param string
* @return string
*/
function _getChannelAliasFileName($alias)
{
return $this->channelsdir . DIRECTORY_SEPARATOR . '.alias' .
DIRECTORY_SEPARATOR . str_replace('/', '_', strtolower($alias)) . '.txt';
}
/**
* Get the name of a channel from its alias
*/
function _getChannelFromAlias($channel)
{
if (!$this->_channelExists($channel)) {
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)));
}
return $channel;
}
/**
* Get the alias of a channel from its alias or its name
*/
function _getAlias($channel)
{
if (!$this->_channelExists($channel)) {
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();
}
/**
* Get the name of the file where data for a given package is stored.
*
* @param string channel name, or false if this is a PEAR package
* @param string package name
*
* @return string registry file name
*
* @access public
*/
function _channelDirectoryName($channel)
{
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
return $this->statedir;
}
$ch = $this->_getChannelFromAlias($channel);
if (!$ch) {
$ch = $channel;
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
str_replace('/', '_', $ch));
}
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;
}
function _closePackageFile($fp)
{
fclose($fp);
}
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;
}
function _closeChannelFile($fp)
{
fclose($fp);
}
function _rebuildFileMap()
{
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$channels = $this->_listAllPackages();
$files = array();
foreach ($channels as $channel => $packages) {
foreach ($packages as $package) {
$version = $this->_packageInfo($package, 'version', $channel);
$filelist = $this->_packageInfo($package, 'filelist', $channel);
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 (!isset($files[$attrs['role']])) {
$files[$attrs['role']] = array();
}
$files[$attrs['role']][$file] = strtolower($package);
}
}
}
}
$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);
return true;
}
function _readFileMap()
{
if (!file_exists($this->filemap)) {
return array();
}
$fp = @fopen($this->filemap, 'r');
if (!$fp) {
$last_errormsg = '';
$last_error = error_get_last();
if (!empty($last_error['message'])) {
$last_errormsg = $last_error['message'];
}
return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $last_errormsg);
}
clearstatcache();
$fsize = filesize($this->filemap);
fclose($fp);
$data = file_get_contents($this->filemap);
$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 the registry.
*
* @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.
* See flock manual for more information.
*
* @return bool TRUE on success, FALSE if locking failed, or a
* PEAR error if some other error occurs (such as the
* lock file not being writable).
*
* @access private
*/
function _lock($mode = LOCK_EX)
{
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');
}
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 = 'r';
}
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;
}
//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;
}
function _unlock()
{
$ret = $this->_lock(LOCK_UN);
if (is_resource($this->lock_fp)) {
fclose($this->lock_fp);
}
$this->lock_fp = null;
return $ret;
}
function _packageExists($package, $channel = false)
{
return file_exists($this->_packageFileName($package, $channel));
}
/**
* Determine whether a channel exists in the registry
*
* @param string Channel name
* @param bool if true, then aliases will be ignored
* @return boolean
*/
function _channelExists($channel, $noaliases = false)
{
$a = file_exists($this->_channelFileName($channel, $noaliases));
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;
}
/**
* Determine whether a mirror exists within the default 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
* @param string Last-Modified HTTP tag from remote request
* @return boolean|PEAR_Error True on creation, false if it already exists
*/
function _addChannel($channel, $update = false, $lastmodified = false)
{
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()));
}
}
} else {
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;
} else {
$info['_lastmodified'] = self::getSourceDateEpoch();
}
fwrite($fp, serialize($info));
fclose($fp);
return true;
}
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
* @return boolean|PEAR_Error True on deletion, false if it doesn't exist
*/
function _deleteChannel($channel)
{
if (!is_string($channel)) {
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);
if (!$test) {
return false;
}
}
$file = $this->_channelFileName($channel);
$ret = true;
if (file_exists($file)) {
$ret = @unlink($file);
}
return $ret;
}
/**
* Determine whether a channel exists in the registry
* @param string Channel Alias
* @return boolean
*/
function _isChannelAlias($alias)
{
return file_exists($this->_getChannelAliasFileName($alias));
}
/**
* @param string|null
* @param string|null
* @param string|null
* @return array|null
* @access private
*/
function _packageInfo($package = null, $key = null, $channel = 'pear.php.net')
{
if ($package === null) {
if ($channel === null) {
$channels = $this->_listChannels();
$ret = array();
foreach ($channels as $channel) {
$channel = strtolower($channel);
$ret[$channel] = array();
$packages = $this->_listPackages($channel);
foreach ($packages as $package) {
$ret[$channel][] = $this->_packageInfo($package, null, $channel);
}
}
return $ret;
}
$ps = $this->_listPackages($channel);
if (!count($ps)) {
return array();
}
return array_map(array(&$this, '_packageInfo'),
$ps, array_fill(0, count($ps), null),
array_fill(0, count($ps), $channel));
}
$fp = $this->_openPackageFile($package, 'r', $channel);
if ($fp === null) {
return null;
}
clearstatcache();
$this->_closePackageFile($fp);
$data = file_get_contents($this->_packageFileName($package, $channel));
$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;
}
/**
* @param string Channel name
* @param bool whether to strictly retrieve info of channels, not just aliases
* @return array|null
*/
function _channelInfo($channel, $noaliases = false)
{
if (!$this->_channelExists($channel, $noaliases)) {
return null;
}
$fp = $this->_openChannelFile($channel, 'r');
if ($fp === null) {
return null;
}
clearstatcache();
$this->_closeChannelFile($fp);
$data = file_get_contents($this->_channelFileName($channel));
$data = unserialize($data);
return $data;
}
function _listChannels()
{
$channellist = array();
if (!file_exists($this->channelsdir) || !is_dir($this->channelsdir)) {
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;
}
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);
sort($pkglist);
return $pkglist;
}
function _listChannelPackages($channel)
{
$pkglist = array();
if (!file_exists($this->_channelDirectoryName($channel)) ||
!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;
}
$pkglist[] = substr($ent, 0, -4);
}
closedir($dp);
return $pkglist;
}
function _listAllPackages()
{
$ret = array();
foreach ($this->_listChannels() as $channel) {
$ret[$channel] = $this->_listPackages($channel);
}
return $ret;
}
/**
* Add an installed package to the registry
* @param string package name
* @param array package info (parsed by PEAR_Common::infoFrom*() methods)
* @return bool success of saving
* @access private
*/
function _addPackage($package, $info)
{
if ($this->_packageExists($package)) {
return false;
}
$fp = $this->_openPackageFile($package, 'wb');
if ($fp === null) {
return false;
}
$info['_lastmodified'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($info['filelist'])) {
$this->_rebuildFileMap();
}
return true;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @return bool
* @access private
*/
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();
if ($ui) {
foreach ($info->getValidationWarnings() as $err) {
$ui->log($err['message'], true);
}
}
}
return false;
}
$channel = $info->getChannel();
$package = $info->getPackage();
$save = $info;
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'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
$this->_rebuildFileMap();
return true;
}
/**
* @param string Package name
* @param array parsed package.xml 1.0
* @param bool this parameter is only here for BC. Don't use it.
* @access private
*/
function _updatePackage($package, $info, $merge = true)
{
$oldinfo = $this->_packageInfo($package);
if (empty($oldinfo)) {
return false;
}
$fp = $this->_openPackageFile($package, 'w');
if ($fp === null) {
return false;
}
if (is_object($info)) {
$info = $info->toArray();
}
$info['_lastmodified'] = self::getSourceDateEpoch();
$newinfo = $info;
if ($merge) {
$info = array_merge($oldinfo, $info);
} else {
$diff = $info;
}
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($newinfo['filelist'])) {
$this->_rebuildFileMap();
}
return true;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @return bool
* @access private
*/
function _updatePackage2($info)
{
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'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
$this->_rebuildFileMap();
return true;
}
/**
* @param string Package name
* @param string Channel name
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
* @access private
*/
function &_getPackage($package, $channel = 'pear.php.net')
{
$info = $this->_packageInfo($package, null, $channel);
if ($info === null) {
return $info;
}
$a = $this->_config;
if (!$a) {
$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);
$pf = &$pkg->fromArray($info);
return $pf;
}
/**
* @param string channel name
* @param bool whether to strictly retrieve channel names
* @return PEAR_ChannelFile|PEAR_Error
* @access private
*/
function &_getChannel($channel, $noaliases = false)
{
$ch = false;
if ($this->_channelExists($channel, $noaliases)) {
$chinfo = $this->_channelInfo($channel, $noaliases);
if ($chinfo) {
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->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')) {
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setServer('pecl.php.net');
$pear_channel->setAlias('pecl');
$pear_channel->setSummary('PHP Extension Community Library');
$pear_channel->setDefaultPEARProtocols();
$pear_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
$pear_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$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->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
return $private;
}
return $ch;
}
/**
* @param string Package name
* @param string Channel name
* @return bool
*/
function packageExists($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_packageExists($package, $channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ channelExists()
/**
* @param string channel name
* @param bool if true, then aliases will be ignored
* @return bool
*/
function channelExists($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_channelExists($channel, $noaliases);
$this->_unlock();
return $ret;
}
// }}}
/**
* @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()
/**
* Determines whether the parameter is an alias of a channel
* @param string
* @return bool
*/
function isAlias($alias)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_isChannelAlias($alias);
$this->_unlock();
return $ret;
}
// }}}
// {{{ packageInfo()
/**
* @param string|null
* @param string|null
* @param string
* @return array|null
*/
function packageInfo($package = null, $key = null, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_packageInfo($package, $key, $channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ channelInfo()
/**
* Retrieve a raw array of channel data.
*
* Do not use this, instead use {@link getChannel()} for normal
* operations. Array structure is undefined in this method
* @param string channel name
* @param bool whether to strictly retrieve information only on non-aliases
* @return array|null|PEAR_Error
*/
function channelInfo($channel = null, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_channelInfo($channel, $noaliases);
$this->_unlock();
return $ret;
}
// }}}
/**
* @param string
*/
function channelName($channel)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getChannelFromAlias($channel);
$this->_unlock();
return $ret;
}
/**
* @param string
*/
function channelAlias($channel)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getAlias($channel);
$this->_unlock();
return $ret;
}
// {{{ listPackages()
function listPackages($channel = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listPackages($channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ listAllPackages()
function listAllPackages()
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listAllPackages();
$this->_unlock();
return $ret;
}
// }}}
// {{{ listChannel()
function listChannels()
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listChannels();
$this->_unlock();
return $ret;
}
// }}}
// {{{ addPackage()
/**
* Add an installed package to the registry
* @param string|PEAR_PackageFile_v1|PEAR_PackageFile_v2 package name or object
* that will be passed to {@link addPackage2()}
* @param array package info (parsed by PEAR_Common::infoFrom*() methods)
* @return bool success of saving
*/
function addPackage($package, $info)
{
if (is_object($info)) {
return $this->addPackage2($info);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_addPackage($package, $info);
$this->_unlock();
if ($ret) {
if (!class_exists('PEAR_PackageFile_v1')) {
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->_config);
$pf->fromArray($info);
$this->_dependencyDB->uninstallPackage($pf);
$this->_dependencyDB->installPackage($pf);
}
return $ret;
}
// }}}
// {{{ addPackage2()
function addPackage2($info)
{
if (!is_object($info)) {
return $this->addPackage($info['package'], $info);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_addPackage2($info);
$this->_unlock();
if ($ret) {
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
return $ret;
}
// }}}
// {{{ updateChannel()
/**
* For future expandibility purposes, separate this
* @param PEAR_ChannelFile
*/
function updateChannel($channel, $lastmodified = null)
{
if ($channel->getName() == '__uri') {
return false;
}
return $this->addChannel($channel, $lastmodified, true);
}
// }}}
// {{{ deleteChannel()
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
* @return boolean|PEAR_Error True on deletion, false if it doesn't exist
*/
function deleteChannel($channel)
{
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;
}
// }}}
// {{{ addChannel()
/**
* @param PEAR_ChannelFile Channel object
* @param string Last-Modified header from HTTP for caching
* @return boolean|PEAR_Error True on creation, false if it already exists
*/
function addChannel($channel, $lastmodified = false, $update = false)
{
if (!is_a($channel, 'PEAR_ChannelFile') || !$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;
}
// }}}
// {{{ deletePackage()
function deletePackage($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$file = $this->_packageFileName($package, $channel);
$ret = file_exists($file) ? @unlink($file) : false;
$this->_rebuildFileMap();
$this->_unlock();
$p = array('channel' => $channel, 'package' => $package);
$this->_dependencyDB->uninstallPackage($p);
return $ret;
}
// }}}
// {{{ updatePackage()
function updatePackage($package, $info, $merge = true)
{
if (is_object($info)) {
return $this->updatePackage2($info, $merge);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_updatePackage($package, $info, $merge);
$this->_unlock();
if ($ret) {
if (!class_exists('PEAR_PackageFile_v1')) {
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->_config);
$pf->fromArray($this->packageInfo($package));
$this->_dependencyDB->uninstallPackage($pf);
$this->_dependencyDB->installPackage($pf);
}
return $ret;
}
// }}}
// {{{ updatePackage2()
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) {
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
return $ret;
}
// }}}
// {{{ getChannel()
/**
* @param string channel name
* @param bool whether to strictly return raw channels (no aliases)
* @return PEAR_ChannelFile|PEAR_Error
*/
function getChannel($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getChannel($channel, $noaliases);
$this->_unlock();
if (!$ret) {
return PEAR::raiseError('Unknown channel: ' . $channel);
}
return $ret;
}
// }}}
// {{{ getPackage()
/**
* @param string package name
* @param string channel name
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
*/
function &getPackage($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$pf = &$this->_getPackage($package, $channel);
$this->_unlock();
return $pf;
}
// }}}
/**
* Get PEAR_PackageFile_v[1/2] objects representing the contents of
* a dependency group that are installed.
*
* This is used at uninstall-time
* @param array
* @return array|false
*/
function getInstalledGroup($group)
{
$ret = array();
if (isset($group['package'])) {
if (!isset($group['package'][0])) {
$group['package'] = array($group['package']);
}
foreach ($group['package'] as $package) {
$depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
$p = &$this->getPackage($package['name'], $depchannel);
if ($p) {
$save = &$p;
$ret[] = &$save;
}
}
}
if (isset($group['subpackage'])) {
if (!isset($group['subpackage'][0])) {
$group['subpackage'] = array($group['subpackage']);
}
foreach ($group['subpackage'] as $package) {
$depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
$p = &$this->getPackage($package['name'], $depchannel);
if ($p) {
$save = &$p;
$ret[] = &$save;
}
}
}
if (!count($ret)) {
return false;
}
return $ret;
}
// {{{ getChannelValidator()
/**
* @param string channel name
* @return PEAR_Validate|false
*/
function &getChannelValidator($channel)
{
$chan = $this->getChannel($channel);
if (PEAR::isError($chan)) {
return $chan;
}
$val = $chan->getValidationObject();
return $val;
}
// }}}
// {{{ getChannels()
/**
* @param string channel name
* @return array an array of PEAR_ChannelFile objects representing every installed channel
*/
function &getChannels()
{
$ret = array();
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
foreach ($this->_listChannels() as $channel) {
$e = &$this->_getChannel($channel);
if (!$e || PEAR::isError($e)) {
continue;
}
$ret[] = $e;
}
$this->_unlock();
return $ret;
}
// }}}
// {{{ checkFileMap()
/**
* Test whether a file or set of files belongs to a package.
*
* If an array is passed in
* @param string|array file path, absolute or relative to the pear
* install dir
* @param string|array name of PEAR package or array('package' => name, 'channel' =>
* channel) of a package that will be ignored
* @param string API version - 1.1 will exclude any files belonging to a package
* @param array private recursion variable
* @return array|false which package and channel the file belongs to, or an empty
* string if the file does not belong to an installed package,
* or belongs to the second parameter's package
*/
function checkFileMap($path, $package = false, $api = '1.0', $attrs = false)
{
if (is_array($path)) {
static $notempty;
if (empty($notempty)) {
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$notempty = function($a) { return !empty($a); };
}
$package = is_array($package) ? array(strtolower($package[0]), strtolower($package[1]))
: strtolower($package);
$pkgs = array();
foreach ($path as $name => $attrs) {
if (is_array($attrs)) {
if (isset($attrs['install-as'])) {
$name = $attrs['install-as'];
}
if (!in_array($attrs['role'], PEAR_Installer_Role::getInstallableRoles())) {
// these are not installed
continue;
}
if (!in_array($attrs['role'], PEAR_Installer_Role::getBaseinstallRoles())) {
$attrs['baseinstalldir'] = is_array($package) ? $package[1] : $package;
}
if (isset($attrs['baseinstalldir'])) {
$name = $attrs['baseinstalldir'] . DIRECTORY_SEPARATOR . $name;
}
}
$pkgs[$name] = $this->checkFileMap($name, $package, $api, $attrs);
if (PEAR::isError($pkgs[$name])) {
return $pkgs[$name];
}
}
return array_filter($pkgs, $notempty);
}
if (empty($this->filemap_cache)) {
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$err = $this->_readFileMap();
$this->_unlock();
if (PEAR::isError($err)) {
return $err;
}
}
if (!$attrs) {
$attrs = array('role' => 'php'); // any old call would be for PHP role only
}
if (isset($this->filemap_cache[$attrs['role']][$path])) {
if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
return false;
}
return $this->filemap_cache[$attrs['role']][$path];
}
$l = strlen($this->install_dir);
if (substr($path, 0, $l) == $this->install_dir) {
$path = preg_replace('!^'.DIRECTORY_SEPARATOR.'+!', '', substr($path, $l));
}
if (isset($this->filemap_cache[$attrs['role']][$path])) {
if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
return false;
}
return $this->filemap_cache[$attrs['role']][$path];
}
return false;
}
// }}}
// {{{ flush()
/**
* Force a reload of the filemap
* @since 1.5.0RC3
*/
function flushFileMap()
{
$this->filemap_cache = null;
clearstatcache(); // ensure that the next read gets the full, current filemap
}
// }}}
// {{{ apiVersion()
/**
* Get the expected API version. Channels API is version 1.1, as it is backwards
* compatible with 1.0
* @return string
*/
function apiVersion()
{
return '1.1';
}
// }}}
/**
* Parse a package name, or validate a parsed package name array
* @param string|array pass in an array of format
* array(
* 'package' => 'pname',
* ['channel' => 'channame',]
* ['version' => 'version',]
* ['state' => 'state',]
* ['group' => 'groupname'])
* or a string of format
* [channel://][channame/]pname[-version|-state][/group=groupname]
* @return array|PEAR_Error
*/
function parsePackageName($param, $defaultchannel = 'pear.php.net')
{
$saveparam = $param;
if (is_array($param)) {
// convert to string for error messages
$saveparam = $this->parsedPackageNameToString($param);
// process the array
if (!isset($param['package'])) {
return PEAR::raiseError('parsePackageName(): array $param ' .
'must contain a valid package name in index "param"',
'package', null, null, $param);
}
if (!isset($param['uri'])) {
if (!isset($param['channel'])) {
$param['channel'] = $defaultchannel;
}
} else {
$param['channel'] = '__uri';
}
} else {
$components = @parse_url((string) $param);
if (isset($components['scheme'])) {
if ($components['scheme'] == 'http') {
// uri package
$param = array('uri' => $param, 'channel' => '__uri');
} elseif($components['scheme'] != 'channel') {
return PEAR::raiseError('parsePackageName(): only channel:// uris may ' .
'be downloaded, not "' . $param . '"', 'invalid', null, null, $param);
}
}
if (!isset($components['path'])) {
return PEAR::raiseError('parsePackageName(): array $param ' .
'must contain a valid package name in "' . $param . '"',
'package', null, null, $param);
}
if (isset($components['host'])) {
// remove the leading "/"
$components['path'] = substr($components['path'], 1);
}
if (!isset($components['scheme'])) {
if (strpos($components['path'], '/') !== false) {
if ($components['path'][0] == '/') {
return PEAR::raiseError('parsePackageName(): this is not ' .
'a package name, it begins with "/" in "' . $param . '"',
'invalid', null, null, $param);
}
$parts = explode('/', $components['path']);
$components['host'] = array_shift($parts);
if (count($parts) > 1) {
$components['path'] = array_pop($parts);
$components['host'] .= '/' . implode('/', $parts);
} else {
$components['path'] = implode('/', $parts);
}
} else {
$components['host'] = $defaultchannel;
}
} else {
if (strpos($components['path'], '/')) {
$parts = explode('/', $components['path']);
$components['path'] = array_pop($parts);
$components['host'] .= '/' . implode('/', $parts);
}
}
if (is_array($param)) {
$param['package'] = $components['path'];
} else {
$param = array(
'package' => $components['path']
);
if (isset($components['host'])) {
$param['channel'] = $components['host'];
}
}
if (isset($components['fragment'])) {
$param['group'] = $components['fragment'];
}
if (isset($components['user'])) {
$param['user'] = $components['user'];
}
if (isset($components['pass'])) {
$param['pass'] = $components['pass'];
}
if (isset($components['query'])) {
parse_str($components['query'], $param['opts']);
}
// check for extension
$pathinfo = pathinfo($param['package']);
if (isset($pathinfo['extension']) &&
in_array(strtolower($pathinfo['extension']), array('tgz', 'tar'))) {
$param['extension'] = $pathinfo['extension'];
$param['package'] = substr($pathinfo['basename'], 0,
strlen($pathinfo['basename']) - 4);
}
// check for version
if (strpos($param['package'], '-')) {
$test = explode('-', $param['package']);
if (count($test) != 2) {
return PEAR::raiseError('parsePackageName(): only one version/state ' .
'delimiter "-" is allowed in "' . $saveparam . '"',
'version', null, null, $param);
}
list($param['package'], $param['version']) = $test;
}
}
// validation
$info = $this->channelExists($param['channel']);
if (PEAR::isError($info)) {
return $info;
}
if (!$info) {
return PEAR::raiseError('unknown channel "' . $param['channel'] .
'" in "' . $saveparam . '"', 'channel', null, null, $param);
}
$chan = $this->getChannel($param['channel']);
if (PEAR::isError($chan)) {
return $chan;
}
if (!$chan) {
return PEAR::raiseError("Exception: corrupt registry, could not " .
"retrieve channel " . $param['channel'] . " information",
'registry', null, null, $param);
}
$param['channel'] = $chan->getName();
$validate = $chan->getValidationObject();
$vpackage = $chan->getValidationPackage();
// validate package name
if (!$validate->validPackageName($param['package'], $vpackage['_content'])) {
return PEAR::raiseError('parsePackageName(): invalid package name "' .
$param['package'] . '" in "' . $saveparam . '"',
'package', null, null, $param);
}
if (isset($param['group'])) {
if (!PEAR_Validate::validGroupName($param['group'])) {
return PEAR::raiseError('parsePackageName(): dependency group "' . $param['group'] .
'" is not a valid group name in "' . $saveparam . '"', 'group', null, null,
$param);
}
}
if (isset($param['state'])) {
if (!in_array(strtolower($param['state']), $validate->getValidStates())) {
return PEAR::raiseError('parsePackageName(): state "' . $param['state']
. '" is not a valid state in "' . $saveparam . '"',
'state', null, null, $param);
}
}
if (isset($param['version'])) {
if (isset($param['state'])) {
return PEAR::raiseError('parsePackageName(): cannot contain both ' .
'a version and a stability (state) in "' . $saveparam . '"',
'version/state', null, null, $param);
}
// check whether version is actually a state
if (in_array(strtolower($param['version']), $validate->getValidStates())) {
$param['state'] = strtolower($param['version']);
unset($param['version']);
} else {
if (!$validate->validVersion($param['version'])) {
return PEAR::raiseError('parsePackageName(): "' . $param['version'] .
'" is neither a valid version nor a valid state in "' .
$saveparam . '"', 'version/state', null, null, $param);
}
}
}
return $param;
}
/**
* @param array
* @return string
*/
function parsedPackageNameToString($parsed, $brief = false)
{
if (is_string($parsed)) {
return $parsed;
}
if (is_object($parsed)) {
$p = $parsed;
$parsed = array(
'package' => $p->getPackage(),
'channel' => $p->getChannel(),
'version' => $p->getVersion(),
);
}
if (isset($parsed['uri'])) {
return $parsed['uri'];
}
if ($brief) {
if ($channel = $this->channelAlias($parsed['channel'])) {
return $channel . '/' . $parsed['package'];
}
}
$upass = '';
if (isset($parsed['user'])) {
$upass = $parsed['user'];
if (isset($parsed['pass'])) {
$upass .= ':' . $parsed['pass'];
}
$upass = "$upass@";
}
$ret = 'channel://' . $upass . $parsed['channel'] . '/' . $parsed['package'];
if (isset($parsed['version']) || isset($parsed['state'])) {
$ver = isset($parsed['version']) ? $parsed['version'] : '';
$ver .= isset($parsed['state']) ? $parsed['state'] : '';
$ret .= '-' . $ver;
}
if (isset($parsed['extension'])) {
$ret .= '.' . $parsed['extension'];
}
if (isset($parsed['opts'])) {
$ret .= '?';
foreach ($parsed['opts'] as $name => $value) {
$parsed['opts'][$name] = "$name=$value";
}
$ret .= implode('&', $parsed['opts']);
}
if (isset($parsed['group'])) {
$ret .= '#' . $parsed['group'];
}
return $ret;
}
}
opt/cpanel/ea-php56/root/usr/share/pear/PEAR/Registry.php 0000644 00000224270 14756556064 0017063 0 ustar 00
* @author Tomas V. V. Cox
* @author Greg Beaver
* @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
*/
/**
* for PEAR_Error
*/
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_CHANNEL_FILE', -6);
/**
* Administration class used to maintain the installed package database.
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Tomas V. V. Cox
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_Registry extends PEAR
{
/**
* File containing all channel information.
* @var string
*/
var $channels = '';
/** Directory where registry files are stored.
* @var string
*/
var $statedir = '';
/** File where the file map is stored
* @var string
*/
var $filemap = '';
/** Directory where registry files for channels are stored.
* @var string
*/
var $channelsdir = '';
/** Name of file used for locking the registry
* @var string
*/
var $lockfile = '';
/** File descriptor used during locking
* @var resource
*/
var $lock_fp = null;
/** Mode used during locking
* @var int
*/
var $lock_mode = 0; // XXX UNUSED
/** Cache of package information. Structure:
* array(
* 'package' => array('id' => ... ),
* ... )
* @var array
*/
var $pkginfo_cache = array();
/** Cache of file map. Structure:
* array( '/path/to/file' => 'package', ... )
* @var array
*/
var $filemap_cache = array();
/**
* @var false|PEAR_ChannelFile
*/
var $_pearChannel;
/**
* @var false|PEAR_ChannelFile
*/
var $_peclChannel;
/**
* @var false|PEAR_ChannelFile
*/
var $_docChannel;
/**
* @var PEAR_DependencyDB
*/
var $_dependencyDB;
/**
* @var PEAR_Config
*/
var $_config;
/**
* PEAR_Registry constructor.
*
* @param string (optional) PEAR install directory (for .php files)
* @param PEAR_ChannelFile PEAR_ChannelFile object representing the PEAR channel, if
* default values are not desired. Only used the very first time a PEAR
* repository is initialized
* @param PEAR_ChannelFile PEAR_ChannelFile object representing the PECL channel, if
* default values are not desired. Only used the very first time a PEAR
* repository is initialized
*
* @access public
*/
function __construct($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
$pecl_channel = false, $pear_metadata_dir = '')
{
parent::__construct();
$this->setInstallDir($pear_install_dir, $pear_metadata_dir);
$this->_pearChannel = $pear_channel;
$this->_peclChannel = $pecl_channel;
$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 != '.') {
$olddir = $dir;
$dir = dirname($dir);
if ($dir != '.' && file_exists($dir)) {
if (is_writeable($dir)) {
return true;
}
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, $resetInstallDir = true)
{
$this->_config = &$config;
if ($resetInstallDir) {
$this->setInstallDir($config->get('php_dir'), $config->get('metadata_dir'));
}
}
function _initializeChannelDirs()
{
static $running = false;
if (!$running) {
$running = true;
$ds = DIRECTORY_SEPARATOR;
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;
if (!is_a($pear_channel, 'PEAR_ChannelFile') || !$pear_channel->validate()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setAlias('pear');
$pear_channel->setServer('pear.php.net');
$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/');
//$pear_channel->setBaseURL('REST1.4', 'http://pear.php.net/rest/');
} else {
$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()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$pecl_channel = new PEAR_ChannelFile;
$pecl_channel->setAlias('pecl');
$pecl_channel->setServer('pecl.php.net');
$pecl_channel->setSummary('PHP Extension Community Library');
$pecl_channel->setDefaultPEARProtocols();
$pecl_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
$pecl_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$pecl_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
} else {
$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->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
$this->_addChannel($private);
}
$this->_rebuildFileMap();
}
$running = false;
}
}
function _initializeDirs()
{
$ds = DIRECTORY_SEPARATOR;
// XXX Compatibility code should be removed in the future
// rename all registry files if any to lowercase
if (!OS_WINDOWS && file_exists($this->statedir) && is_dir($this->statedir) &&
$handle = opendir($this->statedir)) {
$dest = $this->statedir . $ds;
while (false !== ($file = readdir($handle))) {
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();
}
$this->_initializeDepDB();
}
function _initializeDepDB()
{
if (!isset($this->_dependencyDB)) {
static $initializing = false;
if (!$initializing) {
$initializing = true;
if (!$this->_config) { // never used?
$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('metadata_dir', null, 'pear.php.net') .
DIRECTORY_SEPARATOR . '.depdb')) {
@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();
echo 'Unrecoverable error';
exit(1);
}
}
$initializing = false;
}
}
}
/**
* PEAR_Registry destructor. Makes sure no locks are forgotten.
*
* @access private
*/
function _PEAR_Registry()
{
parent::_PEAR();
if (is_resource($this->lock_fp)) {
$this->_unlock();
}
}
/**
* Make sure the directory where we keep registry files exists.
*
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertStateDir($channel = false)
{
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}'");
}
$init = true;
} elseif (!is_dir($this->statedir)) {
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;
}
} elseif (!is_dir($this->channelsdir)) {
return $this->raiseError('Cannot create directory ' . $this->channelsdir . ', ' .
'it already exists and is not a directory');
}
if ($init) {
static $running = false;
if (!$running) {
$running = true;
$this->_initializeDirs();
$running = false;
$init = false;
}
} else {
$this->_initializeDepDB();
}
return true;
}
/**
* Make sure the directory where we keep registry files exists for a non-standard channel.
*
* @param string channel name
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertChannelStateDir($channel)
{
$ds = DIRECTORY_SEPARATOR;
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
$this->_initializeChannelDirs();
}
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 .
"'");
}
} elseif (!is_dir($channelDir)) {
return $this->raiseError("could not create directory '" . $channelDir .
"', already exists and is not a directory");
}
return true;
}
/**
* Make sure the directory where we keep registry files for channels exists
*
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertChannelDir()
{
if (!file_exists($this->channelsdir)) {
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}'");
}
} 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'");
}
} 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;
}
/**
* Get the name of the file where data for a given package is stored.
*
* @param string channel name, or false if this is a PEAR package
* @param string package name
*
* @return string registry file name
*
* @access public
*/
function _packageFileName($package, $channel = false)
{
if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
return $this->_channelDirectoryName($channel) . DIRECTORY_SEPARATOR .
strtolower($package) . '.reg';
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower($package) . '.reg';
}
/**
* Get the name of the file where data for a given channel is stored.
* @param string channel name
* @return string registry file name
*/
function _channelFileName($channel, $noaliases = false)
{
if (!$noaliases) {
if (file_exists($this->_getChannelAliasFileName($channel))) {
$channel = implode('', file($this->_getChannelAliasFileName($channel)));
}
}
return $this->channelsdir . DIRECTORY_SEPARATOR . str_replace('/', '_',
strtolower($channel)) . '.reg';
}
/**
* @param string
* @return string
*/
function _getChannelAliasFileName($alias)
{
return $this->channelsdir . DIRECTORY_SEPARATOR . '.alias' .
DIRECTORY_SEPARATOR . str_replace('/', '_', strtolower($alias)) . '.txt';
}
/**
* Get the name of a channel from its alias
*/
function _getChannelFromAlias($channel)
{
if (!$this->_channelExists($channel)) {
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)));
}
return $channel;
}
/**
* Get the alias of a channel from its alias or its name
*/
function _getAlias($channel)
{
if (!$this->_channelExists($channel)) {
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();
}
/**
* Get the name of the file where data for a given package is stored.
*
* @param string channel name, or false if this is a PEAR package
* @param string package name
*
* @return string registry file name
*
* @access public
*/
function _channelDirectoryName($channel)
{
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
return $this->statedir;
}
$ch = $this->_getChannelFromAlias($channel);
if (!$ch) {
$ch = $channel;
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
str_replace('/', '_', $ch));
}
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;
}
function _closePackageFile($fp)
{
fclose($fp);
}
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;
}
function _closeChannelFile($fp)
{
fclose($fp);
}
function _rebuildFileMap()
{
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$channels = $this->_listAllPackages();
$files = array();
foreach ($channels as $channel => $packages) {
foreach ($packages as $package) {
$version = $this->_packageInfo($package, 'version', $channel);
$filelist = $this->_packageInfo($package, 'filelist', $channel);
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 (!isset($files[$attrs['role']])) {
$files[$attrs['role']] = array();
}
$files[$attrs['role']][$file] = strtolower($package);
}
}
}
}
$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);
return true;
}
function _readFileMap()
{
if (!file_exists($this->filemap)) {
return array();
}
$fp = @fopen($this->filemap, 'r');
if (!$fp) {
$last_errormsg = '';
$last_error = error_get_last();
if (!empty($last_error['message'])) {
$last_errormsg = $last_error['message'];
}
return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $last_errormsg);
}
clearstatcache();
$fsize = filesize($this->filemap);
fclose($fp);
$data = file_get_contents($this->filemap);
$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 the registry.
*
* @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.
* See flock manual for more information.
*
* @return bool TRUE on success, FALSE if locking failed, or a
* PEAR error if some other error occurs (such as the
* lock file not being writable).
*
* @access private
*/
function _lock($mode = LOCK_EX)
{
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');
}
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 = 'r';
}
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;
}
//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;
}
function _unlock()
{
$ret = $this->_lock(LOCK_UN);
if (is_resource($this->lock_fp)) {
fclose($this->lock_fp);
}
$this->lock_fp = null;
return $ret;
}
function _packageExists($package, $channel = false)
{
return file_exists($this->_packageFileName($package, $channel));
}
/**
* Determine whether a channel exists in the registry
*
* @param string Channel name
* @param bool if true, then aliases will be ignored
* @return boolean
*/
function _channelExists($channel, $noaliases = false)
{
$a = file_exists($this->_channelFileName($channel, $noaliases));
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;
}
/**
* Determine whether a mirror exists within the default 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
* @param string Last-Modified HTTP tag from remote request
* @return boolean|PEAR_Error True on creation, false if it already exists
*/
function _addChannel($channel, $update = false, $lastmodified = false)
{
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()));
}
}
} else {
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;
} else {
$info['_lastmodified'] = self::getSourceDateEpoch();
}
fwrite($fp, serialize($info));
fclose($fp);
return true;
}
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
* @return boolean|PEAR_Error True on deletion, false if it doesn't exist
*/
function _deleteChannel($channel)
{
if (!is_string($channel)) {
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);
if (!$test) {
return false;
}
}
$file = $this->_channelFileName($channel);
$ret = true;
if (file_exists($file)) {
$ret = @unlink($file);
}
return $ret;
}
/**
* Determine whether a channel exists in the registry
* @param string Channel Alias
* @return boolean
*/
function _isChannelAlias($alias)
{
return file_exists($this->_getChannelAliasFileName($alias));
}
/**
* @param string|null
* @param string|null
* @param string|null
* @return array|null
* @access private
*/
function _packageInfo($package = null, $key = null, $channel = 'pear.php.net')
{
if ($package === null) {
if ($channel === null) {
$channels = $this->_listChannels();
$ret = array();
foreach ($channels as $channel) {
$channel = strtolower($channel);
$ret[$channel] = array();
$packages = $this->_listPackages($channel);
foreach ($packages as $package) {
$ret[$channel][] = $this->_packageInfo($package, null, $channel);
}
}
return $ret;
}
$ps = $this->_listPackages($channel);
if (!count($ps)) {
return array();
}
return array_map(array(&$this, '_packageInfo'),
$ps, array_fill(0, count($ps), null),
array_fill(0, count($ps), $channel));
}
$fp = $this->_openPackageFile($package, 'r', $channel);
if ($fp === null) {
return null;
}
clearstatcache();
$this->_closePackageFile($fp);
$data = file_get_contents($this->_packageFileName($package, $channel));
$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;
}
/**
* @param string Channel name
* @param bool whether to strictly retrieve info of channels, not just aliases
* @return array|null
*/
function _channelInfo($channel, $noaliases = false)
{
if (!$this->_channelExists($channel, $noaliases)) {
return null;
}
$fp = $this->_openChannelFile($channel, 'r');
if ($fp === null) {
return null;
}
clearstatcache();
$this->_closeChannelFile($fp);
$data = file_get_contents($this->_channelFileName($channel));
$data = unserialize($data);
return $data;
}
function _listChannels()
{
$channellist = array();
if (!file_exists($this->channelsdir) || !is_dir($this->channelsdir)) {
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;
}
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);
sort($pkglist);
return $pkglist;
}
function _listChannelPackages($channel)
{
$pkglist = array();
if (!file_exists($this->_channelDirectoryName($channel)) ||
!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;
}
$pkglist[] = substr($ent, 0, -4);
}
closedir($dp);
return $pkglist;
}
function _listAllPackages()
{
$ret = array();
foreach ($this->_listChannels() as $channel) {
$ret[$channel] = $this->_listPackages($channel);
}
return $ret;
}
/**
* Add an installed package to the registry
* @param string package name
* @param array package info (parsed by PEAR_Common::infoFrom*() methods)
* @return bool success of saving
* @access private
*/
function _addPackage($package, $info)
{
if ($this->_packageExists($package)) {
return false;
}
$fp = $this->_openPackageFile($package, 'wb');
if ($fp === null) {
return false;
}
$info['_lastmodified'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($info['filelist'])) {
$this->_rebuildFileMap();
}
return true;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @return bool
* @access private
*/
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();
if ($ui) {
foreach ($info->getValidationWarnings() as $err) {
$ui->log($err['message'], true);
}
}
}
return false;
}
$channel = $info->getChannel();
$package = $info->getPackage();
$save = $info;
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'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
$this->_rebuildFileMap();
return true;
}
/**
* @param string Package name
* @param array parsed package.xml 1.0
* @param bool this parameter is only here for BC. Don't use it.
* @access private
*/
function _updatePackage($package, $info, $merge = true)
{
$oldinfo = $this->_packageInfo($package);
if (empty($oldinfo)) {
return false;
}
$fp = $this->_openPackageFile($package, 'w');
if ($fp === null) {
return false;
}
if (is_object($info)) {
$info = $info->toArray();
}
$info['_lastmodified'] = self::getSourceDateEpoch();
$newinfo = $info;
if ($merge) {
$info = array_merge($oldinfo, $info);
} else {
$diff = $info;
}
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($newinfo['filelist'])) {
$this->_rebuildFileMap();
}
return true;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @return bool
* @access private
*/
function _updatePackage2($info)
{
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'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
$this->_rebuildFileMap();
return true;
}
/**
* @param string Package name
* @param string Channel name
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
* @access private
*/
function &_getPackage($package, $channel = 'pear.php.net')
{
$info = $this->_packageInfo($package, null, $channel);
if ($info === null) {
return $info;
}
$a = $this->_config;
if (!$a) {
$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);
$pf = &$pkg->fromArray($info);
return $pf;
}
/**
* @param string channel name
* @param bool whether to strictly retrieve channel names
* @return PEAR_ChannelFile|PEAR_Error
* @access private
*/
function &_getChannel($channel, $noaliases = false)
{
$ch = false;
if ($this->_channelExists($channel, $noaliases)) {
$chinfo = $this->_channelInfo($channel, $noaliases);
if ($chinfo) {
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->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')) {
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setServer('pecl.php.net');
$pear_channel->setAlias('pecl');
$pear_channel->setSummary('PHP Extension Community Library');
$pear_channel->setDefaultPEARProtocols();
$pear_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
$pear_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$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->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
return $private;
}
return $ch;
}
/**
* @param string Package name
* @param string Channel name
* @return bool
*/
function packageExists($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_packageExists($package, $channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ channelExists()
/**
* @param string channel name
* @param bool if true, then aliases will be ignored
* @return bool
*/
function channelExists($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_channelExists($channel, $noaliases);
$this->_unlock();
return $ret;
}
// }}}
/**
* @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()
/**
* Determines whether the parameter is an alias of a channel
* @param string
* @return bool
*/
function isAlias($alias)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_isChannelAlias($alias);
$this->_unlock();
return $ret;
}
// }}}
// {{{ packageInfo()
/**
* @param string|null
* @param string|null
* @param string
* @return array|null
*/
function packageInfo($package = null, $key = null, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_packageInfo($package, $key, $channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ channelInfo()
/**
* Retrieve a raw array of channel data.
*
* Do not use this, instead use {@link getChannel()} for normal
* operations. Array structure is undefined in this method
* @param string channel name
* @param bool whether to strictly retrieve information only on non-aliases
* @return array|null|PEAR_Error
*/
function channelInfo($channel = null, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_channelInfo($channel, $noaliases);
$this->_unlock();
return $ret;
}
// }}}
/**
* @param string
*/
function channelName($channel)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getChannelFromAlias($channel);
$this->_unlock();
return $ret;
}
/**
* @param string
*/
function channelAlias($channel)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getAlias($channel);
$this->_unlock();
return $ret;
}
// {{{ listPackages()
function listPackages($channel = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listPackages($channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ listAllPackages()
function listAllPackages()
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listAllPackages();
$this->_unlock();
return $ret;
}
// }}}
// {{{ listChannel()
function listChannels()
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listChannels();
$this->_unlock();
return $ret;
}
// }}}
// {{{ addPackage()
/**
* Add an installed package to the registry
* @param string|PEAR_PackageFile_v1|PEAR_PackageFile_v2 package name or object
* that will be passed to {@link addPackage2()}
* @param array package info (parsed by PEAR_Common::infoFrom*() methods)
* @return bool success of saving
*/
function addPackage($package, $info)
{
if (is_object($info)) {
return $this->addPackage2($info);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_addPackage($package, $info);
$this->_unlock();
if ($ret) {
if (!class_exists('PEAR_PackageFile_v1')) {
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->_config);
$pf->fromArray($info);
$this->_dependencyDB->uninstallPackage($pf);
$this->_dependencyDB->installPackage($pf);
}
return $ret;
}
// }}}
// {{{ addPackage2()
function addPackage2($info)
{
if (!is_object($info)) {
return $this->addPackage($info['package'], $info);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_addPackage2($info);
$this->_unlock();
if ($ret) {
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
return $ret;
}
// }}}
// {{{ updateChannel()
/**
* For future expandibility purposes, separate this
* @param PEAR_ChannelFile
*/
function updateChannel($channel, $lastmodified = null)
{
if ($channel->getName() == '__uri') {
return false;
}
return $this->addChannel($channel, $lastmodified, true);
}
// }}}
// {{{ deleteChannel()
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
* @return boolean|PEAR_Error True on deletion, false if it doesn't exist
*/
function deleteChannel($channel)
{
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;
}
// }}}
// {{{ addChannel()
/**
* @param PEAR_ChannelFile Channel object
* @param string Last-Modified header from HTTP for caching
* @return boolean|PEAR_Error True on creation, false if it already exists
*/
function addChannel($channel, $lastmodified = false, $update = false)
{
if (!is_a($channel, 'PEAR_ChannelFile') || !$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;
}
// }}}
// {{{ deletePackage()
function deletePackage($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$file = $this->_packageFileName($package, $channel);
$ret = file_exists($file) ? @unlink($file) : false;
$this->_rebuildFileMap();
$this->_unlock();
$p = array('channel' => $channel, 'package' => $package);
$this->_dependencyDB->uninstallPackage($p);
return $ret;
}
// }}}
// {{{ updatePackage()
function updatePackage($package, $info, $merge = true)
{
if (is_object($info)) {
return $this->updatePackage2($info, $merge);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_updatePackage($package, $info, $merge);
$this->_unlock();
if ($ret) {
if (!class_exists('PEAR_PackageFile_v1')) {
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->_config);
$pf->fromArray($this->packageInfo($package));
$this->_dependencyDB->uninstallPackage($pf);
$this->_dependencyDB->installPackage($pf);
}
return $ret;
}
// }}}
// {{{ updatePackage2()
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) {
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
return $ret;
}
// }}}
// {{{ getChannel()
/**
* @param string channel name
* @param bool whether to strictly return raw channels (no aliases)
* @return PEAR_ChannelFile|PEAR_Error
*/
function getChannel($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getChannel($channel, $noaliases);
$this->_unlock();
if (!$ret) {
return PEAR::raiseError('Unknown channel: ' . $channel);
}
return $ret;
}
// }}}
// {{{ getPackage()
/**
* @param string package name
* @param string channel name
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
*/
function &getPackage($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$pf = &$this->_getPackage($package, $channel);
$this->_unlock();
return $pf;
}
// }}}
/**
* Get PEAR_PackageFile_v[1/2] objects representing the contents of
* a dependency group that are installed.
*
* This is used at uninstall-time
* @param array
* @return array|false
*/
function getInstalledGroup($group)
{
$ret = array();
if (isset($group['package'])) {
if (!isset($group['package'][0])) {
$group['package'] = array($group['package']);
}
foreach ($group['package'] as $package) {
$depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
$p = &$this->getPackage($package['name'], $depchannel);
if ($p) {
$save = &$p;
$ret[] = &$save;
}
}
}
if (isset($group['subpackage'])) {
if (!isset($group['subpackage'][0])) {
$group['subpackage'] = array($group['subpackage']);
}
foreach ($group['subpackage'] as $package) {
$depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
$p = &$this->getPackage($package['name'], $depchannel);
if ($p) {
$save = &$p;
$ret[] = &$save;
}
}
}
if (!count($ret)) {
return false;
}
return $ret;
}
// {{{ getChannelValidator()
/**
* @param string channel name
* @return PEAR_Validate|false
*/
function &getChannelValidator($channel)
{
$chan = $this->getChannel($channel);
if (PEAR::isError($chan)) {
return $chan;
}
$val = $chan->getValidationObject();
return $val;
}
// }}}
// {{{ getChannels()
/**
* @param string channel name
* @return array an array of PEAR_ChannelFile objects representing every installed channel
*/
function &getChannels()
{
$ret = array();
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
foreach ($this->_listChannels() as $channel) {
$e = &$this->_getChannel($channel);
if (!$e || PEAR::isError($e)) {
continue;
}
$ret[] = $e;
}
$this->_unlock();
return $ret;
}
// }}}
// {{{ checkFileMap()
/**
* Test whether a file or set of files belongs to a package.
*
* If an array is passed in
* @param string|array file path, absolute or relative to the pear
* install dir
* @param string|array name of PEAR package or array('package' => name, 'channel' =>
* channel) of a package that will be ignored
* @param string API version - 1.1 will exclude any files belonging to a package
* @param array private recursion variable
* @return array|false which package and channel the file belongs to, or an empty
* string if the file does not belong to an installed package,
* or belongs to the second parameter's package
*/
function checkFileMap($path, $package = false, $api = '1.0', $attrs = false)
{
if (is_array($path)) {
static $notempty;
if (empty($notempty)) {
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$notempty = function($a) { return !empty($a); };
}
$package = is_array($package) ? array(strtolower($package[0]), strtolower($package[1]))
: strtolower($package);
$pkgs = array();
foreach ($path as $name => $attrs) {
if (is_array($attrs)) {
if (isset($attrs['install-as'])) {
$name = $attrs['install-as'];
}
if (!in_array($attrs['role'], PEAR_Installer_Role::getInstallableRoles())) {
// these are not installed
continue;
}
if (!in_array($attrs['role'], PEAR_Installer_Role::getBaseinstallRoles())) {
$attrs['baseinstalldir'] = is_array($package) ? $package[1] : $package;
}
if (isset($attrs['baseinstalldir'])) {
$name = $attrs['baseinstalldir'] . DIRECTORY_SEPARATOR . $name;
}
}
$pkgs[$name] = $this->checkFileMap($name, $package, $api, $attrs);
if (PEAR::isError($pkgs[$name])) {
return $pkgs[$name];
}
}
return array_filter($pkgs, $notempty);
}
if (empty($this->filemap_cache)) {
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$err = $this->_readFileMap();
$this->_unlock();
if (PEAR::isError($err)) {
return $err;
}
}
if (!$attrs) {
$attrs = array('role' => 'php'); // any old call would be for PHP role only
}
if (isset($this->filemap_cache[$attrs['role']][$path])) {
if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
return false;
}
return $this->filemap_cache[$attrs['role']][$path];
}
$l = strlen($this->install_dir);
if (substr($path, 0, $l) == $this->install_dir) {
$path = preg_replace('!^'.DIRECTORY_SEPARATOR.'+!', '', substr($path, $l));
}
if (isset($this->filemap_cache[$attrs['role']][$path])) {
if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
return false;
}
return $this->filemap_cache[$attrs['role']][$path];
}
return false;
}
// }}}
// {{{ flush()
/**
* Force a reload of the filemap
* @since 1.5.0RC3
*/
function flushFileMap()
{
$this->filemap_cache = null;
clearstatcache(); // ensure that the next read gets the full, current filemap
}
// }}}
// {{{ apiVersion()
/**
* Get the expected API version. Channels API is version 1.1, as it is backwards
* compatible with 1.0
* @return string
*/
function apiVersion()
{
return '1.1';
}
// }}}
/**
* Parse a package name, or validate a parsed package name array
* @param string|array pass in an array of format
* array(
* 'package' => 'pname',
* ['channel' => 'channame',]
* ['version' => 'version',]
* ['state' => 'state',]
* ['group' => 'groupname'])
* or a string of format
* [channel://][channame/]pname[-version|-state][/group=groupname]
* @return array|PEAR_Error
*/
function parsePackageName($param, $defaultchannel = 'pear.php.net')
{
$saveparam = $param;
if (is_array($param)) {
// convert to string for error messages
$saveparam = $this->parsedPackageNameToString($param);
// process the array
if (!isset($param['package'])) {
return PEAR::raiseError('parsePackageName(): array $param ' .
'must contain a valid package name in index "param"',
'package', null, null, $param);
}
if (!isset($param['uri'])) {
if (!isset($param['channel'])) {
$param['channel'] = $defaultchannel;
}
} else {
$param['channel'] = '__uri';
}
} else {
$components = @parse_url((string) $param);
if (isset($components['scheme'])) {
if ($components['scheme'] == 'http') {
// uri package
$param = array('uri' => $param, 'channel' => '__uri');
} elseif($components['scheme'] != 'channel') {
return PEAR::raiseError('parsePackageName(): only channel:// uris may ' .
'be downloaded, not "' . $param . '"', 'invalid', null, null, $param);
}
}
if (!isset($components['path'])) {
return PEAR::raiseError('parsePackageName(): array $param ' .
'must contain a valid package name in "' . $param . '"',
'package', null, null, $param);
}
if (isset($components['host'])) {
// remove the leading "/"
$components['path'] = substr($components['path'], 1);
}
if (!isset($components['scheme'])) {
if (strpos($components['path'], '/') !== false) {
if ($components['path'][0] == '/') {
return PEAR::raiseError('parsePackageName(): this is not ' .
'a package name, it begins with "/" in "' . $param . '"',
'invalid', null, null, $param);
}
$parts = explode('/', $components['path']);
$components['host'] = array_shift($parts);
if (count($parts) > 1) {
$components['path'] = array_pop($parts);
$components['host'] .= '/' . implode('/', $parts);
} else {
$components['path'] = implode('/', $parts);
}
} else {
$components['host'] = $defaultchannel;
}
} else {
if (strpos($components['path'], '/')) {
$parts = explode('/', $components['path']);
$components['path'] = array_pop($parts);
$components['host'] .= '/' . implode('/', $parts);
}
}
if (is_array($param)) {
$param['package'] = $components['path'];
} else {
$param = array(
'package' => $components['path']
);
if (isset($components['host'])) {
$param['channel'] = $components['host'];
}
}
if (isset($components['fragment'])) {
$param['group'] = $components['fragment'];
}
if (isset($components['user'])) {
$param['user'] = $components['user'];
}
if (isset($components['pass'])) {
$param['pass'] = $components['pass'];
}
if (isset($components['query'])) {
parse_str($components['query'], $param['opts']);
}
// check for extension
$pathinfo = pathinfo($param['package']);
if (isset($pathinfo['extension']) &&
in_array(strtolower($pathinfo['extension']), array('tgz', 'tar'))) {
$param['extension'] = $pathinfo['extension'];
$param['package'] = substr($pathinfo['basename'], 0,
strlen($pathinfo['basename']) - 4);
}
// check for version
if (strpos($param['package'], '-')) {
$test = explode('-', $param['package']);
if (count($test) != 2) {
return PEAR::raiseError('parsePackageName(): only one version/state ' .
'delimiter "-" is allowed in "' . $saveparam . '"',
'version', null, null, $param);
}
list($param['package'], $param['version']) = $test;
}
}
// validation
$info = $this->channelExists($param['channel']);
if (PEAR::isError($info)) {
return $info;
}
if (!$info) {
return PEAR::raiseError('unknown channel "' . $param['channel'] .
'" in "' . $saveparam . '"', 'channel', null, null, $param);
}
$chan = $this->getChannel($param['channel']);
if (PEAR::isError($chan)) {
return $chan;
}
if (!$chan) {
return PEAR::raiseError("Exception: corrupt registry, could not " .
"retrieve channel " . $param['channel'] . " information",
'registry', null, null, $param);
}
$param['channel'] = $chan->getName();
$validate = $chan->getValidationObject();
$vpackage = $chan->getValidationPackage();
// validate package name
if (!$validate->validPackageName($param['package'], $vpackage['_content'])) {
return PEAR::raiseError('parsePackageName(): invalid package name "' .
$param['package'] . '" in "' . $saveparam . '"',
'package', null, null, $param);
}
if (isset($param['group'])) {
if (!PEAR_Validate::validGroupName($param['group'])) {
return PEAR::raiseError('parsePackageName(): dependency group "' . $param['group'] .
'" is not a valid group name in "' . $saveparam . '"', 'group', null, null,
$param);
}
}
if (isset($param['state'])) {
if (!in_array(strtolower($param['state']), $validate->getValidStates())) {
return PEAR::raiseError('parsePackageName(): state "' . $param['state']
. '" is not a valid state in "' . $saveparam . '"',
'state', null, null, $param);
}
}
if (isset($param['version'])) {
if (isset($param['state'])) {
return PEAR::raiseError('parsePackageName(): cannot contain both ' .
'a version and a stability (state) in "' . $saveparam . '"',
'version/state', null, null, $param);
}
// check whether version is actually a state
if (in_array(strtolower($param['version']), $validate->getValidStates())) {
$param['state'] = strtolower($param['version']);
unset($param['version']);
} else {
if (!$validate->validVersion($param['version'])) {
return PEAR::raiseError('parsePackageName(): "' . $param['version'] .
'" is neither a valid version nor a valid state in "' .
$saveparam . '"', 'version/state', null, null, $param);
}
}
}
return $param;
}
/**
* @param array
* @return string
*/
function parsedPackageNameToString($parsed, $brief = false)
{
if (is_string($parsed)) {
return $parsed;
}
if (is_object($parsed)) {
$p = $parsed;
$parsed = array(
'package' => $p->getPackage(),
'channel' => $p->getChannel(),
'version' => $p->getVersion(),
);
}
if (isset($parsed['uri'])) {
return $parsed['uri'];
}
if ($brief) {
if ($channel = $this->channelAlias($parsed['channel'])) {
return $channel . '/' . $parsed['package'];
}
}
$upass = '';
if (isset($parsed['user'])) {
$upass = $parsed['user'];
if (isset($parsed['pass'])) {
$upass .= ':' . $parsed['pass'];
}
$upass = "$upass@";
}
$ret = 'channel://' . $upass . $parsed['channel'] . '/' . $parsed['package'];
if (isset($parsed['version']) || isset($parsed['state'])) {
$ver = isset($parsed['version']) ? $parsed['version'] : '';
$ver .= isset($parsed['state']) ? $parsed['state'] : '';
$ret .= '-' . $ver;
}
if (isset($parsed['extension'])) {
$ret .= '.' . $parsed['extension'];
}
if (isset($parsed['opts'])) {
$ret .= '?';
foreach ($parsed['opts'] as $name => $value) {
$parsed['opts'][$name] = "$name=$value";
}
$ret .= implode('&', $parsed['opts']);
}
if (isset($parsed['group'])) {
$ret .= '#' . $parsed['group'];
}
return $ret;
}
}
opt/cpanel/ea-php71/root/usr/share/pear/PEAR/Command/Registry.php 0000644 00000132315 14756606516 0020432 0 ustar 00
* @author Greg Beaver
* @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/Command/Common.php';
/**
* PEAR commands for registry manipulation
*
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Registry extends PEAR_Command_Common
{
var $commands = array(
'list' => array(
'summary' => 'List Installed Packages In The Default Channel',
'function' => 'doList',
'shortcut' => 'l',
'options' => array(
'channel' => array(
'shortopt' => 'c',
'doc' => 'list installed packages from this channel',
'arg' => 'CHAN',
),
'allchannels' => array(
'shortopt' => 'a',
'doc' => 'list installed packages from all channels',
),
'channelinfo' => array(
'shortopt' => 'i',
'doc' => 'output fully channel-aware data, even on failure',
),
),
'doc' => '
If invoked without parameters, this command lists the PEAR packages
installed in your php_dir ({config php_dir}). With a parameter, it
lists the files in a package.
',
),
'list-files' => array(
'summary' => 'List Files In Installed Package',
'function' => 'doFileList',
'shortcut' => 'fl',
'options' => array(),
'doc' => '
List the files in an installed package.
'
),
'shell-test' => array(
'summary' => 'Shell Script Test',
'function' => 'doShellTest',
'shortcut' => 'st',
'options' => array(),
'doc' => ' [[relation] version]
Tests if a package is installed in the system. Will exit(1) if it is not.
The version comparison operator. One of:
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
The version to compare with
'),
'info' => array(
'summary' => 'Display information about a package',
'function' => 'doInfo',
'shortcut' => 'in',
'options' => array(),
'doc' => '
Displays information about a package. The package argument may be a
local package file, an URL to a package file, or the name of an
installed package.'
)
);
/**
* PEAR_Command_Registry constructor.
*
* @access public
*/
function __construct(&$ui, &$config)
{
parent::__construct($ui, $config);
}
function _sortinfo($a, $b)
{
$apackage = isset($a['package']) ? $a['package'] : $a['name'];
$bpackage = isset($b['package']) ? $b['package'] : $b['name'];
return strcmp($apackage, $bpackage);
}
function doList($command, $options, $params)
{
$reg = &$this->config->getRegistry();
$channelinfo = isset($options['channelinfo']);
if (isset($options['allchannels']) && !$channelinfo) {
return $this->doListAll($command, array(), $params);
}
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'])) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' .
$channel . ':',
'border' => true,
'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);
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) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Package', 'Version', 'State'),
'channel' => $channel
);
foreach ($packages as $package) {
$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);
}
// 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)'), array()),
'channel' => $channel
);
}
$this->ui->outputData($data, $command);
}
return true;
}
function doFileList($command, $options, $params)
{
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 ($fp) {
fclose($fp);
}
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$pkg = new PEAR_PackageFile($this->config, $this->_debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
$headings = array('Package File', 'Install Path');
$installed = false;
} else {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
PEAR::staticPopErrorHandling();
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) {
$caption = 'Installed Files For ' . $params[0];
} else {
$caption = 'Contents of ' . basename($params[0]);
}
$data = array(
'caption' => $caption,
'border' => true,
'headline' => $headings);
if ($info->getPackagexmlVersion() == '1.0' || $installed) {
foreach ($list as $file => $att) {
if ($installed) {
if (empty($att['installed_as'])) {
continue;
}
$data['data'][] = array($att['role'], $att['installed_as']);
} else {
if (isset($att['baseinstalldir']) && !in_array($att['role'],
array('test', 'data', 'doc'))) {
$dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
$file;
} else {
$dest = $file;
}
switch ($att['role']) {
case 'test':
case 'data':
case 'doc':
$role = $att['role'];
if ($role == 'test') {
$role .= 's';
}
$dest = $this->config->get($role . '_dir') . DIRECTORY_SEPARATOR .
$info->getPackage() . DIRECTORY_SEPARATOR . $dest;
break;
case 'php':
default:
$dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
$dest;
}
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
$dest = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
array(DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR),
$dest);
$file = preg_replace('!/+!', '/', $file);
$data['data'][] = array($file, $dest);
}
}
} else { // package.xml 2.0, not installed
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'];
$role = &PEAR_Installer_Role::factory($info, $att['role'], $this->config);
$role->setup($this, $info, $att, $file);
if (!$role->isInstallable()) {
$dest = '(not installable)';
} else {
$dest = $role->processInstallation($info, $att, $file, '');
if (PEAR::isError($dest)) {
$dest = '(Unknown role "' . $att['role'] . ')';
} else {
list(,, $dest) = $dest;
}
}
$data['data'][] = array($file, $dest);
}
}
$this->ui->outputData($data, $command);
return true;
}
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'));
if (PEAR::isError($info)) {
exit(1); // invalid package name
}
$package = $info['package'];
$channel = $info['channel'];
// "pear shell-test Foo"
if (!$reg->packageExists($package, $channel)) {
if ($channel == 'pecl.php.net') {
if ($reg->packageExists($package, 'pear.php.net')) {
$channel = 'pear.php.net'; // magically change channels for extensions
}
}
}
if (count($params) === 1) {
if (!$reg->packageExists($package, $channel)) {
exit(1);
}
// "pear shell-test Foo 1.0"
} 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 (count($params) === 3) {
$v = $reg->packageInfo($package, 'version', $channel);
if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
exit(1);
}
} else {
PEAR::staticPopErrorHandling();
$this->raiseError("$command: expects 1 to 3 parameters");
exit(1);
}
}
function doInfo($command, $options, $params)
{
if (count($params) !== 1) {
return $this->raiseError('pear info expects 1 parameter');
}
$info = $fp = false;
$reg = &$this->config->getRegistry();
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);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
if (PEAR::isError($obj)) {
$uinfo = $obj->getUserInfo();
if (is_array($uinfo)) {
foreach ($uinfo as $message) {
if (is_array($message)) {
$message = $message['message'];
}
$this->ui->outputData($message);
}
}
return $this->raiseError($obj);
}
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);
if (isset($info['old'])) {
$obj = $reg->getPackage($package, $channel);
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']);
if (isset($info['xsdversion'])) {
$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) {
if (is_array($info[$key])) {
switch ($key) {
case 'maintainers': {
$i = 0;
$mstr = '';
foreach ($info[$key] as $m) {
if ($i++ > 0) {
$mstr .= "\n";
}
$mstr .= $m['name'] . " <";
if (isset($m['email'])) {
$mstr .= $m['email'];
} else {
$mstr .= $m['handle'] . '@php.net';
}
$mstr .= "> ($m[role])";
}
$info[$key] = $mstr;
break;
}
case 'release_deps': {
$i = 0;
$dstr = '';
foreach ($info[$key] as $d) {
if (isset($this->_deps_rel_trans[$d['rel']])) {
$rel = $this->_deps_rel_trans[$d['rel']];
} else {
$rel = $d['rel'];
}
if (isset($this->_deps_type_trans[$d['type']])) {
$type = ucfirst($this->_deps_type_trans[$d['type']]);
} else {
$type = $d['type'];
}
if (isset($d['name'])) {
$name = $d['name'] . ' ';
} else {
$name = '';
}
if (isset($d['version'])) {
$version = $d['version'] . ' ';
} else {
$version = '';
}
if (isset($d['optional']) && $d['optional'] == 'yes') {
$optional = ' (optional)';
} else {
$optional = '';
}
$dstr .= "$type $name$rel $version$optional\n";
}
$info[$key] = $dstr;
break;
}
case 'provides' : {
$debug = $this->config->get('verbose');
if ($debug < 2) {
$pstr = 'Classes: ';
} else {
$pstr = '';
}
$i = 0;
foreach ($info[$key] as $p) {
if ($debug < 2 && $p['type'] != "class") {
continue;
}
// Only print classes when verbosity mode is < 2
if ($debug < 2) {
if ($i++ > 0) {
$pstr .= ", ";
}
$pstr .= $p['name'];
} else {
if ($i++ > 0) {
$pstr .= "\n";
}
$pstr .= ucfirst($p['type']) . " " . $p['name'];
if (isset($p['explicit']) && $p['explicit'] == 1) {
$pstr .= " (explicit)";
}
}
}
$info[$key] = $pstr;
break;
}
case 'configure_options' : {
foreach ($info[$key] as $i => $p) {
$info[$key][$i] = array_map(null, array_keys($p), array_values($p));
$info[$key][$i] = array_map(
function($a) { return join(" = ", $a); },
$info[$key][$i]);
$info[$key][$i] = implode(', ', $info[$key][$i]);
}
$info[$key] = implode("\n", $info[$key]);
break;
}
default: {
$info[$key] = implode(", ", $info[$key]);
break;
}
}
}
if ($key == '_lastmodified') {
$hdate = date('Y-m-d', $info[$key]);
unset($info[$key]);
$info['Last Modified'] = $hdate;
} elseif ($key == '_lastversion') {
$info['Previous Installed Version'] = $info[$key] ? $info[$key] : '- None -';
unset($info[$key]);
} else {
$info[$key] = trim($info[$key]);
if (in_array($key, $longtext)) {
$info[$key] = preg_replace('/ +/', ' ', $info[$key]);
}
}
}
$caption = 'About ' . $info['package'] . '-' . $info['version'];
$data = array(
'caption' => $caption,
'border' => true);
foreach ($info as $key => $value) {
$key = ucwords(trim(str_replace('_', ' ', $key)));
$data['data'][] = array($key, $value);
}
$data['raw'] = $info;
$this->ui->outputData($data, 'package-info');
}
/**
* @access private
*/
function _doInfo2($command, $options, $params, &$obj, $installed)
{
$reg = &$this->config->getRegistry();
$caption = 'About ' . $obj->getChannel() . '/' .$obj->getPackage() . '-' .
$obj->getVersion();
$data = array(
'caption' => $caption,
'border' => true);
switch ($obj->getPackageType()) {
case 'php' :
$release = 'PEAR-style PHP-based Package';
break;
case 'extsrc' :
$release = 'PECL-style PHP extension (source code)';
break;
case 'zendextsrc' :
$release = 'PECL-style Zend extension (source code)';
break;
case 'extbin' :
$release = 'PECL-style PHP extension (binary)';
break;
case 'zendextbin' :
$release = 'PECL-style Zend extension (binary)';
break;
case 'bundle' :
$release = 'Package bundle (collection of packages)';
break;
}
$extends = $obj->getExtends();
$extends = $extends ?
$obj->getPackage() . ' (extends ' . $extends . ')' : $obj->getPackage();
if ($src = $obj->getSourcePackage()) {
$extends .= ' (source package ' . $src['channel'] . '/' . $src['package'] . ')';
}
$info = array(
'Release Type' => $release,
'Name' => $extends,
'Channel' => $obj->getChannel(),
'Summary' => preg_replace('/ +/', ' ', $obj->getSummary()),
'Description' => preg_replace('/ +/', ' ', $obj->getDescription()),
);
$info['Maintainers'] = '';
foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
$leads = $obj->{"get{$role}s"}();
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$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();
$uri = $obj->getLicenseLocation();
if ($uri) {
if (isset($uri['uri'])) {
$info['License'] .= ' (' . $uri['uri'] . ')';
} else {
$extra = $obj->getInstalledLocation($info['filesource']);
if ($extra) {
$info['License'] .= ' (' . $uri['filesource'] . ')';
}
}
}
$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['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 {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= $package['channel'] . '/' .
$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";
} else {
$info['Uses Custom Roles'] = '';
}
if (isset($roledata['package'])) {
$rolepackage = $reg->parsedPackageNameToString($roledata, true);
} else {
$rolepackage = $roledata['uri'];
}
$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";
} else {
$info['Uses Custom Tasks'] = '';
}
if (isset($taskdata['package'])) {
$taskpackage = $reg->parsedPackageNameToString($taskdata, true);
} else {
$taskpackage = $taskdata['uri'];
}
$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'])) {
$info['Required Dependencies'] .= '-' . $deps['required']['php']['max'] . "\n";
} else {
$info['Required Dependencies'] .= "\n";
}
if (isset($deps['required']['php']['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['php']['exclude'])) {
$deps['required']['php']['exclude'] =
implode(', ', $deps['required']['php']['exclude']);
}
$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 ' .
$deps['required']['pearinstaller']['min'] . '-' .
$deps['required']['pearinstaller']['max'];
} else {
$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'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['pearinstaller']['exclude'])) {
$deps['required']['pearinstaller']['exclude'] =
implode(', ', $deps['required']['pearinstaller']['exclude']);
}
$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])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Required Dependencies';
$info[$infoindex] .= "\n";
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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 ';
}
$info['Not Compatible with'] .= 'Package ' .
$reg->parsedPackageNameToString($package, true);
$info['Not Compatible with'] .= "\n Versions " . $package['exclude'];
}
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "$os[name] Operating System";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "$os[name] Operating System";
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "OS/Arch matching pattern '/$os[pattern]/'";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "OS/Arch matching pattern '/$os[pattern]/'";
}
}
}
if (isset($deps['optional'])) {
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($deps['optional'][$index])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Optional Dependencies';
if (!isset($info['Optional Dependencies'])) {
$info['Optional Dependencies'] = '';
} else {
$info['Optional Dependencies'] .= "\n";
}
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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'];
}
}
}
}
}
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';
$info[$groupindex] = '';
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($group[$index])) {
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 {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$name = '__uri/' . $package['name'] . ' (static URI)';
}
}
if (isset($package['uri'])) {
if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
$info[$groupindex] .= "Not Compatible with $type $name";
} 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 " .
$package['min'] . '-' . $package['max'];
} elseif (isset($package['min'])) {
$info[$groupindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} else {
$info[$groupindex] .= "Not Compatible with\n";
}
if (is_array($package['exclude'])) {
$package['exclude'] = implode(', ', $package['exclude']);
}
$info[$groupindex] .= " Package $package\n Versions " .
$package['exclude'];
}
}
}
}
}
}
if ($obj->getPackageType() == 'bundle') {
$info['Bundled Packages'] = '';
foreach ($obj->getBundledPackages() as $package) {
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]";
} else {
$info['Bundled Packages'] .= $package['channel'] . '/' . $package['name'];
}
}
}
$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');
}
}
opt/cpanel/ea-php72/root/usr/share/pear/PEAR/Command/Registry.php 0000644 00000132315 14756617751 0020436 0 ustar 00
* @author Greg Beaver
* @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/Command/Common.php';
/**
* PEAR commands for registry manipulation
*
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Registry extends PEAR_Command_Common
{
var $commands = array(
'list' => array(
'summary' => 'List Installed Packages In The Default Channel',
'function' => 'doList',
'shortcut' => 'l',
'options' => array(
'channel' => array(
'shortopt' => 'c',
'doc' => 'list installed packages from this channel',
'arg' => 'CHAN',
),
'allchannels' => array(
'shortopt' => 'a',
'doc' => 'list installed packages from all channels',
),
'channelinfo' => array(
'shortopt' => 'i',
'doc' => 'output fully channel-aware data, even on failure',
),
),
'doc' => '
If invoked without parameters, this command lists the PEAR packages
installed in your php_dir ({config php_dir}). With a parameter, it
lists the files in a package.
',
),
'list-files' => array(
'summary' => 'List Files In Installed Package',
'function' => 'doFileList',
'shortcut' => 'fl',
'options' => array(),
'doc' => '
List the files in an installed package.
'
),
'shell-test' => array(
'summary' => 'Shell Script Test',
'function' => 'doShellTest',
'shortcut' => 'st',
'options' => array(),
'doc' => ' [[relation] version]
Tests if a package is installed in the system. Will exit(1) if it is not.
The version comparison operator. One of:
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
The version to compare with
'),
'info' => array(
'summary' => 'Display information about a package',
'function' => 'doInfo',
'shortcut' => 'in',
'options' => array(),
'doc' => '
Displays information about a package. The package argument may be a
local package file, an URL to a package file, or the name of an
installed package.'
)
);
/**
* PEAR_Command_Registry constructor.
*
* @access public
*/
function __construct(&$ui, &$config)
{
parent::__construct($ui, $config);
}
function _sortinfo($a, $b)
{
$apackage = isset($a['package']) ? $a['package'] : $a['name'];
$bpackage = isset($b['package']) ? $b['package'] : $b['name'];
return strcmp($apackage, $bpackage);
}
function doList($command, $options, $params)
{
$reg = &$this->config->getRegistry();
$channelinfo = isset($options['channelinfo']);
if (isset($options['allchannels']) && !$channelinfo) {
return $this->doListAll($command, array(), $params);
}
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'])) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' .
$channel . ':',
'border' => true,
'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);
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) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Package', 'Version', 'State'),
'channel' => $channel
);
foreach ($packages as $package) {
$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);
}
// 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)'), array()),
'channel' => $channel
);
}
$this->ui->outputData($data, $command);
}
return true;
}
function doFileList($command, $options, $params)
{
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 ($fp) {
fclose($fp);
}
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$pkg = new PEAR_PackageFile($this->config, $this->_debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
$headings = array('Package File', 'Install Path');
$installed = false;
} else {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
PEAR::staticPopErrorHandling();
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) {
$caption = 'Installed Files For ' . $params[0];
} else {
$caption = 'Contents of ' . basename($params[0]);
}
$data = array(
'caption' => $caption,
'border' => true,
'headline' => $headings);
if ($info->getPackagexmlVersion() == '1.0' || $installed) {
foreach ($list as $file => $att) {
if ($installed) {
if (empty($att['installed_as'])) {
continue;
}
$data['data'][] = array($att['role'], $att['installed_as']);
} else {
if (isset($att['baseinstalldir']) && !in_array($att['role'],
array('test', 'data', 'doc'))) {
$dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
$file;
} else {
$dest = $file;
}
switch ($att['role']) {
case 'test':
case 'data':
case 'doc':
$role = $att['role'];
if ($role == 'test') {
$role .= 's';
}
$dest = $this->config->get($role . '_dir') . DIRECTORY_SEPARATOR .
$info->getPackage() . DIRECTORY_SEPARATOR . $dest;
break;
case 'php':
default:
$dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
$dest;
}
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
$dest = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
array(DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR),
$dest);
$file = preg_replace('!/+!', '/', $file);
$data['data'][] = array($file, $dest);
}
}
} else { // package.xml 2.0, not installed
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'];
$role = &PEAR_Installer_Role::factory($info, $att['role'], $this->config);
$role->setup($this, $info, $att, $file);
if (!$role->isInstallable()) {
$dest = '(not installable)';
} else {
$dest = $role->processInstallation($info, $att, $file, '');
if (PEAR::isError($dest)) {
$dest = '(Unknown role "' . $att['role'] . ')';
} else {
list(,, $dest) = $dest;
}
}
$data['data'][] = array($file, $dest);
}
}
$this->ui->outputData($data, $command);
return true;
}
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'));
if (PEAR::isError($info)) {
exit(1); // invalid package name
}
$package = $info['package'];
$channel = $info['channel'];
// "pear shell-test Foo"
if (!$reg->packageExists($package, $channel)) {
if ($channel == 'pecl.php.net') {
if ($reg->packageExists($package, 'pear.php.net')) {
$channel = 'pear.php.net'; // magically change channels for extensions
}
}
}
if (count($params) === 1) {
if (!$reg->packageExists($package, $channel)) {
exit(1);
}
// "pear shell-test Foo 1.0"
} 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 (count($params) === 3) {
$v = $reg->packageInfo($package, 'version', $channel);
if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
exit(1);
}
} else {
PEAR::staticPopErrorHandling();
$this->raiseError("$command: expects 1 to 3 parameters");
exit(1);
}
}
function doInfo($command, $options, $params)
{
if (count($params) !== 1) {
return $this->raiseError('pear info expects 1 parameter');
}
$info = $fp = false;
$reg = &$this->config->getRegistry();
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);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
if (PEAR::isError($obj)) {
$uinfo = $obj->getUserInfo();
if (is_array($uinfo)) {
foreach ($uinfo as $message) {
if (is_array($message)) {
$message = $message['message'];
}
$this->ui->outputData($message);
}
}
return $this->raiseError($obj);
}
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);
if (isset($info['old'])) {
$obj = $reg->getPackage($package, $channel);
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']);
if (isset($info['xsdversion'])) {
$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) {
if (is_array($info[$key])) {
switch ($key) {
case 'maintainers': {
$i = 0;
$mstr = '';
foreach ($info[$key] as $m) {
if ($i++ > 0) {
$mstr .= "\n";
}
$mstr .= $m['name'] . " <";
if (isset($m['email'])) {
$mstr .= $m['email'];
} else {
$mstr .= $m['handle'] . '@php.net';
}
$mstr .= "> ($m[role])";
}
$info[$key] = $mstr;
break;
}
case 'release_deps': {
$i = 0;
$dstr = '';
foreach ($info[$key] as $d) {
if (isset($this->_deps_rel_trans[$d['rel']])) {
$rel = $this->_deps_rel_trans[$d['rel']];
} else {
$rel = $d['rel'];
}
if (isset($this->_deps_type_trans[$d['type']])) {
$type = ucfirst($this->_deps_type_trans[$d['type']]);
} else {
$type = $d['type'];
}
if (isset($d['name'])) {
$name = $d['name'] . ' ';
} else {
$name = '';
}
if (isset($d['version'])) {
$version = $d['version'] . ' ';
} else {
$version = '';
}
if (isset($d['optional']) && $d['optional'] == 'yes') {
$optional = ' (optional)';
} else {
$optional = '';
}
$dstr .= "$type $name$rel $version$optional\n";
}
$info[$key] = $dstr;
break;
}
case 'provides' : {
$debug = $this->config->get('verbose');
if ($debug < 2) {
$pstr = 'Classes: ';
} else {
$pstr = '';
}
$i = 0;
foreach ($info[$key] as $p) {
if ($debug < 2 && $p['type'] != "class") {
continue;
}
// Only print classes when verbosity mode is < 2
if ($debug < 2) {
if ($i++ > 0) {
$pstr .= ", ";
}
$pstr .= $p['name'];
} else {
if ($i++ > 0) {
$pstr .= "\n";
}
$pstr .= ucfirst($p['type']) . " " . $p['name'];
if (isset($p['explicit']) && $p['explicit'] == 1) {
$pstr .= " (explicit)";
}
}
}
$info[$key] = $pstr;
break;
}
case 'configure_options' : {
foreach ($info[$key] as $i => $p) {
$info[$key][$i] = array_map(null, array_keys($p), array_values($p));
$info[$key][$i] = array_map(
function($a) { return join(" = ", $a); },
$info[$key][$i]);
$info[$key][$i] = implode(', ', $info[$key][$i]);
}
$info[$key] = implode("\n", $info[$key]);
break;
}
default: {
$info[$key] = implode(", ", $info[$key]);
break;
}
}
}
if ($key == '_lastmodified') {
$hdate = date('Y-m-d', $info[$key]);
unset($info[$key]);
$info['Last Modified'] = $hdate;
} elseif ($key == '_lastversion') {
$info['Previous Installed Version'] = $info[$key] ? $info[$key] : '- None -';
unset($info[$key]);
} else {
$info[$key] = trim($info[$key]);
if (in_array($key, $longtext)) {
$info[$key] = preg_replace('/ +/', ' ', $info[$key]);
}
}
}
$caption = 'About ' . $info['package'] . '-' . $info['version'];
$data = array(
'caption' => $caption,
'border' => true);
foreach ($info as $key => $value) {
$key = ucwords(trim(str_replace('_', ' ', $key)));
$data['data'][] = array($key, $value);
}
$data['raw'] = $info;
$this->ui->outputData($data, 'package-info');
}
/**
* @access private
*/
function _doInfo2($command, $options, $params, &$obj, $installed)
{
$reg = &$this->config->getRegistry();
$caption = 'About ' . $obj->getChannel() . '/' .$obj->getPackage() . '-' .
$obj->getVersion();
$data = array(
'caption' => $caption,
'border' => true);
switch ($obj->getPackageType()) {
case 'php' :
$release = 'PEAR-style PHP-based Package';
break;
case 'extsrc' :
$release = 'PECL-style PHP extension (source code)';
break;
case 'zendextsrc' :
$release = 'PECL-style Zend extension (source code)';
break;
case 'extbin' :
$release = 'PECL-style PHP extension (binary)';
break;
case 'zendextbin' :
$release = 'PECL-style Zend extension (binary)';
break;
case 'bundle' :
$release = 'Package bundle (collection of packages)';
break;
}
$extends = $obj->getExtends();
$extends = $extends ?
$obj->getPackage() . ' (extends ' . $extends . ')' : $obj->getPackage();
if ($src = $obj->getSourcePackage()) {
$extends .= ' (source package ' . $src['channel'] . '/' . $src['package'] . ')';
}
$info = array(
'Release Type' => $release,
'Name' => $extends,
'Channel' => $obj->getChannel(),
'Summary' => preg_replace('/ +/', ' ', $obj->getSummary()),
'Description' => preg_replace('/ +/', ' ', $obj->getDescription()),
);
$info['Maintainers'] = '';
foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
$leads = $obj->{"get{$role}s"}();
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$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();
$uri = $obj->getLicenseLocation();
if ($uri) {
if (isset($uri['uri'])) {
$info['License'] .= ' (' . $uri['uri'] . ')';
} else {
$extra = $obj->getInstalledLocation($info['filesource']);
if ($extra) {
$info['License'] .= ' (' . $uri['filesource'] . ')';
}
}
}
$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['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 {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= $package['channel'] . '/' .
$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";
} else {
$info['Uses Custom Roles'] = '';
}
if (isset($roledata['package'])) {
$rolepackage = $reg->parsedPackageNameToString($roledata, true);
} else {
$rolepackage = $roledata['uri'];
}
$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";
} else {
$info['Uses Custom Tasks'] = '';
}
if (isset($taskdata['package'])) {
$taskpackage = $reg->parsedPackageNameToString($taskdata, true);
} else {
$taskpackage = $taskdata['uri'];
}
$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'])) {
$info['Required Dependencies'] .= '-' . $deps['required']['php']['max'] . "\n";
} else {
$info['Required Dependencies'] .= "\n";
}
if (isset($deps['required']['php']['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['php']['exclude'])) {
$deps['required']['php']['exclude'] =
implode(', ', $deps['required']['php']['exclude']);
}
$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 ' .
$deps['required']['pearinstaller']['min'] . '-' .
$deps['required']['pearinstaller']['max'];
} else {
$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'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['pearinstaller']['exclude'])) {
$deps['required']['pearinstaller']['exclude'] =
implode(', ', $deps['required']['pearinstaller']['exclude']);
}
$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])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Required Dependencies';
$info[$infoindex] .= "\n";
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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 ';
}
$info['Not Compatible with'] .= 'Package ' .
$reg->parsedPackageNameToString($package, true);
$info['Not Compatible with'] .= "\n Versions " . $package['exclude'];
}
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "$os[name] Operating System";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "$os[name] Operating System";
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "OS/Arch matching pattern '/$os[pattern]/'";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "OS/Arch matching pattern '/$os[pattern]/'";
}
}
}
if (isset($deps['optional'])) {
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($deps['optional'][$index])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Optional Dependencies';
if (!isset($info['Optional Dependencies'])) {
$info['Optional Dependencies'] = '';
} else {
$info['Optional Dependencies'] .= "\n";
}
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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'];
}
}
}
}
}
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';
$info[$groupindex] = '';
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($group[$index])) {
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 {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$name = '__uri/' . $package['name'] . ' (static URI)';
}
}
if (isset($package['uri'])) {
if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
$info[$groupindex] .= "Not Compatible with $type $name";
} 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 " .
$package['min'] . '-' . $package['max'];
} elseif (isset($package['min'])) {
$info[$groupindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} else {
$info[$groupindex] .= "Not Compatible with\n";
}
if (is_array($package['exclude'])) {
$package['exclude'] = implode(', ', $package['exclude']);
}
$info[$groupindex] .= " Package $package\n Versions " .
$package['exclude'];
}
}
}
}
}
}
if ($obj->getPackageType() == 'bundle') {
$info['Bundled Packages'] = '';
foreach ($obj->getBundledPackages() as $package) {
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]";
} else {
$info['Bundled Packages'] .= $package['channel'] . '/' . $package['name'];
}
}
}
$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');
}
}
opt/cpanel/ea-php56/root/usr/share/pear/PEAR/Command/Registry.php 0000644 00000132315 14756620620 0020425 0 ustar 00
* @author Greg Beaver
* @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/Command/Common.php';
/**
* PEAR commands for registry manipulation
*
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Registry extends PEAR_Command_Common
{
var $commands = array(
'list' => array(
'summary' => 'List Installed Packages In The Default Channel',
'function' => 'doList',
'shortcut' => 'l',
'options' => array(
'channel' => array(
'shortopt' => 'c',
'doc' => 'list installed packages from this channel',
'arg' => 'CHAN',
),
'allchannels' => array(
'shortopt' => 'a',
'doc' => 'list installed packages from all channels',
),
'channelinfo' => array(
'shortopt' => 'i',
'doc' => 'output fully channel-aware data, even on failure',
),
),
'doc' => '
If invoked without parameters, this command lists the PEAR packages
installed in your php_dir ({config php_dir}). With a parameter, it
lists the files in a package.
',
),
'list-files' => array(
'summary' => 'List Files In Installed Package',
'function' => 'doFileList',
'shortcut' => 'fl',
'options' => array(),
'doc' => '
List the files in an installed package.
'
),
'shell-test' => array(
'summary' => 'Shell Script Test',
'function' => 'doShellTest',
'shortcut' => 'st',
'options' => array(),
'doc' => ' [[relation] version]
Tests if a package is installed in the system. Will exit(1) if it is not.
The version comparison operator. One of:
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
The version to compare with
'),
'info' => array(
'summary' => 'Display information about a package',
'function' => 'doInfo',
'shortcut' => 'in',
'options' => array(),
'doc' => '
Displays information about a package. The package argument may be a
local package file, an URL to a package file, or the name of an
installed package.'
)
);
/**
* PEAR_Command_Registry constructor.
*
* @access public
*/
function __construct(&$ui, &$config)
{
parent::__construct($ui, $config);
}
function _sortinfo($a, $b)
{
$apackage = isset($a['package']) ? $a['package'] : $a['name'];
$bpackage = isset($b['package']) ? $b['package'] : $b['name'];
return strcmp($apackage, $bpackage);
}
function doList($command, $options, $params)
{
$reg = &$this->config->getRegistry();
$channelinfo = isset($options['channelinfo']);
if (isset($options['allchannels']) && !$channelinfo) {
return $this->doListAll($command, array(), $params);
}
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'])) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' .
$channel . ':',
'border' => true,
'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);
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) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Package', 'Version', 'State'),
'channel' => $channel
);
foreach ($packages as $package) {
$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);
}
// 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)'), array()),
'channel' => $channel
);
}
$this->ui->outputData($data, $command);
}
return true;
}
function doFileList($command, $options, $params)
{
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 ($fp) {
fclose($fp);
}
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$pkg = new PEAR_PackageFile($this->config, $this->_debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
$headings = array('Package File', 'Install Path');
$installed = false;
} else {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
PEAR::staticPopErrorHandling();
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) {
$caption = 'Installed Files For ' . $params[0];
} else {
$caption = 'Contents of ' . basename($params[0]);
}
$data = array(
'caption' => $caption,
'border' => true,
'headline' => $headings);
if ($info->getPackagexmlVersion() == '1.0' || $installed) {
foreach ($list as $file => $att) {
if ($installed) {
if (empty($att['installed_as'])) {
continue;
}
$data['data'][] = array($att['role'], $att['installed_as']);
} else {
if (isset($att['baseinstalldir']) && !in_array($att['role'],
array('test', 'data', 'doc'))) {
$dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
$file;
} else {
$dest = $file;
}
switch ($att['role']) {
case 'test':
case 'data':
case 'doc':
$role = $att['role'];
if ($role == 'test') {
$role .= 's';
}
$dest = $this->config->get($role . '_dir') . DIRECTORY_SEPARATOR .
$info->getPackage() . DIRECTORY_SEPARATOR . $dest;
break;
case 'php':
default:
$dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
$dest;
}
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
$dest = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
array(DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR),
$dest);
$file = preg_replace('!/+!', '/', $file);
$data['data'][] = array($file, $dest);
}
}
} else { // package.xml 2.0, not installed
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'];
$role = &PEAR_Installer_Role::factory($info, $att['role'], $this->config);
$role->setup($this, $info, $att, $file);
if (!$role->isInstallable()) {
$dest = '(not installable)';
} else {
$dest = $role->processInstallation($info, $att, $file, '');
if (PEAR::isError($dest)) {
$dest = '(Unknown role "' . $att['role'] . ')';
} else {
list(,, $dest) = $dest;
}
}
$data['data'][] = array($file, $dest);
}
}
$this->ui->outputData($data, $command);
return true;
}
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'));
if (PEAR::isError($info)) {
exit(1); // invalid package name
}
$package = $info['package'];
$channel = $info['channel'];
// "pear shell-test Foo"
if (!$reg->packageExists($package, $channel)) {
if ($channel == 'pecl.php.net') {
if ($reg->packageExists($package, 'pear.php.net')) {
$channel = 'pear.php.net'; // magically change channels for extensions
}
}
}
if (count($params) === 1) {
if (!$reg->packageExists($package, $channel)) {
exit(1);
}
// "pear shell-test Foo 1.0"
} 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 (count($params) === 3) {
$v = $reg->packageInfo($package, 'version', $channel);
if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
exit(1);
}
} else {
PEAR::staticPopErrorHandling();
$this->raiseError("$command: expects 1 to 3 parameters");
exit(1);
}
}
function doInfo($command, $options, $params)
{
if (count($params) !== 1) {
return $this->raiseError('pear info expects 1 parameter');
}
$info = $fp = false;
$reg = &$this->config->getRegistry();
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);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
if (PEAR::isError($obj)) {
$uinfo = $obj->getUserInfo();
if (is_array($uinfo)) {
foreach ($uinfo as $message) {
if (is_array($message)) {
$message = $message['message'];
}
$this->ui->outputData($message);
}
}
return $this->raiseError($obj);
}
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);
if (isset($info['old'])) {
$obj = $reg->getPackage($package, $channel);
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']);
if (isset($info['xsdversion'])) {
$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) {
if (is_array($info[$key])) {
switch ($key) {
case 'maintainers': {
$i = 0;
$mstr = '';
foreach ($info[$key] as $m) {
if ($i++ > 0) {
$mstr .= "\n";
}
$mstr .= $m['name'] . " <";
if (isset($m['email'])) {
$mstr .= $m['email'];
} else {
$mstr .= $m['handle'] . '@php.net';
}
$mstr .= "> ($m[role])";
}
$info[$key] = $mstr;
break;
}
case 'release_deps': {
$i = 0;
$dstr = '';
foreach ($info[$key] as $d) {
if (isset($this->_deps_rel_trans[$d['rel']])) {
$rel = $this->_deps_rel_trans[$d['rel']];
} else {
$rel = $d['rel'];
}
if (isset($this->_deps_type_trans[$d['type']])) {
$type = ucfirst($this->_deps_type_trans[$d['type']]);
} else {
$type = $d['type'];
}
if (isset($d['name'])) {
$name = $d['name'] . ' ';
} else {
$name = '';
}
if (isset($d['version'])) {
$version = $d['version'] . ' ';
} else {
$version = '';
}
if (isset($d['optional']) && $d['optional'] == 'yes') {
$optional = ' (optional)';
} else {
$optional = '';
}
$dstr .= "$type $name$rel $version$optional\n";
}
$info[$key] = $dstr;
break;
}
case 'provides' : {
$debug = $this->config->get('verbose');
if ($debug < 2) {
$pstr = 'Classes: ';
} else {
$pstr = '';
}
$i = 0;
foreach ($info[$key] as $p) {
if ($debug < 2 && $p['type'] != "class") {
continue;
}
// Only print classes when verbosity mode is < 2
if ($debug < 2) {
if ($i++ > 0) {
$pstr .= ", ";
}
$pstr .= $p['name'];
} else {
if ($i++ > 0) {
$pstr .= "\n";
}
$pstr .= ucfirst($p['type']) . " " . $p['name'];
if (isset($p['explicit']) && $p['explicit'] == 1) {
$pstr .= " (explicit)";
}
}
}
$info[$key] = $pstr;
break;
}
case 'configure_options' : {
foreach ($info[$key] as $i => $p) {
$info[$key][$i] = array_map(null, array_keys($p), array_values($p));
$info[$key][$i] = array_map(
function($a) { return join(" = ", $a); },
$info[$key][$i]);
$info[$key][$i] = implode(', ', $info[$key][$i]);
}
$info[$key] = implode("\n", $info[$key]);
break;
}
default: {
$info[$key] = implode(", ", $info[$key]);
break;
}
}
}
if ($key == '_lastmodified') {
$hdate = date('Y-m-d', $info[$key]);
unset($info[$key]);
$info['Last Modified'] = $hdate;
} elseif ($key == '_lastversion') {
$info['Previous Installed Version'] = $info[$key] ? $info[$key] : '- None -';
unset($info[$key]);
} else {
$info[$key] = trim($info[$key]);
if (in_array($key, $longtext)) {
$info[$key] = preg_replace('/ +/', ' ', $info[$key]);
}
}
}
$caption = 'About ' . $info['package'] . '-' . $info['version'];
$data = array(
'caption' => $caption,
'border' => true);
foreach ($info as $key => $value) {
$key = ucwords(trim(str_replace('_', ' ', $key)));
$data['data'][] = array($key, $value);
}
$data['raw'] = $info;
$this->ui->outputData($data, 'package-info');
}
/**
* @access private
*/
function _doInfo2($command, $options, $params, &$obj, $installed)
{
$reg = &$this->config->getRegistry();
$caption = 'About ' . $obj->getChannel() . '/' .$obj->getPackage() . '-' .
$obj->getVersion();
$data = array(
'caption' => $caption,
'border' => true);
switch ($obj->getPackageType()) {
case 'php' :
$release = 'PEAR-style PHP-based Package';
break;
case 'extsrc' :
$release = 'PECL-style PHP extension (source code)';
break;
case 'zendextsrc' :
$release = 'PECL-style Zend extension (source code)';
break;
case 'extbin' :
$release = 'PECL-style PHP extension (binary)';
break;
case 'zendextbin' :
$release = 'PECL-style Zend extension (binary)';
break;
case 'bundle' :
$release = 'Package bundle (collection of packages)';
break;
}
$extends = $obj->getExtends();
$extends = $extends ?
$obj->getPackage() . ' (extends ' . $extends . ')' : $obj->getPackage();
if ($src = $obj->getSourcePackage()) {
$extends .= ' (source package ' . $src['channel'] . '/' . $src['package'] . ')';
}
$info = array(
'Release Type' => $release,
'Name' => $extends,
'Channel' => $obj->getChannel(),
'Summary' => preg_replace('/ +/', ' ', $obj->getSummary()),
'Description' => preg_replace('/ +/', ' ', $obj->getDescription()),
);
$info['Maintainers'] = '';
foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
$leads = $obj->{"get{$role}s"}();
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$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();
$uri = $obj->getLicenseLocation();
if ($uri) {
if (isset($uri['uri'])) {
$info['License'] .= ' (' . $uri['uri'] . ')';
} else {
$extra = $obj->getInstalledLocation($info['filesource']);
if ($extra) {
$info['License'] .= ' (' . $uri['filesource'] . ')';
}
}
}
$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['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 {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= $package['channel'] . '/' .
$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";
} else {
$info['Uses Custom Roles'] = '';
}
if (isset($roledata['package'])) {
$rolepackage = $reg->parsedPackageNameToString($roledata, true);
} else {
$rolepackage = $roledata['uri'];
}
$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";
} else {
$info['Uses Custom Tasks'] = '';
}
if (isset($taskdata['package'])) {
$taskpackage = $reg->parsedPackageNameToString($taskdata, true);
} else {
$taskpackage = $taskdata['uri'];
}
$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'])) {
$info['Required Dependencies'] .= '-' . $deps['required']['php']['max'] . "\n";
} else {
$info['Required Dependencies'] .= "\n";
}
if (isset($deps['required']['php']['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['php']['exclude'])) {
$deps['required']['php']['exclude'] =
implode(', ', $deps['required']['php']['exclude']);
}
$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 ' .
$deps['required']['pearinstaller']['min'] . '-' .
$deps['required']['pearinstaller']['max'];
} else {
$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'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['pearinstaller']['exclude'])) {
$deps['required']['pearinstaller']['exclude'] =
implode(', ', $deps['required']['pearinstaller']['exclude']);
}
$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])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Required Dependencies';
$info[$infoindex] .= "\n";
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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 ';
}
$info['Not Compatible with'] .= 'Package ' .
$reg->parsedPackageNameToString($package, true);
$info['Not Compatible with'] .= "\n Versions " . $package['exclude'];
}
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "$os[name] Operating System";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "$os[name] Operating System";
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "OS/Arch matching pattern '/$os[pattern]/'";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "OS/Arch matching pattern '/$os[pattern]/'";
}
}
}
if (isset($deps['optional'])) {
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($deps['optional'][$index])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Optional Dependencies';
if (!isset($info['Optional Dependencies'])) {
$info['Optional Dependencies'] = '';
} else {
$info['Optional Dependencies'] .= "\n";
}
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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'];
}
}
}
}
}
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';
$info[$groupindex] = '';
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($group[$index])) {
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 {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$name = '__uri/' . $package['name'] . ' (static URI)';
}
}
if (isset($package['uri'])) {
if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
$info[$groupindex] .= "Not Compatible with $type $name";
} 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 " .
$package['min'] . '-' . $package['max'];
} elseif (isset($package['min'])) {
$info[$groupindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} else {
$info[$groupindex] .= "Not Compatible with\n";
}
if (is_array($package['exclude'])) {
$package['exclude'] = implode(', ', $package['exclude']);
}
$info[$groupindex] .= " Package $package\n Versions " .
$package['exclude'];
}
}
}
}
}
}
if ($obj->getPackageType() == 'bundle') {
$info['Bundled Packages'] = '';
foreach ($obj->getBundledPackages() as $package) {
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]";
} else {
$info['Bundled Packages'] .= $package['channel'] . '/' . $package['name'];
}
}
}
$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');
}
}
opt/cpanel/ea-php70/root/usr/share/pear/PEAR/Registry.php 0000644 00000224270 14760030250 0017032 0 ustar 00
* @author Tomas V. V. Cox
* @author Greg Beaver
* @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
*/
/**
* for PEAR_Error
*/
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_CHANNEL_FILE', -6);
/**
* Administration class used to maintain the installed package database.
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Tomas V. V. Cox
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_Registry extends PEAR
{
/**
* File containing all channel information.
* @var string
*/
var $channels = '';
/** Directory where registry files are stored.
* @var string
*/
var $statedir = '';
/** File where the file map is stored
* @var string
*/
var $filemap = '';
/** Directory where registry files for channels are stored.
* @var string
*/
var $channelsdir = '';
/** Name of file used for locking the registry
* @var string
*/
var $lockfile = '';
/** File descriptor used during locking
* @var resource
*/
var $lock_fp = null;
/** Mode used during locking
* @var int
*/
var $lock_mode = 0; // XXX UNUSED
/** Cache of package information. Structure:
* array(
* 'package' => array('id' => ... ),
* ... )
* @var array
*/
var $pkginfo_cache = array();
/** Cache of file map. Structure:
* array( '/path/to/file' => 'package', ... )
* @var array
*/
var $filemap_cache = array();
/**
* @var false|PEAR_ChannelFile
*/
var $_pearChannel;
/**
* @var false|PEAR_ChannelFile
*/
var $_peclChannel;
/**
* @var false|PEAR_ChannelFile
*/
var $_docChannel;
/**
* @var PEAR_DependencyDB
*/
var $_dependencyDB;
/**
* @var PEAR_Config
*/
var $_config;
/**
* PEAR_Registry constructor.
*
* @param string (optional) PEAR install directory (for .php files)
* @param PEAR_ChannelFile PEAR_ChannelFile object representing the PEAR channel, if
* default values are not desired. Only used the very first time a PEAR
* repository is initialized
* @param PEAR_ChannelFile PEAR_ChannelFile object representing the PECL channel, if
* default values are not desired. Only used the very first time a PEAR
* repository is initialized
*
* @access public
*/
function __construct($pear_install_dir = PEAR_INSTALL_DIR, $pear_channel = false,
$pecl_channel = false, $pear_metadata_dir = '')
{
parent::__construct();
$this->setInstallDir($pear_install_dir, $pear_metadata_dir);
$this->_pearChannel = $pear_channel;
$this->_peclChannel = $pecl_channel;
$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 != '.') {
$olddir = $dir;
$dir = dirname($dir);
if ($dir != '.' && file_exists($dir)) {
if (is_writeable($dir)) {
return true;
}
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, $resetInstallDir = true)
{
$this->_config = &$config;
if ($resetInstallDir) {
$this->setInstallDir($config->get('php_dir'), $config->get('metadata_dir'));
}
}
function _initializeChannelDirs()
{
static $running = false;
if (!$running) {
$running = true;
$ds = DIRECTORY_SEPARATOR;
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;
if (!is_a($pear_channel, 'PEAR_ChannelFile') || !$pear_channel->validate()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setAlias('pear');
$pear_channel->setServer('pear.php.net');
$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/');
//$pear_channel->setBaseURL('REST1.4', 'http://pear.php.net/rest/');
} else {
$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()) {
if (!class_exists('PEAR_ChannelFile')) {
require_once 'PEAR/ChannelFile.php';
}
$pecl_channel = new PEAR_ChannelFile;
$pecl_channel->setAlias('pecl');
$pecl_channel->setServer('pecl.php.net');
$pecl_channel->setSummary('PHP Extension Community Library');
$pecl_channel->setDefaultPEARProtocols();
$pecl_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
$pecl_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$pecl_channel->setValidationPackage('PEAR_Validator_PECL', '1.0');
} else {
$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->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
$this->_addChannel($private);
}
$this->_rebuildFileMap();
}
$running = false;
}
}
function _initializeDirs()
{
$ds = DIRECTORY_SEPARATOR;
// XXX Compatibility code should be removed in the future
// rename all registry files if any to lowercase
if (!OS_WINDOWS && file_exists($this->statedir) && is_dir($this->statedir) &&
$handle = opendir($this->statedir)) {
$dest = $this->statedir . $ds;
while (false !== ($file = readdir($handle))) {
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();
}
$this->_initializeDepDB();
}
function _initializeDepDB()
{
if (!isset($this->_dependencyDB)) {
static $initializing = false;
if (!$initializing) {
$initializing = true;
if (!$this->_config) { // never used?
$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('metadata_dir', null, 'pear.php.net') .
DIRECTORY_SEPARATOR . '.depdb')) {
@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();
echo 'Unrecoverable error';
exit(1);
}
}
$initializing = false;
}
}
}
/**
* PEAR_Registry destructor. Makes sure no locks are forgotten.
*
* @access private
*/
function _PEAR_Registry()
{
parent::_PEAR();
if (is_resource($this->lock_fp)) {
$this->_unlock();
}
}
/**
* Make sure the directory where we keep registry files exists.
*
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertStateDir($channel = false)
{
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}'");
}
$init = true;
} elseif (!is_dir($this->statedir)) {
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;
}
} elseif (!is_dir($this->channelsdir)) {
return $this->raiseError('Cannot create directory ' . $this->channelsdir . ', ' .
'it already exists and is not a directory');
}
if ($init) {
static $running = false;
if (!$running) {
$running = true;
$this->_initializeDirs();
$running = false;
$init = false;
}
} else {
$this->_initializeDepDB();
}
return true;
}
/**
* Make sure the directory where we keep registry files exists for a non-standard channel.
*
* @param string channel name
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertChannelStateDir($channel)
{
$ds = DIRECTORY_SEPARATOR;
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
if (!file_exists($this->channelsdir . $ds . 'pear.php.net.reg')) {
$this->_initializeChannelDirs();
}
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 .
"'");
}
} elseif (!is_dir($channelDir)) {
return $this->raiseError("could not create directory '" . $channelDir .
"', already exists and is not a directory");
}
return true;
}
/**
* Make sure the directory where we keep registry files for channels exists
*
* @return bool TRUE if directory exists, FALSE if it could not be
* created
*
* @access private
*/
function _assertChannelDir()
{
if (!file_exists($this->channelsdir)) {
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}'");
}
} 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'");
}
} 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;
}
/**
* Get the name of the file where data for a given package is stored.
*
* @param string channel name, or false if this is a PEAR package
* @param string package name
*
* @return string registry file name
*
* @access public
*/
function _packageFileName($package, $channel = false)
{
if ($channel && $this->_getChannelFromAlias($channel) != 'pear.php.net') {
return $this->_channelDirectoryName($channel) . DIRECTORY_SEPARATOR .
strtolower($package) . '.reg';
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower($package) . '.reg';
}
/**
* Get the name of the file where data for a given channel is stored.
* @param string channel name
* @return string registry file name
*/
function _channelFileName($channel, $noaliases = false)
{
if (!$noaliases) {
if (file_exists($this->_getChannelAliasFileName($channel))) {
$channel = implode('', file($this->_getChannelAliasFileName($channel)));
}
}
return $this->channelsdir . DIRECTORY_SEPARATOR . str_replace('/', '_',
strtolower($channel)) . '.reg';
}
/**
* @param string
* @return string
*/
function _getChannelAliasFileName($alias)
{
return $this->channelsdir . DIRECTORY_SEPARATOR . '.alias' .
DIRECTORY_SEPARATOR . str_replace('/', '_', strtolower($alias)) . '.txt';
}
/**
* Get the name of a channel from its alias
*/
function _getChannelFromAlias($channel)
{
if (!$this->_channelExists($channel)) {
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)));
}
return $channel;
}
/**
* Get the alias of a channel from its alias or its name
*/
function _getAlias($channel)
{
if (!$this->_channelExists($channel)) {
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();
}
/**
* Get the name of the file where data for a given package is stored.
*
* @param string channel name, or false if this is a PEAR package
* @param string package name
*
* @return string registry file name
*
* @access public
*/
function _channelDirectoryName($channel)
{
if (!$channel || $this->_getChannelFromAlias($channel) == 'pear.php.net') {
return $this->statedir;
}
$ch = $this->_getChannelFromAlias($channel);
if (!$ch) {
$ch = $channel;
}
return $this->statedir . DIRECTORY_SEPARATOR . strtolower('.channel.' .
str_replace('/', '_', $ch));
}
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;
}
function _closePackageFile($fp)
{
fclose($fp);
}
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;
}
function _closeChannelFile($fp)
{
fclose($fp);
}
function _rebuildFileMap()
{
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$channels = $this->_listAllPackages();
$files = array();
foreach ($channels as $channel => $packages) {
foreach ($packages as $package) {
$version = $this->_packageInfo($package, 'version', $channel);
$filelist = $this->_packageInfo($package, 'filelist', $channel);
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 (!isset($files[$attrs['role']])) {
$files[$attrs['role']] = array();
}
$files[$attrs['role']][$file] = strtolower($package);
}
}
}
}
$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);
return true;
}
function _readFileMap()
{
if (!file_exists($this->filemap)) {
return array();
}
$fp = @fopen($this->filemap, 'r');
if (!$fp) {
$last_errormsg = '';
$last_error = error_get_last();
if (!empty($last_error['message'])) {
$last_errormsg = $last_error['message'];
}
return $this->raiseError('PEAR_Registry: could not open filemap "' . $this->filemap . '"', PEAR_REGISTRY_ERROR_FILE, null, null, $last_errormsg);
}
clearstatcache();
$fsize = filesize($this->filemap);
fclose($fp);
$data = file_get_contents($this->filemap);
$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 the registry.
*
* @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.
* See flock manual for more information.
*
* @return bool TRUE on success, FALSE if locking failed, or a
* PEAR error if some other error occurs (such as the
* lock file not being writable).
*
* @access private
*/
function _lock($mode = LOCK_EX)
{
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');
}
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 = 'r';
}
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;
}
//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;
}
function _unlock()
{
$ret = $this->_lock(LOCK_UN);
if (is_resource($this->lock_fp)) {
fclose($this->lock_fp);
}
$this->lock_fp = null;
return $ret;
}
function _packageExists($package, $channel = false)
{
return file_exists($this->_packageFileName($package, $channel));
}
/**
* Determine whether a channel exists in the registry
*
* @param string Channel name
* @param bool if true, then aliases will be ignored
* @return boolean
*/
function _channelExists($channel, $noaliases = false)
{
$a = file_exists($this->_channelFileName($channel, $noaliases));
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;
}
/**
* Determine whether a mirror exists within the default 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
* @param string Last-Modified HTTP tag from remote request
* @return boolean|PEAR_Error True on creation, false if it already exists
*/
function _addChannel($channel, $update = false, $lastmodified = false)
{
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()));
}
}
} else {
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;
} else {
$info['_lastmodified'] = self::getSourceDateEpoch();
}
fwrite($fp, serialize($info));
fclose($fp);
return true;
}
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
* @return boolean|PEAR_Error True on deletion, false if it doesn't exist
*/
function _deleteChannel($channel)
{
if (!is_string($channel)) {
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);
if (!$test) {
return false;
}
}
$file = $this->_channelFileName($channel);
$ret = true;
if (file_exists($file)) {
$ret = @unlink($file);
}
return $ret;
}
/**
* Determine whether a channel exists in the registry
* @param string Channel Alias
* @return boolean
*/
function _isChannelAlias($alias)
{
return file_exists($this->_getChannelAliasFileName($alias));
}
/**
* @param string|null
* @param string|null
* @param string|null
* @return array|null
* @access private
*/
function _packageInfo($package = null, $key = null, $channel = 'pear.php.net')
{
if ($package === null) {
if ($channel === null) {
$channels = $this->_listChannels();
$ret = array();
foreach ($channels as $channel) {
$channel = strtolower($channel);
$ret[$channel] = array();
$packages = $this->_listPackages($channel);
foreach ($packages as $package) {
$ret[$channel][] = $this->_packageInfo($package, null, $channel);
}
}
return $ret;
}
$ps = $this->_listPackages($channel);
if (!count($ps)) {
return array();
}
return array_map(array(&$this, '_packageInfo'),
$ps, array_fill(0, count($ps), null),
array_fill(0, count($ps), $channel));
}
$fp = $this->_openPackageFile($package, 'r', $channel);
if ($fp === null) {
return null;
}
clearstatcache();
$this->_closePackageFile($fp);
$data = file_get_contents($this->_packageFileName($package, $channel));
$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;
}
/**
* @param string Channel name
* @param bool whether to strictly retrieve info of channels, not just aliases
* @return array|null
*/
function _channelInfo($channel, $noaliases = false)
{
if (!$this->_channelExists($channel, $noaliases)) {
return null;
}
$fp = $this->_openChannelFile($channel, 'r');
if ($fp === null) {
return null;
}
clearstatcache();
$this->_closeChannelFile($fp);
$data = file_get_contents($this->_channelFileName($channel));
$data = unserialize($data);
return $data;
}
function _listChannels()
{
$channellist = array();
if (!file_exists($this->channelsdir) || !is_dir($this->channelsdir)) {
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;
}
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);
sort($pkglist);
return $pkglist;
}
function _listChannelPackages($channel)
{
$pkglist = array();
if (!file_exists($this->_channelDirectoryName($channel)) ||
!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;
}
$pkglist[] = substr($ent, 0, -4);
}
closedir($dp);
return $pkglist;
}
function _listAllPackages()
{
$ret = array();
foreach ($this->_listChannels() as $channel) {
$ret[$channel] = $this->_listPackages($channel);
}
return $ret;
}
/**
* Add an installed package to the registry
* @param string package name
* @param array package info (parsed by PEAR_Common::infoFrom*() methods)
* @return bool success of saving
* @access private
*/
function _addPackage($package, $info)
{
if ($this->_packageExists($package)) {
return false;
}
$fp = $this->_openPackageFile($package, 'wb');
if ($fp === null) {
return false;
}
$info['_lastmodified'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($info['filelist'])) {
$this->_rebuildFileMap();
}
return true;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @return bool
* @access private
*/
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();
if ($ui) {
foreach ($info->getValidationWarnings() as $err) {
$ui->log($err['message'], true);
}
}
}
return false;
}
$channel = $info->getChannel();
$package = $info->getPackage();
$save = $info;
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'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
$this->_rebuildFileMap();
return true;
}
/**
* @param string Package name
* @param array parsed package.xml 1.0
* @param bool this parameter is only here for BC. Don't use it.
* @access private
*/
function _updatePackage($package, $info, $merge = true)
{
$oldinfo = $this->_packageInfo($package);
if (empty($oldinfo)) {
return false;
}
$fp = $this->_openPackageFile($package, 'w');
if ($fp === null) {
return false;
}
if (is_object($info)) {
$info = $info->toArray();
}
$info['_lastmodified'] = self::getSourceDateEpoch();
$newinfo = $info;
if ($merge) {
$info = array_merge($oldinfo, $info);
} else {
$diff = $info;
}
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
if (isset($newinfo['filelist'])) {
$this->_rebuildFileMap();
}
return true;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @return bool
* @access private
*/
function _updatePackage2($info)
{
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'] = self::getSourceDateEpoch();
fwrite($fp, serialize($info));
$this->_closePackageFile($fp);
$this->_rebuildFileMap();
return true;
}
/**
* @param string Package name
* @param string Channel name
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
* @access private
*/
function &_getPackage($package, $channel = 'pear.php.net')
{
$info = $this->_packageInfo($package, null, $channel);
if ($info === null) {
return $info;
}
$a = $this->_config;
if (!$a) {
$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);
$pf = &$pkg->fromArray($info);
return $pf;
}
/**
* @param string channel name
* @param bool whether to strictly retrieve channel names
* @return PEAR_ChannelFile|PEAR_Error
* @access private
*/
function &_getChannel($channel, $noaliases = false)
{
$ch = false;
if ($this->_channelExists($channel, $noaliases)) {
$chinfo = $this->_channelInfo($channel, $noaliases);
if ($chinfo) {
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->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')) {
require_once 'PEAR/ChannelFile.php';
}
$pear_channel = new PEAR_ChannelFile;
$pear_channel->setServer('pecl.php.net');
$pear_channel->setAlias('pecl');
$pear_channel->setSummary('PHP Extension Community Library');
$pear_channel->setDefaultPEARProtocols();
$pear_channel->setBaseURL('REST1.0', 'http://pecl.php.net/rest/');
$pear_channel->setBaseURL('REST1.1', 'http://pecl.php.net/rest/');
$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->setDefaultPEARProtocols();
$private->setBaseURL('REST1.0', '****');
$private->setSummary('Pseudo-channel for static packages');
return $private;
}
return $ch;
}
/**
* @param string Package name
* @param string Channel name
* @return bool
*/
function packageExists($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_packageExists($package, $channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ channelExists()
/**
* @param string channel name
* @param bool if true, then aliases will be ignored
* @return bool
*/
function channelExists($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_channelExists($channel, $noaliases);
$this->_unlock();
return $ret;
}
// }}}
/**
* @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()
/**
* Determines whether the parameter is an alias of a channel
* @param string
* @return bool
*/
function isAlias($alias)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_isChannelAlias($alias);
$this->_unlock();
return $ret;
}
// }}}
// {{{ packageInfo()
/**
* @param string|null
* @param string|null
* @param string
* @return array|null
*/
function packageInfo($package = null, $key = null, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_packageInfo($package, $key, $channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ channelInfo()
/**
* Retrieve a raw array of channel data.
*
* Do not use this, instead use {@link getChannel()} for normal
* operations. Array structure is undefined in this method
* @param string channel name
* @param bool whether to strictly retrieve information only on non-aliases
* @return array|null|PEAR_Error
*/
function channelInfo($channel = null, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_channelInfo($channel, $noaliases);
$this->_unlock();
return $ret;
}
// }}}
/**
* @param string
*/
function channelName($channel)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getChannelFromAlias($channel);
$this->_unlock();
return $ret;
}
/**
* @param string
*/
function channelAlias($channel)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getAlias($channel);
$this->_unlock();
return $ret;
}
// {{{ listPackages()
function listPackages($channel = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listPackages($channel);
$this->_unlock();
return $ret;
}
// }}}
// {{{ listAllPackages()
function listAllPackages()
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listAllPackages();
$this->_unlock();
return $ret;
}
// }}}
// {{{ listChannel()
function listChannels()
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_listChannels();
$this->_unlock();
return $ret;
}
// }}}
// {{{ addPackage()
/**
* Add an installed package to the registry
* @param string|PEAR_PackageFile_v1|PEAR_PackageFile_v2 package name or object
* that will be passed to {@link addPackage2()}
* @param array package info (parsed by PEAR_Common::infoFrom*() methods)
* @return bool success of saving
*/
function addPackage($package, $info)
{
if (is_object($info)) {
return $this->addPackage2($info);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_addPackage($package, $info);
$this->_unlock();
if ($ret) {
if (!class_exists('PEAR_PackageFile_v1')) {
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->_config);
$pf->fromArray($info);
$this->_dependencyDB->uninstallPackage($pf);
$this->_dependencyDB->installPackage($pf);
}
return $ret;
}
// }}}
// {{{ addPackage2()
function addPackage2($info)
{
if (!is_object($info)) {
return $this->addPackage($info['package'], $info);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_addPackage2($info);
$this->_unlock();
if ($ret) {
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
return $ret;
}
// }}}
// {{{ updateChannel()
/**
* For future expandibility purposes, separate this
* @param PEAR_ChannelFile
*/
function updateChannel($channel, $lastmodified = null)
{
if ($channel->getName() == '__uri') {
return false;
}
return $this->addChannel($channel, $lastmodified, true);
}
// }}}
// {{{ deleteChannel()
/**
* Deletion fails if there are any packages installed from the channel
* @param string|PEAR_ChannelFile channel name
* @return boolean|PEAR_Error True on deletion, false if it doesn't exist
*/
function deleteChannel($channel)
{
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;
}
// }}}
// {{{ addChannel()
/**
* @param PEAR_ChannelFile Channel object
* @param string Last-Modified header from HTTP for caching
* @return boolean|PEAR_Error True on creation, false if it already exists
*/
function addChannel($channel, $lastmodified = false, $update = false)
{
if (!is_a($channel, 'PEAR_ChannelFile') || !$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;
}
// }}}
// {{{ deletePackage()
function deletePackage($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$file = $this->_packageFileName($package, $channel);
$ret = file_exists($file) ? @unlink($file) : false;
$this->_rebuildFileMap();
$this->_unlock();
$p = array('channel' => $channel, 'package' => $package);
$this->_dependencyDB->uninstallPackage($p);
return $ret;
}
// }}}
// {{{ updatePackage()
function updatePackage($package, $info, $merge = true)
{
if (is_object($info)) {
return $this->updatePackage2($info, $merge);
}
if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
return $e;
}
$ret = $this->_updatePackage($package, $info, $merge);
$this->_unlock();
if ($ret) {
if (!class_exists('PEAR_PackageFile_v1')) {
require_once 'PEAR/PackageFile/v1.php';
}
$pf = new PEAR_PackageFile_v1;
$pf->setConfig($this->_config);
$pf->fromArray($this->packageInfo($package));
$this->_dependencyDB->uninstallPackage($pf);
$this->_dependencyDB->installPackage($pf);
}
return $ret;
}
// }}}
// {{{ updatePackage2()
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) {
$this->_dependencyDB->uninstallPackage($info);
$this->_dependencyDB->installPackage($info);
}
return $ret;
}
// }}}
// {{{ getChannel()
/**
* @param string channel name
* @param bool whether to strictly return raw channels (no aliases)
* @return PEAR_ChannelFile|PEAR_Error
*/
function getChannel($channel, $noaliases = false)
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$ret = $this->_getChannel($channel, $noaliases);
$this->_unlock();
if (!$ret) {
return PEAR::raiseError('Unknown channel: ' . $channel);
}
return $ret;
}
// }}}
// {{{ getPackage()
/**
* @param string package name
* @param string channel name
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|null
*/
function &getPackage($package, $channel = 'pear.php.net')
{
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$pf = &$this->_getPackage($package, $channel);
$this->_unlock();
return $pf;
}
// }}}
/**
* Get PEAR_PackageFile_v[1/2] objects representing the contents of
* a dependency group that are installed.
*
* This is used at uninstall-time
* @param array
* @return array|false
*/
function getInstalledGroup($group)
{
$ret = array();
if (isset($group['package'])) {
if (!isset($group['package'][0])) {
$group['package'] = array($group['package']);
}
foreach ($group['package'] as $package) {
$depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
$p = &$this->getPackage($package['name'], $depchannel);
if ($p) {
$save = &$p;
$ret[] = &$save;
}
}
}
if (isset($group['subpackage'])) {
if (!isset($group['subpackage'][0])) {
$group['subpackage'] = array($group['subpackage']);
}
foreach ($group['subpackage'] as $package) {
$depchannel = isset($package['channel']) ? $package['channel'] : '__uri';
$p = &$this->getPackage($package['name'], $depchannel);
if ($p) {
$save = &$p;
$ret[] = &$save;
}
}
}
if (!count($ret)) {
return false;
}
return $ret;
}
// {{{ getChannelValidator()
/**
* @param string channel name
* @return PEAR_Validate|false
*/
function &getChannelValidator($channel)
{
$chan = $this->getChannel($channel);
if (PEAR::isError($chan)) {
return $chan;
}
$val = $chan->getValidationObject();
return $val;
}
// }}}
// {{{ getChannels()
/**
* @param string channel name
* @return array an array of PEAR_ChannelFile objects representing every installed channel
*/
function &getChannels()
{
$ret = array();
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
foreach ($this->_listChannels() as $channel) {
$e = &$this->_getChannel($channel);
if (!$e || PEAR::isError($e)) {
continue;
}
$ret[] = $e;
}
$this->_unlock();
return $ret;
}
// }}}
// {{{ checkFileMap()
/**
* Test whether a file or set of files belongs to a package.
*
* If an array is passed in
* @param string|array file path, absolute or relative to the pear
* install dir
* @param string|array name of PEAR package or array('package' => name, 'channel' =>
* channel) of a package that will be ignored
* @param string API version - 1.1 will exclude any files belonging to a package
* @param array private recursion variable
* @return array|false which package and channel the file belongs to, or an empty
* string if the file does not belong to an installed package,
* or belongs to the second parameter's package
*/
function checkFileMap($path, $package = false, $api = '1.0', $attrs = false)
{
if (is_array($path)) {
static $notempty;
if (empty($notempty)) {
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$notempty = function($a) { return !empty($a); };
}
$package = is_array($package) ? array(strtolower($package[0]), strtolower($package[1]))
: strtolower($package);
$pkgs = array();
foreach ($path as $name => $attrs) {
if (is_array($attrs)) {
if (isset($attrs['install-as'])) {
$name = $attrs['install-as'];
}
if (!in_array($attrs['role'], PEAR_Installer_Role::getInstallableRoles())) {
// these are not installed
continue;
}
if (!in_array($attrs['role'], PEAR_Installer_Role::getBaseinstallRoles())) {
$attrs['baseinstalldir'] = is_array($package) ? $package[1] : $package;
}
if (isset($attrs['baseinstalldir'])) {
$name = $attrs['baseinstalldir'] . DIRECTORY_SEPARATOR . $name;
}
}
$pkgs[$name] = $this->checkFileMap($name, $package, $api, $attrs);
if (PEAR::isError($pkgs[$name])) {
return $pkgs[$name];
}
}
return array_filter($pkgs, $notempty);
}
if (empty($this->filemap_cache)) {
if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
return $e;
}
$err = $this->_readFileMap();
$this->_unlock();
if (PEAR::isError($err)) {
return $err;
}
}
if (!$attrs) {
$attrs = array('role' => 'php'); // any old call would be for PHP role only
}
if (isset($this->filemap_cache[$attrs['role']][$path])) {
if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
return false;
}
return $this->filemap_cache[$attrs['role']][$path];
}
$l = strlen($this->install_dir);
if (substr($path, 0, $l) == $this->install_dir) {
$path = preg_replace('!^'.DIRECTORY_SEPARATOR.'+!', '', substr($path, $l));
}
if (isset($this->filemap_cache[$attrs['role']][$path])) {
if ($api >= '1.1' && $this->filemap_cache[$attrs['role']][$path] == $package) {
return false;
}
return $this->filemap_cache[$attrs['role']][$path];
}
return false;
}
// }}}
// {{{ flush()
/**
* Force a reload of the filemap
* @since 1.5.0RC3
*/
function flushFileMap()
{
$this->filemap_cache = null;
clearstatcache(); // ensure that the next read gets the full, current filemap
}
// }}}
// {{{ apiVersion()
/**
* Get the expected API version. Channels API is version 1.1, as it is backwards
* compatible with 1.0
* @return string
*/
function apiVersion()
{
return '1.1';
}
// }}}
/**
* Parse a package name, or validate a parsed package name array
* @param string|array pass in an array of format
* array(
* 'package' => 'pname',
* ['channel' => 'channame',]
* ['version' => 'version',]
* ['state' => 'state',]
* ['group' => 'groupname'])
* or a string of format
* [channel://][channame/]pname[-version|-state][/group=groupname]
* @return array|PEAR_Error
*/
function parsePackageName($param, $defaultchannel = 'pear.php.net')
{
$saveparam = $param;
if (is_array($param)) {
// convert to string for error messages
$saveparam = $this->parsedPackageNameToString($param);
// process the array
if (!isset($param['package'])) {
return PEAR::raiseError('parsePackageName(): array $param ' .
'must contain a valid package name in index "param"',
'package', null, null, $param);
}
if (!isset($param['uri'])) {
if (!isset($param['channel'])) {
$param['channel'] = $defaultchannel;
}
} else {
$param['channel'] = '__uri';
}
} else {
$components = @parse_url((string) $param);
if (isset($components['scheme'])) {
if ($components['scheme'] == 'http') {
// uri package
$param = array('uri' => $param, 'channel' => '__uri');
} elseif($components['scheme'] != 'channel') {
return PEAR::raiseError('parsePackageName(): only channel:// uris may ' .
'be downloaded, not "' . $param . '"', 'invalid', null, null, $param);
}
}
if (!isset($components['path'])) {
return PEAR::raiseError('parsePackageName(): array $param ' .
'must contain a valid package name in "' . $param . '"',
'package', null, null, $param);
}
if (isset($components['host'])) {
// remove the leading "/"
$components['path'] = substr($components['path'], 1);
}
if (!isset($components['scheme'])) {
if (strpos($components['path'], '/') !== false) {
if ($components['path'][0] == '/') {
return PEAR::raiseError('parsePackageName(): this is not ' .
'a package name, it begins with "/" in "' . $param . '"',
'invalid', null, null, $param);
}
$parts = explode('/', $components['path']);
$components['host'] = array_shift($parts);
if (count($parts) > 1) {
$components['path'] = array_pop($parts);
$components['host'] .= '/' . implode('/', $parts);
} else {
$components['path'] = implode('/', $parts);
}
} else {
$components['host'] = $defaultchannel;
}
} else {
if (strpos($components['path'], '/')) {
$parts = explode('/', $components['path']);
$components['path'] = array_pop($parts);
$components['host'] .= '/' . implode('/', $parts);
}
}
if (is_array($param)) {
$param['package'] = $components['path'];
} else {
$param = array(
'package' => $components['path']
);
if (isset($components['host'])) {
$param['channel'] = $components['host'];
}
}
if (isset($components['fragment'])) {
$param['group'] = $components['fragment'];
}
if (isset($components['user'])) {
$param['user'] = $components['user'];
}
if (isset($components['pass'])) {
$param['pass'] = $components['pass'];
}
if (isset($components['query'])) {
parse_str($components['query'], $param['opts']);
}
// check for extension
$pathinfo = pathinfo($param['package']);
if (isset($pathinfo['extension']) &&
in_array(strtolower($pathinfo['extension']), array('tgz', 'tar'))) {
$param['extension'] = $pathinfo['extension'];
$param['package'] = substr($pathinfo['basename'], 0,
strlen($pathinfo['basename']) - 4);
}
// check for version
if (strpos($param['package'], '-')) {
$test = explode('-', $param['package']);
if (count($test) != 2) {
return PEAR::raiseError('parsePackageName(): only one version/state ' .
'delimiter "-" is allowed in "' . $saveparam . '"',
'version', null, null, $param);
}
list($param['package'], $param['version']) = $test;
}
}
// validation
$info = $this->channelExists($param['channel']);
if (PEAR::isError($info)) {
return $info;
}
if (!$info) {
return PEAR::raiseError('unknown channel "' . $param['channel'] .
'" in "' . $saveparam . '"', 'channel', null, null, $param);
}
$chan = $this->getChannel($param['channel']);
if (PEAR::isError($chan)) {
return $chan;
}
if (!$chan) {
return PEAR::raiseError("Exception: corrupt registry, could not " .
"retrieve channel " . $param['channel'] . " information",
'registry', null, null, $param);
}
$param['channel'] = $chan->getName();
$validate = $chan->getValidationObject();
$vpackage = $chan->getValidationPackage();
// validate package name
if (!$validate->validPackageName($param['package'], $vpackage['_content'])) {
return PEAR::raiseError('parsePackageName(): invalid package name "' .
$param['package'] . '" in "' . $saveparam . '"',
'package', null, null, $param);
}
if (isset($param['group'])) {
if (!PEAR_Validate::validGroupName($param['group'])) {
return PEAR::raiseError('parsePackageName(): dependency group "' . $param['group'] .
'" is not a valid group name in "' . $saveparam . '"', 'group', null, null,
$param);
}
}
if (isset($param['state'])) {
if (!in_array(strtolower($param['state']), $validate->getValidStates())) {
return PEAR::raiseError('parsePackageName(): state "' . $param['state']
. '" is not a valid state in "' . $saveparam . '"',
'state', null, null, $param);
}
}
if (isset($param['version'])) {
if (isset($param['state'])) {
return PEAR::raiseError('parsePackageName(): cannot contain both ' .
'a version and a stability (state) in "' . $saveparam . '"',
'version/state', null, null, $param);
}
// check whether version is actually a state
if (in_array(strtolower($param['version']), $validate->getValidStates())) {
$param['state'] = strtolower($param['version']);
unset($param['version']);
} else {
if (!$validate->validVersion($param['version'])) {
return PEAR::raiseError('parsePackageName(): "' . $param['version'] .
'" is neither a valid version nor a valid state in "' .
$saveparam . '"', 'version/state', null, null, $param);
}
}
}
return $param;
}
/**
* @param array
* @return string
*/
function parsedPackageNameToString($parsed, $brief = false)
{
if (is_string($parsed)) {
return $parsed;
}
if (is_object($parsed)) {
$p = $parsed;
$parsed = array(
'package' => $p->getPackage(),
'channel' => $p->getChannel(),
'version' => $p->getVersion(),
);
}
if (isset($parsed['uri'])) {
return $parsed['uri'];
}
if ($brief) {
if ($channel = $this->channelAlias($parsed['channel'])) {
return $channel . '/' . $parsed['package'];
}
}
$upass = '';
if (isset($parsed['user'])) {
$upass = $parsed['user'];
if (isset($parsed['pass'])) {
$upass .= ':' . $parsed['pass'];
}
$upass = "$upass@";
}
$ret = 'channel://' . $upass . $parsed['channel'] . '/' . $parsed['package'];
if (isset($parsed['version']) || isset($parsed['state'])) {
$ver = isset($parsed['version']) ? $parsed['version'] : '';
$ver .= isset($parsed['state']) ? $parsed['state'] : '';
$ret .= '-' . $ver;
}
if (isset($parsed['extension'])) {
$ret .= '.' . $parsed['extension'];
}
if (isset($parsed['opts'])) {
$ret .= '?';
foreach ($parsed['opts'] as $name => $value) {
$parsed['opts'][$name] = "$name=$value";
}
$ret .= implode('&', $parsed['opts']);
}
if (isset($parsed['group'])) {
$ret .= '#' . $parsed['group'];
}
return $ret;
}
}
opt/cpanel/ea-php70/root/usr/share/pear/PEAR/Command/Registry.php 0000644 00000132315 14760061077 0020421 0 ustar 00
* @author Greg Beaver
* @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/Command/Common.php';
/**
* PEAR commands for registry manipulation
*
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Registry extends PEAR_Command_Common
{
var $commands = array(
'list' => array(
'summary' => 'List Installed Packages In The Default Channel',
'function' => 'doList',
'shortcut' => 'l',
'options' => array(
'channel' => array(
'shortopt' => 'c',
'doc' => 'list installed packages from this channel',
'arg' => 'CHAN',
),
'allchannels' => array(
'shortopt' => 'a',
'doc' => 'list installed packages from all channels',
),
'channelinfo' => array(
'shortopt' => 'i',
'doc' => 'output fully channel-aware data, even on failure',
),
),
'doc' => '
If invoked without parameters, this command lists the PEAR packages
installed in your php_dir ({config php_dir}). With a parameter, it
lists the files in a package.
',
),
'list-files' => array(
'summary' => 'List Files In Installed Package',
'function' => 'doFileList',
'shortcut' => 'fl',
'options' => array(),
'doc' => '
List the files in an installed package.
'
),
'shell-test' => array(
'summary' => 'Shell Script Test',
'function' => 'doShellTest',
'shortcut' => 'st',
'options' => array(),
'doc' => ' [[relation] version]
Tests if a package is installed in the system. Will exit(1) if it is not.
The version comparison operator. One of:
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
The version to compare with
'),
'info' => array(
'summary' => 'Display information about a package',
'function' => 'doInfo',
'shortcut' => 'in',
'options' => array(),
'doc' => '
Displays information about a package. The package argument may be a
local package file, an URL to a package file, or the name of an
installed package.'
)
);
/**
* PEAR_Command_Registry constructor.
*
* @access public
*/
function __construct(&$ui, &$config)
{
parent::__construct($ui, $config);
}
function _sortinfo($a, $b)
{
$apackage = isset($a['package']) ? $a['package'] : $a['name'];
$bpackage = isset($b['package']) ? $b['package'] : $b['name'];
return strcmp($apackage, $bpackage);
}
function doList($command, $options, $params)
{
$reg = &$this->config->getRegistry();
$channelinfo = isset($options['channelinfo']);
if (isset($options['allchannels']) && !$channelinfo) {
return $this->doListAll($command, array(), $params);
}
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'])) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' .
$channel . ':',
'border' => true,
'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);
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) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Package', 'Version', 'State'),
'channel' => $channel
);
foreach ($packages as $package) {
$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);
}
// 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)'), array()),
'channel' => $channel
);
}
$this->ui->outputData($data, $command);
}
return true;
}
function doFileList($command, $options, $params)
{
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 ($fp) {
fclose($fp);
}
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$pkg = new PEAR_PackageFile($this->config, $this->_debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
$headings = array('Package File', 'Install Path');
$installed = false;
} else {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
PEAR::staticPopErrorHandling();
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) {
$caption = 'Installed Files For ' . $params[0];
} else {
$caption = 'Contents of ' . basename($params[0]);
}
$data = array(
'caption' => $caption,
'border' => true,
'headline' => $headings);
if ($info->getPackagexmlVersion() == '1.0' || $installed) {
foreach ($list as $file => $att) {
if ($installed) {
if (empty($att['installed_as'])) {
continue;
}
$data['data'][] = array($att['role'], $att['installed_as']);
} else {
if (isset($att['baseinstalldir']) && !in_array($att['role'],
array('test', 'data', 'doc'))) {
$dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
$file;
} else {
$dest = $file;
}
switch ($att['role']) {
case 'test':
case 'data':
case 'doc':
$role = $att['role'];
if ($role == 'test') {
$role .= 's';
}
$dest = $this->config->get($role . '_dir') . DIRECTORY_SEPARATOR .
$info->getPackage() . DIRECTORY_SEPARATOR . $dest;
break;
case 'php':
default:
$dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
$dest;
}
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
$dest = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
array(DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR),
$dest);
$file = preg_replace('!/+!', '/', $file);
$data['data'][] = array($file, $dest);
}
}
} else { // package.xml 2.0, not installed
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'];
$role = &PEAR_Installer_Role::factory($info, $att['role'], $this->config);
$role->setup($this, $info, $att, $file);
if (!$role->isInstallable()) {
$dest = '(not installable)';
} else {
$dest = $role->processInstallation($info, $att, $file, '');
if (PEAR::isError($dest)) {
$dest = '(Unknown role "' . $att['role'] . ')';
} else {
list(,, $dest) = $dest;
}
}
$data['data'][] = array($file, $dest);
}
}
$this->ui->outputData($data, $command);
return true;
}
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'));
if (PEAR::isError($info)) {
exit(1); // invalid package name
}
$package = $info['package'];
$channel = $info['channel'];
// "pear shell-test Foo"
if (!$reg->packageExists($package, $channel)) {
if ($channel == 'pecl.php.net') {
if ($reg->packageExists($package, 'pear.php.net')) {
$channel = 'pear.php.net'; // magically change channels for extensions
}
}
}
if (count($params) === 1) {
if (!$reg->packageExists($package, $channel)) {
exit(1);
}
// "pear shell-test Foo 1.0"
} 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 (count($params) === 3) {
$v = $reg->packageInfo($package, 'version', $channel);
if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
exit(1);
}
} else {
PEAR::staticPopErrorHandling();
$this->raiseError("$command: expects 1 to 3 parameters");
exit(1);
}
}
function doInfo($command, $options, $params)
{
if (count($params) !== 1) {
return $this->raiseError('pear info expects 1 parameter');
}
$info = $fp = false;
$reg = &$this->config->getRegistry();
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);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
if (PEAR::isError($obj)) {
$uinfo = $obj->getUserInfo();
if (is_array($uinfo)) {
foreach ($uinfo as $message) {
if (is_array($message)) {
$message = $message['message'];
}
$this->ui->outputData($message);
}
}
return $this->raiseError($obj);
}
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);
if (isset($info['old'])) {
$obj = $reg->getPackage($package, $channel);
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']);
if (isset($info['xsdversion'])) {
$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) {
if (is_array($info[$key])) {
switch ($key) {
case 'maintainers': {
$i = 0;
$mstr = '';
foreach ($info[$key] as $m) {
if ($i++ > 0) {
$mstr .= "\n";
}
$mstr .= $m['name'] . " <";
if (isset($m['email'])) {
$mstr .= $m['email'];
} else {
$mstr .= $m['handle'] . '@php.net';
}
$mstr .= "> ($m[role])";
}
$info[$key] = $mstr;
break;
}
case 'release_deps': {
$i = 0;
$dstr = '';
foreach ($info[$key] as $d) {
if (isset($this->_deps_rel_trans[$d['rel']])) {
$rel = $this->_deps_rel_trans[$d['rel']];
} else {
$rel = $d['rel'];
}
if (isset($this->_deps_type_trans[$d['type']])) {
$type = ucfirst($this->_deps_type_trans[$d['type']]);
} else {
$type = $d['type'];
}
if (isset($d['name'])) {
$name = $d['name'] . ' ';
} else {
$name = '';
}
if (isset($d['version'])) {
$version = $d['version'] . ' ';
} else {
$version = '';
}
if (isset($d['optional']) && $d['optional'] == 'yes') {
$optional = ' (optional)';
} else {
$optional = '';
}
$dstr .= "$type $name$rel $version$optional\n";
}
$info[$key] = $dstr;
break;
}
case 'provides' : {
$debug = $this->config->get('verbose');
if ($debug < 2) {
$pstr = 'Classes: ';
} else {
$pstr = '';
}
$i = 0;
foreach ($info[$key] as $p) {
if ($debug < 2 && $p['type'] != "class") {
continue;
}
// Only print classes when verbosity mode is < 2
if ($debug < 2) {
if ($i++ > 0) {
$pstr .= ", ";
}
$pstr .= $p['name'];
} else {
if ($i++ > 0) {
$pstr .= "\n";
}
$pstr .= ucfirst($p['type']) . " " . $p['name'];
if (isset($p['explicit']) && $p['explicit'] == 1) {
$pstr .= " (explicit)";
}
}
}
$info[$key] = $pstr;
break;
}
case 'configure_options' : {
foreach ($info[$key] as $i => $p) {
$info[$key][$i] = array_map(null, array_keys($p), array_values($p));
$info[$key][$i] = array_map(
function($a) { return join(" = ", $a); },
$info[$key][$i]);
$info[$key][$i] = implode(', ', $info[$key][$i]);
}
$info[$key] = implode("\n", $info[$key]);
break;
}
default: {
$info[$key] = implode(", ", $info[$key]);
break;
}
}
}
if ($key == '_lastmodified') {
$hdate = date('Y-m-d', $info[$key]);
unset($info[$key]);
$info['Last Modified'] = $hdate;
} elseif ($key == '_lastversion') {
$info['Previous Installed Version'] = $info[$key] ? $info[$key] : '- None -';
unset($info[$key]);
} else {
$info[$key] = trim($info[$key]);
if (in_array($key, $longtext)) {
$info[$key] = preg_replace('/ +/', ' ', $info[$key]);
}
}
}
$caption = 'About ' . $info['package'] . '-' . $info['version'];
$data = array(
'caption' => $caption,
'border' => true);
foreach ($info as $key => $value) {
$key = ucwords(trim(str_replace('_', ' ', $key)));
$data['data'][] = array($key, $value);
}
$data['raw'] = $info;
$this->ui->outputData($data, 'package-info');
}
/**
* @access private
*/
function _doInfo2($command, $options, $params, &$obj, $installed)
{
$reg = &$this->config->getRegistry();
$caption = 'About ' . $obj->getChannel() . '/' .$obj->getPackage() . '-' .
$obj->getVersion();
$data = array(
'caption' => $caption,
'border' => true);
switch ($obj->getPackageType()) {
case 'php' :
$release = 'PEAR-style PHP-based Package';
break;
case 'extsrc' :
$release = 'PECL-style PHP extension (source code)';
break;
case 'zendextsrc' :
$release = 'PECL-style Zend extension (source code)';
break;
case 'extbin' :
$release = 'PECL-style PHP extension (binary)';
break;
case 'zendextbin' :
$release = 'PECL-style Zend extension (binary)';
break;
case 'bundle' :
$release = 'Package bundle (collection of packages)';
break;
}
$extends = $obj->getExtends();
$extends = $extends ?
$obj->getPackage() . ' (extends ' . $extends . ')' : $obj->getPackage();
if ($src = $obj->getSourcePackage()) {
$extends .= ' (source package ' . $src['channel'] . '/' . $src['package'] . ')';
}
$info = array(
'Release Type' => $release,
'Name' => $extends,
'Channel' => $obj->getChannel(),
'Summary' => preg_replace('/ +/', ' ', $obj->getSummary()),
'Description' => preg_replace('/ +/', ' ', $obj->getDescription()),
);
$info['Maintainers'] = '';
foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
$leads = $obj->{"get{$role}s"}();
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$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();
$uri = $obj->getLicenseLocation();
if ($uri) {
if (isset($uri['uri'])) {
$info['License'] .= ' (' . $uri['uri'] . ')';
} else {
$extra = $obj->getInstalledLocation($info['filesource']);
if ($extra) {
$info['License'] .= ' (' . $uri['filesource'] . ')';
}
}
}
$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['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 {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= $package['channel'] . '/' .
$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";
} else {
$info['Uses Custom Roles'] = '';
}
if (isset($roledata['package'])) {
$rolepackage = $reg->parsedPackageNameToString($roledata, true);
} else {
$rolepackage = $roledata['uri'];
}
$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";
} else {
$info['Uses Custom Tasks'] = '';
}
if (isset($taskdata['package'])) {
$taskpackage = $reg->parsedPackageNameToString($taskdata, true);
} else {
$taskpackage = $taskdata['uri'];
}
$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'])) {
$info['Required Dependencies'] .= '-' . $deps['required']['php']['max'] . "\n";
} else {
$info['Required Dependencies'] .= "\n";
}
if (isset($deps['required']['php']['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['php']['exclude'])) {
$deps['required']['php']['exclude'] =
implode(', ', $deps['required']['php']['exclude']);
}
$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 ' .
$deps['required']['pearinstaller']['min'] . '-' .
$deps['required']['pearinstaller']['max'];
} else {
$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'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['pearinstaller']['exclude'])) {
$deps['required']['pearinstaller']['exclude'] =
implode(', ', $deps['required']['pearinstaller']['exclude']);
}
$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])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Required Dependencies';
$info[$infoindex] .= "\n";
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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 ';
}
$info['Not Compatible with'] .= 'Package ' .
$reg->parsedPackageNameToString($package, true);
$info['Not Compatible with'] .= "\n Versions " . $package['exclude'];
}
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "$os[name] Operating System";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "$os[name] Operating System";
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "OS/Arch matching pattern '/$os[pattern]/'";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "OS/Arch matching pattern '/$os[pattern]/'";
}
}
}
if (isset($deps['optional'])) {
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($deps['optional'][$index])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Optional Dependencies';
if (!isset($info['Optional Dependencies'])) {
$info['Optional Dependencies'] = '';
} else {
$info['Optional Dependencies'] .= "\n";
}
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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'];
}
}
}
}
}
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';
$info[$groupindex] = '';
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($group[$index])) {
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 {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$name = '__uri/' . $package['name'] . ' (static URI)';
}
}
if (isset($package['uri'])) {
if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
$info[$groupindex] .= "Not Compatible with $type $name";
} 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 " .
$package['min'] . '-' . $package['max'];
} elseif (isset($package['min'])) {
$info[$groupindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} else {
$info[$groupindex] .= "Not Compatible with\n";
}
if (is_array($package['exclude'])) {
$package['exclude'] = implode(', ', $package['exclude']);
}
$info[$groupindex] .= " Package $package\n Versions " .
$package['exclude'];
}
}
}
}
}
}
if ($obj->getPackageType() == 'bundle') {
$info['Bundled Packages'] = '';
foreach ($obj->getBundledPackages() as $package) {
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]";
} else {
$info['Bundled Packages'] .= $package['channel'] . '/' . $package['name'];
}
}
}
$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');
}
}
opt/cpanel/ea-php80/root/usr/share/pear/PEAR/Command/Registry.php 0000644 00000132315 14760070775 0020427 0 ustar 00
* @author Greg Beaver
* @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/Command/Common.php';
/**
* PEAR commands for registry manipulation
*
* @category pear
* @package PEAR
* @author Stig Bakken
* @author Greg Beaver
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.10.16
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 0.1
*/
class PEAR_Command_Registry extends PEAR_Command_Common
{
var $commands = array(
'list' => array(
'summary' => 'List Installed Packages In The Default Channel',
'function' => 'doList',
'shortcut' => 'l',
'options' => array(
'channel' => array(
'shortopt' => 'c',
'doc' => 'list installed packages from this channel',
'arg' => 'CHAN',
),
'allchannels' => array(
'shortopt' => 'a',
'doc' => 'list installed packages from all channels',
),
'channelinfo' => array(
'shortopt' => 'i',
'doc' => 'output fully channel-aware data, even on failure',
),
),
'doc' => '
If invoked without parameters, this command lists the PEAR packages
installed in your php_dir ({config php_dir}). With a parameter, it
lists the files in a package.
',
),
'list-files' => array(
'summary' => 'List Files In Installed Package',
'function' => 'doFileList',
'shortcut' => 'fl',
'options' => array(),
'doc' => '
List the files in an installed package.
'
),
'shell-test' => array(
'summary' => 'Shell Script Test',
'function' => 'doShellTest',
'shortcut' => 'st',
'options' => array(),
'doc' => ' [[relation] version]
Tests if a package is installed in the system. Will exit(1) if it is not.
The version comparison operator. One of:
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
The version to compare with
'),
'info' => array(
'summary' => 'Display information about a package',
'function' => 'doInfo',
'shortcut' => 'in',
'options' => array(),
'doc' => '
Displays information about a package. The package argument may be a
local package file, an URL to a package file, or the name of an
installed package.'
)
);
/**
* PEAR_Command_Registry constructor.
*
* @access public
*/
function __construct(&$ui, &$config)
{
parent::__construct($ui, $config);
}
function _sortinfo($a, $b)
{
$apackage = isset($a['package']) ? $a['package'] : $a['name'];
$bpackage = isset($b['package']) ? $b['package'] : $b['name'];
return strcmp($apackage, $bpackage);
}
function doList($command, $options, $params)
{
$reg = &$this->config->getRegistry();
$channelinfo = isset($options['channelinfo']);
if (isset($options['allchannels']) && !$channelinfo) {
return $this->doListAll($command, array(), $params);
}
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'])) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' .
$channel . ':',
'border' => true,
'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);
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) {
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'));
$data = array(
'caption' => 'Installed packages, channel ' . $channel . ':',
'border' => true,
'headline' => array('Package', 'Version', 'State'),
'channel' => $channel
);
foreach ($packages as $package) {
$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);
}
// 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)'), array()),
'channel' => $channel
);
}
$this->ui->outputData($data, $command);
}
return true;
}
function doFileList($command, $options, $params)
{
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 ($fp) {
fclose($fp);
}
if (!class_exists('PEAR_PackageFile')) {
require_once 'PEAR/PackageFile.php';
}
$pkg = new PEAR_PackageFile($this->config, $this->_debug);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
$headings = array('Package File', 'Install Path');
$installed = false;
} else {
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
PEAR::staticPopErrorHandling();
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) {
$caption = 'Installed Files For ' . $params[0];
} else {
$caption = 'Contents of ' . basename($params[0]);
}
$data = array(
'caption' => $caption,
'border' => true,
'headline' => $headings);
if ($info->getPackagexmlVersion() == '1.0' || $installed) {
foreach ($list as $file => $att) {
if ($installed) {
if (empty($att['installed_as'])) {
continue;
}
$data['data'][] = array($att['role'], $att['installed_as']);
} else {
if (isset($att['baseinstalldir']) && !in_array($att['role'],
array('test', 'data', 'doc'))) {
$dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
$file;
} else {
$dest = $file;
}
switch ($att['role']) {
case 'test':
case 'data':
case 'doc':
$role = $att['role'];
if ($role == 'test') {
$role .= 's';
}
$dest = $this->config->get($role . '_dir') . DIRECTORY_SEPARATOR .
$info->getPackage() . DIRECTORY_SEPARATOR . $dest;
break;
case 'php':
default:
$dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
$dest;
}
$ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
$dest = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
array(DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR),
$dest);
$file = preg_replace('!/+!', '/', $file);
$data['data'][] = array($file, $dest);
}
}
} else { // package.xml 2.0, not installed
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'];
$role = &PEAR_Installer_Role::factory($info, $att['role'], $this->config);
$role->setup($this, $info, $att, $file);
if (!$role->isInstallable()) {
$dest = '(not installable)';
} else {
$dest = $role->processInstallation($info, $att, $file, '');
if (PEAR::isError($dest)) {
$dest = '(Unknown role "' . $att['role'] . ')';
} else {
list(,, $dest) = $dest;
}
}
$data['data'][] = array($file, $dest);
}
}
$this->ui->outputData($data, $command);
return true;
}
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'));
if (PEAR::isError($info)) {
exit(1); // invalid package name
}
$package = $info['package'];
$channel = $info['channel'];
// "pear shell-test Foo"
if (!$reg->packageExists($package, $channel)) {
if ($channel == 'pecl.php.net') {
if ($reg->packageExists($package, 'pear.php.net')) {
$channel = 'pear.php.net'; // magically change channels for extensions
}
}
}
if (count($params) === 1) {
if (!$reg->packageExists($package, $channel)) {
exit(1);
}
// "pear shell-test Foo 1.0"
} 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 (count($params) === 3) {
$v = $reg->packageInfo($package, 'version', $channel);
if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
exit(1);
}
} else {
PEAR::staticPopErrorHandling();
$this->raiseError("$command: expects 1 to 3 parameters");
exit(1);
}
}
function doInfo($command, $options, $params)
{
if (count($params) !== 1) {
return $this->raiseError('pear info expects 1 parameter');
}
$info = $fp = false;
$reg = &$this->config->getRegistry();
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);
PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
$obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
PEAR::staticPopErrorHandling();
if (PEAR::isError($obj)) {
$uinfo = $obj->getUserInfo();
if (is_array($uinfo)) {
foreach ($uinfo as $message) {
if (is_array($message)) {
$message = $message['message'];
}
$this->ui->outputData($message);
}
}
return $this->raiseError($obj);
}
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);
if (isset($info['old'])) {
$obj = $reg->getPackage($package, $channel);
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']);
if (isset($info['xsdversion'])) {
$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) {
if (is_array($info[$key])) {
switch ($key) {
case 'maintainers': {
$i = 0;
$mstr = '';
foreach ($info[$key] as $m) {
if ($i++ > 0) {
$mstr .= "\n";
}
$mstr .= $m['name'] . " <";
if (isset($m['email'])) {
$mstr .= $m['email'];
} else {
$mstr .= $m['handle'] . '@php.net';
}
$mstr .= "> ($m[role])";
}
$info[$key] = $mstr;
break;
}
case 'release_deps': {
$i = 0;
$dstr = '';
foreach ($info[$key] as $d) {
if (isset($this->_deps_rel_trans[$d['rel']])) {
$rel = $this->_deps_rel_trans[$d['rel']];
} else {
$rel = $d['rel'];
}
if (isset($this->_deps_type_trans[$d['type']])) {
$type = ucfirst($this->_deps_type_trans[$d['type']]);
} else {
$type = $d['type'];
}
if (isset($d['name'])) {
$name = $d['name'] . ' ';
} else {
$name = '';
}
if (isset($d['version'])) {
$version = $d['version'] . ' ';
} else {
$version = '';
}
if (isset($d['optional']) && $d['optional'] == 'yes') {
$optional = ' (optional)';
} else {
$optional = '';
}
$dstr .= "$type $name$rel $version$optional\n";
}
$info[$key] = $dstr;
break;
}
case 'provides' : {
$debug = $this->config->get('verbose');
if ($debug < 2) {
$pstr = 'Classes: ';
} else {
$pstr = '';
}
$i = 0;
foreach ($info[$key] as $p) {
if ($debug < 2 && $p['type'] != "class") {
continue;
}
// Only print classes when verbosity mode is < 2
if ($debug < 2) {
if ($i++ > 0) {
$pstr .= ", ";
}
$pstr .= $p['name'];
} else {
if ($i++ > 0) {
$pstr .= "\n";
}
$pstr .= ucfirst($p['type']) . " " . $p['name'];
if (isset($p['explicit']) && $p['explicit'] == 1) {
$pstr .= " (explicit)";
}
}
}
$info[$key] = $pstr;
break;
}
case 'configure_options' : {
foreach ($info[$key] as $i => $p) {
$info[$key][$i] = array_map(null, array_keys($p), array_values($p));
$info[$key][$i] = array_map(
function($a) { return join(" = ", $a); },
$info[$key][$i]);
$info[$key][$i] = implode(', ', $info[$key][$i]);
}
$info[$key] = implode("\n", $info[$key]);
break;
}
default: {
$info[$key] = implode(", ", $info[$key]);
break;
}
}
}
if ($key == '_lastmodified') {
$hdate = date('Y-m-d', $info[$key]);
unset($info[$key]);
$info['Last Modified'] = $hdate;
} elseif ($key == '_lastversion') {
$info['Previous Installed Version'] = $info[$key] ? $info[$key] : '- None -';
unset($info[$key]);
} else {
$info[$key] = trim($info[$key]);
if (in_array($key, $longtext)) {
$info[$key] = preg_replace('/ +/', ' ', $info[$key]);
}
}
}
$caption = 'About ' . $info['package'] . '-' . $info['version'];
$data = array(
'caption' => $caption,
'border' => true);
foreach ($info as $key => $value) {
$key = ucwords(trim(str_replace('_', ' ', $key)));
$data['data'][] = array($key, $value);
}
$data['raw'] = $info;
$this->ui->outputData($data, 'package-info');
}
/**
* @access private
*/
function _doInfo2($command, $options, $params, &$obj, $installed)
{
$reg = &$this->config->getRegistry();
$caption = 'About ' . $obj->getChannel() . '/' .$obj->getPackage() . '-' .
$obj->getVersion();
$data = array(
'caption' => $caption,
'border' => true);
switch ($obj->getPackageType()) {
case 'php' :
$release = 'PEAR-style PHP-based Package';
break;
case 'extsrc' :
$release = 'PECL-style PHP extension (source code)';
break;
case 'zendextsrc' :
$release = 'PECL-style Zend extension (source code)';
break;
case 'extbin' :
$release = 'PECL-style PHP extension (binary)';
break;
case 'zendextbin' :
$release = 'PECL-style Zend extension (binary)';
break;
case 'bundle' :
$release = 'Package bundle (collection of packages)';
break;
}
$extends = $obj->getExtends();
$extends = $extends ?
$obj->getPackage() . ' (extends ' . $extends . ')' : $obj->getPackage();
if ($src = $obj->getSourcePackage()) {
$extends .= ' (source package ' . $src['channel'] . '/' . $src['package'] . ')';
}
$info = array(
'Release Type' => $release,
'Name' => $extends,
'Channel' => $obj->getChannel(),
'Summary' => preg_replace('/ +/', ' ', $obj->getSummary()),
'Description' => preg_replace('/ +/', ' ', $obj->getDescription()),
);
$info['Maintainers'] = '';
foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
$leads = $obj->{"get{$role}s"}();
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$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();
$uri = $obj->getLicenseLocation();
if ($uri) {
if (isset($uri['uri'])) {
$info['License'] .= ' (' . $uri['uri'] . ')';
} else {
$extra = $obj->getInstalledLocation($info['filesource']);
if ($extra) {
$info['License'] .= ' (' . $uri['filesource'] . ')';
}
}
}
$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['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 {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= $package['channel'] . '/' .
$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";
} else {
$info['Uses Custom Roles'] = '';
}
if (isset($roledata['package'])) {
$rolepackage = $reg->parsedPackageNameToString($roledata, true);
} else {
$rolepackage = $roledata['uri'];
}
$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";
} else {
$info['Uses Custom Tasks'] = '';
}
if (isset($taskdata['package'])) {
$taskpackage = $reg->parsedPackageNameToString($taskdata, true);
} else {
$taskpackage = $taskdata['uri'];
}
$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'])) {
$info['Required Dependencies'] .= '-' . $deps['required']['php']['max'] . "\n";
} else {
$info['Required Dependencies'] .= "\n";
}
if (isset($deps['required']['php']['exclude'])) {
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['php']['exclude'])) {
$deps['required']['php']['exclude'] =
implode(', ', $deps['required']['php']['exclude']);
}
$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 ' .
$deps['required']['pearinstaller']['min'] . '-' .
$deps['required']['pearinstaller']['max'];
} else {
$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'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
if (is_array($deps['required']['pearinstaller']['exclude'])) {
$deps['required']['pearinstaller']['exclude'] =
implode(', ', $deps['required']['pearinstaller']['exclude']);
}
$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])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Required Dependencies';
$info[$infoindex] .= "\n";
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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 ';
}
$info['Not Compatible with'] .= 'Package ' .
$reg->parsedPackageNameToString($package, true);
$info['Not Compatible with'] .= "\n Versions " . $package['exclude'];
}
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "$os[name] Operating System";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "$os[name] Operating System";
}
}
}
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'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
$info['Not Compatible with'] .= "OS/Arch matching pattern '/$os[pattern]/'";
} else {
$info['Required Dependencies'] .= "\n";
$info['Required Dependencies'] .= "OS/Arch matching pattern '/$os[pattern]/'";
}
}
}
if (isset($deps['optional'])) {
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($deps['optional'][$index])) {
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';
if (!isset($info['Not Compatible with'])) {
$info['Not Compatible with'] = '';
} else {
$info['Not Compatible with'] .= "\n";
}
} else {
$infoindex = 'Optional Dependencies';
if (!isset($info['Optional Dependencies'])) {
$info['Optional Dependencies'] = '';
} else {
$info['Optional Dependencies'] .= "\n";
}
}
if ($index == 'extension') {
$name = $package['name'];
} else {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$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'];
} elseif (isset($package['min'])) {
$info[$infoindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} 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'];
}
}
}
}
}
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';
$info[$groupindex] = '';
foreach (array('Package', 'Extension') as $type) {
$index = strtolower($type);
if (isset($group[$index])) {
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 {
if (isset($package['channel'])) {
$name = $package['channel'] . '/' . $package['name'];
} else {
$name = '__uri/' . $package['name'] . ' (static URI)';
}
}
if (isset($package['uri'])) {
if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
$info[$groupindex] .= "Not Compatible with $type $name";
} 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 " .
$package['min'] . '-' . $package['max'];
} elseif (isset($package['min'])) {
$info[$groupindex] .= " \n Version " .
$package['min'] . ' or newer';
} elseif (isset($package['max'])) {
$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'] = '';
} else {
$info[$groupindex] .= "Not Compatible with\n";
}
if (is_array($package['exclude'])) {
$package['exclude'] = implode(', ', $package['exclude']);
}
$info[$groupindex] .= " Package $package\n Versions " .
$package['exclude'];
}
}
}
}
}
}
if ($obj->getPackageType() == 'bundle') {
$info['Bundled Packages'] = '';
foreach ($obj->getBundledPackages() as $package) {
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]";
} else {
$info['Bundled Packages'] .= $package['channel'] . '/' . $package['name'];
}
}
}
$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');
}
}