Subversion Repositories Applications.gtt

Rev

Rev 94 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 jpm 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.8 2007/01/27 16:10:23 cellog 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.5.1
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
 
64
        foreach ($categorylist['c'] as $progress => $category) {
65
            $category = $category['_content'];
66
            $packagesinfo = $this->_rest->retrieveData($base .
67
                'c/' . urlencode($category) . '/packagesinfo.xml');
68
 
69
            if (PEAR::isError($packagesinfo)) {
70
                continue;
71
            }
72
 
73
            if (!is_array($packagesinfo) || !isset($packagesinfo['pi'])) {
74
                continue;
75
            }
76
 
77
            if (!is_array($packagesinfo['pi']) || !isset($packagesinfo['pi'][0])) {
78
                $packagesinfo['pi'] = array($packagesinfo['pi']);
79
            }
80
 
81
            foreach ($packagesinfo['pi'] as $packageinfo) {
82
                $info = $packageinfo['p'];
83
                $package = $info['n'];
84
                $releases = isset($packageinfo['a']) ? $packageinfo['a'] : false;
85
                unset($latest);
86
                unset($unstable);
87
                unset($stable);
88
                unset($state);
89
 
90
                if ($releases) {
91
                    if (!isset($releases['r'][0])) {
92
                        $releases['r'] = array($releases['r']);
93
                    }
94
                    foreach ($releases['r'] as $release) {
95
                        if (!isset($latest)) {
96
                            if ($dostable && $release['s'] == 'stable') {
97
                                $latest = $release['v'];
98
                                $state = 'stable';
99
                            }
100
                            if (!$dostable) {
101
                                $latest = $release['v'];
102
                                $state = $release['s'];
103
                            }
104
                        }
105
                        if (!isset($stable) && $release['s'] == 'stable') {
106
                            $stable = $release['v'];
107
                            if (!isset($unstable)) {
108
                                $unstable = $stable;
109
                            }
110
                        }
111
                        if (!isset($unstable) && $release['s'] != 'stable') {
112
                            $latest = $unstable = $release['v'];
113
                            $state = $release['s'];
114
                        }
115
                        if (isset($latest) && !isset($state)) {
116
                            $state = $release['s'];
117
                        }
118
                        if (isset($latest) && isset($stable) && isset($unstable)) {
119
                            break;
120
                        }
121
                    }
122
                }
123
 
124
                if ($basic) { // remote-list command
125
                    if (!isset($latest)) {
126
                        $latest = false;
127
                    }
128
                    if ($dostable) {
129
                        // $state is not set if there are no releases
130
                        if (isset($state) && $state == 'stable') {
131
                            $ret[$package] = array('stable' => $latest);
132
                        } else {
133
                            $ret[$package] = array('stable' => '-n/a-');
134
                        }
135
                    } else {
136
                        $ret[$package] = array('stable' => $latest);
137
                    }
138
                    continue;
139
                }
140
 
141
                // list-all command
142
                $deps = array();
143
                if (!isset($unstable)) {
144
                    $unstable = false;
145
                    $state = 'stable';
146
                    if (isset($stable)) {
147
                        $latest = $unstable = $stable;
148
                    }
149
                } else {
150
                    $latest = $unstable;
151
                }
152
 
153
                if (!isset($latest)) {
154
                    $latest = false;
155
                }
156
 
157
                if ($latest && $packageinfo['deps'] !== null) {
158
                    if (isset($packageinfo['deps'])) {
159
                        if (!is_array($packageinfo['deps']) ||
160
                              !isset($packageinfo['deps'][0])) {
161
                            $packageinfo['deps'] = array($packageinfo['deps']);
162
                        }
163
                    }
164
                    $d = false;
165
                    foreach ($packageinfo['deps'] as $dep) {
166
                        if ($dep['v'] == $latest) {
167
                            $d = unserialize($dep['d']);
168
                        }
169
                    }
170
                    if ($d) {
171
                        if (isset($d['required'])) {
172
                            if (!class_exists('PEAR_PackageFile_v2')) {
173
                                require_once 'PEAR/PackageFile/v2.php';
174
                            }
175
                            if (!isset($pf)) {
176
                                $pf = new PEAR_PackageFile_v2;
177
                            }
178
                            $pf->setDeps($d);
179
                            $tdeps = $pf->getDeps();
180
                        } else {
181
                            $tdeps = $d;
182
                        }
183
                        foreach ($tdeps as $dep) {
184
                            if ($dep['type'] !== 'pkg') {
185
                                continue;
186
                            }
187
                            $deps[] = $dep;
188
                        }
189
                    }
190
                }
191
 
192
                $info = array('stable' => $latest, 'summary' => $info['s'],
193
                    'description' =>
194
                    $info['d'], 'deps' => $deps, 'category' => $info['ca']['_content'],
195
                    'unstable' => $unstable, 'state' => $state);
196
                $ret[$package] = $info;
197
            }
198
        }
199
        PEAR::popErrorHandling();
200
        return $ret;
201
    }
202
 
203
    /**
204
     * Return an array containing all of the states that are more stable than
205
     * or equal to the passed in state
206
     *
207
     * @param string Release state
208
     * @param boolean Determines whether to include $state in the list
209
     * @return false|array False if $state is not a valid release state
210
     */
211
    function betterStates($state, $include = false)
212
    {
213
        static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable');
214
        $i = array_search($state, $states);
215
        if ($i === false) {
216
            return false;
217
        }
218
        if ($include) {
219
            $i--;
220
        }
221
        return array_slice($states, $i + 1);
222
    }
223
}
224
?>