[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/system/pear/PEAR/Command/ -> Registry.php (source)

   1  <?php
   2  /**
   3   * PEAR_Command_Registry (list, list-files, shell-test, info commands)
   4   *
   5   * PHP versions 4 and 5
   6   *
   7   * LICENSE: This source file is subject to version 3.0 of the PHP license
   8   * that is available through the world-wide-web at the following URI:
   9   * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10   * the PHP License and are unable to obtain it through the web, please
  11   * send a note to license@php.net so we can mail you a copy immediately.
  12   *
  13   * @category   pear
  14   * @package    PEAR
  15   * @author     Stig Bakken <ssb@php.net>
  16   * @author     Greg Beaver <cellog@php.net>
  17   * @copyright  1997-2006 The PHP Group
  18   * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  19   * @version    CVS: $Id: Registry.php,v 1.70 2006/01/06 04:47:36 cellog Exp $
  20   * @link       http://pear.php.net/package/PEAR
  21   * @since      File available since Release 0.1
  22   */
  23  
  24  /**
  25   * base class
  26   */
  27  require_once 'PEAR/Command/Common.php';
  28  
  29  /**
  30   * PEAR commands for registry manipulation
  31   *
  32   * @category   pear
  33   * @package    PEAR
  34   * @author     Stig Bakken <ssb@php.net>
  35   * @author     Greg Beaver <cellog@php.net>
  36   * @copyright  1997-2006 The PHP Group
  37   * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  38   * @version    Release: 1.4.11
  39   * @link       http://pear.php.net/package/PEAR
  40   * @since      Class available since Release 0.1
  41   */
  42  class PEAR_Command_Registry extends PEAR_Command_Common
  43  {
  44      // {{{ properties
  45  
  46      var $commands = array(
  47          'list' => array(
  48              'summary' => 'List Installed Packages In The Default Channel',
  49              'function' => 'doList',
  50              'shortcut' => 'l',
  51              'options' => array(
  52                  'channel' => array(
  53                      'shortopt' => 'c',
  54                      'doc' => 'list installed packages from this channel',
  55                      'arg' => 'CHAN',
  56                      ),
  57                  'allchannels' => array(
  58                      'shortopt' => 'a',
  59                      'doc' => 'list installed packages from all channels',
  60                      ),
  61                  ),
  62              'doc' => '<package>
  63  If invoked without parameters, this command lists the PEAR packages
  64  installed in your php_dir ({config php_dir}).  With a parameter, it
  65  lists the files in a package.
  66  ',
  67              ),
  68          'list-files' => array(
  69              'summary' => 'List Files In Installed Package',
  70              'function' => 'doFileList',
  71              'shortcut' => 'fl',
  72              'options' => array(),
  73              'doc' => '<package>
  74  List the files in an installed package.
  75  '
  76              ),
  77          'shell-test' => array(
  78              'summary' => 'Shell Script Test',
  79              'function' => 'doShellTest',
  80              'shortcut' => 'st',
  81              'options' => array(),
  82              'doc' => '<package> [[relation] version]
  83  Tests if a package is installed in the system. Will exit(1) if it is not.
  84     <relation>   The version comparison operator. One of:
  85                  <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne
  86     <version>    The version to compare with
  87  '),
  88          'info' => array(
  89              'summary'  => 'Display information about a package',
  90              'function' => 'doInfo',
  91              'shortcut' => 'in',
  92              'options'  => array(),
  93              'doc'      => '<package>
  94  Displays information about a package. The package argument may be a
  95  local package file, an URL to a package file, or the name of an
  96  installed package.'
  97              )
  98          );
  99  
 100      // }}}
 101      // {{{ constructor
 102  
 103      /**
 104       * PEAR_Command_Registry constructor.
 105       *
 106       * @access public
 107       */
 108      function PEAR_Command_Registry(&$ui, &$config)
 109      {
 110          parent::PEAR_Command_Common($ui, $config);
 111      }
 112  
 113      // }}}
 114  
 115      // {{{ doList()
 116  
 117      function _sortinfo($a, $b)
 118      {
 119          $apackage = isset($a['package']) ? $a['package'] : $a['name'];
 120          $bpackage = isset($b['package']) ? $b['package'] : $b['name'];
 121          return strcmp($apackage, $bpackage);
 122      }
 123  
 124      function doList($command, $options, $params)
 125      {
 126          if (isset($options['allchannels'])) {
 127              return $this->doListAll($command, array(), $params);
 128          }
 129          $reg = &$this->config->getRegistry();
 130          if (count($params) == 1) {
 131              return $this->doFileList($command, $options, $params);
 132          }
 133          if (isset($options['channel'])) {
 134              if ($reg->channelExists($options['channel'])) {
 135                  $channel = $reg->channelName($options['channel']);
 136              } else {
 137                  return $this->raiseError('Channel "' . $options['channel'] .'" does not exist');
 138              }
 139          } else {
 140              $channel = $this->config->get('default_channel');
 141          }
 142          $installed = $reg->packageInfo(null, null, $channel);
 143          usort($installed, array(&$this, '_sortinfo'));
 144          $i = $j = 0;
 145          $data = array(
 146              'caption' => 'Installed packages, channel ' .
 147                  $channel . ':',
 148              'border' => true,
 149              'headline' => array('Package', 'Version', 'State')
 150              );
 151          foreach ($installed as $package) {
 152              $pobj = $reg->getPackage(isset($package['package']) ?
 153                                          $package['package'] : $package['name'], $channel);
 154              $data['data'][] = array($pobj->getPackage(), $pobj->getVersion(),
 155                                      $pobj->getState() ? $pobj->getState() : null);
 156          }
 157          if (count($installed)==0) {
 158              $data = '(no packages installed from channel ' . $channel . ')';
 159          }
 160          $this->ui->outputData($data, $command);
 161          return true;
 162      }
 163      
 164      function doListAll($command, $options, $params)
 165      {
 166          $reg = &$this->config->getRegistry();
 167          $installed = $reg->packageInfo(null, null, null);
 168          foreach ($installed as $channel => $packages) {
 169              usort($packages, array($this, '_sortinfo'));
 170              $i = $j = 0;
 171              $data = array(
 172                  'caption' => 'Installed packages, channel ' . $channel . ':',
 173                  'border' => true,
 174                  'headline' => array('Package', 'Version', 'State')
 175                  );
 176              foreach ($packages as $package) {
 177                  $pobj = $reg->getPackage(isset($package['package']) ?
 178                                              $package['package'] : $package['name'], $channel);
 179                  $data['data'][] = array($pobj->getPackage(), $pobj->getVersion(),
 180                                          $pobj->getState() ? $pobj->getState() : null);
 181              }
 182              if (count($packages)==0) {
 183                  $data = array(
 184                      'caption' => 'Installed packages, channel ' . $channel . ':',
 185                      'border' => true,
 186                      'data' => array(array('(no packages installed)')),
 187                      );
 188              }
 189              $this->ui->outputData($data, $command);
 190          }
 191          return true;
 192      }
 193      
 194      function doFileList($command, $options, $params)
 195      {
 196          if (count($params) != 1) {
 197              return $this->raiseError('list-files expects 1 parameter');
 198          }
 199          $reg = &$this->config->getRegistry();
 200          if (!is_dir($params[0]) && (file_exists($params[0]) || $fp = @fopen($params[0],
 201                'r'))) {
 202              @fclose($fp);
 203              if (!class_exists('PEAR_PackageFile')) {
 204                  require_once 'PEAR/PackageFile.php';
 205              }
 206              $pkg = &new PEAR_PackageFile($this->config, $this->_debug);
 207              PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 208              $info = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
 209              PEAR::staticPopErrorHandling();
 210              $headings = array('Package File', 'Install Path');
 211              $installed = false;
 212          } else {
 213              PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 214              $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
 215              PEAR::staticPopErrorHandling();
 216              if (PEAR::isError($parsed)) {
 217                  return $this->raiseError($parsed);
 218              }
 219              $info = &$reg->getPackage($parsed['package'], $parsed['channel']);
 220              $headings = array('Type', 'Install Path');
 221              $installed = true;
 222          }
 223          if (PEAR::isError($info)) {
 224              return $this->raiseError($info);
 225          }
 226          if ($info === null) {
 227              return $this->raiseError("`$params[0]' not installed");
 228          }
 229          $list = ($info->getPackagexmlVersion() == '1.0' || $installed) ?
 230              $info->getFilelist() : $info->getContents();
 231          if ($installed) {
 232              $caption = 'Installed Files For ' . $params[0];
 233          } else {
 234              $caption = 'Contents of ' . basename($params[0]);
 235          }
 236          $data = array(
 237              'caption' => $caption,
 238              'border' => true,
 239              'headline' => $headings);
 240          if ($info->getPackagexmlVersion() == '1.0' || $installed) {
 241              foreach ($list as $file => $att) {
 242                  if ($installed) {
 243                      if (empty($att['installed_as'])) {
 244                          continue;
 245                      }
 246                      $data['data'][] = array($att['role'], $att['installed_as']);
 247                  } else {
 248                      if (isset($att['baseinstalldir']) && !in_array($att['role'],
 249                            array('test', 'data', 'doc'))) {
 250                          $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
 251                              $file;
 252                      } else {
 253                          $dest = $file;
 254                      }
 255                      switch ($att['role']) {
 256                          case 'test':
 257                          case 'data':
 258                          case 'doc':
 259                              $role = $att['role'];
 260                              if ($role == 'test') {
 261                                  $role .= 's';
 262                              }
 263                              $dest = $this->config->get($role . '_dir') . DIRECTORY_SEPARATOR .
 264                                  $info->getPackage() . DIRECTORY_SEPARATOR . $dest;
 265                              break;
 266                          case 'php':
 267                          default:
 268                              $dest = $this->config->get('php_dir') . DIRECTORY_SEPARATOR .
 269                                  $dest;
 270                      }
 271                      $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
 272                      $dest = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
 273                                                      array(DIRECTORY_SEPARATOR,
 274                                                            DIRECTORY_SEPARATOR,
 275                                                            DIRECTORY_SEPARATOR),
 276                                                      $dest);
 277                      $file = preg_replace('!/+!', '/', $file);
 278                      $data['data'][] = array($file, $dest);
 279                  }
 280              }
 281          } else { // package.xml 2.0, not installed
 282              if (!isset($list['dir']['file'][0])) {
 283                  $list['dir']['file'] = array($list['dir']['file']);
 284              }
 285              foreach ($list['dir']['file'] as $att) {
 286                  $att = $att['attribs'];
 287                  $file = $att['name'];
 288                  $role = &PEAR_Installer_Role::factory($info, $att['role'], $this->config);
 289                  $role->setup($this, $info, $att, $file);
 290                  if (!$role->isInstallable()) {
 291                      $dest = '(not installable)';
 292                  } else {
 293                      $dest = $role->processInstallation($info, $att, $file, '');
 294                      if (PEAR::isError($dest)) {
 295                          $dest = '(Unknown role "' . $att['role'] . ')';
 296                      } else {
 297                          list(,, $dest) = $dest;
 298                      }
 299                  }
 300                  $data['data'][] = array($file, $dest);
 301              }
 302          }
 303          $this->ui->outputData($data, $command);
 304          return true;
 305      }
 306  
 307      // }}}
 308      // {{{ doShellTest()
 309  
 310      function doShellTest($command, $options, $params)
 311      {
 312          $this->pushErrorHandling(PEAR_ERROR_RETURN);
 313          $reg = &$this->config->getRegistry();
 314          $info = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
 315          if (PEAR::isError($info)) {
 316              exit(1); // invalid package name
 317          }
 318          $package = $info['package'];
 319          $channel = $info['channel'];
 320          // "pear shell-test Foo"
 321          if (!$reg->packageExists($package, $channel)) {
 322              if ($channel == 'pecl.php.net') {
 323                  if ($reg->packageExists($package, 'pear.php.net')) {
 324                      $channel = 'pear.php.net'; // magically change channels for extensions
 325                  }
 326              }
 327          }
 328          if (sizeof($params) == 1) {
 329              if (!$reg->packageExists($package, $channel)) {
 330                  exit(1);
 331              }
 332              // "pear shell-test Foo 1.0"
 333          } elseif (sizeof($params) == 2) {
 334              $v = $reg->packageInfo($package, 'version', $channel);
 335              if (!$v || !version_compare("$v", "{$params[1]}", "ge")) {
 336                  exit(1);
 337              }
 338              // "pear shell-test Foo ge 1.0"
 339          } elseif (sizeof($params) == 3) {
 340              $v = $reg->packageInfo($package, 'version', $channel);
 341              if (!$v || !version_compare("$v", "{$params[2]}", $params[1])) {
 342                  exit(1);
 343              }
 344          } else {
 345              $this->popErrorHandling();
 346              $this->raiseError("$command: expects 1 to 3 parameters");
 347              exit(1);
 348          }
 349      }
 350  
 351      // }}}
 352      // {{{ doInfo
 353  
 354      function doInfo($command, $options, $params)
 355      {
 356          if (count($params) != 1) {
 357              return $this->raiseError('pear info expects 1 parameter');
 358          }
 359          $info = false;
 360          $reg = &$this->config->getRegistry();
 361          if ((@is_file($params[0]) && !is_dir($params[0])) || $fp = @fopen($params[0], 'r')) {
 362              @fclose($fp);
 363              if (!class_exists('PEAR_PackageFile')) {
 364                  require_once 'PEAR/PackageFile.php';
 365              }
 366              $pkg = &new PEAR_PackageFile($this->config, $this->_debug);
 367              PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
 368              $obj = &$pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
 369              PEAR::staticPopErrorHandling();
 370              if (PEAR::isError($obj)) {
 371                  $uinfo = $obj->getUserInfo();
 372                  if (is_array($uinfo)) {
 373                      foreach ($uinfo as $message) {
 374                          if (is_array($message)) {
 375                              $message = $message['message'];
 376                          }
 377                          $this->ui->outputData($message);
 378                      }
 379                  }
 380                  return $this->raiseError($obj);
 381              }
 382              if ($obj->getPackagexmlVersion() == '1.0') {
 383                  $info = $obj->toArray();
 384              } else {
 385                  return $this->_doInfo2($command, $options, $params, $obj, false);
 386              }
 387          } else {
 388              $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel'));
 389              if (PEAR::isError($parsed)) {
 390                  return $this->raiseError($parsed);
 391              }
 392              $package = $parsed['package'];
 393              $channel = $parsed['channel'];
 394              $info = $reg->packageInfo($package, null, $channel);
 395              if (isset($info['old'])) {
 396                  $obj = $reg->getPackage($package, $channel);
 397                  return $this->_doInfo2($command, $options, $params, $obj, true);
 398              }
 399          }
 400          if (PEAR::isError($info)) {
 401              return $info;
 402          }
 403          if (empty($info)) {
 404              $this->raiseError("No information found for `$params[0]'");
 405              return;
 406          }
 407          unset($info['filelist']);
 408          unset($info['dirtree']);
 409          unset($info['changelog']);
 410          if (isset($info['xsdversion'])) {
 411              $info['package.xml version'] = $info['xsdversion'];
 412              unset($info['xsdversion']);
 413          }
 414          if (isset($info['packagerversion'])) {
 415              $info['packaged with PEAR version'] = $info['packagerversion'];
 416              unset($info['packagerversion']);
 417          }
 418          $keys = array_keys($info);
 419          $longtext = array('description', 'summary');
 420          foreach ($keys as $key) {
 421              if (is_array($info[$key])) {
 422                  switch ($key) {
 423                      case 'maintainers': {
 424                          $i = 0;
 425                          $mstr = '';
 426                          foreach ($info[$key] as $m) {
 427                              if ($i++ > 0) {
 428                                  $mstr .= "\n";
 429                              }
 430                              $mstr .= $m['name'] . " <";
 431                              if (isset($m['email'])) {
 432                                  $mstr .= $m['email'];
 433                              } else {
 434                                  $mstr .= $m['handle'] . '@php.net';
 435                              }
 436                              $mstr .= "> ($m[role])";
 437                          }
 438                          $info[$key] = $mstr;
 439                          break;
 440                      }
 441                      case 'release_deps': {
 442                          $i = 0;
 443                          $dstr = '';
 444                          foreach ($info[$key] as $d) {
 445                              if (isset($this->_deps_rel_trans[$d['rel']])) {
 446                                  $rel = $this->_deps_rel_trans[$d['rel']];
 447                              } else {
 448                                  $rel = $d['rel'];
 449                              }
 450                              if (isset($this->_deps_type_trans[$d['type']])) {
 451                                  $type = ucfirst($this->_deps_type_trans[$d['type']]);
 452                              } else {
 453                                  $type = $d['type'];
 454                              }
 455                              if (isset($d['name'])) {
 456                                  $name = $d['name'] . ' ';
 457                              } else {
 458                                  $name = '';
 459                              }
 460                              if (isset($d['version'])) {
 461                                  $version = $d['version'] . ' ';
 462                              } else {
 463                                  $version = '';
 464                              }
 465                              if (isset($d['optional']) && $d['optional'] == 'yes') {
 466                                  $optional = ' (optional)';
 467                              } else {
 468                                  $optional = '';
 469                              }
 470                              $dstr .= "$type $name$rel $version$optional\n";
 471                          }
 472                          $info[$key] = $dstr;
 473                          break;
 474                      }
 475                      case 'provides' : {
 476                          $debug = $this->config->get('verbose');
 477                          if ($debug < 2) {
 478                              $pstr = 'Classes: ';
 479                          } else {
 480                              $pstr = '';
 481                          }
 482                          $i = 0;
 483                          foreach ($info[$key] as $p) {
 484                              if ($debug < 2 && $p['type'] != "class") {
 485                                  continue;
 486                              }
 487                              // Only print classes when verbosity mode is < 2
 488                              if ($debug < 2) {
 489                                  if ($i++ > 0) {
 490                                      $pstr .= ", ";
 491                                  }
 492                                  $pstr .= $p['name'];
 493                              } else {
 494                                  if ($i++ > 0) {
 495                                      $pstr .= "\n";
 496                                  }
 497                                  $pstr .= ucfirst($p['type']) . " " . $p['name'];
 498                                  if (isset($p['explicit']) && $p['explicit'] == 1) {
 499                                      $pstr .= " (explicit)";
 500                                  }
 501                              }
 502                          }
 503                          $info[$key] = $pstr;
 504                          break;
 505                      }
 506                      case 'configure_options' : {
 507                          foreach ($info[$key] as $i => $p) {
 508                              $info[$key][$i] = array_map(null, array_keys($p), array_values($p));
 509                              $info[$key][$i] = array_map(create_function('$a',
 510                                  'return join(" = ",$a);'), $info[$key][$i]);
 511                              $info[$key][$i] = implode(', ', $info[$key][$i]);
 512                          }
 513                          $info[$key] = implode("\n", $info[$key]);
 514                          break;
 515                      }
 516                      default: {
 517                          $info[$key] = implode(", ", $info[$key]);
 518                          break;
 519                      }
 520                  }
 521              }
 522              if ($key == '_lastmodified') {
 523                  $hdate = date('Y-m-d', $info[$key]);
 524                  unset($info[$key]);
 525                  $info['Last Modified'] = $hdate;
 526              } elseif ($key == '_lastversion') {
 527                  $info['Last Installed Version'] = $info[$key] ? $info[$key] : '- None -';
 528                  unset($info[$key]);
 529              } else {
 530                  $info[$key] = trim($info[$key]);
 531                  if (in_array($key, $longtext)) {
 532                      $info[$key] = preg_replace('/  +/', ' ', $info[$key]);
 533                  }
 534              }
 535          }
 536          $caption = 'About ' . $info['package'] . '-' . $info['version'];
 537          $data = array(
 538              'caption' => $caption,
 539              'border' => true);
 540          foreach ($info as $key => $value) {
 541              $key = ucwords(trim(str_replace('_', ' ', $key)));
 542              $data['data'][] = array($key, $value);
 543          }
 544          $data['raw'] = $info;
 545  
 546          $this->ui->outputData($data, 'package-info');
 547      }
 548  
 549      // }}}
 550  
 551      /**
 552       * @access private
 553       */
 554      function _doInfo2($command, $options, $params, &$obj, $installed)
 555      {
 556          $reg = &$this->config->getRegistry();
 557          $caption = 'About ' . $obj->getChannel() . '/' .$obj->getPackage() . '-' .
 558              $obj->getVersion();
 559          $data = array(
 560              'caption' => $caption,
 561              'border' => true);
 562          switch ($obj->getPackageType()) {
 563              case 'php' :
 564                  $release = 'PEAR-style PHP-based Package';
 565              break;
 566              case 'extsrc' :
 567                  $release = 'PECL-style PHP extension (source code)';
 568              break;
 569              case 'extbin' :
 570                  $release = 'PECL-style PHP extension (binary)';
 571              break;
 572              case 'bundle' :
 573                  $release = 'Package bundle (collection of packages)';
 574              break;
 575          }
 576          $extends = $obj->getExtends();
 577          $extends = $extends ?
 578              $obj->getPackage() . ' (extends ' . $extends . ')' : $obj->getPackage();
 579          if ($src = $obj->getSourcePackage()) {
 580              $extends .= ' (source package ' . $src['channel'] . '/' . $src['package'] . ')';
 581          }
 582          $info = array(
 583              'Release Type' => $release,
 584              'Name' => $extends,
 585              'Channel' => $obj->getChannel(),
 586              'Summary' => preg_replace('/  +/', ' ', $obj->getSummary()),
 587              'Description' => preg_replace('/  +/', ' ', $obj->getDescription()),
 588              );
 589          $info['Maintainers'] = '';
 590          foreach (array('lead', 'developer', 'contributor', 'helper') as $role) {
 591              $leads = $obj->{"get{$role}s"}();
 592              if (!$leads) {
 593                  continue;
 594              }
 595              if (isset($leads['active'])) {
 596                  $leads = array($leads);
 597              }
 598              foreach ($leads as $lead) {
 599                  if (!empty($info['Maintainers'])) {
 600                      $info['Maintainers'] .= "\n";
 601                  }
 602                  $info['Maintainers'] .= $lead['name'] . ' <';
 603                  $info['Maintainers'] .= $lead['email'] . "> ($role)";
 604              }
 605          }
 606          $info['Release Date'] = $obj->getDate();
 607          if ($time = $obj->getTime()) {
 608              $info['Release Date'] .= ' ' . $time;
 609          }
 610          $info['Release Version'] = $obj->getVersion() . ' (' . $obj->getState() . ')';
 611          $info['API Version'] = $obj->getVersion('api') . ' (' . $obj->getState('api') . ')';
 612          $info['License'] = $obj->getLicense();
 613          $uri = $obj->getLicenseLocation();
 614          if ($uri) {
 615              if (isset($uri['uri'])) {
 616                  $info['License'] .= ' (' . $uri['uri'] . ')';
 617              } else {
 618                  $extra = $obj->getInstalledLocation($info['filesource']);
 619                  if ($extra) {
 620                      $info['License'] .= ' (' . $uri['filesource'] . ')';
 621                  }
 622              }
 623          }
 624          $info['Release Notes'] = $obj->getNotes();
 625          if ($compat = $obj->getCompatible()) {
 626              $info['Compatible with'] = '';
 627              foreach ($compat as $package) {
 628                  $info['Compatible with'] .= $package['channel'] . '/' . $package['package'] .
 629                      "\nVersions >= " . $package['min'] . ', <= ' . $package['max'];
 630                  if (isset($package['exclude'])) {
 631                      if (is_array($package['exclude'])) {
 632                          $package['exclude'] = implode(', ', $package['exclude']);
 633                      }
 634                      if (!isset($info['Not Compatible with'])) {
 635                          $info['Not Compatible with'] = '';
 636                      } else {
 637                          $info['Not Compatible with'] .= "\n";
 638                      }
 639                      $info['Not Compatible with'] .= $package['channel'] . '/' .
 640                          $package['package'] . "\nVersions " . $package['exclude'];
 641                  }
 642              }
 643          }
 644          $usesrole = $obj->getUsesrole();
 645          if ($usesrole) {
 646              if (!isset($usesrole[0])) {
 647                  $usesrole = array($usesrole);
 648              }
 649              foreach ($usesrole as $roledata) {
 650                  if (isset($info['Uses Custom Roles'])) {
 651                      $info['Uses Custom Roles'] .= "\n";
 652                  } else {
 653                      $info['Uses Custom Roles'] = '';
 654                  }
 655                  if (isset($roledata['package'])) {
 656                      $rolepackage = $reg->parsedPackageNameToString($roledata, true);
 657                  } else {
 658                      $rolepackage = $roledata['uri'];
 659                  }
 660                  $info['Uses Custom Roles'] .= $roledata['role'] . ' (' . $rolepackage . ')';
 661              }
 662          }
 663          $usestask = $obj->getUsestask();
 664          if ($usestask) {
 665              if (!isset($usestask[0])) {
 666                  $usestask = array($usestask);
 667              }
 668              foreach ($usestask as $taskdata) {
 669                  if (isset($info['Uses Custom Tasks'])) {
 670                      $info['Uses Custom Tasks'] .= "\n";
 671                  } else {
 672                      $info['Uses Custom Tasks'] = '';
 673                  }
 674                  if (isset($taskdata['package'])) {
 675                      $taskpackage = $reg->parsedPackageNameToString($taskdata, true);
 676                  } else {
 677                      $taskpackage = $taskdata['uri'];
 678                  }
 679                  $info['Uses Custom Tasks'] .= $taskdata['task'] . ' (' . $taskpackage . ')';
 680              }
 681          }
 682          $deps = $obj->getDependencies();
 683          $info['Required Dependencies'] = 'PHP version ' . $deps['required']['php']['min'];
 684          if (isset($deps['required']['php']['max'])) {
 685              $info['Required Dependencies'] .= '-' . $deps['required']['php']['max'] . "\n";
 686          } else {
 687              $info['Required Dependencies'] .= "\n";
 688          }
 689          if (isset($deps['required']['php']['exclude'])) {
 690              if (!isset($info['Not Compatible with'])) {
 691                  $info['Not Compatible with'] = '';
 692              } else {
 693                  $info['Not Compatible with'] .= "\n";
 694              }
 695              if (is_array($deps['required']['php']['exclude'])) {
 696                  $deps['required']['php']['exclude'] =
 697                      implode(', ', $deps['required']['php']['exclude']);
 698              }
 699              $info['Not Compatible with'] .= "PHP versions\n  " .
 700                  $deps['required']['php']['exclude'];
 701          }
 702          $info['Required Dependencies'] .= 'PEAR installer version';
 703          if (isset($deps['required']['pearinstaller']['max'])) {
 704              $info['Required Dependencies'] .= 's ' .
 705                  $deps['required']['pearinstaller']['min'] . '-' .
 706                  $deps['required']['pearinstaller']['max'];
 707          } else {
 708              $info['Required Dependencies'] .= ' ' .
 709                  $deps['required']['pearinstaller']['min'] . ' or newer';
 710          }
 711          if (isset($deps['required']['pearinstaller']['exclude'])) {
 712              if (!isset($info['Not Compatible with'])) {
 713                  $info['Not Compatible with'] = '';
 714              } else {
 715                  $info['Not Compatible with'] .= "\n";
 716              }
 717              if (is_array($deps['required']['pearinstaller']['exclude'])) {
 718                  $deps['required']['pearinstaller']['exclude'] =
 719                      implode(', ', $deps['required']['pearinstaller']['exclude']);
 720              }
 721              $info['Not Compatible with'] .= "PEAR installer\n  Versions " .
 722                  $deps['required']['pearinstaller']['exclude'];
 723          }
 724          foreach (array('Package', 'Extension') as $type) {
 725              $index = strtolower($type);
 726              if (isset($deps['required'][$index])) {
 727                  if (isset($deps['required'][$index]['name'])) {
 728                      $deps['required'][$index] = array($deps['required'][$index]);
 729                  }
 730                  foreach ($deps['required'][$index] as $package) {
 731                      if (isset($package['conflicts'])) {
 732                          $infoindex = 'Not Compatible with';
 733                          if (!isset($info['Not Compatible with'])) {
 734                              $info['Not Compatible with'] = '';
 735                          } else {
 736                              $info['Not Compatible with'] .= "\n";
 737                          }
 738                      } else {
 739                          $infoindex = 'Required Dependencies';
 740                          $info[$infoindex] .= "\n";
 741                      }
 742                      if ($index == 'extension') {
 743                          $name = $package['name'];
 744                      } else {
 745                          if (isset($package['channel'])) {
 746                              $name = $package['channel'] . '/' . $package['name'];
 747                          } else {
 748                              $name = '__uri/' . $package['name'] . ' (static URI)';
 749                          }
 750                      }
 751                      $info[$infoindex] .= "$type $name";
 752                      if (isset($package['uri'])) {
 753                          $info[$infoindex] .= "\n  Download URI: $package[uri]";
 754                          continue;
 755                      }
 756                      if (isset($package['max']) && isset($package['min'])) {
 757                          $info[$infoindex] .= " \n  Versions " .
 758                              $package['min'] . '-' . $package['max'];
 759                      } elseif (isset($package['min'])) {
 760                          $info[$infoindex] .= " \n  Version " .
 761                              $package['min'] . ' or newer';
 762                      } elseif (isset($package['max'])) {
 763                          $info[$infoindex] .= " \n  Version " .
 764                              $package['max'] . ' or older';
 765                      }
 766                      if (isset($package['recommended'])) {
 767                          $info[$infoindex] .= "\n  Recommended version: $package[recommended]";
 768                      }
 769                      if (isset($package['exclude'])) {
 770                          if (!isset($info['Not Compatible with'])) {
 771                              $info['Not Compatible with'] = '';
 772                          } else {
 773                              $info['Not Compatible with'] .= "\n";
 774                          }
 775                          if (is_array($package['exclude'])) {
 776                              $package['exclude'] = implode(', ', $package['exclude']);
 777                          }
 778                          $package['package'] = $package['name']; // for parsedPackageNameToString
 779                           if (isset($package['conflicts'])) {
 780                              $info['Not Compatible with'] .= '=> except ';
 781                          }
 782                         $info['Not Compatible with'] .= 'Package ' .
 783                              $reg->parsedPackageNameToString($package, true);
 784                          $info['Not Compatible with'] .= "\n  Versions " . $package['exclude'];
 785                      }
 786                  }
 787              }
 788          }
 789          if (isset($deps['required']['os'])) {
 790              if (isset($deps['required']['os']['name'])) {
 791                  $dep['required']['os']['name'] = array($dep['required']['os']['name']);
 792              }
 793              foreach ($dep['required']['os'] as $os) {
 794                  if (isset($os['conflicts']) && $os['conflicts'] == 'yes') {
 795                      if (!isset($info['Not Compatible with'])) {
 796                          $info['Not Compatible with'] = '';
 797                      } else {
 798                          $info['Not Compatible with'] .= "\n";
 799                      }
 800                      $info['Not Compatible with'] .= "$os[name] Operating System";
 801                  } else {
 802                      $info['Required Dependencies'] .= "\n";
 803                      $info['Required Dependencies'] .= "$os[name] Operating System";
 804                  }
 805              }
 806          }
 807          if (isset($deps['required']['arch'])) {
 808              if (isset($deps['required']['arch']['pattern'])) {
 809                  $dep['required']['arch']['pattern'] = array($dep['required']['os']['pattern']);
 810              }
 811              foreach ($dep['required']['arch'] as $os) {
 812                  if (isset($os['conflicts']) && $os['conflicts'] == 'yes') {
 813                      if (!isset($info['Not Compatible with'])) {
 814                          $info['Not Compatible with'] = '';
 815                      } else {
 816                          $info['Not Compatible with'] .= "\n";
 817                      }
 818                      $info['Not Compatible with'] .= "OS/Arch matching pattern '/$os[pattern]/'";
 819                  } else {
 820                      $info['Required Dependencies'] .= "\n";
 821                      $info['Required Dependencies'] .= "OS/Arch matching pattern '/$os[pattern]/'";
 822                  }
 823              }
 824          }
 825          if (isset($deps['optional'])) {
 826              foreach (array('Package', 'Extension') as $type) {
 827                  $index = strtolower($type);
 828                  if (isset($deps['optional'][$index])) {
 829                      if (isset($deps['optional'][$index]['name'])) {
 830                          $deps['optional'][$index] = array($deps['optional'][$index]);
 831                      }
 832                      foreach ($deps['optional'][$index] as $package) {
 833                          if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
 834                              $infoindex = 'Not Compatible with';
 835                              if (!isset($info['Not Compatible with'])) {
 836                                  $info['Not Compatible with'] = '';
 837                              } else {
 838                                  $info['Not Compatible with'] .= "\n";
 839                              }
 840                          } else {
 841                              $infoindex = 'Optional Dependencies';
 842                              if (!isset($info['Optional Dependencies'])) {
 843                                  $info['Optional Dependencies'] = '';
 844                              } else {
 845                                  $info['Optional Dependencies'] .= "\n";
 846                              }
 847                          }
 848                          if ($index == 'extension') {
 849                              $name = $package['name'];
 850                          } else {
 851                              if (isset($package['channel'])) {
 852                                  $name = $package['channel'] . '/' . $package['name'];
 853                              } else {
 854                                  $name = '__uri/' . $package['name'] . ' (static URI)';
 855                              }
 856                          }
 857                          $info[$infoindex] .= "$type $name";
 858                          if (isset($package['uri'])) {
 859                              $info[$infoindex] .= "\n  Download URI: $package[uri]";
 860                              continue;
 861                          }
 862                          if ($infoindex == 'Not Compatible with') {
 863                              // conflicts is only used to say that all versions conflict
 864                              continue;
 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['min'] . ' or older';
 875                          }
 876                          if (isset($package['recommended'])) {
 877                              $info[$infoindex] .= "\n  Recommended version: $package[recommended]";
 878                          }
 879                          if (isset($package['exclude'])) {
 880                              if (!isset($info['Not Compatible with'])) {
 881                                  $info['Not Compatible with'] = '';
 882                              } else {
 883                                  $info['Not Compatible with'] .= "\n";
 884                              }
 885                              if (is_array($package['exclude'])) {
 886                                  $package['exclude'] = implode(', ', $package['exclude']);
 887                              }
 888                              $info['Not Compatible with'] .= "Package $package\n  Versions " .
 889                                  $package['exclude'];
 890                          }
 891                      }
 892                  }
 893              }
 894          }
 895          if (isset($deps['group'])) {
 896              if (!isset($deps['group'][0])) {
 897                  $deps['group'] = array($deps['group']);
 898              }
 899              foreach ($deps['group'] as $group) {
 900                  $info['Dependency Group ' . $group['attribs']['name']] = $group['attribs']['hint'];
 901                  $groupindex = $group['attribs']['name'] . ' Contents';
 902                  $info[$groupindex] = '';
 903                  foreach (array('Package', 'Extension') as $type) {
 904                      $index = strtolower($type);
 905                      if (isset($group[$index])) {
 906                          if (isset($group[$index]['name'])) {
 907                              $group[$index] = array($group[$index]);
 908                          }
 909                          foreach ($group[$index] as $package) {
 910                              if (!empty($info[$groupindex])) {
 911                                  $info[$groupindex] .= "\n";
 912                              }
 913                              if ($index == 'extension') {
 914                                  $name = $package['name'];
 915                              } else {
 916                                  if (isset($package['channel'])) {
 917                                      $name = $package['channel'] . '/' . $package['name'];
 918                                  } else {
 919                                      $name = '__uri/' . $package['name'] . ' (static URI)';
 920                                  }
 921                              }
 922                              if (isset($package['uri'])) {
 923                                  if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
 924                                      $info[$groupindex] .= "Not Compatible with $type $name";
 925                                  } else {
 926                                      $info[$groupindex] .= "$type $name";
 927                                  }
 928                                  $info[$groupindex] .= "\n  Download URI: $package[uri]";
 929                                  continue;
 930                              }
 931                              if (isset($package['conflicts']) && $package['conflicts'] == 'yes') {
 932                                  $info[$groupindex] .= "Not Compatible with $type $name";
 933                                  continue;
 934                              }
 935                              $info[$groupindex] .= "$type $name";
 936                              if (isset($package['max']) && isset($package['min'])) {
 937                                  $info[$groupindex] .= " \n  Versions " .
 938                                      $package['min'] . '-' . $package['max'];
 939                              } elseif (isset($package['min'])) {
 940                                  $info[$groupindex] .= " \n  Version " .
 941                                      $package['min'] . ' or newer';
 942                              } elseif (isset($package['max'])) {
 943                                  $info[$groupindex] .= " \n  Version " .
 944                                      $package['min'] . ' or older';
 945                              }
 946                              if (isset($package['recommended'])) {
 947                                  $info[$groupindex] .= "\n  Recommended version: $package[recommended]";
 948                              }
 949                              if (isset($package['exclude'])) {
 950                                  if (!isset($info['Not Compatible with'])) {
 951                                      $info['Not Compatible with'] = '';
 952                                  } else {
 953                                      $info[$groupindex] .= "Not Compatible with\n";
 954                                  }
 955                                  if (is_array($package['exclude'])) {
 956                                      $package['exclude'] = implode(', ', $package['exclude']);
 957                                  }
 958                                  $info[$groupindex] .= "  Package $package\n  Versions " .
 959                                      $package['exclude'];
 960                              }
 961                          }
 962                      }
 963                  }
 964              }
 965          }
 966          if ($obj->getPackageType() == 'bundle') {
 967              $info['Bundled Packages'] = '';
 968              foreach ($obj->getBundledPackages() as $package) {
 969                  if (!empty($info['Bundled Packages'])) {
 970                      $info['Bundled Packages'] .= "\n";
 971                  }
 972                  if (isset($package['uri'])) {
 973                      $info['Bundled Packages'] .= '__uri/' . $package['name'];
 974                      $info['Bundled Packages'] .= "\n  (URI: $package[uri]";
 975                  } else {
 976                      $info['Bundled Packages'] .= $package['channel'] . '/' . $package['name'];
 977                  }
 978              }
 979          }
 980          $info['package.xml version'] = '2.0';
 981          if ($installed) {
 982              if ($obj->getLastModified()) {
 983                  $info['Last Modified'] = date('Y-m-d H:i', $obj->getLastModified());
 984              }
 985              $v = $obj->getLastInstalledVersion();
 986              $info['Last Installed Version'] = $v ? $v : '- None -';
 987          }
 988          foreach ($info as $key => $value) {
 989              $data['data'][] = array($key, $value);
 990          }
 991          $data['raw'] = $obj->getArray(); // no validation needed
 992  
 993          $this->ui->outputData($data, 'package-info');
 994      }
 995  }
 996  
 997  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics