logo       
Google Custom Search
    AddThis Social Bookmark Button

cvs: pear-core / package-PEAR.xml package2.xml /PEAR/REST 11.php: msg#00242

Subject: cvs: pear-core / package-PEAR.xml package2.xml /PEAR/REST 11.php
cellog          Tue May 29 15:08:59 2007 UTC

  Modified files:              
    /pear-core  package-PEAR.xml package2.xml 
    /pear-core/PEAR/REST        11.php 
  Log:
    * implement Request #10812: list-categories and list-category [tias]
  
  
http://cvs.php.net/viewvc.cgi/pear-core/package-PEAR.xml?r1=1.463&r2=1.464&diff_format=u
Index: pear-core/package-PEAR.xml
diff -u pear-core/package-PEAR.xml:1.463 pear-core/package-PEAR.xml:1.464
--- pear-core/package-PEAR.xml:1.463    Tue May 29 14:55:00 2007
+++ pear-core/package-PEAR.xml  Tue May 29 15:08:59 2007
@@ -107,6 +107,7 @@
   * implement Request #10495: list-all with channel information etc [tias]
   * implement Request #10496: list with channel information [tias]
   * implement Request #10515: list-upgrades with channel information [tias]
+  * implement Request #10812: list-categories and list-category [tias]
   </notes>
   <provides type="class" name="OS_Guess"/>
   <provides type="class" name="System"/>
http://cvs.php.net/viewvc.cgi/pear-core/package2.xml?r1=1.361&r2=1.362&diff_format=u
Index: pear-core/package2.xml
diff -u pear-core/package2.xml:1.361 pear-core/package2.xml:1.362
--- pear-core/package2.xml:1.361        Tue May 29 14:55:00 2007
+++ pear-core/package2.xml      Tue May 29 15:08:59 2007
@@ -112,6 +112,7 @@
   * implement Request #10495: list-all with channel information etc [tias]
   * implement Request #10496: list with channel information [tias]
   * implement Request #10515: list-upgrades with channel information [tias]
+  * implement Request #10812: list-categories and list-category [tias]
  </notes>
  <contents>
   <dir name="/">
http://cvs.php.net/viewvc.cgi/pear-core/PEAR/REST/11.php?r1=1.10&r2=1.11&diff_format=u
Index: pear-core/PEAR/REST/11.php
diff -u pear-core/PEAR/REST/11.php:1.10 pear-core/PEAR/REST/11.php:1.11
--- pear-core/PEAR/REST/11.php:1.10     Tue Apr  3 23:06:39 2007
+++ pear-core/PEAR/REST/11.php  Tue May 29 15:08:59 2007
@@ -15,7 +15,7 @@
  * @author     Greg Beaver <cellog@xxxxxxx>
  * @copyright  1997-2006 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    CVS: $Id: 11.php,v 1.10 2007/04/03 23:06:39 cellog Exp $
+ * @version    CVS: $Id: 11.php,v 1.11 2007/05/29 15:08:59 cellog Exp $
  * @link       http://pear.php.net/package/PEAR
  * @since      File available since Release 1.4.3
  */
@@ -199,6 +199,101 @@
     }
 
     /**
+     * List all categories of a REST server
+     *
+     * @param string $base base URL of the server
+     * @return array of categorynames
+     */
+    function listCategories($base)
+    {
+        $categorylist = $this->_rest->retrieveData($base . 'c/categories.xml');
+        if (PEAR::isError($categorylist)) {
+            return $categorylist;
+        }
+        if (!is_array($categorylist) || !isset($categorylist['c'])) {
+            return array();
+        }
+        if (isset($categorylist['c']['_content'])) {
+            // only 1 category
+            $categorylist['c'] = array($categorylist['c']);
+        }
+        return $categorylist['c'];
+    }
+
+    /**
+     * List packages in a category of a REST server
+     *
+     * @param string $base base URL of the server
+     * @param string $category name of the category
+     * @param boolean $info also download full package info
+     * @return array of packagenames
+     */
+    function listPackagesInCategory($base, $category, $info=false)
+    {
+        if ($info == false) {
+            $url = '%s'.'c/%s/packages.xml';
+        } else {
+            $url = '%s'.'c/%s/packagesinfo.xml';
+        }
+        $url = sprintf($url,
+                    $base,
+                    urlencode($category));
+            
+        // gives '404 Not Found' error when category doesn't exist
+        $packagelist = $this->_rest->retrieveData($url);
+        if (PEAR::isError($packagelist)) {
+            return $packagelist;
+        }
+        if (!is_array($packagelist)) {
+            return array();
+        }
+
+        if ($info == false) {
+            if (!isset($packagelist['p'])) {
+                return array();
+            }
+            if (!is_array($packagelist['p']) ||
+                !isset($packagelist['p'][0])) { // only 1 pkg
+                $packagelist = array($packagelist['p']);
+            } else {
+                $packagelist = $packagelist['p'];
+            }
+            return $packagelist;
+        } else {
+            // info == true
+            if (!isset($packagelist['pi'])) {
+                return array();
+            }
+            if (!is_array($packagelist['pi']) ||
+                !isset($packagelist['pi'][0])) { // only 1 pkg
+                $packagelist_pre = array($packagelist['pi']);
+            } else {
+                $packagelist_pre = $packagelist['pi'];
+            }
+
+            $packagelist = array();
+            foreach ($packagelist_pre as $i => $item) {
+                // compatibility with r/<latest.txt>.xml
+                if (isset($item['a']['r'][0])) {
+                    // multiple releases
+                    $item['p']['v'] = $item['a']['r'][0]['v'];
+                    $item['p']['st'] = $item['a']['r'][0]['s'];
+                } elseif (isset($item['a'])) {
+                    // first and only release
+                    $item['p']['v'] = $item['a']['r']['v'];
+                    $item['p']['st'] = $item['a']['r']['s'];
+                }
+
+                $packagelist[$i] = array('attribs' => $item['p']['r'],
+                                         '_content' => $item['p']['n'],
+                                         'info' => $item['p']);
+            }
+        }
+
+        return $packagelist;
+    }
+
+    /**
      * Return an array containing all of the states that are more stable than
      * or equal to the passed in state
      *

-- 
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>