PEAR
[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Source for file Registry.php

Documentation is available at Registry.php

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

Documentation generated on Wed, 06 Jul 2011 23:31:15 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.