3 * PEAR_Command_Registry (list, list-files, shell-test, info commands)
9 * @author Stig Bakken <ssb@php.net>
10 * @author Greg Beaver <cellog@php.net>
11 * @copyright 1997-2009 The Authors
12 * @license http://opensource.org/licenses/bsd-license.php New BSD License
13 * @link http://pear.php.net/package/PEAR
14 * @since File available since Release 0.1
20 require_once 'PEAR/Command/Common.php';
23 * PEAR commands for registry manipulation
27 * @author Stig Bakken <ssb@php.net>
28 * @author Greg Beaver <cellog@php.net>
29 * @copyright 1997-2009 The Authors
30 * @license http://opensource.org/licenses/bsd-license.php New BSD License
31 * @version Release: 1.10.1
32 * @link http://pear.php.net/package/PEAR
33 * @since Class available since Release 0.1
35 class PEAR_Command_Registry extends PEAR_Command_Common
37 var $commands = array(
39 'summary' => 'List Installed Packages In The Default Channel',
40 'function' => 'doList',
45 'doc' => 'list installed packages from this channel',
48 'allchannels' => array(
50 'doc' => 'list installed packages from all channels',
52 'channelinfo' => array(
54 'doc' => 'output fully channel-aware data, even on failure',
58 If invoked without parameters, this command lists the PEAR packages
59 installed in your php_dir ({config php_dir}). With a parameter, it
60 lists the files in a package.
63 'list-files' => array(
64 'summary' => 'List Files In Installed Package',
65 'function' => 'doFileList',
69 List the files in an installed package.
72 'shell-test' => array(
73 'summary' => 'Shell Script Test',
74 'function' => 'doShellTest',
77 'doc' => '<package> [[relation] version]
78 Tests if a package is installed in the system. Will exit(1) if it is not.
79 <relation> The version comparison operator. One of:
80 <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
81 <version> The version to compare with
84 'summary' => 'Display information about a package',
85 'function' => 'doInfo',
89 Displays information about a package. The package argument may be a
90 local package file, an URL to a package file, or the name of an
96 * PEAR_Command_Registry constructor.
100 function __construct(&$ui, &$config)
102 parent::__construct($ui, $config);
105 function _sortinfo($a, $b)
107 $apackage = isset($a['package']) ? $a['package'] : $a['name'];
108 $bpackage = isset($b['package']) ? $b['package'] : $b['name'];
109 return strcmp($apackage, $bpackage);
112 function doList($command, $options, $params)
114 $reg = &$this->config->getRegistry();
115 $channelinfo = isset($options['channelinfo']);
116 if (isset($options['allchannels']) && !$channelinfo) {
117 return $this->doListAll($command, array(), $params);
120 if (isset($options['allchannels']) && $channelinfo) {
121 // allchannels with $channelinfo
122 unset($options['allchannels']);
123 $channels = $reg->getChannels();
125 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
126 foreach ($channels as $channel) {
127 $options['channel'] = $channel->getName();
128 $ret = $this->doList($command, $options, $params);
130 if (PEAR::isError($ret)) {
135 PEAR::staticPopErrorHandling();
136 if (count($errors)) {
137 // for now, only give first error
138 return PEAR::raiseError($errors[0]);
144 if (count($params) === 1) {
145 return $this->doFileList($command, $options, $params);
148 if (isset($options['channel'])) {
149 if (!$reg->channelExists($options['channel'])) {
150 return $this->raiseError('Channel "' . $options['channel'] .'" does not exist');
153 $channel = $reg->channelName($options['channel']);
155 $channel = $this->config->get('default_channel');
158 $installed = $reg->packageInfo(null, null, $channel);
159 usort($installed, array(&$this, '_sortinfo'));
162 'caption' => 'Installed packages, channel ' .
165 'headline' => array('Package', 'Version', 'State'),
166 'channel' => $channel,
169 $data['headline'] = array('Channel', 'Package', 'Version', 'State');
172 if (count($installed) && !isset($data['data'])) {
173 $data['data'] = array();
176 foreach ($installed as $package) {
177 $pobj = $reg->getPackage(isset($package['package']) ?
178 $package['package'] : $package['name'], $channel);
180 $packageinfo = array($pobj->getChannel(), $pobj->getPackage(), $pobj->getVersion(),
181 $pobj->getState() ? $pobj->getState() : null);
183 $packageinfo = array($pobj->getPackage(), $pobj->getVersion(),
184 $pobj->getState() ? $pobj->getState() : null);
186 $data['data'][] = $packageinfo;
189 if (count($installed) === 0) {
191 $data = '(no packages installed from channel ' . $channel . ')';
194 'caption' => 'Installed packages, channel ' .
197 'channel' => $channel,
198 'data' => array(array('(no packages installed)')),
203 $this->ui->outputData($data, $command);
207 function doListAll($command, $options, $params)
209 // This duplicate code is deprecated over
210 // list --channelinfo, which gives identical
211 // output for list and list --allchannels.
212 $reg = &$this->config->getRegistry();
213 $installed = $reg->packageInfo(null, null, null);
214 foreach ($installed as $channel => $packages) {
215 usort($packages, array($this, '_sortinfo'));
217 'caption' => 'Installed packages, channel ' . $channel . ':',
219 'headline' => array('Package', 'Version', 'State'),
220 'channel' => $channel
223 foreach ($packages as $package) {
224 $p = isset($package['package']) ? $package['package'] : $package['name'];
225 $pobj = $reg->getPackage($p, $channel);
226 $data['data'][] = array($pobj->getPackage(), $pobj->getVersion(),
227 $pobj->getState() ? $pobj->getState() : null);
230 // Adds a blank line after each section
231 $data['data'][] = array();
233 if (count($packages) === 0) {
235 'caption' => 'Installed packages, channel ' . $channel . ':',
237 'data' => array(array('(no packages installed)'), array()),
238 'channel' => $channel
241 $this->ui->outputData($data, $command);
246 function doFileList($command, $options, $params)
248 if (count($params) !== 1) {
249 return $this->raiseError('list-files expects 1 parameter');
252 $reg = &$this->config->getRegistry();
254 if (!is_dir($params[0]) && (file_exists($params[0]) || $fp = @fopen($params[0], 'r'))) {
259 if (!class_exists('PEAR_PackageFile')) {
260 require_once 'PEAR/PackageFile.php';
263 $pkg = new PEAR_PackageFile($this->config, $this->_debug);
264 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
265 $info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
266 PEAR::staticPopErrorHandling();
267 $headings = array('Package File', 'Install Path');
270 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
271 $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
272 PEAR::staticPopErrorHandling();
273 if (PEAR::isError($parsed)) {
274 return $this->raiseError($parsed);
277 $info = &$reg->getPackage($parsed['package'], $parsed['channel']);
278 $headings = array('Type', 'Install Path');
282 if (PEAR::isError($info)) {
283 return $this->raiseError($info);
286 if ($info === null) {
287 return $this->raiseError("`$params[0]' not installed");
290 $list = ($info->getPackagexmlVersion() == '1.0' || $installed) ?
291 $info->getFilelist() : $info->getContents();
293 $caption = 'Installed Files For ' . $params[0];
295 $caption = 'Contents of ' . basename($params[0]);
299 'caption' => $caption,
301 'headline' => $headings);
302 if ($info->getPackagexmlVersion() == '1.0' || $installed) {
303 foreach ($list as $file => $att) {
305 if (empty($att['installed_as'])) {
308 $data['data'][] = array($att['role'], $att['installed_as']);
310 if (isset($att['baseinstalldir']) && !in_array($att['role'],
311 array('test', 'data', 'doc'))) {
312 $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
317 switch ($att['role']) {
321 $role = $att['role'];
322 if ($role == 'test') {
325 $dest = $this->config->get($role . '_dir') . DIRECTORY_SEPARATOR .
326 $info->getPackage() . DIRECTORY_SEPARATOR . $dest;
330 $dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
333 $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
334 $dest = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
335 array(DIRECTORY_SEPARATOR,
337 DIRECTORY_SEPARATOR),
339 $file = preg_replace('!/+!', '/', $file);
340 $data['data'][] = array($file, $dest);
343 } else { // package.xml 2.0, not installed
344 if (!isset($list['dir']['file'][0])) {
345 $list['dir']['file'] = array($list['dir']['file']);
348 foreach ($list['dir']['file'] as $att) {
349 $att = $att['attribs'];
350 $file = $att['name'];
351 $role = &PEAR_Installer_Role::factory($info, $att['role'], $this->config);
352 $role->setup($this, $info, $att, $file);
353 if (!$role->isInstallable()) {
354 $dest = '(not installable)';
356 $dest = $role->processInstallation($info, $att, $file, '');
357 if (PEAR::isError($dest)) {
358 $dest = '(Unknown role "' . $att['role'] . ')';
360 list(,, $dest) = $dest;
363 $data['data'][] = array($file, $dest);
367 $this->ui->outputData($data, $command);
371 function doShellTest($command, $options, $params)
373 if (count($params) < 1) {
374 return PEAR::raiseError('ERROR, usage: pear shell-test packagename [[relation] version]');
377 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
378 $reg = &$this->config->getRegistry();
379 $info = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
380 if (PEAR::isError($info)) {
381 exit(1); // invalid package name
384 $package = $info['package'];
385 $channel = $info['channel'];
386 // "pear shell-test Foo"
387 if (!$reg->packageExists($package, $channel)) {
388 if ($channel == 'pecl.php.net') {
389 if ($reg->packageExists($package, 'pear.php.net')) {
390 $channel = 'pear.php.net'; // magically change channels for extensions
395 if (count($params) === 1) {
396 if (!$reg->packageExists($package, $channel)) {
399 // "pear shell-test Foo 1.0"
400 } elseif (count($params) === 2) {
401 $v = $reg->packageInfo($package, 'version', $channel);
402 if (!$v || !version_compare("$v", "{$params[1]}", "ge")) {
405 // "pear shell-test Foo ge 1.0"
406 } elseif (count($params) === 3) {
407 $v = $reg->packageInfo($package, 'version', $channel);
408 if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
412 PEAR::staticPopErrorHandling();
413 $this->raiseError("$command: expects 1 to 3 parameters");
418 function doInfo($command, $options, $params)
420 if (count($params) !== 1) {
421 return $this->raiseError('pear info expects 1 parameter');
425 $reg = &$this->config->getRegistry();
426 if (is_file($params[0]) && !is_dir($params[0]) &&
427 (file_exists($params[0]) || $fp = @fopen($params[0], 'r'))
433 if (!class_exists('PEAR_PackageFile')) {
434 require_once 'PEAR/PackageFile.php';
437 $pkg = new PEAR_PackageFile($this->config, $this->_debug);
438 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
439 $obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
440 PEAR::staticPopErrorHandling();
441 if (PEAR::isError($obj)) {
442 $uinfo = $obj->getUserInfo();
443 if (is_array($uinfo)) {
444 foreach ($uinfo as $message) {
445 if (is_array($message)) {
446 $message = $message['message'];
448 $this->ui->outputData($message);
452 return $this->raiseError($obj);
455 if ($obj->getPackagexmlVersion() != '1.0') {
456 return $this->_doInfo2($command, $options, $params, $obj, false);
459 $info = $obj->toArray();
461 $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
462 if (PEAR::isError($parsed)) {
463 return $this->raiseError($parsed);
466 $package = $parsed['package'];
467 $channel = $parsed['channel'];
468 $info = $reg->packageInfo($package, null, $channel);
469 if (isset($info['old'])) {
470 $obj = $reg->getPackage($package, $channel);
471 return $this->_doInfo2($command, $options, $params, $obj, true);
475 if (PEAR::isError($info)) {
480 $this->raiseError("No information found for `$params[0]'");
484 unset($info['filelist']);
485 unset($info['dirtree']);
486 unset($info['changelog']);
487 if (isset($info['xsdversion'])) {
488 $info['package.xml version'] = $info['xsdversion'];
489 unset($info['xsdversion']);
492 if (isset($info['packagerversion'])) {
493 $info['packaged with PEAR version'] = $info['packagerversion'];
494 unset($info['packagerversion']);
497 $keys = array_keys($info);
498 $longtext = array('description', 'summary');
499 foreach ($keys as $key) {
500 if (is_array($info[$key])) {
502 case 'maintainers': {
505 foreach ($info[$key] as $m) {
509 $mstr .= $m['name'] . " <";
510 if (isset($m['email'])) {
511 $mstr .= $m['email'];
513 $mstr .= $m['handle'] . '@php.net';
515 $mstr .= "> ($m[role])";
520 case 'release_deps': {
523 foreach ($info[$key] as $d) {
524 if (isset($this->_deps_rel_trans[$d['rel']])) {
525 $rel = $this->_deps_rel_trans[$d['rel']];
529 if (isset($this->_deps_type_trans[$d['type']])) {
530 $type = ucfirst($this->_deps_type_trans[$d['type']]);
534 if (isset($d['name'])) {
535 $name = $d['name'] . ' ';
539 if (isset($d['version'])) {
540 $version = $d['version'] . ' ';
544 if (isset($d['optional']) && $d['optional'] == 'yes') {
545 $optional = ' (optional)';
549 $dstr .= "$type $name$rel $version$optional\n";
555 $debug = $this->config->get('verbose');
562 foreach ($info[$key] as $p) {
563 if ($debug < 2 && $p['type'] != "class") {
566 // Only print classes when verbosity mode is < 2
576 $pstr .= ucfirst($p['type']) . " " . $p['name'];
577 if (isset($p['explicit']) && $p['explicit'] == 1) {
578 $pstr .= " (explicit)";
585 case 'configure_options' : {
586 foreach ($info[$key] as $i => $p) {
587 $info[$key][$i] = array_map(null, array_keys($p), array_values($p));
588 $info[$key][$i] = array_map(create_function('$a',
589 'return join(" = ",$a);'), $info[$key][$i]);
590 $info[$key][$i] = implode(', ', $info[$key][$i]);
592 $info[$key] = implode("\n", $info[$key]);
596 $info[$key] = implode(", ", $info[$key]);
602 if ($key == '_lastmodified') {
603 $hdate = date('Y-m-d', $info[$key]);
605 $info['Last Modified'] = $hdate;
606 } elseif ($key == '_lastversion') {
607 $info['Previous Installed Version'] = $info[$key] ? $info[$key] : '- None -';
610 $info[$key] = trim($info[$key]);
611 if (in_array($key, $longtext)) {
612 $info[$key] = preg_replace('/ +/', ' ', $info[$key]);
617 $caption = 'About ' . $info['package'] . '-' . $info['version'];
619 'caption' => $caption,
621 foreach ($info as $key => $value) {
622 $key = ucwords(trim(str_replace('_', ' ', $key)));
623 $data['data'][] = array($key, $value);
625 $data['raw'] = $info;
627 $this->ui->outputData($data, 'package-info');
633 function _doInfo2($command, $options, $params, &$obj, $installed)
635 $reg = &$this->config->getRegistry();
636 $caption = 'About ' . $obj->getChannel() . '/' .$obj->getPackage() . '-' .
639 'caption' => $caption,
641 switch ($obj->getPackageType()) {
643 $release = 'PEAR-style PHP-based Package';
646 $release = 'PECL-style PHP extension (source code)';
649 $release = 'PECL-style Zend extension (source code)';
652 $release = 'PECL-style PHP extension (binary)';
655 $release = 'PECL-style Zend extension (binary)';
658 $release = 'Package bundle (collection of packages)';
661 $extends = $obj->getExtends();
662 $extends = $extends ?
663 $obj->getPackage() . ' (extends ' . $extends . ')' : $obj->getPackage();
664 if ($src = $obj->getSourcePackage()) {
665 $extends .= ' (source package ' . $src['channel'] . '/' . $src['package'] . ')';
669 'Release Type' => $release,
671 'Channel' => $obj->getChannel(),
672 'Summary' => preg_replace('/ +/', ' ', $obj->getSummary()),
673 'Description' => preg_replace('/ +/', ' ', $obj->getDescription()),
675 $info['Maintainers'] = '';
676 foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
677 $leads = $obj->{"get{$role}s"}();
682 if (isset($leads['active'])) {
683 $leads = array($leads);
686 foreach ($leads as $lead) {
687 if (!empty($info['Maintainers'])) {
688 $info['Maintainers'] .= "\n";
691 $active = $lead['active'] == 'no' ? ', inactive' : '';
692 $info['Maintainers'] .= $lead['name'] . ' <';
693 $info['Maintainers'] .= $lead['email'] . "> ($role$active)";
697 $info['Release Date'] = $obj->getDate();
698 if ($time = $obj->getTime()) {
699 $info['Release Date'] .= ' ' . $time;
702 $info['Release Version'] = $obj->getVersion() . ' (' . $obj->getState() . ')';
703 $info['API Version'] = $obj->getVersion('api') . ' (' . $obj->getState('api') . ')';
704 $info['License'] = $obj->getLicense();
705 $uri = $obj->getLicenseLocation();
707 if (isset($uri['uri'])) {
708 $info['License'] .= ' (' . $uri['uri'] . ')';
710 $extra = $obj->getInstalledLocation($info['filesource']);
712 $info['License'] .= ' (' . $uri['filesource'] . ')';
717 $info['Release Notes'] = $obj->getNotes();
718 if ($compat = $obj->getCompatible()) {
719 if (!isset($compat[0])) {
720 $compat = array($compat);
723 $info['Compatible with'] = '';
724 foreach ($compat as $package) {
725 $info['Compatible with'] .= $package['channel'] . '/' . $package['name'] .
726 "\nVersions >= " . $package['min'] . ', <= ' . $package['max'];
727 if (isset($package['exclude'])) {
728 if (is_array($package['exclude'])) {
729 $package['exclude'] = implode(', ', $package['exclude']);
732 if (!isset($info['Not Compatible with'])) {
733 $info['Not Compatible with'] = '';
735 $info['Not Compatible with'] .= "\n";
737 $info['Not Compatible with'] .= $package['channel'] . '/' .
738 $package['name'] . "\nVersions " . $package['exclude'];
743 $usesrole = $obj->getUsesrole();
745 if (!isset($usesrole[0])) {
746 $usesrole = array($usesrole);
749 foreach ($usesrole as $roledata) {
750 if (isset($info['Uses Custom Roles'])) {
751 $info['Uses Custom Roles'] .= "\n";
753 $info['Uses Custom Roles'] = '';
756 if (isset($roledata['package'])) {
757 $rolepackage = $reg->parsedPackageNameToString($roledata, true);
759 $rolepackage = $roledata['uri'];
761 $info['Uses Custom Roles'] .= $roledata['role'] . ' (' . $rolepackage . ')';
765 $usestask = $obj->getUsestask();
767 if (!isset($usestask[0])) {
768 $usestask = array($usestask);
771 foreach ($usestask as $taskdata) {
772 if (isset($info['Uses Custom Tasks'])) {
773 $info['Uses Custom Tasks'] .= "\n";
775 $info['Uses Custom Tasks'] = '';
778 if (isset($taskdata['package'])) {
779 $taskpackage = $reg->parsedPackageNameToString($taskdata, true);
781 $taskpackage = $taskdata['uri'];
783 $info['Uses Custom Tasks'] .= $taskdata['task'] . ' (' . $taskpackage . ')';
787 $deps = $obj->getDependencies();
788 $info['Required Dependencies'] = 'PHP version ' . $deps['required']['php']['min'];
789 if (isset($deps['required']['php']['max'])) {
790 $info['Required Dependencies'] .= '-' . $deps['required']['php']['max'] . "\n";
792 $info['Required Dependencies'] .= "\n";
795 if (isset($deps['required']['php']['exclude'])) {
796 if (!isset($info['Not Compatible with'])) {
797 $info['Not Compatible with'] = '';
799 $info['Not Compatible with'] .= "\n";
802 if (is_array($deps['required']['php']['exclude'])) {
803 $deps['required']['php']['exclude'] =
804 implode(', ', $deps['required']['php']['exclude']);
806 $info['Not Compatible with'] .= "PHP versions\n " .
807 $deps['required']['php']['exclude'];
810 $info['Required Dependencies'] .= 'PEAR installer version';
811 if (isset($deps['required']['pearinstaller']['max'])) {
812 $info['Required Dependencies'] .= 's ' .
813 $deps['required']['pearinstaller']['min'] . '-' .
814 $deps['required']['pearinstaller']['max'];
816 $info['Required Dependencies'] .= ' ' .
817 $deps['required']['pearinstaller']['min'] . ' or newer';
820 if (isset($deps['required']['pearinstaller']['exclude'])) {
821 if (!isset($info['Not Compatible with'])) {
822 $info['Not Compatible with'] = '';
824 $info['Not Compatible with'] .= "\n";
827 if (is_array($deps['required']['pearinstaller']['exclude'])) {
828 $deps['required']['pearinstaller']['exclude'] =
829 implode(', ', $deps['required']['pearinstaller']['exclude']);
831 $info['Not Compatible with'] .= "PEAR installer\n Versions " .
832 $deps['required']['pearinstaller']['exclude'];
835 foreach (array('Package', 'Extension') as $type) {
836 $index = strtolower($type);
837 if (isset($deps['required'][$index])) {
838 if (isset($deps['required'][$index]['name'])) {
839 $deps['required'][$index] = array($deps['required'][$index]);
842 foreach ($deps['required'][$index] as $package) {
843 if (isset($package['conflicts'])) {
844 $infoindex = 'Not Compatible with';
845 if (!isset($info['Not Compatible with'])) {
846 $info['Not Compatible with'] = '';
848 $info['Not Compatible with'] .= "\n";
851 $infoindex = 'Required Dependencies';
852 $info[$infoindex] .= "\n";
855 if ($index == 'extension') {
856 $name = $package['name'];
858 if (isset($package['channel'])) {
859 $name = $package['channel'] . '/' . $package['name'];
861 $name = '__uri/' . $package['name'] . ' (static URI)';
865 $info[$infoindex] .= "$type $name";
866 if (isset($package['uri'])) {
867 $info[$infoindex] .= "\n Download URI: $package[uri]";
871 if (isset($package['max']) && isset($package['min'])) {
872 $info[$infoindex] .= " \n Versions " .
873 $package['min'] . '-' . $package['max'];
874 } elseif (isset($package['min'])) {
875 $info[$infoindex] .= " \n Version " .
876 $package['min'] . ' or newer';
877 } elseif (isset($package['max'])) {
878 $info[$infoindex] .= " \n Version " .
879 $package['max'] . ' or older';
882 if (isset($package['recommended'])) {
883 $info[$infoindex] .= "\n Recommended version: $package[recommended]";
886 if (isset($package['exclude'])) {
887 if (!isset($info['Not Compatible with'])) {
888 $info['Not Compatible with'] = '';
890 $info['Not Compatible with'] .= "\n";
893 if (is_array($package['exclude'])) {
894 $package['exclude'] = implode(', ', $package['exclude']);
897 $package['package'] = $package['name']; // for parsedPackageNameToString
898 if (isset($package['conflicts'])) {
899 $info['Not Compatible with'] .= '=> except ';
901 $info['Not Compatible with'] .= 'Package ' .
902 $reg->parsedPackageNameToString($package, true);
903 $info['Not Compatible with'] .= "\n Versions " . $package['exclude'];
909 if (isset($deps['required']['os'])) {
910 if (isset($deps['required']['os']['name'])) {
911 $dep['required']['os']['name'] = array($dep['required']['os']['name']);
914 foreach ($dep['required']['os'] as $os) {
915 if (isset($os['conflicts']) && $os['conflicts'] == 'yes') {
916 if (!isset($info['Not Compatible with'])) {
917 $info['Not Compatible with'] = '';
919 $info['Not Compatible with'] .= "\n";
921 $info['Not Compatible with'] .= "$os[name] Operating System";
923 $info['Required Dependencies'] .= "\n";
924 $info['Required Dependencies'] .= "$os[name] Operating System";
929 if (isset($deps['required']['arch'])) {
930 if (isset($deps['required']['arch']['pattern'])) {
931 $dep['required']['arch']['pattern'] = array($dep['required']['os']['pattern']);
934 foreach ($dep['required']['arch'] as $os) {
935 if (isset($os['conflicts']) && $os['conflicts'] == 'yes') {
936 if (!isset($info['Not Compatible with'])) {
937 $info['Not Compatible with'] = '';
939 $info['Not Compatible with'] .= "\n";
941 $info['Not Compatible with'] .= "OS/Arch matching pattern '/$os[pattern]/'";
943 $info['Required Dependencies'] .= "\n";
944 $info['Required Dependencies'] .= "OS/Arch matching pattern '/$os[pattern]/'";
949 if (isset($deps['optional'])) {
950 foreach (array('Package', 'Extension') as $type) {
951 $index = strtolower($type);
952 if (isset($deps['optional'][$index])) {
953 if (isset($deps['optional'][$index]['name'])) {
954 $deps['optional'][$index] = array($deps['optional'][$index]);
957 foreach ($deps['optional'][$index] as $package) {
958 if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
959 $infoindex = 'Not Compatible with';
960 if (!isset($info['Not Compatible with'])) {
961 $info['Not Compatible with'] = '';
963 $info['Not Compatible with'] .= "\n";
966 $infoindex = 'Optional Dependencies';
967 if (!isset($info['Optional Dependencies'])) {
968 $info['Optional Dependencies'] = '';
970 $info['Optional Dependencies'] .= "\n";
974 if ($index == 'extension') {
975 $name = $package['name'];
977 if (isset($package['channel'])) {
978 $name = $package['channel'] . '/' . $package['name'];
980 $name = '__uri/' . $package['name'] . ' (static URI)';
984 $info[$infoindex] .= "$type $name";
985 if (isset($package['uri'])) {
986 $info[$infoindex] .= "\n Download URI: $package[uri]";
990 if ($infoindex == 'Not Compatible with') {
991 // conflicts is only used to say that all versions conflict
995 if (isset($package['max']) && isset($package['min'])) {
996 $info[$infoindex] .= " \n Versions " .
997 $package['min'] . '-' . $package['max'];
998 } elseif (isset($package['min'])) {
999 $info[$infoindex] .= " \n Version " .
1000 $package['min'] . ' or newer';
1001 } elseif (isset($package['max'])) {
1002 $info[$infoindex] .= " \n Version " .
1003 $package['min'] . ' or older';
1006 if (isset($package['recommended'])) {
1007 $info[$infoindex] .= "\n Recommended version: $package[recommended]";
1010 if (isset($package['exclude'])) {
1011 if (!isset($info['Not Compatible with'])) {
1012 $info['Not Compatible with'] = '';
1014 $info['Not Compatible with'] .= "\n";
1017 if (is_array($package['exclude'])) {
1018 $package['exclude'] = implode(', ', $package['exclude']);
1021 $info['Not Compatible with'] .= "Package $package\n Versions " .
1022 $package['exclude'];
1029 if (isset($deps['group'])) {
1030 if (!isset($deps['group'][0])) {
1031 $deps['group'] = array($deps['group']);
1034 foreach ($deps['group'] as $group) {
1035 $info['Dependency Group ' . $group['attribs']['name']] = $group['attribs']['hint'];
1036 $groupindex = $group['attribs']['name'] . ' Contents';
1037 $info[$groupindex] = '';
1038 foreach (array('Package', 'Extension') as $type) {
1039 $index = strtolower($type);
1040 if (isset($group[$index])) {
1041 if (isset($group[$index]['name'])) {
1042 $group[$index] = array($group[$index]);
1045 foreach ($group[$index] as $package) {
1046 if (!empty($info[$groupindex])) {
1047 $info[$groupindex] .= "\n";
1050 if ($index == 'extension') {
1051 $name = $package['name'];
1053 if (isset($package['channel'])) {
1054 $name = $package['channel'] . '/' . $package['name'];
1056 $name = '__uri/' . $package['name'] . ' (static URI)';
1060 if (isset($package['uri'])) {
1061 if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
1062 $info[$groupindex] .= "Not Compatible with $type $name";
1064 $info[$groupindex] .= "$type $name";
1067 $info[$groupindex] .= "\n Download URI: $package[uri]";
1071 if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
1072 $info[$groupindex] .= "Not Compatible with $type $name";
1076 $info[$groupindex] .= "$type $name";
1077 if (isset($package['max']) && isset($package['min'])) {
1078 $info[$groupindex] .= " \n Versions " .
1079 $package['min'] . '-' . $package['max'];
1080 } elseif (isset($package['min'])) {
1081 $info[$groupindex] .= " \n Version " .
1082 $package['min'] . ' or newer';
1083 } elseif (isset($package['max'])) {
1084 $info[$groupindex] .= " \n Version " .
1085 $package['min'] . ' or older';
1088 if (isset($package['recommended'])) {
1089 $info[$groupindex] .= "\n Recommended version: $package[recommended]";
1092 if (isset($package['exclude'])) {
1093 if (!isset($info['Not Compatible with'])) {
1094 $info['Not Compatible with'] = '';
1096 $info[$groupindex] .= "Not Compatible with\n";
1099 if (is_array($package['exclude'])) {
1100 $package['exclude'] = implode(', ', $package['exclude']);
1102 $info[$groupindex] .= " Package $package\n Versions " .
1103 $package['exclude'];
1111 if ($obj->getPackageType() == 'bundle') {
1112 $info['Bundled Packages'] = '';
1113 foreach ($obj->getBundledPackages() as $package) {
1114 if (!empty($info['Bundled Packages'])) {
1115 $info['Bundled Packages'] .= "\n";
1118 if (isset($package['uri'])) {
1119 $info['Bundled Packages'] .= '__uri/' . $package['name'];
1120 $info['Bundled Packages'] .= "\n (URI: $package[uri]";
1122 $info['Bundled Packages'] .= $package['channel'] . '/' . $package['name'];
1127 $info['package.xml version'] = '2.0';
1129 if ($obj->getLastModified()) {
1130 $info['Last Modified'] = date('Y-m-d H:i', $obj->getLastModified());
1133 $v = $obj->getLastInstalledVersion();
1134 $info['Previous Installed Version'] = $v ? $v : '- None -';
1137 foreach ($info as $key => $value) {
1138 $data['data'][] = array($key, $value);
1141 $data['raw'] = $obj->getArray(); // no validation needed
1142 $this->ui->outputData($data, 'package-info');