Bearsampp 2026.9.23
Loading...
Searching...
No Matches
Registry.php
Go to the documentation of this file.
1<?php
16
20require_once 'PEAR/Command/Common.php';
21
36{
37 var $commands = array(
38 'list' => array(
39 'summary' => 'List Installed Packages In The Default Channel',
40 'function' => 'doList',
41 'shortcut' => 'l',
42 'options' => array(
43 'channel' => array(
44 'shortopt' => 'c',
45 'doc' => 'list installed packages from this channel',
46 'arg' => 'CHAN',
47 ),
48 'allchannels' => array(
49 'shortopt' => 'a',
50 'doc' => 'list installed packages from all channels',
51 ),
52 'channelinfo' => array(
53 'shortopt' => 'i',
54 'doc' => 'output fully channel-aware data, even on failure',
55 ),
56 ),
57 'doc' => '<package>
58If invoked without parameters, this command lists the PEAR packages
59installed in your php_dir ({config php_dir}). With a parameter, it
60lists the files in a package.
61',
62 ),
63 'list-files' => array(
64 'summary' => 'List Files In Installed Package',
65 'function' => 'doFileList',
66 'shortcut' => 'fl',
67 'options' => array(),
68 'doc' => '<package>
69List the files in an installed package.
70'
71 ),
72 'shell-test' => array(
73 'summary' => 'Shell Script Test',
74 'function' => 'doShellTest',
75 'shortcut' => 'st',
76 'options' => array(),
77 'doc' => '<package> [[relation] version]
78Tests 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
82'),
83 'info' => array(
84 'summary' => 'Display information about a package',
85 'function' => 'doInfo',
86 'shortcut' => 'in',
87 'options' => array(),
88 'doc' => '<package>
89Displays information about a package. The package argument may be a
90local package file, an URL to a package file, or the name of an
91installed package.'
92 )
93 );
94
101 {
102 parent::__construct($ui, $config);
103 }
104
105 function _sortinfo($a, $b)
106 {
107 $apackage = isset($a['package']) ? $a['package'] : $a['name'];
108 $bpackage = isset($b['package']) ? $b['package'] : $b['name'];
109 return strcmp($apackage, $bpackage);
110 }
111
112 function doList($command, $options, $params)
113 {
114 $reg = &$this->config->getRegistry();
115 $channelinfo = isset($options['channelinfo']);
116 if (isset($options['allchannels']) && !$channelinfo) {
117 return $this->doListAll($command, array(), $params);
118 }
119
120 if (isset($options['allchannels']) && $channelinfo) {
121 // allchannels with $channelinfo
122 unset($options['allchannels']);
123 $channels = $reg->getChannels();
124 $errors = array();
126 foreach ($channels as $channel) {
127 $options['channel'] = $channel->getName();
128 $ret = $this->doList($command, $options, $params);
129
130 if (PEAR::isError($ret)) {
131 $errors[] = $ret;
132 }
133 }
134
136 if (count($errors)) {
137 // for now, only give first error
138 return PEAR::raiseError($errors[0]);
139 }
140
141 return true;
142 }
143
144 if (count($params) === 1) {
145 return $this->doFileList($command, $options, $params);
146 }
147
148 if (isset($options['channel'])) {
149 if (!$reg->channelExists($options['channel'])) {
150 return $this->raiseError('Channel "' . $options['channel'] .'" does not exist');
151 }
152
153 $channel = $reg->channelName($options['channel']);
154 } else {
155 $channel = $this->config->get('default_channel');
156 }
157
158 $installed = $reg->packageInfo(null, null, $channel);
159 usort($installed, array(&$this, '_sortinfo'));
160
161 $data = array(
162 'caption' => 'Installed packages, channel ' .
163 $channel . ':',
164 'border' => true,
165 'headline' => array('Package', 'Version', 'State'),
166 'channel' => $channel,
167 );
168 if ($channelinfo) {
169 $data['headline'] = array('Channel', 'Package', 'Version', 'State');
170 }
171
172 if (count($installed) && !isset($data['data'])) {
173 $data['data'] = array();
174 }
175
176 foreach ($installed as $package) {
177 $pobj = $reg->getPackage(isset($package['package']) ?
178 $package['package'] : $package['name'], $channel);
179 if ($channelinfo) {
180 $packageinfo = array($pobj->getChannel(), $pobj->getPackage(), $pobj->getVersion(),
181 $pobj->getState() ? $pobj->getState() : null);
182 } else {
183 $packageinfo = array($pobj->getPackage(), $pobj->getVersion(),
184 $pobj->getState() ? $pobj->getState() : null);
185 }
186 $data['data'][] = $packageinfo;
187 }
188
189 if (count($installed) === 0) {
190 if (!$channelinfo) {
191 $data = '(no packages installed from channel ' . $channel . ')';
192 } else {
193 $data = array(
194 'caption' => 'Installed packages, channel ' .
195 $channel . ':',
196 'border' => true,
197 'channel' => $channel,
198 'data' => array(array('(no packages installed)')),
199 );
200 }
201 }
202
203 $this->ui->outputData($data, $command);
204 return true;
205 }
206
207 function doListAll($command, $options, $params)
208 {
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'));
216 $data = array(
217 'caption' => 'Installed packages, channel ' . $channel . ':',
218 'border' => true,
219 'headline' => array('Package', 'Version', 'State'),
220 'channel' => $channel
221 );
222
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);
228 }
229
230 // Adds a blank line after each section
231 $data['data'][] = array();
232
233 if (count($packages) === 0) {
234 $data = array(
235 'caption' => 'Installed packages, channel ' . $channel . ':',
236 'border' => true,
237 'data' => array(array('(no packages installed)'), array()),
238 'channel' => $channel
239 );
240 }
241 $this->ui->outputData($data, $command);
242 }
243 return true;
244 }
245
246 function doFileList($command, $options, $params)
247 {
248 if (count($params) !== 1) {
249 return $this->raiseError('list-files expects 1 parameter');
250 }
251
252 $reg = &$this->config->getRegistry();
253 $fp = false;
254 if (!is_dir($params[0]) && (file_exists($params[0]) || $fp = @fopen($params[0], 'r'))) {
255 if ($fp) {
256 fclose($fp);
257 }
258
259 if (!class_exists('PEAR_PackageFile')) {
260 require_once 'PEAR/PackageFile.php';
261 }
262
263 $pkg = new PEAR_PackageFile($this->config, $this->_debug);
265 $info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
267 $headings = array('Package File', 'Install Path');
268 $installed = false;
269 } else {
271 $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
273 if (PEAR::isError($parsed)) {
274 return $this->raiseError($parsed);
275 }
276
277 $info = &$reg->getPackage($parsed['package'], $parsed['channel']);
278 $headings = array('Type', 'Install Path');
279 $installed = true;
280 }
281
282 if (PEAR::isError($info)) {
283 return $this->raiseError($info);
284 }
285
286 if ($info === null) {
287 return $this->raiseError("`$params[0]' not installed");
288 }
289
290 $list = ($info->getPackagexmlVersion() == '1.0' || $installed) ?
291 $info->getFilelist() : $info->getContents();
292 if ($installed) {
293 $caption = 'Installed Files For ' . $params[0];
294 } else {
295 $caption = 'Contents of ' . basename($params[0]);
296 }
297
298 $data = array(
299 'caption' => $caption,
300 'border' => true,
301 'headline' => $headings);
302 if ($info->getPackagexmlVersion() == '1.0' || $installed) {
303 foreach ($list as $file => $att) {
304 if ($installed) {
305 if (empty($att['installed_as'])) {
306 continue;
307 }
308 $data['data'][] = array($att['role'], $att['installed_as']);
309 } else {
310 if (isset($att['baseinstalldir']) && !in_array($att['role'],
311 array('test', 'data', 'doc'))) {
312 $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
313 $file;
314 } else {
315 $dest = $file;
316 }
317 switch ($att['role']) {
318 case 'test':
319 case 'data':
320 case 'doc':
321 $role = $att['role'];
322 if ($role == 'test') {
323 $role .= 's';
324 }
325 $dest = $this->config->get($role . '_dir') . DIRECTORY_SEPARATOR .
326 $info->getPackage() . DIRECTORY_SEPARATOR . $dest;
327 break;
328 case 'php':
329 default:
330 $dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
331 $dest;
332 }
333 $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
334 $dest = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
335 array(DIRECTORY_SEPARATOR,
336 DIRECTORY_SEPARATOR,
337 DIRECTORY_SEPARATOR),
338 $dest);
339 $file = preg_replace('!/+!', '/', $file);
340 $data['data'][] = array($file, $dest);
341 }
342 }
343 } else { // package.xml 2.0, not installed
344 if (!isset($list['dir']['file'][0])) {
345 $list['dir']['file'] = array($list['dir']['file']);
346 }
347
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)';
355 } else {
356 $dest = $role->processInstallation($info, $att, $file, '');
357 if (PEAR::isError($dest)) {
358 $dest = '(Unknown role "' . $att['role'] . ')';
359 } else {
360 list(,, $dest) = $dest;
361 }
362 }
363 $data['data'][] = array($file, $dest);
364 }
365 }
366
367 $this->ui->outputData($data, $command);
368 return true;
369 }
370
371 function doShellTest($command, $options, $params)
372 {
373 if (count($params) < 1) {
374 return PEAR::raiseError('ERROR, usage: pear shell-test packagename [[relation] version]');
375 }
376
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
382 }
383
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
391 }
392 }
393 }
394
395 if (count($params) === 1) {
396 if (!$reg->packageExists($package, $channel)) {
397 exit(1);
398 }
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")) {
403 exit(1);
404 }
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])) {
409 exit(1);
410 }
411 } else {
413 $this->raiseError("$command: expects 1 to 3 parameters");
414 exit(1);
415 }
416 }
417
418 function doInfo($command, $options, $params)
419 {
420 if (count($params) !== 1) {
421 return $this->raiseError('pear info expects 1 parameter');
422 }
423
424 $info = $fp = false;
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'))
428 ) {
429 if ($fp) {
430 fclose($fp);
431 }
432
433 if (!class_exists('PEAR_PackageFile')) {
434 require_once 'PEAR/PackageFile.php';
435 }
436
437 $pkg = new PEAR_PackageFile($this->config, $this->_debug);
439 $obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
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'];
447 }
448 $this->ui->outputData($message);
449 }
450 }
451
452 return $this->raiseError($obj);
453 }
454
455 if ($obj->getPackagexmlVersion() != '1.0') {
456 return $this->_doInfo2($command, $options, $params, $obj, false);
457 }
458
459 $info = $obj->toArray();
460 } else {
461 $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
462 if (PEAR::isError($parsed)) {
463 return $this->raiseError($parsed);
464 }
465
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);
472 }
473 }
474
475 if (PEAR::isError($info)) {
476 return $info;
477 }
478
479 if (empty($info)) {
480 $this->raiseError("No information found for `$params[0]'");
481 return;
482 }
483
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']);
490 }
491
492 if (isset($info['packagerversion'])) {
493 $info['packaged with PEAR version'] = $info['packagerversion'];
494 unset($info['packagerversion']);
495 }
496
497 $keys = array_keys($info);
498 $longtext = array('description', 'summary');
499 foreach ($keys as $key) {
500 if (is_array($info[$key])) {
501 switch ($key) {
502 case 'maintainers': {
503 $i = 0;
504 $mstr = '';
505 foreach ($info[$key] as $m) {
506 if ($i++ > 0) {
507 $mstr .= "\n";
508 }
509 $mstr .= $m['name'] . " <";
510 if (isset($m['email'])) {
511 $mstr .= $m['email'];
512 } else {
513 $mstr .= $m['handle'] . '@php.net';
514 }
515 $mstr .= "> ($m[role])";
516 }
517 $info[$key] = $mstr;
518 break;
519 }
520 case 'release_deps': {
521 $i = 0;
522 $dstr = '';
523 foreach ($info[$key] as $d) {
524 if (isset($this->_deps_rel_trans[$d['rel']])) {
525 $rel = $this->_deps_rel_trans[$d['rel']];
526 } else {
527 $rel = $d['rel'];
528 }
529 if (isset($this->_deps_type_trans[$d['type']])) {
530 $type = ucfirst($this->_deps_type_trans[$d['type']]);
531 } else {
532 $type = $d['type'];
533 }
534 if (isset($d['name'])) {
535 $name = $d['name'] . ' ';
536 } else {
537 $name = '';
538 }
539 if (isset($d['version'])) {
540 $version = $d['version'] . ' ';
541 } else {
542 $version = '';
543 }
544 if (isset($d['optional']) && $d['optional'] == 'yes') {
545 $optional = ' (optional)';
546 } else {
547 $optional = '';
548 }
549 $dstr .= "$type $name$rel $version$optional\n";
550 }
551 $info[$key] = $dstr;
552 break;
553 }
554 case 'provides' : {
555 $debug = $this->config->get('verbose');
556 if ($debug < 2) {
557 $pstr = 'Classes: ';
558 } else {
559 $pstr = '';
560 }
561 $i = 0;
562 foreach ($info[$key] as $p) {
563 if ($debug < 2 && $p['type'] != "class") {
564 continue;
565 }
566 // Only print classes when verbosity mode is < 2
567 if ($debug < 2) {
568 if ($i++ > 0) {
569 $pstr .= ", ";
570 }
571 $pstr .= $p['name'];
572 } else {
573 if ($i++ > 0) {
574 $pstr .= "\n";
575 }
576 $pstr .= ucfirst($p['type']) . " " . $p['name'];
577 if (isset($p['explicit']) && $p['explicit'] == 1) {
578 $pstr .= " (explicit)";
579 }
580 }
581 }
582 $info[$key] = $pstr;
583 break;
584 }
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(
589 function($a) { return join(" = ", $a); },
590 $info[$key][$i]);
591 $info[$key][$i] = implode(', ', $info[$key][$i]);
592 }
593 $info[$key] = implode("\n", $info[$key]);
594 break;
595 }
596 default: {
597 $info[$key] = implode(", ", $info[$key]);
598 break;
599 }
600 }
601 }
602
603 if ($key == '_lastmodified') {
604 $hdate = date('Y-m-d', $info[$key]);
605 unset($info[$key]);
606 $info['Last Modified'] = $hdate;
607 } elseif ($key == '_lastversion') {
608 $info['Previous Installed Version'] = $info[$key] ? $info[$key] : '- None -';
609 unset($info[$key]);
610 } else {
611 $info[$key] = trim($info[$key]);
612 if (in_array($key, $longtext)) {
613 $info[$key] = preg_replace('/ +/', ' ', $info[$key]);
614 }
615 }
616 }
617
618 $caption = 'About ' . $info['package'] . '-' . $info['version'];
619 $data = array(
620 'caption' => $caption,
621 'border' => true);
622 foreach ($info as $key => $value) {
623 $key = ucwords(trim(str_replace('_', ' ', $key)));
624 $data['data'][] = array($key, $value);
625 }
626 $data['raw'] = $info;
627
628 $this->ui->outputData($data, 'package-info');
629 }
630
634 function _doInfo2($command, $options, $params, &$obj, $installed)
635 {
636 $reg = &$this->config->getRegistry();
637 $caption = 'About ' . $obj->getChannel() . '/' .$obj->getPackage() . '-' .
638 $obj->getVersion();
639 $data = array(
640 'caption' => $caption,
641 'border' => true);
642 switch ($obj->getPackageType()) {
643 case 'php' :
644 $release = 'PEAR-style PHP-based Package';
645 break;
646 case 'extsrc' :
647 $release = 'PECL-style PHP extension (source code)';
648 break;
649 case 'zendextsrc' :
650 $release = 'PECL-style Zend extension (source code)';
651 break;
652 case 'extbin' :
653 $release = 'PECL-style PHP extension (binary)';
654 break;
655 case 'zendextbin' :
656 $release = 'PECL-style Zend extension (binary)';
657 break;
658 case 'bundle' :
659 $release = 'Package bundle (collection of packages)';
660 break;
661 }
662 $extends = $obj->getExtends();
663 $extends = $extends ?
664 $obj->getPackage() . ' (extends ' . $extends . ')' : $obj->getPackage();
665 if ($src = $obj->getSourcePackage()) {
666 $extends .= ' (source package ' . $src['channel'] . '/' . $src['package'] . ')';
667 }
668
669 $info = array(
670 'Release Type' => $release,
671 'Name' => $extends,
672 'Channel' => $obj->getChannel(),
673 'Summary' => preg_replace('/ +/', ' ', $obj->getSummary()),
674 'Description' => preg_replace('/ +/', ' ', $obj->getDescription()),
675 );
676 $info['Maintainers'] = '';
677 foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
678 $leads = $obj->{"get{$role}s"}();
679 if (!$leads) {
680 continue;
681 }
682
683 if (isset($leads['active'])) {
684 $leads = array($leads);
685 }
686
687 foreach ($leads as $lead) {
688 if (!empty($info['Maintainers'])) {
689 $info['Maintainers'] .= "\n";
690 }
691
692 $active = $lead['active'] == 'no' ? ', inactive' : '';
693 $info['Maintainers'] .= $lead['name'] . ' <';
694 $info['Maintainers'] .= $lead['email'] . "> ($role$active)";
695 }
696 }
697
698 $info['Release Date'] = $obj->getDate();
699 if ($time = $obj->getTime()) {
700 $info['Release Date'] .= ' ' . $time;
701 }
702
703 $info['Release Version'] = $obj->getVersion() . ' (' . $obj->getState() . ')';
704 $info['API Version'] = $obj->getVersion('api') . ' (' . $obj->getState('api') . ')';
705 $info['License'] = $obj->getLicense();
706 $uri = $obj->getLicenseLocation();
707 if ($uri) {
708 if (isset($uri['uri'])) {
709 $info['License'] .= ' (' . $uri['uri'] . ')';
710 } else {
711 $extra = $obj->getInstalledLocation($info['filesource']);
712 if ($extra) {
713 $info['License'] .= ' (' . $uri['filesource'] . ')';
714 }
715 }
716 }
717
718 $info['Release Notes'] = $obj->getNotes();
719 if ($compat = $obj->getCompatible()) {
720 if (!isset($compat[0])) {
721 $compat = array($compat);
722 }
723
724 $info['Compatible with'] = '';
725 foreach ($compat as $package) {
726 $info['Compatible with'] .= $package['channel'] . '/' . $package['name'] .
727 "\nVersions >= " . $package['min'] . ', <= ' . $package['max'];
728 if (isset($package['exclude'])) {
729 if (is_array($package['exclude'])) {
730 $package['exclude'] = implode(', ', $package['exclude']);
731 }
732
733 if (!isset($info['Not Compatible with'])) {
734 $info['Not Compatible with'] = '';
735 } else {
736 $info['Not Compatible with'] .= "\n";
737 }
738 $info['Not Compatible with'] .= $package['channel'] . '/' .
739 $package['name'] . "\nVersions " . $package['exclude'];
740 }
741 }
742 }
743
744 $usesrole = $obj->getUsesrole();
745 if ($usesrole) {
746 if (!isset($usesrole[0])) {
747 $usesrole = array($usesrole);
748 }
749
750 foreach ($usesrole as $roledata) {
751 if (isset($info['Uses Custom Roles'])) {
752 $info['Uses Custom Roles'] .= "\n";
753 } else {
754 $info['Uses Custom Roles'] = '';
755 }
756
757 if (isset($roledata['package'])) {
758 $rolepackage = $reg->parsedPackageNameToString($roledata, true);
759 } else {
760 $rolepackage = $roledata['uri'];
761 }
762 $info['Uses Custom Roles'] .= $roledata['role'] . ' (' . $rolepackage . ')';
763 }
764 }
765
766 $usestask = $obj->getUsestask();
767 if ($usestask) {
768 if (!isset($usestask[0])) {
769 $usestask = array($usestask);
770 }
771
772 foreach ($usestask as $taskdata) {
773 if (isset($info['Uses Custom Tasks'])) {
774 $info['Uses Custom Tasks'] .= "\n";
775 } else {
776 $info['Uses Custom Tasks'] = '';
777 }
778
779 if (isset($taskdata['package'])) {
780 $taskpackage = $reg->parsedPackageNameToString($taskdata, true);
781 } else {
782 $taskpackage = $taskdata['uri'];
783 }
784 $info['Uses Custom Tasks'] .= $taskdata['task'] . ' (' . $taskpackage . ')';
785 }
786 }
787
788 $deps = $obj->getDependencies();
789 $info['Required Dependencies'] = 'PHP version ' . $deps['required']['php']['min'];
790 if (isset($deps['required']['php']['max'])) {
791 $info['Required Dependencies'] .= '-' . $deps['required']['php']['max'] . "\n";
792 } else {
793 $info['Required Dependencies'] .= "\n";
794 }
795
796 if (isset($deps['required']['php']['exclude'])) {
797 if (!isset($info['Not Compatible with'])) {
798 $info['Not Compatible with'] = '';
799 } else {
800 $info['Not Compatible with'] .= "\n";
801 }
802
803 if (is_array($deps['required']['php']['exclude'])) {
804 $deps['required']['php']['exclude'] =
805 implode(', ', $deps['required']['php']['exclude']);
806 }
807 $info['Not Compatible with'] .= "PHP versions\n " .
808 $deps['required']['php']['exclude'];
809 }
810
811 $info['Required Dependencies'] .= 'PEAR installer version';
812 if (isset($deps['required']['pearinstaller']['max'])) {
813 $info['Required Dependencies'] .= 's ' .
814 $deps['required']['pearinstaller']['min'] . '-' .
815 $deps['required']['pearinstaller']['max'];
816 } else {
817 $info['Required Dependencies'] .= ' ' .
818 $deps['required']['pearinstaller']['min'] . ' or newer';
819 }
820
821 if (isset($deps['required']['pearinstaller']['exclude'])) {
822 if (!isset($info['Not Compatible with'])) {
823 $info['Not Compatible with'] = '';
824 } else {
825 $info['Not Compatible with'] .= "\n";
826 }
827
828 if (is_array($deps['required']['pearinstaller']['exclude'])) {
829 $deps['required']['pearinstaller']['exclude'] =
830 implode(', ', $deps['required']['pearinstaller']['exclude']);
831 }
832 $info['Not Compatible with'] .= "PEAR installer\n Versions " .
833 $deps['required']['pearinstaller']['exclude'];
834 }
835
836 foreach (array('Package', 'Extension') as $type) {
837 $index = strtolower($type);
838 if (isset($deps['required'][$index])) {
839 if (isset($deps['required'][$index]['name'])) {
840 $deps['required'][$index] = array($deps['required'][$index]);
841 }
842
843 foreach ($deps['required'][$index] as $package) {
844 if (isset($package['conflicts'])) {
845 $infoindex = 'Not Compatible with';
846 if (!isset($info['Not Compatible with'])) {
847 $info['Not Compatible with'] = '';
848 } else {
849 $info['Not Compatible with'] .= "\n";
850 }
851 } else {
852 $infoindex = 'Required Dependencies';
853 $info[$infoindex] .= "\n";
854 }
855
856 if ($index == 'extension') {
857 $name = $package['name'];
858 } else {
859 if (isset($package['channel'])) {
860 $name = $package['channel'] . '/' . $package['name'];
861 } else {
862 $name = '__uri/' . $package['name'] . ' (static URI)';
863 }
864 }
865
866 $info[$infoindex] .= "$type $name";
867 if (isset($package['uri'])) {
868 $info[$infoindex] .= "\n Download URI: $package[uri]";
869 continue;
870 }
871
872 if (isset($package['max']) && isset($package['min'])) {
873 $info[$infoindex] .= " \n Versions " .
874 $package['min'] . '-' . $package['max'];
875 } elseif (isset($package['min'])) {
876 $info[$infoindex] .= " \n Version " .
877 $package['min'] . ' or newer';
878 } elseif (isset($package['max'])) {
879 $info[$infoindex] .= " \n Version " .
880 $package['max'] . ' or older';
881 }
882
883 if (isset($package['recommended'])) {
884 $info[$infoindex] .= "\n Recommended version: $package[recommended]";
885 }
886
887 if (isset($package['exclude'])) {
888 if (!isset($info['Not Compatible with'])) {
889 $info['Not Compatible with'] = '';
890 } else {
891 $info['Not Compatible with'] .= "\n";
892 }
893
894 if (is_array($package['exclude'])) {
895 $package['exclude'] = implode(', ', $package['exclude']);
896 }
897
898 $package['package'] = $package['name']; // for parsedPackageNameToString
899 if (isset($package['conflicts'])) {
900 $info['Not Compatible with'] .= '=> except ';
901 }
902 $info['Not Compatible with'] .= 'Package ' .
903 $reg->parsedPackageNameToString($package, true);
904 $info['Not Compatible with'] .= "\n Versions " . $package['exclude'];
905 }
906 }
907 }
908 }
909
910 if (isset($deps['required']['os'])) {
911 if (isset($deps['required']['os']['name'])) {
912 $dep['required']['os']['name'] = array($dep['required']['os']['name']);
913 }
914
915 foreach ($dep['required']['os'] as $os) {
916 if (isset($os['conflicts']) && $os['conflicts'] == 'yes') {
917 if (!isset($info['Not Compatible with'])) {
918 $info['Not Compatible with'] = '';
919 } else {
920 $info['Not Compatible with'] .= "\n";
921 }
922 $info['Not Compatible with'] .= "$os[name] Operating System";
923 } else {
924 $info['Required Dependencies'] .= "\n";
925 $info['Required Dependencies'] .= "$os[name] Operating System";
926 }
927 }
928 }
929
930 if (isset($deps['required']['arch'])) {
931 if (isset($deps['required']['arch']['pattern'])) {
932 $dep['required']['arch']['pattern'] = array($dep['required']['os']['pattern']);
933 }
934
935 foreach ($dep['required']['arch'] as $os) {
936 if (isset($os['conflicts']) && $os['conflicts'] == 'yes') {
937 if (!isset($info['Not Compatible with'])) {
938 $info['Not Compatible with'] = '';
939 } else {
940 $info['Not Compatible with'] .= "\n";
941 }
942 $info['Not Compatible with'] .= "OS/Arch matching pattern '/$os[pattern]/'";
943 } else {
944 $info['Required Dependencies'] .= "\n";
945 $info['Required Dependencies'] .= "OS/Arch matching pattern '/$os[pattern]/'";
946 }
947 }
948 }
949
950 if (isset($deps['optional'])) {
951 foreach (array('Package', 'Extension') as $type) {
952 $index = strtolower($type);
953 if (isset($deps['optional'][$index])) {
954 if (isset($deps['optional'][$index]['name'])) {
955 $deps['optional'][$index] = array($deps['optional'][$index]);
956 }
957
958 foreach ($deps['optional'][$index] as $package) {
959 if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
960 $infoindex = 'Not Compatible with';
961 if (!isset($info['Not Compatible with'])) {
962 $info['Not Compatible with'] = '';
963 } else {
964 $info['Not Compatible with'] .= "\n";
965 }
966 } else {
967 $infoindex = 'Optional Dependencies';
968 if (!isset($info['Optional Dependencies'])) {
969 $info['Optional Dependencies'] = '';
970 } else {
971 $info['Optional Dependencies'] .= "\n";
972 }
973 }
974
975 if ($index == 'extension') {
976 $name = $package['name'];
977 } else {
978 if (isset($package['channel'])) {
979 $name = $package['channel'] . '/' . $package['name'];
980 } else {
981 $name = '__uri/' . $package['name'] . ' (static URI)';
982 }
983 }
984
985 $info[$infoindex] .= "$type $name";
986 if (isset($package['uri'])) {
987 $info[$infoindex] .= "\n Download URI: $package[uri]";
988 continue;
989 }
990
991 if ($infoindex == 'Not Compatible with') {
992 // conflicts is only used to say that all versions conflict
993 continue;
994 }
995
996 if (isset($package['max']) && isset($package['min'])) {
997 $info[$infoindex] .= " \n Versions " .
998 $package['min'] . '-' . $package['max'];
999 } elseif (isset($package['min'])) {
1000 $info[$infoindex] .= " \n Version " .
1001 $package['min'] . ' or newer';
1002 } elseif (isset($package['max'])) {
1003 $info[$infoindex] .= " \n Version " .
1004 $package['min'] . ' or older';
1005 }
1006
1007 if (isset($package['recommended'])) {
1008 $info[$infoindex] .= "\n Recommended version: $package[recommended]";
1009 }
1010
1011 if (isset($package['exclude'])) {
1012 if (!isset($info['Not Compatible with'])) {
1013 $info['Not Compatible with'] = '';
1014 } else {
1015 $info['Not Compatible with'] .= "\n";
1016 }
1017
1018 if (is_array($package['exclude'])) {
1019 $package['exclude'] = implode(', ', $package['exclude']);
1020 }
1021
1022 $info['Not Compatible with'] .= "Package $package\n Versions " .
1023 $package['exclude'];
1024 }
1025 }
1026 }
1027 }
1028 }
1029
1030 if (isset($deps['group'])) {
1031 if (!isset($deps['group'][0])) {
1032 $deps['group'] = array($deps['group']);
1033 }
1034
1035 foreach ($deps['group'] as $group) {
1036 $info['Dependency Group ' . $group['attribs']['name']] = $group['attribs']['hint'];
1037 $groupindex = $group['attribs']['name'] . ' Contents';
1038 $info[$groupindex] = '';
1039 foreach (array('Package', 'Extension') as $type) {
1040 $index = strtolower($type);
1041 if (isset($group[$index])) {
1042 if (isset($group[$index]['name'])) {
1043 $group[$index] = array($group[$index]);
1044 }
1045
1046 foreach ($group[$index] as $package) {
1047 if (!empty($info[$groupindex])) {
1048 $info[$groupindex] .= "\n";
1049 }
1050
1051 if ($index == 'extension') {
1052 $name = $package['name'];
1053 } else {
1054 if (isset($package['channel'])) {
1055 $name = $package['channel'] . '/' . $package['name'];
1056 } else {
1057 $name = '__uri/' . $package['name'] . ' (static URI)';
1058 }
1059 }
1060
1061 if (isset($package['uri'])) {
1062 if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
1063 $info[$groupindex] .= "Not Compatible with $type $name";
1064 } else {
1065 $info[$groupindex] .= "$type $name";
1066 }
1067
1068 $info[$groupindex] .= "\n Download URI: $package[uri]";
1069 continue;
1070 }
1071
1072 if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
1073 $info[$groupindex] .= "Not Compatible with $type $name";
1074 continue;
1075 }
1076
1077 $info[$groupindex] .= "$type $name";
1078 if (isset($package['max']) && isset($package['min'])) {
1079 $info[$groupindex] .= " \n Versions " .
1080 $package['min'] . '-' . $package['max'];
1081 } elseif (isset($package['min'])) {
1082 $info[$groupindex] .= " \n Version " .
1083 $package['min'] . ' or newer';
1084 } elseif (isset($package['max'])) {
1085 $info[$groupindex] .= " \n Version " .
1086 $package['min'] . ' or older';
1087 }
1088
1089 if (isset($package['recommended'])) {
1090 $info[$groupindex] .= "\n Recommended version: $package[recommended]";
1091 }
1092
1093 if (isset($package['exclude'])) {
1094 if (!isset($info['Not Compatible with'])) {
1095 $info['Not Compatible with'] = '';
1096 } else {
1097 $info[$groupindex] .= "Not Compatible with\n";
1098 }
1099
1100 if (is_array($package['exclude'])) {
1101 $package['exclude'] = implode(', ', $package['exclude']);
1102 }
1103 $info[$groupindex] .= " Package $package\n Versions " .
1104 $package['exclude'];
1105 }
1106 }
1107 }
1108 }
1109 }
1110 }
1111
1112 if ($obj->getPackageType() == 'bundle') {
1113 $info['Bundled Packages'] = '';
1114 foreach ($obj->getBundledPackages() as $package) {
1115 if (!empty($info['Bundled Packages'])) {
1116 $info['Bundled Packages'] .= "\n";
1117 }
1118
1119 if (isset($package['uri'])) {
1120 $info['Bundled Packages'] .= '__uri/' . $package['name'];
1121 $info['Bundled Packages'] .= "\n (URI: $package[uri]";
1122 } else {
1123 $info['Bundled Packages'] .= $package['channel'] . '/' . $package['name'];
1124 }
1125 }
1126 }
1127
1128 $info['package.xml version'] = '2.0';
1129 if ($installed) {
1130 if ($obj->getLastModified()) {
1131 $info['Last Modified'] = date('Y-m-d H:i', $obj->getLastModified());
1132 }
1133
1134 $v = $obj->getLastInstalledVersion();
1135 $info['Previous Installed Version'] = $v ? $v : '- None -';
1136 }
1137
1138 foreach ($info as $key => $value) {
1139 $data['data'][] = array($key, $value);
1140 }
1141
1142 $data['raw'] = $obj->getArray(); // no validation needed
1143 $this->ui->outputData($data, 'package-info');
1144 }
1145}
const PEAR_ERROR_RETURN
Definition PEAR.php:24
const PEAR_VALIDATE_NORMAL
Definition Validate.php:20
doList($command, $options, $params)
Definition Registry.php:112
doInfo($command, $options, $params)
Definition Registry.php:418
__construct(&$ui, &$config)
Definition Registry.php:100
doShellTest($command, $options, $params)
Definition Registry.php:371
_doInfo2($command, $options, $params, &$obj, $installed)
Definition Registry.php:634
doFileList($command, $options, $params)
Definition Registry.php:246
doListAll($command, $options, $params)
Definition Registry.php:207
static & factory($pkg, $role, &$config)
Definition Role.php:60
static staticPopErrorHandling()
Definition PEAR.php:654
static staticPushErrorHandling($mode, $options=null)
Definition PEAR.php:619
static isError($data, $code=null)
Definition PEAR.php:306
$options
Definition pearcmd.php:145
if( $raw) foreach($opts as $opt) if( $store_system_config) if($store_user_config) $command
Definition pearcmd.php:322