[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 /** 3 * PEAR_REST_11 - implement faster list-all/remote-list command 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 Greg Beaver <cellog@php.net> 16 * @copyright 1997-2006 The PHP Group 17 * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 * @version CVS: $Id: 11.php,v 1.4.2.3 2006/08/15 21:25:12 pajoye Exp $ 19 * @link http://pear.php.net/package/PEAR 20 * @since File available since Release 1.4.3 21 */ 22 23 /** 24 * For downloading REST xml/txt files 25 */ 26 require_once 'PEAR/REST.php'; 27 28 /** 29 * Implement REST 1.1 30 * 31 * @category pear 32 * @package PEAR 33 * @author Greg Beaver <cellog@php.net> 34 * @copyright 1997-2006 The PHP Group 35 * @license http://www.php.net/license/3_0.txt PHP License 3.0 36 * @version Release: 1.4.11 37 * @link http://pear.php.net/package/PEAR 38 * @since Class available since Release 1.4.3 39 */ 40 class PEAR_REST_11 41 { 42 /** 43 * @var PEAR_REST 44 */ 45 var $_rest; 46 47 function PEAR_REST_11($config, $options = array()) 48 { 49 $this->_rest = &new PEAR_REST($config, $options); 50 } 51 52 function listAll($base, $dostable, $basic = true) 53 { 54 $categorylist = $this->_rest->retrieveData($base . 'c/categories.xml'); 55 if (PEAR::isError($categorylist)) { 56 return $categorylist; 57 } 58 $ret = array(); 59 if (!is_array($categorylist['c']) || !isset($categorylist['c'][0])) { 60 $categorylist['c'] = array($categorylist['c']); 61 } 62 PEAR::pushErrorHandling(PEAR_ERROR_RETURN); 63 foreach ($categorylist['c'] as $progress => $category) { 64 $category = $category['_content']; 65 $packagesinfo = $this->_rest->retrieveData($base . 66 'c/' . urlencode($category) . '/packagesinfo.xml'); 67 if (PEAR::isError($packagesinfo)) { 68 continue; 69 } 70 if (!is_array($packagesinfo) || !isset($packagesinfo['pi'])) { 71 continue; 72 } 73 if (!is_array($packagesinfo['pi']) || !isset($packagesinfo['pi'][0])) { 74 $packagesinfo['pi'] = array($packagesinfo['pi']); 75 } 76 foreach ($packagesinfo['pi'] as $packageinfo) { 77 $info = $packageinfo['p']; 78 $package = $info['n']; 79 $releases = isset($packageinfo['a']) ? $packageinfo['a'] : false; 80 unset($latest); 81 unset($unstable); 82 unset($stable); 83 unset($state); 84 if ($releases) { 85 if (!isset($releases['r'][0])) { 86 $releases['r'] = array($releases['r']); 87 } 88 foreach ($releases['r'] as $release) { 89 if (!isset($latest)) { 90 if ($dostable && $release['s'] == 'stable') { 91 $latest = $release['v']; 92 $state = 'stable'; 93 } 94 if (!$dostable) { 95 $latest = $release['v']; 96 $state = $release['s']; 97 } 98 } 99 if (!isset($stable) && $release['s'] == 'stable') { 100 $stable = $release['v']; 101 if (!isset($unstable)) { 102 $unstable = $stable; 103 } 104 } 105 if (!isset($unstable) && $release['s'] != 'stable') { 106 $latest = $unstable = $release['v']; 107 $state = $release['s']; 108 } 109 if (isset($latest) && !isset($state)) { 110 $state = $release['s']; 111 } 112 if (isset($latest) && isset($stable) && isset($unstable)) { 113 break; 114 } 115 } 116 } 117 if ($basic) { // remote-list command 118 if (!isset($latest)) { 119 $latest = false; 120 } 121 $ret[$package] = array('stable' => $latest); 122 continue; 123 } 124 // list-all command 125 $deps = array(); 126 if (!isset($unstable)) { 127 $unstable = false; 128 $state = 'stable'; 129 if (isset($stable)) { 130 $latest = $unstable = $stable; 131 } 132 } else { 133 $latest = $unstable; 134 } 135 if (!isset($latest)) { 136 $latest = false; 137 } 138 if ($latest) { 139 if (isset($packageinfo['deps'])) { 140 if (!is_array($packageinfo['deps']) || 141 !isset($packageinfo['deps'][0])) { 142 $packageinfo['deps'] = array($packageinfo['deps']); 143 } 144 } 145 $d = false; 146 if (isset($packageinfo['deps']) && is_array($packageinfo['deps'])) { 147 foreach ($packageinfo['deps'] as $dep) { 148 if ($dep['v'] == $latest) { 149 $d = unserialize($dep['d']); 150 } 151 } 152 } 153 if ($d) { 154 if (isset($d['required'])) { 155 if (!class_exists('PEAR_PackageFile_v2')) { 156 require_once 'PEAR/PackageFile/v2.php'; 157 } 158 if (!isset($pf)) { 159 $pf = new PEAR_PackageFile_v2; 160 } 161 $pf->setDeps($d); 162 $tdeps = $pf->getDeps(); 163 } else { 164 $tdeps = $d; 165 } 166 foreach ($tdeps as $dep) { 167 if ($dep['type'] !== 'pkg') { 168 continue; 169 } 170 $deps[] = $dep; 171 } 172 } 173 } 174 if (!isset($stable)) { 175 $stable = '-n/a-'; 176 } 177 $info = array('stable' => $latest, 'summary' => $info['s'], 178 'description' => 179 $info['d'], 'deps' => $deps, 'category' => $info['ca']['_content'], 180 'unstable' => $unstable, 'state' => $state); 181 $ret[$package] = $info; 182 } 183 } 184 PEAR::popErrorHandling(); 185 return $ret; 186 } 187 188 /** 189 * Return an array containing all of the states that are more stable than 190 * or equal to the passed in state 191 * 192 * @param string Release state 193 * @param boolean Determines whether to include $state in the list 194 * @return false|array False if $state is not a valid release state 195 */ 196 function betterStates($state, $include = false) 197 { 198 static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable'); 199 $i = array_search($state, $states); 200 if ($i === false) { 201 return false; 202 } 203 if ($include) { 204 $i--; 205 } 206 return array_slice($states, $i + 1); 207 } 208 } 209 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |