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

Source for file 10.php

Documentation is available at 10.php

  1. <?php
  2. /**
  3.  * PEAR_REST_10
  4.  *
  5.  * PHP versions 4 and 5
  6.  *
  7.  * @category   pear
  8.  * @package    PEAR
  9.  * @author     Greg Beaver <cellog@php.net>
  10.  * @copyright  1997-2009 The Authors
  11.  * @license    http://opensource.org/licenses/bsd-license.php New BSD License
  12.  * @version    CVS: $Id: 10.php 313023 2011-07-06 19:17:11Z dufuz $
  13.  * @link       http://pear.php.net/package/PEAR
  14.  * @since      File available since Release 1.4.0a12
  15.  */
  16.  
  17. /**
  18.  * For downloading REST xml/txt files
  19.  */
  20. require_once 'PEAR/REST.php';
  21.  
  22. /**
  23.  * Implement REST 1.0
  24.  *
  25.  * @category   pear
  26.  * @package    PEAR
  27.  * @author     Greg Beaver <cellog@php.net>
  28.  * @copyright  1997-2009 The Authors
  29.  * @license    http://opensource.org/licenses/bsd-license.php New BSD License
  30.  * @version    Release: 1.9.4
  31.  * @link       http://pear.php.net/package/PEAR
  32.  * @since      Class available since Release 1.4.0a12
  33.  */
  34. {
  35.     /**
  36.      * @var PEAR_REST 
  37.      */
  38.     var $_rest;
  39.     function PEAR_REST_10($config$options = array())
  40.     {
  41.         $this->_rest &new PEAR_REST($config$options);
  42.     }
  43.  
  44.     /**
  45.      * Retrieve information about a remote package to be downloaded from a REST server
  46.      *
  47.      * @param string $base The uri to prepend to all REST calls
  48.      * @param array $packageinfo an array of format:
  49.      *  <pre>
  50.      *   array(
  51.      *    'package' => 'packagename',
  52.      *    'channel' => 'channelname',
  53.      *   ['state' => 'alpha' (or valid state),]
  54.      *   -or-
  55.      *   ['version' => '1.whatever']
  56.      *  </pre>
  57.      * @param string $prefstate Current preferred_state config variable value
  58.      * @param bool $installed the installed version of this package to compare against
  59.      * @return array|false|PEAR_Errorsee {@link _returnDownloadURL()}
  60.      */
  61.     function getDownloadURL($base$packageinfo$prefstate$installed$channel = false)
  62.     {
  63.         $states $this->betterStates($prefstatetrue);
  64.         if (!$states{
  65.             return PEAR::raiseError('"' $prefstate '" is not a valid state');
  66.         }
  67.  
  68.         $channel  $packageinfo['channel'];
  69.         $package  $packageinfo['package'];
  70.         $state    = isset($packageinfo['state'])   $packageinfo['state']   : null;
  71.         $version  = isset($packageinfo['version']$packageinfo['version': null;
  72.         $restFile $base 'r/' strtolower($package'/allreleases.xml';
  73.  
  74.         $info $this->_rest->retrieveData($restFilefalsefalse$channel);
  75.         if (PEAR::isError($info)) {
  76.             return PEAR::raiseError('No releases available for package "' .
  77.                 $channel '/' $package '"');
  78.         }
  79.  
  80.         if (!isset($info['r'])) {
  81.             return false;
  82.         }
  83.  
  84.         $release $found = false;
  85.         if (!is_array($info['r']|| !isset($info['r'][0])) {
  86.             $info['r'= array($info['r']);
  87.         }
  88.  
  89.         foreach ($info['r'as $release{
  90.             if (!isset($this->_rest->_options['force']&& ($installed &&
  91.                   version_compare($release['v']$installed'<'))) {
  92.                 continue;
  93.             }
  94.  
  95.             if (isset($state)) {
  96.                 // try our preferred state first
  97.                 if ($release['s'== $state{
  98.                     $found = true;
  99.                     break;
  100.                 }
  101.                 // see if there is something newer and more stable
  102.                 // bug #7221
  103.                 if (in_array($release['s']$this->betterStates($state)true)) {
  104.                     $found = true;
  105.                     break;
  106.                 }
  107.             elseif (isset($version)) {
  108.                 if ($release['v'== $version{
  109.                     $found = true;
  110.                     break;
  111.                 }
  112.             else {
  113.                 if (in_array($release['s']$states)) {
  114.                     $found = true;
  115.                     break;
  116.                 }
  117.             }
  118.         }
  119.  
  120.         return $this->_returnDownloadURL($base$package$release$info$foundfalse$channel);
  121.     }
  122.  
  123.     function getDepDownloadURL($base$xsdversion$dependency$deppackage,
  124.                                $prefstate 'stable'$installed = false$channel = false)
  125.     {
  126.         $states $this->betterStates($prefstatetrue);
  127.         if (!$states{
  128.             return PEAR::raiseError('"' $prefstate '" is not a valid state');
  129.         }
  130.  
  131.         $channel  $dependency['channel'];
  132.         $package  $dependency['name'];
  133.         $state    = isset($dependency['state'])   $dependency['state']   : null;
  134.         $version  = isset($dependency['version']$dependency['version': null;
  135.         $restFile $base 'r/' strtolower($package'/allreleases.xml';
  136.  
  137.         $info $this->_rest->retrieveData($restFilefalsefalse$channel);
  138.         if (PEAR::isError($info)) {
  139.             return PEAR::raiseError('Package "' $deppackage['channel''/' $deppackage['package']
  140.                 . '" dependency "' $channel '/' $package '" has no releases');
  141.         }
  142.  
  143.         if (!is_array($info|| !isset($info['r'])) {
  144.             return false;
  145.         }
  146.  
  147.         $exclude = array();
  148.         $min $max $recommended = false;
  149.         if ($xsdversion == '1.0'{
  150.             switch ($dependency['rel']{
  151.                 case 'ge' :
  152.                     $min $dependency['version'];
  153.                 break;
  154.                 case 'gt' :
  155.                     $min $dependency['version'];
  156.                     $exclude = array($dependency['version']);
  157.                 break;
  158.                 case 'eq' :
  159.                     $recommended $dependency['version'];
  160.                 break;
  161.                 case 'lt' :
  162.                     $max $dependency['version'];
  163.                     $exclude = array($dependency['version']);
  164.                 break;
  165.                 case 'le' :
  166.                     $max $dependency['version'];
  167.                 break;
  168.                 case 'ne' :
  169.                     $exclude = array($dependency['version']);
  170.                 break;
  171.             }
  172.         else {
  173.             $min = isset($dependency['min']$dependency['min': false;
  174.             $max = isset($dependency['max']$dependency['max': false;
  175.             $recommended = isset($dependency['recommended']?
  176.                 $dependency['recommended': false;
  177.             if (isset($dependency['exclude'])) {
  178.                 if (!isset($dependency['exclude'][0])) {
  179.                     $exclude = array($dependency['exclude']);
  180.                 }
  181.             }
  182.         }
  183.         $release $found = false;
  184.         if (!is_array($info['r']|| !isset($info['r'][0])) {
  185.             $info['r'= array($info['r']);
  186.         }
  187.         foreach ($info['r'as $release{
  188.             if (!isset($this->_rest->_options['force']&& ($installed &&
  189.                   version_compare($release['v']$installed'<'))) {
  190.                 continue;
  191.             }
  192.             if (in_array($release['v']$exclude)) // skip excluded versions
  193.                 continue;
  194.             }
  195.             // allow newer releases to say "I'm OK with the dependent package"
  196.             if ($xsdversion == '2.0' && isset($release['co'])) {
  197.                 if (!is_array($release['co']|| !isset($release['co'][0])) {
  198.                     $release['co'= array($release['co']);
  199.                 }
  200.                 foreach ($release['co'as $entry{
  201.                     if (isset($entry['x']&& !is_array($entry['x'])) {
  202.                         $entry['x'= array($entry['x']);
  203.                     elseif (!isset($entry['x'])) {
  204.                         $entry['x'= array();
  205.                     }
  206.                     if ($entry['c'== $deppackage['channel'&&
  207.                           strtolower($entry['p']== strtolower($deppackage['package']&&
  208.                           version_compare($deppackage['version']$entry['min']'>='&&
  209.                           version_compare($deppackage['version']$entry['max']'<='&&
  210.                           !in_array($release['v']$entry['x'])) {
  211.                         $recommended $release['v'];
  212.                         break;
  213.                     }
  214.                 }
  215.             }
  216.             if ($recommended{
  217.                 if ($release['v'!= $recommended// if we want a specific
  218.                     // version, then skip all others
  219.                     continue;
  220.                 else {
  221.                     if (!in_array($release['s']$states)) {
  222.                         // the stability is too low, but we must return the
  223.                         // recommended version if possible
  224.                         return $this->_returnDownloadURL($base$package$release$infotruefalse$channel);
  225.                     }
  226.                 }
  227.             }
  228.             if ($min && version_compare($release['v']$min'lt')) // skip too old versions
  229.                 continue;
  230.             }
  231.             if ($max && version_compare($release['v']$max'gt')) // skip too new versions
  232.                 continue;
  233.             }
  234.             if ($installed && version_compare($release['v']$installed'<')) {
  235.                 continue;
  236.             }
  237.             if (in_array($release['s']$states)) // if in the preferred state...
  238.                 $found = true; // ... then use it
  239.                 break;
  240.             }
  241.         }
  242.         return $this->_returnDownloadURL($base$package$release$info$foundfalse$channel);
  243.     }
  244.  
  245.     /**
  246.      * Take raw data and return the array needed for processing a download URL
  247.      *
  248.      * @param string $base REST base uri
  249.      * @param string $package Package name
  250.      * @param array $release an array of format array('v' => version, 's' => state)
  251.      *                        describing the release to download
  252.      * @param array $info list of all releases as defined by allreleases.xml
  253.      * @param bool|null$found determines whether the release was found or this is the next
  254.      *                     best alternative.  If null, then versions were skipped because
  255.      *                     of PHP dependency
  256.      * @return array|PEAR_Error
  257.      * @access private
  258.      */
  259.     function _returnDownloadURL($base$package$release$info$found$phpversion = false$channel = false)
  260.     {
  261.         if (!$found{
  262.             $release $info['r'][0];
  263.         }
  264.  
  265.         $packageLower strtolower($package);
  266.         $pinfo $this->_rest->retrieveCacheFirst($base 'p/' $packageLower '/' .
  267.             'info.xml'falsefalse$channel);
  268.         if (PEAR::isError($pinfo)) {
  269.             return PEAR::raiseError('Package "' $package .
  270.                 '" does not have REST info xml available');
  271.         }
  272.  
  273.         $releaseinfo $this->_rest->retrieveCacheFirst($base 'r/' $packageLower '/' .
  274.             $release['v''.xml'falsefalse$channel);
  275.         if (PEAR::isError($releaseinfo)) {
  276.             return PEAR::raiseError('Package "' $package '" Version "' $release['v'.
  277.                 '" does not have REST xml available');
  278.         }
  279.  
  280.         $packagexml $this->_rest->retrieveCacheFirst($base 'r/' $packageLower '/' .
  281.             'deps.' $release['v''.txt'falsetrue$channel);
  282.         if (PEAR::isError($packagexml)) {
  283.             return PEAR::raiseError('Package "' $package '" Version "' $release['v'.
  284.                 '" does not have REST dependency information available');
  285.         }
  286.  
  287.         $packagexml unserialize($packagexml);
  288.         if (!$packagexml{
  289.             $packagexml = array();
  290.         }
  291.  
  292.         $allinfo $this->_rest->retrieveData($base 'r/' $packageLower .
  293.             '/allreleases.xml'falsefalse$channel);
  294.         if (PEAR::isError($allinfo)) {
  295.             return $allinfo;
  296.         }
  297.  
  298.         if (!is_array($allinfo['r']|| !isset($allinfo['r'][0])) {
  299.             $allinfo['r'= array($allinfo['r']);
  300.         }
  301.  
  302.         $compatible = false;
  303.         foreach ($allinfo['r'as $release{
  304.             if ($release['v'!= $releaseinfo['v']{
  305.                 continue;
  306.             }
  307.  
  308.             if (!isset($release['co'])) {
  309.                 break;
  310.             }
  311.  
  312.             $compatible = array();
  313.             if (!is_array($release['co']|| !isset($release['co'][0])) {
  314.                 $release['co'= array($release['co']);
  315.             }
  316.  
  317.             foreach ($release['co'as $entry{
  318.                 $comp = array();
  319.                 $comp['name']    $entry['p'];
  320.                 $comp['channel'$entry['c'];
  321.                 $comp['min']     $entry['min'];
  322.                 $comp['max']     $entry['max'];
  323.                 if (isset($entry['x']&& !is_array($entry['x'])) {
  324.                     $comp['exclude'$entry['x'];
  325.                 }
  326.  
  327.                 $compatible[$comp;
  328.             }
  329.  
  330.             if (count($compatible== 1{
  331.                 $compatible $compatible[0];
  332.             }
  333.  
  334.             break;
  335.         }
  336.  
  337.         $deprecated = false;
  338.         if (isset($pinfo['dc']&& isset($pinfo['dp'])) {
  339.             if (is_array($pinfo['dp'])) {
  340.                 $deprecated = array('channel' => (string) $pinfo['dc'],
  341.                                     'package' => trim($pinfo['dp']['_content']));
  342.             else {
  343.                 $deprecated = array('channel' => (string) $pinfo['dc'],
  344.                                     'package' => trim($pinfo['dp']));
  345.             }
  346.         }
  347.  
  348.         $return = array(
  349.             'version'    => $releaseinfo['v'],
  350.             'info'       => $packagexml,
  351.             'package'    => $releaseinfo['p']['_content'],
  352.             'stability'  => $releaseinfo['st'],
  353.             'compatible' => $compatible,
  354.             'deprecated' => $deprecated,
  355.         );
  356.  
  357.         if ($found{
  358.             $return['url'$releaseinfo['g'];
  359.             return $return;
  360.         }
  361.  
  362.         $return['php'$phpversion;
  363.         return $return;
  364.     }
  365.  
  366.     function listPackages($base$channel = false)
  367.     {
  368.         $packagelist $this->_rest->retrieveData($base 'p/packages.xml'falsefalse$channel);
  369.         if (PEAR::isError($packagelist)) {
  370.             return $packagelist;
  371.         }
  372.  
  373.         if (!is_array($packagelist|| !isset($packagelist['p'])) {
  374.             return array();
  375.         }
  376.  
  377.         if (!is_array($packagelist['p'])) {
  378.             $packagelist['p'= array($packagelist['p']);
  379.         }
  380.  
  381.         return $packagelist['p'];
  382.     }
  383.  
  384.     /**
  385.      * List all categories of a REST server
  386.      *
  387.      * @param string $base base URL of the server
  388.      * @return array of categorynames
  389.      */
  390.     function listCategories($base$channel = false)
  391.     {
  392.         $categories = array();
  393.  
  394.         // c/categories.xml does not exist;
  395.         // check for every package its category manually
  396.         // This is SLOOOWWWW : ///
  397.         $packagelist $this->_rest->retrieveData($base 'p/packages.xml'falsefalse$channel);
  398.         if (PEAR::isError($packagelist)) {
  399.             return $packagelist;
  400.         }
  401.  
  402.         if (!is_array($packagelist|| !isset($packagelist['p'])) {
  403.             $ret = array();
  404.             return $ret;
  405.         }
  406.  
  407.         if (!is_array($packagelist['p'])) {
  408.             $packagelist['p'= array($packagelist['p']);
  409.         }
  410.  
  411.         foreach ($packagelist['p'as $package{
  412.                 $inf $this->_rest->retrieveData($base 'p/' strtolower($package'/info.xml'falsefalse$channel);
  413.                 if (PEAR::isError($inf)) {
  414.                     PEAR::popErrorHandling();
  415.                     return $inf;
  416.                 }
  417.                 $cat $inf['ca']['_content'];
  418.                 if (!isset($categories[$cat])) {
  419.                     $categories[$cat$inf['ca'];
  420.                 }
  421.         }
  422.  
  423.         return array_values($categories);
  424.     }
  425.  
  426.     /**
  427.      * List a category of a REST server
  428.      *
  429.      * @param string $base base URL of the server
  430.      * @param string $category name of the category
  431.      * @param boolean $info also download full package info
  432.      * @return array of packagenames
  433.      */
  434.     function listCategory($base$category$info = false$channel = false)
  435.     {
  436.         // gives '404 Not Found' error when category doesn't exist
  437.         $packagelist $this->_rest->retrieveData($base.'c/'.urlencode($category).'/packages.xml'falsefalse$channel);
  438.         if (PEAR::isError($packagelist)) {
  439.             return $packagelist;
  440.         }
  441.  
  442.         if (!is_array($packagelist|| !isset($packagelist['p'])) {
  443.             return array();
  444.         }
  445.  
  446.         if (!is_array($packagelist['p']||
  447.             !isset($packagelist['p'][0])) // only 1 pkg
  448.             $packagelist = array($packagelist['p']);
  449.         else {
  450.             $packagelist $packagelist['p'];
  451.         }
  452.  
  453.         if ($info == true{
  454.             // get individual package info
  455.             PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  456.             foreach ($packagelist as $i => $packageitem{
  457.                 $url sprintf('%s'.'r/%s/latest.txt',
  458.                         $base,
  459.                         strtolower($packageitem['_content']));
  460.                 $version $this->_rest->retrieveData($urlfalsefalse$channel);
  461.                 if (PEAR::isError($version)) {
  462.                     break; // skipit
  463.                 }
  464.                 $url sprintf('%s'.'r/%s/%s.xml',
  465.                         $base,
  466.                         strtolower($packageitem['_content']),
  467.                         $version);
  468.                 $info $this->_rest->retrieveData($urlfalsefalse$channel);
  469.                 if (PEAR::isError($info)) {
  470.                     break; // skipit
  471.                 }
  472.                 $packagelist[$i]['info'$info;
  473.             }
  474.             PEAR::popErrorHandling();
  475.         }
  476.  
  477.         return $packagelist;
  478.     }
  479.  
  480.  
  481.     function listAll($base$dostable$basic = true$searchpackage = false$searchsummary = false$channel = false)
  482.     {
  483.         $packagelist $this->_rest->retrieveData($base 'p/packages.xml'falsefalse$channel);
  484.         if (PEAR::isError($packagelist)) {
  485.             return $packagelist;
  486.         }
  487.         if ($this->_rest->config->get('verbose'> 0{
  488.             $ui &PEAR_Frontend::singleton();
  489.             $ui->log('Retrieving data...0%'true);
  490.         }
  491.         $ret = array();
  492.         if (!is_array($packagelist|| !isset($packagelist['p'])) {
  493.             return $ret;
  494.         }
  495.         if (!is_array($packagelist['p'])) {
  496.             $packagelist['p'= array($packagelist['p']);
  497.         }
  498.  
  499.         // only search-packagename = quicksearch !
  500.         if ($searchpackage && (!$searchsummary || empty($searchpackage))) {
  501.             $newpackagelist = array();
  502.             foreach ($packagelist['p'as $package{
  503.                 if (!empty($searchpackage&& stristr($package$searchpackage!== false{
  504.                     $newpackagelist[$package;
  505.                 }
  506.             }
  507.             $packagelist['p'$newpackagelist;
  508.         }
  509.         $next = .1;
  510.         foreach ($packagelist['p'as $progress => $package{
  511.             if ($this->_rest->config->get('verbose'> 0{
  512.                 if ($progress count($packagelist['p']>= $next{
  513.                     if ($next == .5{
  514.                         $ui->log('50%'false);
  515.                     else {
  516.                         $ui->log('.'false);
  517.                     }
  518.                     $next += .1;
  519.                 }
  520.             }
  521.  
  522.             if ($basic// remote-list command
  523.                 if ($dostable{
  524.                     $latest $this->_rest->retrieveData($base 'r/' strtolower($package.
  525.                         '/stable.txt'falsefalse$channel);
  526.                 else {
  527.                     $latest $this->_rest->retrieveData($base 'r/' strtolower($package.
  528.                         '/latest.txt'falsefalse$channel);
  529.                 }
  530.                 if (PEAR::isError($latest)) {
  531.                     $latest = false;
  532.                 }
  533.                 $info = array('stable' => $latest);
  534.             else // list-all command
  535.                 $inf $this->_rest->retrieveData($base 'p/' strtolower($package'/info.xml'falsefalse$channel);
  536.                 if (PEAR::isError($inf)) {
  537.                     PEAR::popErrorHandling();
  538.                     return $inf;
  539.                 }
  540.                 if ($searchpackage{
  541.                     $found (!empty($searchpackage&& stristr($package$searchpackage!== false);
  542.                     if (!$found && !(isset($searchsummary&& !empty($searchsummary)
  543.                         && (stristr($inf['s']$searchsummary!== false
  544.                             || stristr($inf['d']$searchsummary!== false)))
  545.                     {
  546.                         continue;
  547.                     };
  548.                 }
  549.                 $releases $this->_rest->retrieveData($base 'r/' strtolower($package.
  550.                     '/allreleases.xml'falsefalse$channel);
  551.                 if (PEAR::isError($releases)) {
  552.                     continue;
  553.                 }
  554.                 if (!isset($releases['r'][0])) {
  555.                     $releases['r'= array($releases['r']);
  556.                 }
  557.                 unset($latest);
  558.                 unset($unstable);
  559.                 unset($stable);
  560.                 unset($state);
  561.                 foreach ($releases['r'as $release{
  562.                     if (!isset($latest)) {
  563.                         if ($dostable && $release['s'== 'stable'{
  564.                             $latest $release['v'];
  565.                             $state 'stable';
  566.                         }
  567.                         if (!$dostable{
  568.                             $latest $release['v'];
  569.                             $state $release['s'];
  570.                         }
  571.                     }
  572.                     if (!isset($stable&& $release['s'== 'stable'{
  573.                         $stable $release['v'];
  574.                         if (!isset($unstable)) {
  575.                             $unstable $stable;
  576.                         }
  577.                     }
  578.                     if (!isset($unstable&& $release['s'!= 'stable'{
  579.                         $latest $unstable $release['v'];
  580.                         $state $release['s'];
  581.                     }
  582.                     if (isset($latest&& !isset($state)) {
  583.                         $state $release['s'];
  584.                     }
  585.                     if (isset($latest&& isset($stable&& isset($unstable)) {
  586.                         break;
  587.                     }
  588.                 }
  589.                 $deps = array();
  590.                 if (!isset($unstable)) {
  591.                     $unstable = false;
  592.                     $state 'stable';
  593.                     if (isset($stable)) {
  594.                         $latest $unstable $stable;
  595.                     }
  596.                 else {
  597.                     $latest $unstable;
  598.                 }
  599.                 if (!isset($latest)) {
  600.                     $latest = false;
  601.                 }
  602.                 if ($latest{
  603.                     $d $this->_rest->retrieveCacheFirst($base 'r/' strtolower($package'/deps.' .
  604.                         $latest '.txt'falsefalse$channel);
  605.                     if (!PEAR::isError($d)) {
  606.                         $d unserialize($d);
  607.                         if ($d{
  608.                             if (isset($d['required'])) {
  609.                                 if (!class_exists('PEAR_PackageFile_v2')) {
  610.                                     require_once 'PEAR/PackageFile/v2.php';
  611.                                 }
  612.                                 if (!isset($pf)) {
  613.                                     $pf = new PEAR_PackageFile_v2;
  614.                                 }
  615.                                 $pf->setDeps($d);
  616.                                 $tdeps $pf->getDeps();
  617.                             else {
  618.                                 $tdeps $d;
  619.                             }
  620.                             foreach ($tdeps as $dep{
  621.                                 if ($dep['type'!== 'pkg'{
  622.                                     continue;
  623.                                 }
  624.                                 $deps[$dep;
  625.                             }
  626.                         }
  627.                     }
  628.                 }
  629.                 if (!isset($stable)) {
  630.                     $stable '-n/a-';
  631.                 }
  632.                 if (!$searchpackage{
  633.                     $info = array('stable' => $latest'summary' => $inf['s']'description' =>
  634.                         $inf['d']'deps' => $deps'category' => $inf['ca']['_content'],
  635.                         'unstable' => $unstable'state' => $state);
  636.                 else {
  637.                     $info = array('stable' => $stable'summary' => $inf['s']'description' =>
  638.                         $inf['d']'deps' => $deps'category' => $inf['ca']['_content'],
  639.                         'unstable' => $unstable'state' => $state);
  640.                 }
  641.             }
  642.             $ret[$package$info;
  643.         }
  644.         PEAR::popErrorHandling();
  645.         return $ret;
  646.     }
  647.  
  648.     function listLatestUpgrades($base$pref_state$installed$channel&$reg)
  649.     {
  650.         $packagelist $this->_rest->retrieveData($base 'p/packages.xml'falsefalse$channel);
  651.         if (PEAR::isError($packagelist)) {
  652.             return $packagelist;
  653.         }
  654.  
  655.         $ret = array();
  656.         if (!is_array($packagelist|| !isset($packagelist['p'])) {
  657.             return $ret;
  658.         }
  659.  
  660.         if (!is_array($packagelist['p'])) {
  661.             $packagelist['p'= array($packagelist['p']);
  662.         }
  663.  
  664.         foreach ($packagelist['p'as $package{
  665.             if (!isset($installed[strtolower($package)])) {
  666.                 continue;
  667.             }
  668.  
  669.             $inst_version $reg->packageInfo($package'version'$channel);
  670.             $inst_state   $reg->packageInfo($package'release_state'$channel);
  671.             PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  672.             $info $this->_rest->retrieveData($base 'r/' strtolower($package.
  673.                 '/allreleases.xml'falsefalse$channel);
  674.             PEAR::popErrorHandling();
  675.             if (PEAR::isError($info)) {
  676.                 continue; // no remote releases
  677.             }
  678.  
  679.             if (!isset($info['r'])) {
  680.                 continue;
  681.             }
  682.  
  683.             $release $found = false;
  684.             if (!is_array($info['r']|| !isset($info['r'][0])) {
  685.                 $info['r'= array($info['r']);
  686.             }
  687.  
  688.             // $info['r'] is sorted by version number
  689.             usort($info['r']array($this'_sortReleasesByVersionNumber'));
  690.             foreach ($info['r'as $release{
  691.                 if ($inst_version && version_compare($release['v']$inst_version'<=')) {
  692.                     // not newer than the one installed
  693.                     break;
  694.                 }
  695.  
  696.                 // new version > installed version
  697.                 if (!$pref_state{
  698.                     // every state is a good state
  699.                     $found = true;
  700.                     break;
  701.                 else {
  702.                     $new_state $release['s'];
  703.                     // if new state >= installed state: go
  704.                     if (in_array($new_state$this->betterStates($inst_statetrue))) {
  705.                         $found = true;
  706.                         break;
  707.                     else {
  708.                         // only allow to lower the state of package,
  709.                         // if new state >= preferred state: go
  710.                         if (in_array($new_state$this->betterStates($pref_statetrue))) {
  711.                             $found = true;
  712.                             break;
  713.                         }
  714.                     }
  715.                 }
  716.             }
  717.  
  718.             if (!$found{
  719.                 continue;
  720.             }
  721.  
  722.             $relinfo $this->_rest->retrieveCacheFirst($base 'r/' strtolower($package'/' .
  723.                 $release['v''.xml'falsefalse$channel);
  724.             if (PEAR::isError($relinfo)) {
  725.                 return $relinfo;
  726.             }
  727.  
  728.             $ret[$package= array(
  729.                 'version'  => $release['v'],
  730.                 'state'    => $release['s'],
  731.                 'filesize' => $relinfo['f'],
  732.             );
  733.         }
  734.  
  735.         return $ret;
  736.     }
  737.  
  738.     function packageInfo($base$package$channel = false)
  739.     {
  740.         $pinfo $this->_rest->retrieveData($base 'p/' strtolower($package'/info.xml'falsefalse$channel);
  741.         if (PEAR::isError($pinfo)) {
  742.             PEAR::popErrorHandling();
  743.             return PEAR::raiseError('Unknown package: "' $package '" in channel "' $channel '"' "\n"'Debug: ' .
  744.                 $pinfo->getMessage());
  745.         }
  746.  
  747.         $releases = array();
  748.         $allreleases $this->_rest->retrieveData($base 'r/' strtolower($package.
  749.             '/allreleases.xml'falsefalse$channel);
  750.         if (!PEAR::isError($allreleases)) {
  751.             if (!class_exists('PEAR_PackageFile_v2')) {
  752.                 require_once 'PEAR/PackageFile/v2.php';
  753.             }
  754.  
  755.             if (!is_array($allreleases['r']|| !isset($allreleases['r'][0])) {
  756.                 $allreleases['r'= array($allreleases['r']);
  757.             }
  758.  
  759.             $pf = new PEAR_PackageFile_v2;
  760.             foreach ($allreleases['r'as $release{
  761.                 $ds $this->_rest->retrieveCacheFirst($base 'r/' strtolower($package'/deps.' .
  762.                     $release['v''.txt'falsefalse$channel);
  763.                 if (PEAR::isError($ds)) {
  764.                     continue;
  765.                 }
  766.  
  767.                 if (!isset($latest)) {
  768.                     $latest $release['v'];
  769.                 }
  770.  
  771.                 $pf->setDeps(unserialize($ds));
  772.                 $ds $pf->getDeps();
  773.                 $info $this->_rest->retrieveCacheFirst($base 'r/' strtolower($package)
  774.                     . '/' $release['v''.xml'falsefalse$channel);
  775.  
  776.                 if (PEAR::isError($info)) {
  777.                     continue;
  778.                 }
  779.  
  780.                 $releases[$release['v']] = array(
  781.                     'doneby' => $info['m'],
  782.                     'license' => $info['l'],
  783.                     'summary' => $info['s'],
  784.                     'description' => $info['d'],
  785.                     'releasedate' => $info['da'],
  786.                     'releasenotes' => $info['n'],
  787.                     'state' => $release['s'],
  788.                     'deps' => $ds $ds : array(),
  789.                 );
  790.             }
  791.         else {
  792.             $latest '';
  793.         }
  794.  
  795.         PEAR::popErrorHandling();
  796.         if (isset($pinfo['dc']&& isset($pinfo['dp'])) {
  797.             if (is_array($pinfo['dp'])) {
  798.                 $deprecated = array('channel' => (string) $pinfo['dc'],
  799.                                     'package' => trim($pinfo['dp']['_content']));
  800.             else {
  801.                 $deprecated = array('channel' => (string) $pinfo['dc'],
  802.                                     'package' => trim($pinfo['dp']));
  803.             }
  804.         else {
  805.             $deprecated = false;
  806.         }
  807.  
  808.         if (!isset($latest)) {
  809.             $latest '';
  810.         }
  811.  
  812.         return array(
  813.             'name' => $pinfo['n'],
  814.             'channel' => $pinfo['c'],
  815.             'category' => $pinfo['ca']['_content'],
  816.             'stable' => $latest,
  817.             'license' => $pinfo['l'],
  818.             'summary' => $pinfo['s'],
  819.             'description' => $pinfo['d'],
  820.             'releases' => $releases,
  821.             'deprecated' => $deprecated,
  822.             );
  823.     }
  824.  
  825.     /**
  826.      * Return an array containing all of the states that are more stable than
  827.      * or equal to the passed in state
  828.      *
  829.      * @param string Release state
  830.      * @param boolean Determines whether to include $state in the list
  831.      * @return false|arrayFalse if $state is not a valid release state
  832.      */
  833.     function betterStates($state$include = false)
  834.     {
  835.         static $states = array('snapshot''devel''alpha''beta''stable');
  836.         $i = array_search($state$states);
  837.         if ($i === false{
  838.             return false;
  839.         }
  840.  
  841.         if ($include{
  842.             $i--;
  843.         }
  844.  
  845.         return array_slice($states$i + 1);
  846.     }
  847.  
  848.     /**
  849.      * Sort releases by version number
  850.      *
  851.      * @access private
  852.      */
  853.     function _sortReleasesByVersionNumber($a$b)
  854.     {
  855.         if (version_compare($a['v']$b['v']'=')) {
  856.             return 0;
  857.         }
  858.  
  859.         if (version_compare($a['v']$b['v']'>')) {
  860.             return -1;
  861.         }
  862.  
  863.         if (version_compare($a['v']$b['v']'<')) {
  864.             return 1;
  865.         }
  866.     }
  867. }

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