⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registry.php

📁 php-4.4.7学习linux时下载的源代码
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php/** * PEAR_Command_Registry (list, list-files, shell-test, info commands) * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt.  If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category   pear * @package    PEAR * @author     Stig Bakken <ssb@php.net> * @author     Greg Beaver <cellog@php.net> * @copyright  1997-2005 The PHP Group * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 * @version    CVS: $Id: Registry.php,v 1.24.4.14.2.1 2005/11/02 16:57:23 cellog Exp $ * @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 <ssb@php.net> * @author     Greg Beaver <cellog@php.net> * @copyright  1997-2005 The PHP Group * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 * @version    Release: @package_version@ * @link       http://pear.php.net/package/PEAR * @since      Class available since Release 0.1 */class PEAR_Command_Registry extends PEAR_Command_Common{    // {{{ properties    var $commands = array(        'list' => array(            'summary' => 'List Installed Packages In The Default Channel',            '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',                    ),                ),            'doc' => '<package>If invoked without parameters, this command lists the PEAR packagesinstalled in your php_dir ({config php_dir}).  With a parameter, itlists the files in a package.',            ),        'list-files' => array(            'summary' => 'List Files In Installed Package',            'function' => 'doFileList',            'shortcut' => 'fl',            'options' => array(),            'doc' => '<package>List the files in an installed package.'            ),        'shell-test' => array(            'summary' => 'Shell Script Test',            'function' => 'doShellTest',            'shortcut' => 'st',            'options' => array(),            'doc' => '<package> [[relation] version]Tests if a package is installed in the system. Will exit(1) if it is not.   <relation>   The version comparison operator. One of:                <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne   <version>    The version to compare with'),        'info' => array(            'summary'  => 'Display information about a package',            'function' => 'doInfo',            'shortcut' => 'in',            'options'  => array(),            'doc'      => '<package>Displays information about a package. The package argument may be alocal package file, an URL to a package file, or the name of aninstalled package.'            )        );    // }}}    // {{{ constructor    /**     * PEAR_Command_Registry constructor.     *     * @access public     */    function PEAR_Command_Registry(&$ui, &$config)    {        parent::PEAR_Command_Common($ui, $config);    }    // }}}    // {{{ doList()    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)    {        if (isset($options['allchannels'])) {            return $this->doListAll($command, array(), $params);        }        $reg = &$this->config->getRegistry();        if (count($params) == 1) {            return $this->doFileList($command, $options, $params);        }        if (isset($options['channel'])) {            if ($reg->channelExists($options['channel'])) {                $channel = $reg->channelName($options['channel']);            } else {                return $this->raiseError('Channel "' . $options['channel'] .'" does not exist');            }        } else {            $channel = $this->config->get('default_channel');        }        $installed = $reg->packageInfo(null, null, $channel);        usort($installed, array(&$this, '_sortinfo'));        $i = $j = 0;        $data = array(            'caption' => 'Installed packages, channel ' .                $channel . ':',            'border' => true,            'headline' => array('Package', 'Version', 'State')            );        foreach ($installed as $package) {            $pobj = $reg->getPackage(isset($package['package']) ?                                        $package['package'] : $package['name'], $channel);            $data['data'][] = array($pobj->getPackage(), $pobj->getVersion(),                                    $pobj->getState() ? $pobj->getState() : null);        }        if (count($installed)==0) {            $data = '(no packages installed from channel ' . $channel . ')';        }        $this->ui->outputData($data, $command);        return true;    }        function doListAll($command, $options, $params)    {        $reg = &$this->config->getRegistry();        $installed = $reg->packageInfo(null, null, null);        foreach ($installed as $channel => $packages) {            usort($packages, array($this, '_sortinfo'));            $i = $j = 0;            $data = array(                'caption' => 'Installed packages, channel ' . $channel . ':',                'border' => true,                'headline' => array('Package', 'Version', 'State')                );            foreach ($packages as $package) {                $pobj = $reg->getPackage(isset($package['package']) ?                                            $package['package'] : $package['name'], $channel);                $data['data'][] = array($pobj->getPackage(), $pobj->getVersion(),                                        $pobj->getState() ? $pobj->getState() : null);            }            if (count($packages)==0) {                $data = array(                    'caption' => 'Installed packages, channel ' . $channel . ':',                    'border' => true,                    'data' => array(array('(no packages installed)')),                    );            }            $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();        if (!is_dir($params[0]) && (file_exists($params[0]) || $fp = @fopen($params[0],              'r'))) {            @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;    }    // }}}    // {{{ doShellTest()    function doShellTest($command, $options, $params)    {        $this->pushErrorHandling(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 (sizeof($params) == 1) {            if (!$reg->packageExists($package, $channel)) {                exit(1);            }            // "pear shell-test Foo 1.0"        } elseif (sizeof($params) == 2) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -