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

Source for file 11.php

Documentation is available at 11.php

  1. <?php
  2. /**
  3.  * PEAR_REST_11 - implement faster list-all/remote-list command
  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: 11.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.3
  15.  */
  16.  
  17. /**
  18.  * For downloading REST xml/txt files
  19.  */
  20. require_once 'PEAR/REST.php';
  21.  
  22. /**
  23.  * Implement REST 1.1
  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.3
  33.  */
  34. {
  35.     /**
  36.      * @var PEAR_REST 
  37.      */
  38.     var $_rest;
  39.  
  40.     function PEAR_REST_11($config$options = array())
  41.     {
  42.         $this->_rest &new PEAR_REST($config$options);
  43.     }
  44.  
  45.     function listAll($base$dostable$basic = true$searchpackage = false$searchsummary = false$channel = false)
  46.     {
  47.         $categorylist $this->_rest->retrieveData($base 'c/categories.xml'falsefalse$channel);
  48.         if (PEAR::isError($categorylist)) {
  49.             return $categorylist;
  50.         }
  51.  
  52.         $ret = array();
  53.         if (!is_array($categorylist['c']|| !isset($categorylist['c'][0])) {
  54.             $categorylist['c'= array($categorylist['c']);
  55.         }
  56.  
  57.  
  58.         foreach ($categorylist['c'as $progress => $category{
  59.             $category $category['_content'];
  60.             $packagesinfo $this->_rest->retrieveData($base .
  61.                 'c/' urlencode($category'/packagesinfo.xml'falsefalse$channel);
  62.  
  63.             if (PEAR::isError($packagesinfo)) {
  64.                 continue;
  65.             }
  66.  
  67.             if (!is_array($packagesinfo|| !isset($packagesinfo['pi'])) {
  68.                 continue;
  69.             }
  70.  
  71.             if (!is_array($packagesinfo['pi']|| !isset($packagesinfo['pi'][0])) {
  72.                 $packagesinfo['pi'= array($packagesinfo['pi']);
  73.             }
  74.  
  75.             foreach ($packagesinfo['pi'as $packageinfo{
  76.                 if (empty($packageinfo)) {
  77.                     continue;
  78.                 }
  79.  
  80.                 $info     $packageinfo['p'];
  81.                 $package  $info['n'];
  82.                 $releases = isset($packageinfo['a']$packageinfo['a': false;
  83.                 unset($latest);
  84.                 unset($unstable);
  85.                 unset($stable);
  86.                 unset($state);
  87.  
  88.                 if ($releases{
  89.                     if (!isset($releases['r'][0])) {
  90.                         $releases['r'= array($releases['r']);
  91.                     }
  92.  
  93.                     foreach ($releases['r'as $release{
  94.                         if (!isset($latest)) {
  95.                             if ($dostable && $release['s'== 'stable'{
  96.                                 $latest $release['v'];
  97.                                 $state 'stable';
  98.                             }
  99.                             if (!$dostable{
  100.                                 $latest $release['v'];
  101.                                 $state $release['s'];
  102.                             }
  103.                         }
  104.  
  105.                         if (!isset($stable&& $release['s'== 'stable'{
  106.                             $stable $release['v'];
  107.                             if (!isset($unstable)) {
  108.                                 $unstable $stable;
  109.                             }
  110.                         }
  111.  
  112.                         if (!isset($unstable&& $release['s'!= 'stable'{
  113.                             $unstable $release['v'];
  114.                             $state $release['s'];
  115.                         }
  116.  
  117.                         if (isset($latest&& !isset($state)) {
  118.                             $state $release['s'];
  119.                         }
  120.  
  121.                         if (isset($latest&& isset($stable&& isset($unstable)) {
  122.                             break;
  123.                         }
  124.                     }
  125.                 }
  126.  
  127.                 if ($basic// remote-list command
  128.                     if (!isset($latest)) {
  129.                         $latest = false;
  130.                     }
  131.  
  132.                     if ($dostable{
  133.                         // $state is not set if there are no releases
  134.                         if (isset($state&& $state == 'stable'{
  135.                             $ret[$package= array('stable' => $latest);
  136.                         else {
  137.                             $ret[$package= array('stable' => '-n/a-');
  138.                         }
  139.                     else {
  140.                         $ret[$package= array('stable' => $latest);
  141.                     }
  142.  
  143.                     continue;
  144.                 }
  145.  
  146.                 // list-all command
  147.                 if (!isset($unstable)) {
  148.                     $unstable = false;
  149.                     $state 'stable';
  150.                     if (isset($stable)) {
  151.                         $latest $unstable $stable;
  152.                     }
  153.                 else {
  154.                     $latest $unstable;
  155.                 }
  156.  
  157.                 if (!isset($latest)) {
  158.                     $latest = false;
  159.                 }
  160.  
  161.                 $deps = array();
  162.                 if ($latest && isset($packageinfo['deps'])) {
  163.                     if (!is_array($packageinfo['deps']||
  164.                           !isset($packageinfo['deps'][0])
  165.                     {
  166.                         $packageinfo['deps'= array($packageinfo['deps']);
  167.                     }
  168.  
  169.                     $d = false;
  170.                     foreach ($packageinfo['deps'as $dep{
  171.                         if ($dep['v'== $latest{
  172.                             $d unserialize($dep['d']);
  173.                         }
  174.                     }
  175.  
  176.                     if ($d{
  177.                         if (isset($d['required'])) {
  178.                             if (!class_exists('PEAR_PackageFile_v2')) {
  179.                                 require_once 'PEAR/PackageFile/v2.php';
  180.                             }
  181.  
  182.                             if (!isset($pf)) {
  183.                                 $pf = new PEAR_PackageFile_v2;
  184.                             }
  185.  
  186.                             $pf->setDeps($d);
  187.                             $tdeps $pf->getDeps();
  188.                         else {
  189.                             $tdeps $d;
  190.                         }
  191.  
  192.                         foreach ($tdeps as $dep{
  193.                             if ($dep['type'!== 'pkg'{
  194.                                 continue;
  195.                             }
  196.  
  197.                             $deps[$dep;
  198.                         }
  199.                     }
  200.                 }
  201.  
  202.                 $info = array(
  203.                     'stable'      => $latest,
  204.                     'summary'     => $info['s'],
  205.                     'description' => $info['d'],
  206.                     'deps'        => $deps,
  207.                     'category'    => $info['ca']['_content'],
  208.                     'unstable'    => $unstable,
  209.                     'state'       => $state
  210.                 );
  211.                 $ret[$package$info;
  212.             }
  213.         }
  214.  
  215.         PEAR::popErrorHandling();
  216.         return $ret;
  217.     }
  218.  
  219.     /**
  220.      * List all categories of a REST server
  221.      *
  222.      * @param string $base base URL of the server
  223.      * @return array of categorynames
  224.      */
  225.     function listCategories($base$channel = false)
  226.     {
  227.         $categorylist $this->_rest->retrieveData($base 'c/categories.xml'falsefalse$channel);
  228.         if (PEAR::isError($categorylist)) {
  229.             return $categorylist;
  230.         }
  231.  
  232.         if (!is_array($categorylist|| !isset($categorylist['c'])) {
  233.             return array();
  234.         }
  235.  
  236.         if (isset($categorylist['c']['_content'])) {
  237.             // only 1 category
  238.             $categorylist['c'= array($categorylist['c']);
  239.         }
  240.  
  241.         return $categorylist['c'];
  242.     }
  243.  
  244.     /**
  245.      * List packages in a category of a REST server
  246.      *
  247.      * @param string $base base URL of the server
  248.      * @param string $category name of the category
  249.      * @param boolean $info also download full package info
  250.      * @return array of packagenames
  251.      */
  252.     function listCategory($base$category$info = false$channel = false)
  253.     {
  254.         if ($info == false{
  255.             $url '%s'.'c/%s/packages.xml';
  256.         else {
  257.             $url '%s'.'c/%s/packagesinfo.xml';
  258.         }
  259.         $url sprintf($url,
  260.                     $base,
  261.                     urlencode($category));
  262.  
  263.         // gives '404 Not Found' error when category doesn't exist
  264.         $packagelist $this->_rest->retrieveData($urlfalsefalse$channel);
  265.         if (PEAR::isError($packagelist)) {
  266.             return $packagelist;
  267.         }
  268.         if (!is_array($packagelist)) {
  269.             return array();
  270.         }
  271.  
  272.         if ($info == false{
  273.             if (!isset($packagelist['p'])) {
  274.                 return array();
  275.             }
  276.             if (!is_array($packagelist['p']||
  277.                 !isset($packagelist['p'][0])) // only 1 pkg
  278.                 $packagelist = array($packagelist['p']);
  279.             else {
  280.                 $packagelist $packagelist['p'];
  281.             }
  282.             return $packagelist;
  283.         }
  284.  
  285.         // info == true
  286.         if (!isset($packagelist['pi'])) {
  287.             return array();
  288.         }
  289.  
  290.         if (!is_array($packagelist['pi']||
  291.             !isset($packagelist['pi'][0])) // only 1 pkg
  292.             $packagelist_pre = array($packagelist['pi']);
  293.         else {
  294.             $packagelist_pre $packagelist['pi'];
  295.         }
  296.  
  297.         $packagelist = array();
  298.         foreach ($packagelist_pre as $i => $item{
  299.             // compatibility with r/<latest.txt>.xml
  300.             if (isset($item['a']['r'][0])) {
  301.                 // multiple releases
  302.                 $item['p']['v'$item['a']['r'][0]['v'];
  303.                 $item['p']['st'$item['a']['r'][0]['s'];
  304.             elseif (isset($item['a'])) {
  305.                 // first and only release
  306.                 $item['p']['v'$item['a']['r']['v'];
  307.                 $item['p']['st'$item['a']['r']['s'];
  308.             }
  309.  
  310.             $packagelist[$i= array('attribs' => $item['p']['r'],
  311.                                      '_content' => $item['p']['n'],
  312.                                      'info' => $item['p']);
  313.         }
  314.  
  315.         return $packagelist;
  316.     }
  317.  
  318.     /**
  319.      * Return an array containing all of the states that are more stable than
  320.      * or equal to the passed in state
  321.      *
  322.      * @param string Release state
  323.      * @param boolean Determines whether to include $state in the list
  324.      * @return false|arrayFalse if $state is not a valid release state
  325.      */
  326.     function betterStates($state$include = false)
  327.     {
  328.         static $states = array('snapshot''devel''alpha''beta''stable');
  329.         $i = array_search($state$states);
  330.         if ($i === false{
  331.             return false;
  332.         }
  333.         if ($include{
  334.             $i--;
  335.         }
  336.         return array_slice($states$i + 1);
  337.     }
  338. }
  339. ?>

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