php-src/pear/PEAR/Command/Registry.php

229 lines
8.3 KiB
PHP
Raw Normal View History

<?php
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Stig Bakken <ssb@fast.no> |
// | |
// +----------------------------------------------------------------------+
//
// $Id$
require_once 'PEAR/Command/Common.php';
require_once 'PEAR/Registry.php';
require_once 'PEAR/Config.php';
class PEAR_Command_Registry extends PEAR_Command_Common
{
2002-06-02 13:07:19 +00:00
// {{{ command definitions
2002-05-20 08:56:00 +00:00
var $commands = array(
'list' => array(
2002-05-20 08:56:00 +00:00
'summary' => 'List Installed Packages',
'function' => 'doList',
2002-05-21 01:38:50 +00:00
'shortcut' => 'l',
2002-05-20 08:56:00 +00:00
'options' => array(),
'doc' => '[package]
If invoked without parameters, this command lists the PEAR packages
installed in your php_dir ({config php_dir)). With a parameter, it
2002-06-02 13:07:19 +00:00
lists the files in that package.
',
2002-05-20 08:56:00 +00:00
),
'shell-test' => array(
'summary' => 'Shell Script Test',
'function' => 'doShellTest',
'shortcut' => 'st',
2002-05-20 08:56:00 +00:00
'options' => array(),
'doc' => '<package> [[relation] version]
Tests if a package is installed in the system. Will exit(1) if it is not.
2002-05-20 08:56:00 +00:00
<relation> The version comparison operator. One of:
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
2002-06-02 13:07:19 +00:00
<version> The version to compare with
'),
'info' => array(
'summary' => 'Information of an installed package',
'function' => 'doInfo',
'shortcut' => 'i',
'options' => array(),
'doc' => '[package] Displays the information of an installed package'
)
2002-05-20 08:56:00 +00:00
);
2002-06-02 13:07:19 +00:00
// }}}
// {{{ constructor
/**
* PEAR_Command_Registry constructor.
*
* @access public
*/
2002-03-22 11:59:52 +00:00
function PEAR_Command_Registry(&$ui, &$config)
{
2002-03-22 11:59:52 +00:00
parent::PEAR_Command_Common($ui, $config);
}
2002-06-02 13:07:19 +00:00
// }}}
// {{{ doList()
2002-05-27 00:22:01 +00:00
2002-06-04 15:25:23 +00:00
function _sortinfo($a, $b)
{
return strcmp($a['package'], $b['package']);
}
function doList($command, $options, $params)
2002-04-01 15:23:46 +00:00
{
2002-06-02 13:07:19 +00:00
$reg = new PEAR_Registry($this->config->get('php_dir'));
if (sizeof($params) == 0) {
$installed = $reg->packageInfo();
2002-06-04 15:25:23 +00:00
usort($installed, array(&$this, '_sortinfo'));
$i = $j = 0;
2002-06-02 13:07:19 +00:00
$data = array(
'caption' => 'Installed packages:',
'border' => true,
'headline' => array('Package', 'Version', 'State')
);
foreach ($installed as $package) {
2002-06-02 13:07:19 +00:00
$data['data'][] = array($package['package'],
$package['version'],
2002-06-02 13:07:19 +00:00
@$package['release_state']);
2002-05-20 08:56:00 +00:00
}
2002-06-02 13:07:19 +00:00
if (count($installed)==0) {
$data = '(no packages installed)';
}
2002-06-02 13:07:19 +00:00
$this->ui->outputData($data, $command);
} else {
if (file_exists($params[0]) && !is_dir($params[0])) {
include_once "PEAR/Common.php";
$obj = &new PEAR_Common;
$info = $obj->infoFromAny($params[0]);
$headings = array('Package File', 'Install Path');
$installed = false;
} else {
$info = $reg->packageInfo($params[0]);
$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['filelist'];
if ($installed) {
$caption = 'Installed Files For ' . $params[0];
} else {
$caption = 'Contents of ' . basename($params[0]);
}
2002-06-02 13:07:19 +00:00
$data = array(
'caption' => $caption,
'border' => true,
'headline' => $headings);
foreach ($list as $file => $att) {
if ($installed) {
if (empty($att['installed_as'])) {
continue;
}
2002-06-02 13:07:19 +00:00
$data['data'][] = array($att['role'], $att['installed_as']);
} else {
if (isset($att['baseinstalldir'])) {
$dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
$file;
} else {
$dest = $file;
}
switch ($att['role']) {
case 'test':
case 'data':
if ($installed) {
break 2;
}
$dest = '-- will not be installed --';
break;
case 'doc':
$dest = $this->config->get('doc_dir') . DIRECTORY_SEPARATOR .
$dest;
break;
case 'php':
default:
$dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
$dest;
}
$dest = preg_replace('!/+!', '/', $dest);
$file = preg_replace('!/+!', '/', $file);
2002-06-02 13:07:19 +00:00
$data['data'][] = array($file, $dest);
}
}
2002-06-02 13:07:19 +00:00
$this->ui->outputData($data, $command);
2002-05-20 08:56:00 +00:00
}
return true;
2002-04-01 15:23:46 +00:00
}
2002-06-02 13:07:19 +00:00
// }}}
// {{{ doShellTest()
function doShellTest($command, $options, $params)
{
2002-05-20 08:56:00 +00:00
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$reg = &new PEAR_Registry($this->config->get('php_dir'));
// "pear shell-test Foo"
if (sizeof($params) == 1) {
if (!$reg->packageExists($params[0])) {
exit(1);
}
2002-05-20 08:56:00 +00:00
// "pear shell-test Foo 1.0"
} elseif (sizeof($params) == 2) {
$v = $reg->packageInfo($params[0], 'version');
if (!$v || !version_compare($v, $params[1], "ge")) {
exit(1);
}
2002-05-20 08:56:00 +00:00
// "pear shell-test Foo ge 1.0"
} elseif (sizeof($params) == 3) {
$v = $reg->packageInfo($params[0], 'version');
if (!$v || !version_compare($v, $params[2], $params[1])) {
exit(1);
}
2002-05-20 08:56:00 +00:00
} else {
$this->popErrorHandling();
$this->raiseError("$command: expects 1 to 3 parameters");
exit(1);
}
}
// }}}
// {{{ doInfo
function doInfo($command, $options, $params)
{
// $params[0] The package for showing info
if (sizeof($params) != 1) {
return $this->raiseError("This command only accepts one param: ".
"the package you want information");
}
$package = $params[0];
$reg = &new PEAR_Registry($this->config->get('php_dir'));
if (!$reg->packageExists($package)) {
return $this->raiseError("The package $package is not installed");
}
$info = $reg->packageInfo($package);
include_once 'PEAR/Command/Package.php';
$data = &PEAR_Command_Package::_infoForDisplaying($info);
$this->ui->outputData($data, $command);
}
2002-06-02 13:07:19 +00:00
// }}}
}
?>