2
// /* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2004 The PHP Group |
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 3.0 of the PHP license, |
9
// | that is bundled with this package in the file LICENSE, and is |
10
// | available through the world-wide-web at the following url: |
11
// | http://www.php.net/license/3_0.txt. |
12
// | If you did not receive a copy of the PHP license and are unable to |
13
// | obtain it through the world-wide-web, please send a note to |
14
// | license@php.net so we can mail you a copy immediately. |
15
// +----------------------------------------------------------------------+
16
// | Author: Stig Bakken <ssb@php.net> |
18
// +----------------------------------------------------------------------+
20
// $Id: Registry.php,v 1.36 2004/01/08 17:33:13 sniper Exp $
22
require_once 'PEAR/Command/Common.php';
23
require_once 'PEAR/Registry.php';
24
require_once 'PEAR/Config.php';
26
class PEAR_Command_Registry extends PEAR_Command_Common
30
var $commands = array(
32
'summary' => 'List Installed Packages',
33
'function' => 'doList',
37
If invoked without parameters, this command lists the PEAR packages
38
installed in your php_dir ({config php_dir)). With a parameter, it
39
lists the files in that package.
42
'shell-test' => array(
43
'summary' => 'Shell Script Test',
44
'function' => 'doShellTest',
47
'doc' => '<package> [[relation] version]
48
Tests if a package is installed in the system. Will exit(1) if it is not.
49
<relation> The version comparison operator. One of:
50
<, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
51
<version> The version to compare with
54
'summary' => 'Display information about a package',
55
'function' => 'doInfo',
59
Displays information about a package. The package argument may be a
60
local package file, an URL to a package file, or the name of an
69
* PEAR_Command_Registry constructor.
73
function PEAR_Command_Registry(&$ui, &$config)
75
parent::PEAR_Command_Common($ui, $config);
82
function _sortinfo($a, $b)
84
return strcmp($a['package'], $b['package']);
87
function doList($command, $options, $params)
89
$reg = new PEAR_Registry($this->config->get('php_dir'));
90
if (sizeof($params) == 0) {
91
$installed = $reg->packageInfo();
92
usort($installed, array(&$this, '_sortinfo'));
95
'caption' => 'Installed packages:',
97
'headline' => array('Package', 'Version', 'State')
99
foreach ($installed as $package) {
100
$data['data'][] = array($package['package'],
102
@$package['release_state']);
104
if (count($installed)==0) {
105
$data = '(no packages installed)';
107
$this->ui->outputData($data, $command);
109
if (file_exists($params[0]) && !is_dir($params[0])) {
110
include_once "PEAR/Common.php";
111
$obj = &new PEAR_Common;
112
$info = $obj->infoFromAny($params[0]);
113
$headings = array('Package File', 'Install Path');
116
$info = $reg->packageInfo($params[0]);
117
$headings = array('Type', 'Install Path');
120
if (PEAR::isError($info)) {
121
return $this->raiseError($info);
123
if ($info === null) {
124
return $this->raiseError("`$params[0]' not installed");
126
$list = $info['filelist'];
128
$caption = 'Installed Files For ' . $params[0];
130
$caption = 'Contents of ' . basename($params[0]);
133
'caption' => $caption,
135
'headline' => $headings);
136
foreach ($list as $file => $att) {
138
if (empty($att['installed_as'])) {
141
$data['data'][] = array($att['role'], $att['installed_as']);
143
if (isset($att['baseinstalldir'])) {
144
$dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
149
switch ($att['role']) {
155
$dest = '-- will not be installed --';
158
$dest = $this->config->get('doc_dir') . DIRECTORY_SEPARATOR .
163
$dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
166
$dest = preg_replace('!/+!', '/', $dest);
167
$file = preg_replace('!/+!', '/', $file);
168
$data['data'][] = array($file, $dest);
171
$this->ui->outputData($data, $command);
181
function doShellTest($command, $options, $params)
183
$this->pushErrorHandling(PEAR_ERROR_RETURN);
184
$reg = &new PEAR_Registry($this->config->get('php_dir'));
185
// "pear shell-test Foo"
186
if (sizeof($params) == 1) {
187
if (!$reg->packageExists($params[0])) {
190
// "pear shell-test Foo 1.0"
191
} elseif (sizeof($params) == 2) {
192
$v = $reg->packageInfo($params[0], 'version');
193
if (!$v || !version_compare("$v", "{$params[1]}", "ge")) {
196
// "pear shell-test Foo ge 1.0"
197
} elseif (sizeof($params) == 3) {
198
$v = $reg->packageInfo($params[0], 'version');
199
if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
203
$this->popErrorHandling();
204
$this->raiseError("$command: expects 1 to 3 parameters");
212
function doInfo($command, $options, $params)
214
// $params[0] The package for showing info
215
if (sizeof($params) != 1) {
216
return $this->raiseError("This command only accepts one param: ".
217
"the package you want information");
219
if (@is_file($params[0])) {
220
$obj = &new PEAR_Common();
221
$info = $obj->infoFromAny($params[0]);
223
$reg = &new PEAR_Registry($this->config->get('php_dir'));
224
$info = $reg->packageInfo($params[0]);
226
if (PEAR::isError($info)) {
230
$this->raiseError("Nothing found for `$params[0]'");
233
unset($info['filelist']);
234
unset($info['changelog']);
235
$keys = array_keys($info);
236
$longtext = array('description', 'summary');
237
foreach ($keys as $key) {
238
if (is_array($info[$key])) {
240
case 'maintainers': {
243
foreach ($info[$key] as $m) {
247
$mstr .= $m['name'] . " <";
248
if (isset($m['email'])) {
249
$mstr .= $m['email'];
251
$mstr .= $m['handle'] . '@php.net';
253
$mstr .= "> ($m[role])";
258
case 'release_deps': {
261
foreach ($info[$key] as $d) {
262
if (isset($this->_deps_rel_trans[$d['rel']])) {
263
$rel = $this->_deps_rel_trans[$d['rel']];
267
if (isset($this->_deps_type_trans[$d['type']])) {
268
$type = ucfirst($this->_deps_type_trans[$d['type']]);
272
if (isset($d['name'])) {
273
$name = $d['name'] . ' ';
277
if (isset($d['version'])) {
278
$version = $d['version'] . ' ';
282
$dstr .= "$type $name$rel $version\n";
288
$debug = $this->config->get('verbose');
295
foreach ($info[$key] as $p) {
296
if ($debug < 2 && $p['type'] != "class") {
299
// Only print classes when verbosity mode is < 2
309
$pstr .= ucfirst($p['type']) . " " . $p['name'];
310
if (isset($p['explicit']) && $p['explicit'] == 1) {
311
$pstr .= " (explicit)";
319
$info[$key] = implode(", ", $info[$key]);
324
if ($key == '_lastmodified') {
325
$hdate = date('Y-m-d', $info[$key]);
327
$info['Last Modified'] = $hdate;
329
$info[$key] = trim($info[$key]);
330
if (in_array($key, $longtext)) {
331
$info[$key] = preg_replace('/ +/', ' ', $info[$key]);
335
$caption = 'About ' . $info['package'] . '-' . $info['version'];
337
'caption' => $caption,
339
foreach ($info as $key => $value) {
340
$key = ucwords(trim(str_replace('_', ' ', $key)));
341
$data['data'][] = array($key, $value);
343
$data['raw'] = $info;
345
$this->ui->outputData($data, 'package-info');