Subversion Repositories Applications.gtt

Rev

Rev 94 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
1
<?php
1
<?php
2
/**
2
/**
3
 * PEAR_PackageFile_v2, package.xml version 2.0
3
 * PEAR_PackageFile_v2, package.xml version 2.0
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
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
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Greg Beaver <cellog@php.net>
9
 * @author     Greg Beaver <cellog@php.net>
16
 * @copyright  1997-2006 The PHP Group
10
 * @copyright  1997-2009 The Authors
17
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
11
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
18
 * @version    CVS: $Id: v2.php,v 1.136 2007/02/20 00:16:12 cellog Exp $
-
 
19
 * @link       http://pear.php.net/package/PEAR
12
 * @link       http://pear.php.net/package/PEAR
20
 * @since      File available since Release 1.4.0a1
13
 * @since      File available since Release 1.4.0a1
21
 */
14
 */
22
/**
15
/**
23
 * For error handling
16
 * For error handling
24
 */
17
 */
25
require_once 'PEAR/ErrorStack.php';
18
require_once 'PEAR/ErrorStack.php';
26
/**
19
/**
27
 * @category   pear
20
 * @category   pear
28
 * @package    PEAR
21
 * @package    PEAR
29
 * @author     Greg Beaver <cellog@php.net>
22
 * @author     Greg Beaver <cellog@php.net>
30
 * @copyright  1997-2006 The PHP Group
23
 * @copyright  1997-2009 The Authors
31
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
24
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
32
 * @version    Release: 1.5.1
25
 * @version    Release: 1.10.1
33
 * @link       http://pear.php.net/package/PEAR
26
 * @link       http://pear.php.net/package/PEAR
34
 * @since      Class available since Release 1.4.0a1
27
 * @since      Class available since Release 1.4.0a1
35
 */
28
 */
36
class PEAR_PackageFile_v2
29
class PEAR_PackageFile_v2
37
{
30
{
38
 
31
 
39
    /**
32
    /**
40
     * Parsed package information
33
     * Parsed package information
41
     * @var array
34
     * @var array
42
     * @access private
35
     * @access private
43
     */
36
     */
44
    var $_packageInfo = array();
37
    var $_packageInfo = array();
45
 
38
 
46
    /**
39
    /**
47
     * path to package .tgz or false if this is a local/extracted package.xml
40
     * path to package .tgz or false if this is a local/extracted package.xml
48
     * @var string|false
41
     * @var string|false
49
     * @access private
42
     * @access private
50
     */
43
     */
51
    var $_archiveFile;
44
    var $_archiveFile;
52
 
45
 
53
    /**
46
    /**
54
     * path to package .xml or false if this is an abstract parsed-from-string xml
47
     * path to package .xml or false if this is an abstract parsed-from-string xml
55
     * @var string|false
48
     * @var string|false
56
     * @access private
49
     * @access private
57
     */
50
     */
58
    var $_packageFile;
51
    var $_packageFile;
59
 
52
 
60
    /**
53
    /**
61
     * This is used by file analysis routines to log progress information
54
     * This is used by file analysis routines to log progress information
62
     * @var PEAR_Common
55
     * @var PEAR_Common
63
     * @access protected
56
     * @access protected
64
     */
57
     */
65
    var $_logger;
58
    var $_logger;
66
 
59
 
67
    /**
60
    /**
68
     * This is set to the highest validation level that has been validated
61
     * This is set to the highest validation level that has been validated
69
     *
62
     *
70
     * If the package.xml is invalid or unknown, this is set to 0.  If
63
     * If the package.xml is invalid or unknown, this is set to 0.  If
71
     * normal validation has occurred, this is set to PEAR_VALIDATE_NORMAL.  If
64
     * normal validation has occurred, this is set to PEAR_VALIDATE_NORMAL.  If
72
     * downloading/installation validation has occurred it is set to PEAR_VALIDATE_DOWNLOADING
65
     * downloading/installation validation has occurred it is set to PEAR_VALIDATE_DOWNLOADING
73
     * or INSTALLING, and so on up to PEAR_VALIDATE_PACKAGING.  This allows validation
66
     * or INSTALLING, and so on up to PEAR_VALIDATE_PACKAGING.  This allows validation
74
     * "caching" to occur, which is particularly important for package validation, so
67
     * "caching" to occur, which is particularly important for package validation, so
75
     * that PHP files are not validated twice
68
     * that PHP files are not validated twice
76
     * @var int
69
     * @var int
77
     * @access private
70
     * @access private
78
     */
71
     */
79
    var $_isValid = 0;
72
    var $_isValid = 0;
80
 
73
 
81
    /**
74
    /**
82
     * True if the filelist has been validated
75
     * True if the filelist has been validated
83
     * @param bool
76
     * @param bool
84
     */
77
     */
85
    var $_filesValid = false;
78
    var $_filesValid = false;
86
 
79
 
87
    /**
80
    /**
88
     * @var PEAR_Registry
81
     * @var PEAR_Registry
89
     * @access protected
82
     * @access protected
90
     */
83
     */
91
    var $_registry;
84
    var $_registry;
92
 
85
 
93
    /**
86
    /**
94
     * @var PEAR_Config
87
     * @var PEAR_Config
95
     * @access protected
88
     * @access protected
96
     */
89
     */
97
    var $_config;
90
    var $_config;
98
 
91
 
99
    /**
92
    /**
100
     * Optional Dependency group requested for installation
93
     * Optional Dependency group requested for installation
101
     * @var string
94
     * @var string
102
     * @access private
95
     * @access private
103
     */
96
     */
104
    var $_requestedGroup = false;
97
    var $_requestedGroup = false;
105
 
98
 
106
    /**
99
    /**
107
     * @var PEAR_ErrorStack
100
     * @var PEAR_ErrorStack
108
     * @access protected
101
     * @access protected
109
     */
102
     */
110
    var $_stack;
103
    var $_stack;
111
 
104
 
112
    /**
105
    /**
113
     * Namespace prefix used for tasks in this package.xml - use tasks: whenever possible
106
     * Namespace prefix used for tasks in this package.xml - use tasks: whenever possible
114
     */
107
     */
115
    var $_tasksNs;
108
    var $_tasksNs;
116
 
109
 
117
    /**
110
    /**
118
     * Determines whether this packagefile was initialized only with partial package info
111
     * Determines whether this packagefile was initialized only with partial package info
119
     *
112
     *
120
     * If this package file was constructed via parsing REST, it will only contain
113
     * If this package file was constructed via parsing REST, it will only contain
121
     *
114
     *
122
     * - package name
115
     * - package name
123
     * - channel name
116
     * - channel name
124
     * - dependencies 
117
     * - dependencies
125
     * @var boolean
118
     * @var boolean
126
     * @access private
119
     * @access private
127
     */
120
     */
128
    var $_incomplete = true;
121
    var $_incomplete = true;
129
 
122
 
130
    /**
123
    /**
131
     * @var PEAR_PackageFile_v2_Validator
124
     * @var PEAR_PackageFile_v2_Validator
132
     */
125
     */
133
    var $_v2Validator;
126
    var $_v2Validator;
134
 
127
 
135
    /**
128
    /**
136
     * The constructor merely sets up the private error stack
129
     * The constructor merely sets up the private error stack
137
     */
130
     */
138
    function PEAR_PackageFile_v2()
131
    function __construct()
139
    {
132
    {
140
        $this->_stack = new PEAR_ErrorStack('PEAR_PackageFile_v2', false, null);
133
        $this->_stack = new PEAR_ErrorStack('PEAR_PackageFile_v2', false, null);
141
        $this->_isValid = false;
134
        $this->_isValid = false;
142
    }
135
    }
143
 
136
 
144
    /**
137
    /**
-
 
138
     * PHP 4 style constructor for backwards compatibility.
-
 
139
     * Used by PEAR_PackageFileManager2
-
 
140
     */
-
 
141
    public function PEAR_PackageFile_v2()
-
 
142
    {
-
 
143
        $this->__construct();
-
 
144
    }
-
 
145
 
-
 
146
    /**
145
     * To make unit-testing easier
147
     * To make unit-testing easier
146
     * @param PEAR_Frontend_*
148
     * @param PEAR_Frontend_*
147
     * @param array options
149
     * @param array options
148
     * @param PEAR_Config
150
     * @param PEAR_Config
149
     * @return PEAR_Downloader
151
     * @return PEAR_Downloader
150
     * @access protected
152
     * @access protected
151
     */
153
     */
152
    function &getPEARDownloader(&$i, $o, &$c)
154
    function &getPEARDownloader(&$i, $o, &$c)
153
    {
155
    {
154
        $z = &new PEAR_Downloader($i, $o, $c);
156
        $z = new PEAR_Downloader($i, $o, $c);
155
        return $z;
157
        return $z;
156
    }
158
    }
157
 
159
 
158
    /**
160
    /**
159
     * To make unit-testing easier
161
     * To make unit-testing easier
160
     * @param PEAR_Config
162
     * @param PEAR_Config
161
     * @param array options
163
     * @param array options
162
     * @param array package name as returned from {@link PEAR_Registry::parsePackageName()}
164
     * @param array package name as returned from {@link PEAR_Registry::parsePackageName()}
163
     * @param int PEAR_VALIDATE_* constant
165
     * @param int PEAR_VALIDATE_* constant
164
     * @return PEAR_Dependency2
166
     * @return PEAR_Dependency2
165
     * @access protected
167
     * @access protected
166
     */
168
     */
167
    function &getPEARDependency2(&$c, $o, $p, $s = PEAR_VALIDATE_INSTALLING)
169
    function &getPEARDependency2(&$c, $o, $p, $s = PEAR_VALIDATE_INSTALLING)
168
    {
170
    {
169
        if (!class_exists('PEAR_Dependency2')) {
171
        if (!class_exists('PEAR_Dependency2')) {
170
            require_once 'PEAR/Dependency2.php';
172
            require_once 'PEAR/Dependency2.php';
171
        }
173
        }
172
        $z = &new PEAR_Dependency2($c, $o, $p, $s);
174
        $z = new PEAR_Dependency2($c, $o, $p, $s);
173
        return $z;
175
        return $z;
174
    }
176
    }
175
 
177
 
176
    function getInstalledBinary()
178
    function getInstalledBinary()
177
    {
179
    {
178
        return isset($this->_packageInfo['#binarypackage']) ? $this->_packageInfo['#binarypackage'] :
180
        return isset($this->_packageInfo['#binarypackage']) ? $this->_packageInfo['#binarypackage'] :
179
            false;
181
            false;
180
    }
182
    }
181
 
183
 
182
    /**
184
    /**
183
     * Installation of source package has failed, attempt to download and install the
185
     * Installation of source package has failed, attempt to download and install the
184
     * binary version of this package.
186
     * binary version of this package.
185
     * @param PEAR_Installer
187
     * @param PEAR_Installer
186
     * @return array|false
188
     * @return array|false
187
     */
189
     */
188
    function installBinary(&$installer)
190
    function installBinary(&$installer)
189
    {
191
    {
190
        if (!OS_WINDOWS) {
192
        if (!OS_WINDOWS) {
191
            $a = false;
193
            $a = false;
192
            return $a;
194
            return $a;
193
        }
195
        }
194
        if ($this->getPackageType() == 'extsrc' || $this->getPackageType() == 'zendextsrc') {
196
        if ($this->getPackageType() == 'extsrc' || $this->getPackageType() == 'zendextsrc') {
195
            $releasetype = $this->getPackageType() . 'release';
197
            $releasetype = $this->getPackageType() . 'release';
196
            if (!is_array($installer->getInstallPackages())) {
198
            if (!is_array($installer->getInstallPackages())) {
197
                $a = false;
199
                $a = false;
198
                return $a;
200
                return $a;
199
            }
201
            }
200
            foreach ($installer->getInstallPackages() as $p) {
202
            foreach ($installer->getInstallPackages() as $p) {
201
                if ($p->isExtension($this->_packageInfo['providesextension'])) {
203
                if ($p->isExtension($this->_packageInfo['providesextension'])) {
202
                    if ($p->getPackageType() != 'extsrc' && $p->getPackageType() != 'zendextsrc') {
204
                    if ($p->getPackageType() != 'extsrc' && $p->getPackageType() != 'zendextsrc') {
203
                        $a = false;
205
                        $a = false;
204
                        return $a; // the user probably downloaded it separately
206
                        return $a; // the user probably downloaded it separately
205
                    }
207
                    }
206
                }
208
                }
207
            }
209
            }
208
            if (isset($this->_packageInfo[$releasetype]['binarypackage'])) {
210
            if (isset($this->_packageInfo[$releasetype]['binarypackage'])) {
209
                $installer->log(0, 'Attempting to download binary version of extension "' .
211
                $installer->log(0, 'Attempting to download binary version of extension "' .
210
                    $this->_packageInfo['providesextension'] . '"');
212
                    $this->_packageInfo['providesextension'] . '"');
211
                $params = $this->_packageInfo[$releasetype]['binarypackage'];
213
                $params = $this->_packageInfo[$releasetype]['binarypackage'];
212
                if (!is_array($params) || !isset($params[0])) {
214
                if (!is_array($params) || !isset($params[0])) {
213
                    $params = array($params);
215
                    $params = array($params);
214
                }
216
                }
215
                if (isset($this->_packageInfo['channel'])) {
217
                if (isset($this->_packageInfo['channel'])) {
216
                    foreach ($params as $i => $param) {
218
                    foreach ($params as $i => $param) {
217
                        $params[$i] = array('channel' => $this->_packageInfo['channel'],
219
                        $params[$i] = array('channel' => $this->_packageInfo['channel'],
218
                            'package' => $param, 'version' => $this->getVersion());
220
                            'package' => $param, 'version' => $this->getVersion());
219
                    }
221
                    }
220
                }
222
                }
221
                $dl = &$this->getPEARDownloader($installer->ui, $installer->getOptions(),
223
                $dl = &$this->getPEARDownloader($installer->ui, $installer->getOptions(),
222
                    $installer->config);
224
                    $installer->config);
223
                $verbose = $dl->config->get('verbose');
225
                $verbose = $dl->config->get('verbose');
224
                $dl->config->set('verbose', -1);
226
                $dl->config->set('verbose', -1);
225
                foreach ($params as $param) {
227
                foreach ($params as $param) {
226
                    PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
228
                    PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
227
                    $ret = $dl->download(array($param));
229
                    $ret = $dl->download(array($param));
228
                    PEAR::popErrorHandling();
230
                    PEAR::popErrorHandling();
229
                    if (is_array($ret) && count($ret)) {
231
                    if (is_array($ret) && count($ret)) {
230
                        break;
232
                        break;
231
                    }
233
                    }
232
                }
234
                }
233
                $dl->config->set('verbose', $verbose);
235
                $dl->config->set('verbose', $verbose);
234
                if (is_array($ret)) {
236
                if (is_array($ret)) {
235
                    if (count($ret) == 1) {
237
                    if (count($ret) == 1) {
236
                        $pf = $ret[0]->getPackageFile();
238
                        $pf = $ret[0]->getPackageFile();
237
                        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
239
                        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
238
                        $err = $installer->install($ret[0]);
240
                        $err = $installer->install($ret[0]);
239
                        PEAR::popErrorHandling();
241
                        PEAR::popErrorHandling();
240
                        if (is_array($err)) {
242
                        if (is_array($err)) {
241
                            $this->_packageInfo['#binarypackage'] = $ret[0]->getPackage();
243
                            $this->_packageInfo['#binarypackage'] = $ret[0]->getPackage();
242
                            // "install" self, so all dependencies will work transparently
244
                            // "install" self, so all dependencies will work transparently
243
                            $this->_registry->addPackage2($this);
245
                            $this->_registry->addPackage2($this);
244
                            $installer->log(0, 'Download and install of binary extension "' .
246
                            $installer->log(0, 'Download and install of binary extension "' .
245
                                $this->_registry->parsedPackageNameToString(
247
                                $this->_registry->parsedPackageNameToString(
246
                                    array('channel' => $pf->getChannel(),
248
                                    array('channel' => $pf->getChannel(),
247
                                          'package' => $pf->getPackage()), true) . '" successful');
249
                                          'package' => $pf->getPackage()), true) . '" successful');
248
                            $a = array($ret[0], $err);
250
                            $a = array($ret[0], $err);
249
                            return $a;
251
                            return $a;
250
                        }
252
                        }
251
                        $installer->log(0, 'Download and install of binary extension "' .
253
                        $installer->log(0, 'Download and install of binary extension "' .
252
                            $this->_registry->parsedPackageNameToString(
254
                            $this->_registry->parsedPackageNameToString(
253
                                    array('channel' => $pf->getChannel(),
255
                                    array('channel' => $pf->getChannel(),
254
                                          'package' => $pf->getPackage()), true) . '" failed');
256
                                          'package' => $pf->getPackage()), true) . '" failed');
255
                    }
257
                    }
256
                }
258
                }
257
            }
259
            }
258
        }
260
        }
259
        $a = false;
261
        $a = false;
260
        return $a;
262
        return $a;
261
    }
263
    }
262
 
264
 
263
    /**
265
    /**
264
     * @return string|false Extension name
266
     * @return string|false Extension name
265
     */
267
     */
266
    function getProvidesExtension()
268
    function getProvidesExtension()
267
    {
269
    {
268
        if (in_array($this->getPackageType(),
270
        if (in_array($this->getPackageType(),
269
              array('extsrc', 'extbin', 'zendextsrc', 'zendextbin'))) {
271
              array('extsrc', 'extbin', 'zendextsrc', 'zendextbin'))) {
270
            if (isset($this->_packageInfo['providesextension'])) {
272
            if (isset($this->_packageInfo['providesextension'])) {
271
                return $this->_packageInfo['providesextension'];
273
                return $this->_packageInfo['providesextension'];
272
            }
274
            }
273
        }
275
        }
274
        return false;
276
        return false;
275
    }
277
    }
276
 
278
 
277
    /**
279
    /**
278
     * @param string Extension name
280
     * @param string Extension name
279
     * @return bool
281
     * @return bool
280
     */
282
     */
281
    function isExtension($extension)
283
    function isExtension($extension)
282
    {
284
    {
283
        if (in_array($this->getPackageType(),
285
        if (in_array($this->getPackageType(),
284
              array('extsrc', 'extbin', 'zendextsrc', 'zendextbin'))) {
286
              array('extsrc', 'extbin', 'zendextsrc', 'zendextbin'))) {
285
            return $this->_packageInfo['providesextension'] == $extension;
287
            return $this->_packageInfo['providesextension'] == $extension;
286
        }
288
        }
287
        return false;
289
        return false;
288
    }
290
    }
289
 
291
 
290
    /**
292
    /**
291
     * Tests whether every part of the package.xml 1.0 is represented in
293
     * Tests whether every part of the package.xml 1.0 is represented in
292
     * this package.xml 2.0
294
     * this package.xml 2.0
293
     * @param PEAR_PackageFile_v1
295
     * @param PEAR_PackageFile_v1
294
     * @return bool
296
     * @return bool
295
     */
297
     */
296
    function isEquivalent($pf1)
298
    function isEquivalent($pf1)
297
    {
299
    {
298
        if (!$pf1) {
300
        if (!$pf1) {
299
            return true;
301
            return true;
300
        }
302
        }
301
        if ($this->getPackageType() == 'bundle') {
303
        if ($this->getPackageType() == 'bundle') {
302
            return false;
304
            return false;
303
        }
305
        }
304
        $this->_stack->getErrors(true);
306
        $this->_stack->getErrors(true);
305
        if (!$pf1->validate(PEAR_VALIDATE_NORMAL)) {
307
        if (!$pf1->validate(PEAR_VALIDATE_NORMAL)) {
306
            return false;
308
            return false;
307
        }
309
        }
308
        $pass = true;
310
        $pass = true;
309
        if ($pf1->getPackage() != $this->getPackage()) {
311
        if ($pf1->getPackage() != $this->getPackage()) {
310
            $this->_differentPackage($pf1->getPackage());
312
            $this->_differentPackage($pf1->getPackage());
311
            $pass = false;
313
            $pass = false;
312
        }
314
        }
313
        if ($pf1->getVersion() != $this->getVersion()) {
315
        if ($pf1->getVersion() != $this->getVersion()) {
314
            $this->_differentVersion($pf1->getVersion());
316
            $this->_differentVersion($pf1->getVersion());
315
            $pass = false;
317
            $pass = false;
316
        }
318
        }
317
        if (trim($pf1->getSummary()) != $this->getSummary()) {
319
        if (trim($pf1->getSummary()) != $this->getSummary()) {
318
            $this->_differentSummary($pf1->getSummary());
320
            $this->_differentSummary($pf1->getSummary());
319
            $pass = false;
321
            $pass = false;
320
        }
322
        }
321
        if (preg_replace('/\s+/', '', $pf1->getDescription()) !=
323
        if (preg_replace('/\s+/', '', $pf1->getDescription()) !=
322
              preg_replace('/\s+/', '', $this->getDescription())) {
324
              preg_replace('/\s+/', '', $this->getDescription())) {
323
            $this->_differentDescription($pf1->getDescription());
325
            $this->_differentDescription($pf1->getDescription());
324
            $pass = false;
326
            $pass = false;
325
        }
327
        }
326
        if ($pf1->getState() != $this->getState()) {
328
        if ($pf1->getState() != $this->getState()) {
327
            $this->_differentState($pf1->getState());
329
            $this->_differentState($pf1->getState());
328
            $pass = false;
330
            $pass = false;
329
        }
331
        }
330
        if (!strstr(preg_replace('/\s+/', '', $this->getNotes()),
332
        if (!strstr(preg_replace('/\s+/', '', $this->getNotes()),
331
              preg_replace('/\s+/', '', $pf1->getNotes()))) {
333
              preg_replace('/\s+/', '', $pf1->getNotes()))) {
332
            $this->_differentNotes($pf1->getNotes());
334
            $this->_differentNotes($pf1->getNotes());
333
            $pass = false;
335
            $pass = false;
334
        }
336
        }
335
        $mymaintainers = $this->getMaintainers();
337
        $mymaintainers = $this->getMaintainers();
336
        $yourmaintainers = $pf1->getMaintainers();
338
        $yourmaintainers = $pf1->getMaintainers();
337
        for ($i1 = 0; $i1 < count($yourmaintainers); $i1++) {
339
        for ($i1 = 0; $i1 < count($yourmaintainers); $i1++) {
338
            $reset = false;
340
            $reset = false;
339
            for ($i2 = 0; $i2 < count($mymaintainers); $i2++) {
341
            for ($i2 = 0; $i2 < count($mymaintainers); $i2++) {
340
                if ($mymaintainers[$i2]['handle'] == $yourmaintainers[$i1]['handle']) {
342
                if ($mymaintainers[$i2]['handle'] == $yourmaintainers[$i1]['handle']) {
341
                    if ($mymaintainers[$i2]['role'] != $yourmaintainers[$i1]['role']) {
343
                    if ($mymaintainers[$i2]['role'] != $yourmaintainers[$i1]['role']) {
342
                        $this->_differentRole($mymaintainers[$i2]['handle'],
344
                        $this->_differentRole($mymaintainers[$i2]['handle'],
343
                            $yourmaintainers[$i1]['role'], $mymaintainers[$i2]['role']);
345
                            $yourmaintainers[$i1]['role'], $mymaintainers[$i2]['role']);
344
                        $pass = false;
346
                        $pass = false;
345
                    }
347
                    }
346
                    if ($mymaintainers[$i2]['email'] != $yourmaintainers[$i1]['email']) {
348
                    if ($mymaintainers[$i2]['email'] != $yourmaintainers[$i1]['email']) {
347
                        $this->_differentEmail($mymaintainers[$i2]['handle'],
349
                        $this->_differentEmail($mymaintainers[$i2]['handle'],
348
                            $yourmaintainers[$i1]['email'], $mymaintainers[$i2]['email']);
350
                            $yourmaintainers[$i1]['email'], $mymaintainers[$i2]['email']);
349
                        $pass = false;
351
                        $pass = false;
350
                    }
352
                    }
351
                    if ($mymaintainers[$i2]['name'] != $yourmaintainers[$i1]['name']) {
353
                    if ($mymaintainers[$i2]['name'] != $yourmaintainers[$i1]['name']) {
352
                        $this->_differentName($mymaintainers[$i2]['handle'],
354
                        $this->_differentName($mymaintainers[$i2]['handle'],
353
                            $yourmaintainers[$i1]['name'], $mymaintainers[$i2]['name']);
355
                            $yourmaintainers[$i1]['name'], $mymaintainers[$i2]['name']);
354
                        $pass = false;
356
                        $pass = false;
355
                    }
357
                    }
356
                    unset($mymaintainers[$i2]);
358
                    unset($mymaintainers[$i2]);
357
                    $mymaintainers = array_values($mymaintainers);
359
                    $mymaintainers = array_values($mymaintainers);
358
                    unset($yourmaintainers[$i1]);
360
                    unset($yourmaintainers[$i1]);
359
                    $yourmaintainers = array_values($yourmaintainers);
361
                    $yourmaintainers = array_values($yourmaintainers);
360
                    $reset = true;
362
                    $reset = true;
361
                    break;
363
                    break;
362
                }
364
                }
363
            }
365
            }
364
            if ($reset) {
366
            if ($reset) {
365
                $i1 = -1;
367
                $i1 = -1;
366
            }
368
            }
367
        }
369
        }
368
        $this->_unmatchedMaintainers($mymaintainers, $yourmaintainers);
370
        $this->_unmatchedMaintainers($mymaintainers, $yourmaintainers);
369
        $filelist = $this->getFilelist();
371
        $filelist = $this->getFilelist();
370
        foreach ($pf1->getFilelist() as $file => $atts) {
372
        foreach ($pf1->getFilelist() as $file => $atts) {
371
            if (!isset($filelist[$file])) {
373
            if (!isset($filelist[$file])) {
372
                $this->_missingFile($file);
374
                $this->_missingFile($file);
373
                $pass = false;
375
                $pass = false;
374
            }
376
            }
375
        }
377
        }
376
        return $pass;
378
        return $pass;
377
    }
379
    }
378
 
380
 
379
    function _differentPackage($package)
381
    function _differentPackage($package)
380
    {
382
    {
381
        $this->_stack->push(__FUNCTION__, 'error', array('package' => $package,
383
        $this->_stack->push(__FUNCTION__, 'error', array('package' => $package,
382
            'self' => $this->getPackage()),
384
            'self' => $this->getPackage()),
383
            'package.xml 1.0 package "%package%" does not match "%self%"');
385
            'package.xml 1.0 package "%package%" does not match "%self%"');
384
    }
386
    }
385
 
387
 
386
    function _differentVersion($version)
388
    function _differentVersion($version)
387
    {
389
    {
388
        $this->_stack->push(__FUNCTION__, 'error', array('version' => $version,
390
        $this->_stack->push(__FUNCTION__, 'error', array('version' => $version,
389
            'self' => $this->getVersion()),
391
            'self' => $this->getVersion()),
390
            'package.xml 1.0 version "%version%" does not match "%self%"');
392
            'package.xml 1.0 version "%version%" does not match "%self%"');
391
    }
393
    }
392
 
394
 
393
    function _differentState($state)
395
    function _differentState($state)
394
    {
396
    {
395
        $this->_stack->push(__FUNCTION__, 'error', array('state' => $state,
397
        $this->_stack->push(__FUNCTION__, 'error', array('state' => $state,
396
            'self' => $this->getState()),
398
            'self' => $this->getState()),
397
            'package.xml 1.0 state "%state%" does not match "%self%"');
399
            'package.xml 1.0 state "%state%" does not match "%self%"');
398
    }
400
    }
399
 
401
 
400
    function _differentRole($handle, $role, $selfrole)
402
    function _differentRole($handle, $role, $selfrole)
401
    {
403
    {
402
        $this->_stack->push(__FUNCTION__, 'error', array('handle' => $handle,
404
        $this->_stack->push(__FUNCTION__, 'error', array('handle' => $handle,
403
            'role' => $role, 'self' => $selfrole),
405
            'role' => $role, 'self' => $selfrole),
404
            'package.xml 1.0 maintainer "%handle%" role "%role%" does not match "%self%"');
406
            'package.xml 1.0 maintainer "%handle%" role "%role%" does not match "%self%"');
405
    }
407
    }
406
 
408
 
407
    function _differentEmail($handle, $email, $selfemail)
409
    function _differentEmail($handle, $email, $selfemail)
408
    {
410
    {
409
        $this->_stack->push(__FUNCTION__, 'error', array('handle' => $handle,
411
        $this->_stack->push(__FUNCTION__, 'error', array('handle' => $handle,
410
            'email' => $email, 'self' => $selfemail),
412
            'email' => $email, 'self' => $selfemail),
411
            'package.xml 1.0 maintainer "%handle%" email "%email%" does not match "%self%"');
413
            'package.xml 1.0 maintainer "%handle%" email "%email%" does not match "%self%"');
412
    }
414
    }
413
 
415
 
414
    function _differentName($handle, $name, $selfname)
416
    function _differentName($handle, $name, $selfname)
415
    {
417
    {
416
        $this->_stack->push(__FUNCTION__, 'error', array('handle' => $handle,
418
        $this->_stack->push(__FUNCTION__, 'error', array('handle' => $handle,
417
            'name' => $name, 'self' => $selfname),
419
            'name' => $name, 'self' => $selfname),
418
            'package.xml 1.0 maintainer "%handle%" name "%name%" does not match "%self%"');
420
            'package.xml 1.0 maintainer "%handle%" name "%name%" does not match "%self%"');
419
    }
421
    }
420
 
422
 
421
    function _unmatchedMaintainers($my, $yours)
423
    function _unmatchedMaintainers($my, $yours)
422
    {
424
    {
423
        if ($my) {
425
        if ($my) {
424
            array_walk($my, create_function('&$i, $k', '$i = $i["handle"];'));
426
            array_walk($my, create_function('&$i, $k', '$i = $i["handle"];'));
425
            $this->_stack->push(__FUNCTION__, 'error', array('handles' => $my),
427
            $this->_stack->push(__FUNCTION__, 'error', array('handles' => $my),
426
                'package.xml 2.0 has unmatched extra maintainers "%handles%"');
428
                'package.xml 2.0 has unmatched extra maintainers "%handles%"');
427
        }
429
        }
428
        if ($yours) {
430
        if ($yours) {
429
            array_walk($yours, create_function('&$i, $k', '$i = $i["handle"];'));
431
            array_walk($yours, create_function('&$i, $k', '$i = $i["handle"];'));
430
            $this->_stack->push(__FUNCTION__, 'error', array('handles' => $yours),
432
            $this->_stack->push(__FUNCTION__, 'error', array('handles' => $yours),
431
                'package.xml 1.0 has unmatched extra maintainers "%handles%"');
433
                'package.xml 1.0 has unmatched extra maintainers "%handles%"');
432
        }
434
        }
433
    }
435
    }
434
 
436
 
435
    function _differentNotes($notes)
437
    function _differentNotes($notes)
436
    {
438
    {
437
        $truncnotes = strlen($notes) < 25 ? $notes : substr($notes, 0, 24) . '...';
439
        $truncnotes = strlen($notes) < 25 ? $notes : substr($notes, 0, 24) . '...';
438
        $truncmynotes = strlen($this->getNotes()) < 25 ? $this->getNotes() :
440
        $truncmynotes = strlen($this->getNotes()) < 25 ? $this->getNotes() :
439
            substr($this->getNotes(), 0, 24) . '...';
441
            substr($this->getNotes(), 0, 24) . '...';
440
        $this->_stack->push(__FUNCTION__, 'error', array('notes' => $truncnotes,
442
        $this->_stack->push(__FUNCTION__, 'error', array('notes' => $truncnotes,
441
            'self' => $truncmynotes),
443
            'self' => $truncmynotes),
442
            'package.xml 1.0 release notes "%notes%" do not match "%self%"');
444
            'package.xml 1.0 release notes "%notes%" do not match "%self%"');
443
    }
445
    }
444
 
446
 
445
    function _differentSummary($summary)
447
    function _differentSummary($summary)
446
    {
448
    {
447
        $truncsummary = strlen($summary) < 25 ? $summary : substr($summary, 0, 24) . '...';
449
        $truncsummary = strlen($summary) < 25 ? $summary : substr($summary, 0, 24) . '...';
448
        $truncmysummary = strlen($this->getsummary()) < 25 ? $this->getSummary() :
450
        $truncmysummary = strlen($this->getsummary()) < 25 ? $this->getSummary() :
449
            substr($this->getsummary(), 0, 24) . '...';
451
            substr($this->getsummary(), 0, 24) . '...';
450
        $this->_stack->push(__FUNCTION__, 'error', array('summary' => $truncsummary,
452
        $this->_stack->push(__FUNCTION__, 'error', array('summary' => $truncsummary,
451
            'self' => $truncmysummary),
453
            'self' => $truncmysummary),
452
            'package.xml 1.0 summary "%summary%" does not match "%self%"');
454
            'package.xml 1.0 summary "%summary%" does not match "%self%"');
453
    }
455
    }
454
 
456
 
455
    function _differentDescription($description)
457
    function _differentDescription($description)
456
    {
458
    {
457
        $truncdescription = trim(strlen($description) < 25 ? $description : substr($description, 0, 24) . '...');
459
        $truncdescription = trim(strlen($description) < 25 ? $description : substr($description, 0, 24) . '...');
458
        $truncmydescription = trim(strlen($this->getDescription()) < 25 ? $this->getDescription() :
460
        $truncmydescription = trim(strlen($this->getDescription()) < 25 ? $this->getDescription() :
459
            substr($this->getdescription(), 0, 24) . '...');
461
            substr($this->getdescription(), 0, 24) . '...');
460
        $this->_stack->push(__FUNCTION__, 'error', array('description' => $truncdescription,
462
        $this->_stack->push(__FUNCTION__, 'error', array('description' => $truncdescription,
461
            'self' => $truncmydescription),
463
            'self' => $truncmydescription),
462
            'package.xml 1.0 description "%description%" does not match "%self%"');
464
            'package.xml 1.0 description "%description%" does not match "%self%"');
463
    }
465
    }
464
 
466
 
465
    function _missingFile($file)
467
    function _missingFile($file)
466
    {
468
    {
467
        $this->_stack->push(__FUNCTION__, 'error', array('file' => $file),
469
        $this->_stack->push(__FUNCTION__, 'error', array('file' => $file),
468
            'package.xml 1.0 file "%file%" is not present in <contents>');
470
            'package.xml 1.0 file "%file%" is not present in <contents>');
469
    }
471
    }
470
 
472
 
471
    /**
473
    /**
472
     * WARNING - do not use this function unless you know what you're doing
474
     * WARNING - do not use this function unless you know what you're doing
473
     */
475
     */
474
    function setRawState($state)
476
    function setRawState($state)
475
    {
477
    {
-
 
478
        if (!isset($this->_packageInfo['stability'])) {
-
 
479
            $this->_packageInfo['stability'] = array();
-
 
480
        }
476
        $this->_packageInfo['stability']['release'] = $state;
481
        $this->_packageInfo['stability']['release'] = $state;
477
    }
482
    }
478
 
483
 
479
    /**
484
    /**
480
     * WARNING - do not use this function unless you know what you're doing
485
     * WARNING - do not use this function unless you know what you're doing
481
     */
486
     */
482
    function setRawCompatible($compatible)
487
    function setRawCompatible($compatible)
483
    {
488
    {
484
        $this->_packageInfo['compatible'] = $compatible;
489
        $this->_packageInfo['compatible'] = $compatible;
485
    }
490
    }
486
 
491
 
487
    /**
492
    /**
488
     * WARNING - do not use this function unless you know what you're doing
493
     * WARNING - do not use this function unless you know what you're doing
489
     */
494
     */
490
    function setRawPackage($package)
495
    function setRawPackage($package)
491
    {
496
    {
492
        $this->_packageInfo['name'] = $package;
497
        $this->_packageInfo['name'] = $package;
493
    }
498
    }
494
 
499
 
495
    /**
500
    /**
496
     * WARNING - do not use this function unless you know what you're doing
501
     * WARNING - do not use this function unless you know what you're doing
497
     */
502
     */
498
    function setRawChannel($channel)
503
    function setRawChannel($channel)
499
    {
504
    {
500
        $this->_packageInfo['channel'] = $channel;
505
        $this->_packageInfo['channel'] = $channel;
501
    }
506
    }
502
 
507
 
503
    function setRequestedGroup($group)
508
    function setRequestedGroup($group)
504
    {
509
    {
505
        $this->_requestedGroup = $group;
510
        $this->_requestedGroup = $group;
506
    }
511
    }
507
 
512
 
508
    function getRequestedGroup()
513
    function getRequestedGroup()
509
    {
514
    {
510
        if (isset($this->_requestedGroup)) {
515
        if (isset($this->_requestedGroup)) {
511
            return $this->_requestedGroup;
516
            return $this->_requestedGroup;
512
        }
517
        }
513
        return false;
518
        return false;
514
    }
519
    }
515
 
520
 
516
    /**
521
    /**
517
     * For saving in the registry.
522
     * For saving in the registry.
518
     *
523
     *
519
     * Set the last version that was installed
524
     * Set the last version that was installed
520
     * @param string
525
     * @param string
521
     */
526
     */
522
    function setLastInstalledVersion($version)
527
    function setLastInstalledVersion($version)
523
    {
528
    {
524
        $this->_packageInfo['_lastversion'] = $version;
529
        $this->_packageInfo['_lastversion'] = $version;
525
    }
530
    }
526
 
531
 
527
    /**
532
    /**
528
     * @return string|false
533
     * @return string|false
529
     */
534
     */
530
    function getLastInstalledVersion()
535
    function getLastInstalledVersion()
531
    {
536
    {
532
        if (isset($this->_packageInfo['_lastversion'])) {
537
        if (isset($this->_packageInfo['_lastversion'])) {
533
            return $this->_packageInfo['_lastversion'];
538
            return $this->_packageInfo['_lastversion'];
534
        }
539
        }
535
        return false;
540
        return false;
536
    }
541
    }
537
 
542
 
538
    /**
543
    /**
539
     * Determines whether this package.xml has post-install scripts or not
544
     * Determines whether this package.xml has post-install scripts or not
540
     * @return array|false
545
     * @return array|false
541
     */
546
     */
542
    function listPostinstallScripts()
547
    function listPostinstallScripts()
543
    {
548
    {
544
        $filelist = $this->getFilelist();
549
        $filelist = $this->getFilelist();
545
        $contents = $this->getContents();
550
        $contents = $this->getContents();
546
        $contents = $contents['dir']['file'];
551
        $contents = $contents['dir']['file'];
547
        if (!is_array($contents) || !isset($contents[0])) {
552
        if (!is_array($contents) || !isset($contents[0])) {
548
            $contents = array($contents);
553
            $contents = array($contents);
549
        }
554
        }
550
        $taskfiles = array();
555
        $taskfiles = array();
551
        foreach ($contents as $file) {
556
        foreach ($contents as $file) {
552
            $atts = $file['attribs'];
557
            $atts = $file['attribs'];
553
            unset($file['attribs']);
558
            unset($file['attribs']);
554
            if (count($file)) {
559
            if (count($file)) {
555
                $taskfiles[$atts['name']] = $file;
560
                $taskfiles[$atts['name']] = $file;
556
            }
561
            }
557
        }
562
        }
558
        $common = new PEAR_Common;
563
        $common = new PEAR_Common;
559
        $common->debug = $this->_config->get('verbose');
564
        $common->debug = $this->_config->get('verbose');
560
        $this->_scripts = array();
565
        $this->_scripts = array();
561
        $ret = array();
566
        $ret = array();
562
        foreach ($taskfiles as $name => $tasks) {
567
        foreach ($taskfiles as $name => $tasks) {
563
            if (!isset($filelist[$name])) {
568
            if (!isset($filelist[$name])) {
564
                // ignored files will not be in the filelist
569
                // ignored files will not be in the filelist
565
                continue;
570
                continue;
566
            }
571
            }
567
            $atts = $filelist[$name];
572
            $atts = $filelist[$name];
568
            foreach ($tasks as $tag => $raw) {
573
            foreach ($tasks as $tag => $raw) {
569
                $task = $this->getTask($tag);
574
                $task = $this->getTask($tag);
570
                $task = &new $task($this->_config, $common, PEAR_TASK_INSTALL);
575
                $task = new $task($this->_config, $common, PEAR_TASK_INSTALL);
571
                if ($task->isScript()) {
576
                if ($task->isScript()) {
572
                    $ret[] = $filelist[$name]['installed_as'];
577
                    $ret[] = $filelist[$name]['installed_as'];
573
                }
578
                }
574
            }
579
            }
575
        }
580
        }
576
        if (count($ret)) {
581
        if (count($ret)) {
577
            return $ret;
582
            return $ret;
578
        }
583
        }
579
        return false;
584
        return false;
580
    }
585
    }
581
 
586
 
582
    /**
587
    /**
583
     * Initialize post-install scripts for running
588
     * Initialize post-install scripts for running
584
     *
589
     *
585
     * This method can be used to detect post-install scripts, as the return value
590
     * This method can be used to detect post-install scripts, as the return value
586
     * indicates whether any exist
591
     * indicates whether any exist
587
     * @return bool
592
     * @return bool
588
     */
593
     */
589
    function initPostinstallScripts()
594
    function initPostinstallScripts()
590
    {
595
    {
591
        $filelist = $this->getFilelist();
596
        $filelist = $this->getFilelist();
592
        $contents = $this->getContents();
597
        $contents = $this->getContents();
593
        $contents = $contents['dir']['file'];
598
        $contents = $contents['dir']['file'];
594
        if (!is_array($contents) || !isset($contents[0])) {
599
        if (!is_array($contents) || !isset($contents[0])) {
595
            $contents = array($contents);
600
            $contents = array($contents);
596
        }
601
        }
597
        $taskfiles = array();
602
        $taskfiles = array();
598
        foreach ($contents as $file) {
603
        foreach ($contents as $file) {
599
            $atts = $file['attribs'];
604
            $atts = $file['attribs'];
600
            unset($file['attribs']);
605
            unset($file['attribs']);
601
            if (count($file)) {
606
            if (count($file)) {
602
                $taskfiles[$atts['name']] = $file;
607
                $taskfiles[$atts['name']] = $file;
603
            }
608
            }
604
        }
609
        }
605
        $common = new PEAR_Common;
610
        $common = new PEAR_Common;
606
        $common->debug = $this->_config->get('verbose');
611
        $common->debug = $this->_config->get('verbose');
607
        $this->_scripts = array();
612
        $this->_scripts = array();
608
        foreach ($taskfiles as $name => $tasks) {
613
        foreach ($taskfiles as $name => $tasks) {
609
            if (!isset($filelist[$name])) {
614
            if (!isset($filelist[$name])) {
610
                // file was not installed due to installconditions
615
                // file was not installed due to installconditions
611
                continue;
616
                continue;
612
            }
617
            }
613
            $atts = $filelist[$name];
618
            $atts = $filelist[$name];
614
            foreach ($tasks as $tag => $raw) {
619
            foreach ($tasks as $tag => $raw) {
615
                $taskname = $this->getTask($tag);
620
                $taskname = $this->getTask($tag);
616
                $task = &new $taskname($this->_config, $common, PEAR_TASK_INSTALL);
621
                $task = new $taskname($this->_config, $common, PEAR_TASK_INSTALL);
617
                if (!$task->isScript()) {
622
                if (!$task->isScript()) {
618
                    continue; // scripts are only handled after installation
623
                    continue; // scripts are only handled after installation
619
                }
624
                }
620
                $lastversion = isset($this->_packageInfo['_lastversion']) ?
625
                $lastversion = isset($this->_packageInfo['_lastversion']) ?
621
                    $this->_packageInfo['_lastversion'] : null;
626
                    $this->_packageInfo['_lastversion'] : null;
622
                $task->init($raw, $atts, $lastversion);
627
                $task->init($raw, $atts, $lastversion);
623
                $res = $task->startSession($this, $atts['installed_as']);
628
                $res = $task->startSession($this, $atts['installed_as']);
624
                if (!$res) {
629
                if (!$res) {
625
                    continue; // skip this file
630
                    continue; // skip this file
626
                }
631
                }
627
                if (PEAR::isError($res)) {
632
                if (PEAR::isError($res)) {
628
                    return $res;
633
                    return $res;
629
                }
634
                }
630
                $assign = &$task;
635
                $assign = &$task;
631
                $this->_scripts[] = &$assign;
636
                $this->_scripts[] = &$assign;
632
            }
637
            }
633
        }
638
        }
634
        if (count($this->_scripts)) {
639
        if (count($this->_scripts)) {
635
            return true;
640
            return true;
636
        }
641
        }
637
        return false;
642
        return false;
638
    }
643
    }
639
 
644
 
640
    function runPostinstallScripts()
645
    function runPostinstallScripts()
641
    {
646
    {
642
        if ($this->initPostinstallScripts()) {
647
        if ($this->initPostinstallScripts()) {
643
            $ui = &PEAR_Frontend::singleton();
648
            $ui = &PEAR_Frontend::singleton();
644
            if ($ui) {
649
            if ($ui) {
645
                $ui->runPostinstallScripts($this->_scripts, $this);
650
                $ui->runPostinstallScripts($this->_scripts, $this);
646
            }
651
            }
647
        }
652
        }
648
    }
653
    }
649
 
654
 
650
 
655
 
651
    /**
656
    /**
652
     * Convert a recursive set of <dir> and <file> tags into a single <dir> tag with
657
     * Convert a recursive set of <dir> and <file> tags into a single <dir> tag with
653
     * <file> tags.
658
     * <file> tags.
654
     */
659
     */
655
    function flattenFilelist()
660
    function flattenFilelist()
656
    {
661
    {
657
        if (isset($this->_packageInfo['bundle'])) {
662
        if (isset($this->_packageInfo['bundle'])) {
658
            return;
663
            return;
659
        }
664
        }
660
        $filelist = array();
665
        $filelist = array();
661
        if (isset($this->_packageInfo['contents']['dir']['dir'])) {
666
        if (isset($this->_packageInfo['contents']['dir']['dir'])) {
662
            $this->_getFlattenedFilelist($filelist, $this->_packageInfo['contents']['dir']);
667
            $this->_getFlattenedFilelist($filelist, $this->_packageInfo['contents']['dir']);
663
            if (!isset($filelist[1])) {
668
            if (!isset($filelist[1])) {
664
                $filelist = $filelist[0];
669
                $filelist = $filelist[0];
665
            }
670
            }
666
            $this->_packageInfo['contents']['dir']['file'] = $filelist;
671
            $this->_packageInfo['contents']['dir']['file'] = $filelist;
667
            unset($this->_packageInfo['contents']['dir']['dir']);
672
            unset($this->_packageInfo['contents']['dir']['dir']);
668
        } else {
673
        } else {
669
            // else already flattened but check for baseinstalldir propagation
674
            // else already flattened but check for baseinstalldir propagation
670
            if (isset($this->_packageInfo['contents']['dir']['attribs']['baseinstalldir'])) {
675
            if (isset($this->_packageInfo['contents']['dir']['attribs']['baseinstalldir'])) {
671
                if (isset($this->_packageInfo['contents']['dir']['file'][0])) {
676
                if (isset($this->_packageInfo['contents']['dir']['file'][0])) {
672
                    foreach ($this->_packageInfo['contents']['dir']['file'] as $i => $file) {
677
                    foreach ($this->_packageInfo['contents']['dir']['file'] as $i => $file) {
673
                        if (isset($file['attribs']['baseinstalldir'])) {
678
                        if (isset($file['attribs']['baseinstalldir'])) {
674
                            continue;
679
                            continue;
675
                        }
680
                        }
676
                        $this->_packageInfo['contents']['dir']['file'][$i]['attribs']['baseinstalldir']
681
                        $this->_packageInfo['contents']['dir']['file'][$i]['attribs']['baseinstalldir']
677
                            = $this->_packageInfo['contents']['dir']['attribs']['baseinstalldir'];
682
                            = $this->_packageInfo['contents']['dir']['attribs']['baseinstalldir'];
678
                    }
683
                    }
679
                } else {
684
                } else {
680
                    if (!isset($this->_packageInfo['contents']['dir']['file']['attribs']['baseinstalldir'])) {
685
                    if (!isset($this->_packageInfo['contents']['dir']['file']['attribs']['baseinstalldir'])) {
681
                       $this->_packageInfo['contents']['dir']['file']['attribs']['baseinstalldir']
686
                       $this->_packageInfo['contents']['dir']['file']['attribs']['baseinstalldir']
682
                            = $this->_packageInfo['contents']['dir']['attribs']['baseinstalldir'];
687
                            = $this->_packageInfo['contents']['dir']['attribs']['baseinstalldir'];
683
                    }
688
                    }
684
                }
689
                }
685
            }
690
            }
686
        }
691
        }
687
    }
692
    }
688
 
693
 
689
    /**
694
    /**
690
     * @param array the final flattened file list
695
     * @param array the final flattened file list
691
     * @param array the current directory being processed
696
     * @param array the current directory being processed
692
     * @param string|false any recursively inherited baeinstalldir attribute
697
     * @param string|false any recursively inherited baeinstalldir attribute
693
     * @param string private recursion variable
698
     * @param string private recursion variable
694
     * @return array
699
     * @return array
695
     * @access protected
700
     * @access protected
696
     */
701
     */
697
    function _getFlattenedFilelist(&$files, $dir, $baseinstall = false, $path = '')
702
    function _getFlattenedFilelist(&$files, $dir, $baseinstall = false, $path = '')
698
    {
703
    {
699
        if (isset($dir['attribs']) && isset($dir['attribs']['baseinstalldir'])) {
704
        if (isset($dir['attribs']) && isset($dir['attribs']['baseinstalldir'])) {
700
            $baseinstall = $dir['attribs']['baseinstalldir'];
705
            $baseinstall = $dir['attribs']['baseinstalldir'];
701
        }
706
        }
702
        if (isset($dir['dir'])) {
707
        if (isset($dir['dir'])) {
703
            if (!isset($dir['dir'][0])) {
708
            if (!isset($dir['dir'][0])) {
704
                $dir['dir'] = array($dir['dir']);
709
                $dir['dir'] = array($dir['dir']);
705
            }
710
            }
706
            foreach ($dir['dir'] as $subdir) {
711
            foreach ($dir['dir'] as $subdir) {
707
                if (!isset($subdir['attribs']) || !isset($subdir['attribs']['name'])) {
712
                if (!isset($subdir['attribs']) || !isset($subdir['attribs']['name'])) {
708
                    $name = '*unknown*';
713
                    $name = '*unknown*';
709
                } else {
714
                } else {
710
                    $name = $subdir['attribs']['name'];
715
                    $name = $subdir['attribs']['name'];
711
                }
716
                }
712
                $newpath = empty($path) ? $name :
717
                $newpath = empty($path) ? $name :
713
                    $path . '/' . $name;
718
                    $path . '/' . $name;
714
                $this->_getFlattenedFilelist($files, $subdir,
719
                $this->_getFlattenedFilelist($files, $subdir,
715
                    $baseinstall, $newpath);
720
                    $baseinstall, $newpath);
716
            }
721
            }
717
        }
722
        }
718
        if (isset($dir['file'])) {
723
        if (isset($dir['file'])) {
719
            if (!isset($dir['file'][0])) {
724
            if (!isset($dir['file'][0])) {
720
                $dir['file'] = array($dir['file']);
725
                $dir['file'] = array($dir['file']);
721
            }
726
            }
722
            foreach ($dir['file'] as $file) {
727
            foreach ($dir['file'] as $file) {
723
                $attrs = $file['attribs'];
728
                $attrs = $file['attribs'];
724
                $name = $attrs['name'];
729
                $name = $attrs['name'];
725
                if ($baseinstall && !isset($attrs['baseinstalldir'])) {
730
                if ($baseinstall && !isset($attrs['baseinstalldir'])) {
726
                    $attrs['baseinstalldir'] = $baseinstall;
731
                    $attrs['baseinstalldir'] = $baseinstall;
727
                }
732
                }
728
                $attrs['name'] = empty($path) ? $name : $path . '/' . $name;
733
                $attrs['name'] = empty($path) ? $name : $path . '/' . $name;
729
                $attrs['name'] = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'),
734
                $attrs['name'] = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'),
730
                    $attrs['name']);
735
                    $attrs['name']);
731
                $file['attribs'] = $attrs;
736
                $file['attribs'] = $attrs;
732
                $files[] = $file;
737
                $files[] = $file;
733
            }
738
            }
734
        }
739
        }
735
    }
740
    }
736
 
741
 
737
    function setConfig(&$config)
742
    function setConfig(&$config)
738
    {
743
    {
739
        $this->_config = &$config;
744
        $this->_config = &$config;
740
        $this->_registry = &$config->getRegistry();
745
        $this->_registry = &$config->getRegistry();
741
    }
746
    }
742
 
747
 
743
    function setLogger(&$logger)
748
    function setLogger(&$logger)
744
    {
749
    {
745
        if (!is_object($logger) || !method_exists($logger, 'log')) {
750
        if (!is_object($logger) || !method_exists($logger, 'log')) {
746
            return PEAR::raiseError('Logger must be compatible with PEAR_Common::log');
751
            return PEAR::raiseError('Logger must be compatible with PEAR_Common::log');
747
        }
752
        }
748
        $this->_logger = &$logger;
753
        $this->_logger = &$logger;
749
    }
754
    }
750
 
755
 
751
    /**
756
    /**
752
     * WARNING - do not use this function directly unless you know what you're doing
757
     * WARNING - do not use this function directly unless you know what you're doing
753
     */
758
     */
754
    function setDeps($deps)
759
    function setDeps($deps)
755
    {
760
    {
756
        $this->_packageInfo['dependencies'] = $deps;
761
        $this->_packageInfo['dependencies'] = $deps;
757
    }
762
    }
758
 
763
 
759
    /**
764
    /**
760
     * WARNING - do not use this function directly unless you know what you're doing
765
     * WARNING - do not use this function directly unless you know what you're doing
761
     */
766
     */
762
    function setCompatible($compat)
767
    function setCompatible($compat)
763
    {
768
    {
764
        $this->_packageInfo['compatible'] = $compat;
769
        $this->_packageInfo['compatible'] = $compat;
765
    }
770
    }
766
 
771
 
767
    function setPackagefile($file, $archive = false)
772
    function setPackagefile($file, $archive = false)
768
    {
773
    {
769
        $this->_packageFile = $file;
774
        $this->_packageFile = $file;
770
        $this->_archiveFile = $archive ? $archive : $file;
775
        $this->_archiveFile = $archive ? $archive : $file;
771
    }
776
    }
772
 
777
 
773
    /**
778
    /**
774
     * Wrapper to {@link PEAR_ErrorStack::getErrors()}
779
     * Wrapper to {@link PEAR_ErrorStack::getErrors()}
775
     * @param boolean determines whether to purge the error stack after retrieving
780
     * @param boolean determines whether to purge the error stack after retrieving
776
     * @return array
781
     * @return array
777
     */
782
     */
778
    function getValidationWarnings($purge = true)
783
    function getValidationWarnings($purge = true)
779
    {
784
    {
780
        return $this->_stack->getErrors($purge);
785
        return $this->_stack->getErrors($purge);
781
    }
786
    }
782
 
787
 
783
    function getPackageFile()
788
    function getPackageFile()
784
    {
789
    {
785
        return $this->_packageFile;
790
        return $this->_packageFile;
786
    }
791
    }
787
 
792
 
788
    function getArchiveFile()
793
    function getArchiveFile()
789
    {
794
    {
790
        return $this->_archiveFile;
795
        return $this->_archiveFile;
791
    }
796
    }
792
 
797
 
793
 
798
 
794
    /**
799
    /**
795
     * Directly set the array that defines this packagefile
800
     * Directly set the array that defines this packagefile
796
     *
801
     *
797
     * WARNING: no validation.  This should only be performed by internal methods
802
     * WARNING: no validation.  This should only be performed by internal methods
798
     * inside PEAR or by inputting an array saved from an existing PEAR_PackageFile_v2
803
     * inside PEAR or by inputting an array saved from an existing PEAR_PackageFile_v2
799
     * @param array
804
     * @param array
800
     */
805
     */
801
    function fromArray($pinfo)
806
    function fromArray($pinfo)
802
    {
807
    {
803
        unset($pinfo['old']);
808
        unset($pinfo['old']);
804
        unset($pinfo['xsdversion']);
809
        unset($pinfo['xsdversion']);
-
 
810
        // If the changelog isn't an array then it was passed in as an empty tag
-
 
811
        if (isset($pinfo['changelog']) && !is_array($pinfo['changelog'])) {
-
 
812
          unset($pinfo['changelog']);
-
 
813
        }
805
        $this->_incomplete = false;
814
        $this->_incomplete = false;
806
        $this->_packageInfo = $pinfo;
815
        $this->_packageInfo = $pinfo;
807
    }
816
    }
808
 
817
 
809
    function isIncomplete()
818
    function isIncomplete()
810
    {
819
    {
811
        return $this->_incomplete;
820
        return $this->_incomplete;
812
    }
821
    }
813
 
822
 
814
    /**
823
    /**
815
     * @return array
824
     * @return array
816
     */
825
     */
817
    function toArray($forreg = false)
826
    function toArray($forreg = false)
818
    {
827
    {
819
        if (!$this->validate(PEAR_VALIDATE_NORMAL)) {
828
        if (!$this->validate(PEAR_VALIDATE_NORMAL)) {
820
            return false;
829
            return false;
821
        }
830
        }
822
        return $this->getArray($forreg);
831
        return $this->getArray($forreg);
823
    }
832
    }
824
 
833
 
825
    function getArray($forReg = false)
834
    function getArray($forReg = false)
826
    {
835
    {
827
        if ($forReg) {
836
        if ($forReg) {
828
            $arr = $this->_packageInfo;
837
            $arr = $this->_packageInfo;
829
            $arr['old'] = array();
838
            $arr['old'] = array();
830
            $arr['old']['version'] = $this->getVersion();
839
            $arr['old']['version'] = $this->getVersion();
831
            $arr['old']['release_date'] = $this->getDate();
840
            $arr['old']['release_date'] = $this->getDate();
832
            $arr['old']['release_state'] = $this->getState();
841
            $arr['old']['release_state'] = $this->getState();
833
            $arr['old']['release_license'] = $this->getLicense();
842
            $arr['old']['release_license'] = $this->getLicense();
834
            $arr['old']['release_notes'] = $this->getNotes();
843
            $arr['old']['release_notes'] = $this->getNotes();
835
            $arr['old']['release_deps'] = $this->getDeps();
844
            $arr['old']['release_deps'] = $this->getDeps();
836
            $arr['old']['maintainers'] = $this->getMaintainers();
845
            $arr['old']['maintainers'] = $this->getMaintainers();
837
            $arr['xsdversion'] = '2.0';
846
            $arr['xsdversion'] = '2.0';
838
            return $arr;
847
            return $arr;
839
        } else {
848
        } else {
840
            $info = $this->_packageInfo;
849
            $info = $this->_packageInfo;
841
            unset($info['dirtree']);
850
            unset($info['dirtree']);
842
            if (isset($info['_lastversion'])) {
851
            if (isset($info['_lastversion'])) {
843
                unset($info['_lastversion']);
852
                unset($info['_lastversion']);
844
            }
853
            }
845
            if (isset($info['#binarypackage'])) {
854
            if (isset($info['#binarypackage'])) {
846
                unset($info['#binarypackage']);
855
                unset($info['#binarypackage']);
847
            }
856
            }
848
            return $info;
857
            return $info;
849
        }
858
        }
850
    }
859
    }
851
 
860
 
852
    function packageInfo($field)
861
    function packageInfo($field)
853
    {
862
    {
854
        $arr = $this->getArray(true);
863
        $arr = $this->getArray(true);
855
        if ($field == 'state') {
864
        if ($field == 'state') {
856
            return $arr['stability']['release'];
865
            return $arr['stability']['release'];
857
        }
866
        }
858
        if ($field == 'api-version') {
867
        if ($field == 'api-version') {
859
            return $arr['version']['api'];
868
            return $arr['version']['api'];
860
        }
869
        }
861
        if ($field == 'api-state') {
870
        if ($field == 'api-state') {
862
            return $arr['stability']['api'];
871
            return $arr['stability']['api'];
863
        }
872
        }
864
        if (isset($arr['old'][$field])) {
873
        if (isset($arr['old'][$field])) {
865
            if (!is_string($arr['old'][$field])) {
874
            if (!is_string($arr['old'][$field])) {
866
                return null;
875
                return null;
867
            }
876
            }
868
            return $arr['old'][$field];
877
            return $arr['old'][$field];
869
        }
878
        }
870
        if (isset($arr[$field])) {
879
        if (isset($arr[$field])) {
871
            if (!is_string($arr[$field])) {
880
            if (!is_string($arr[$field])) {
872
                return null;
881
                return null;
873
            }
882
            }
874
            return $arr[$field];
883
            return $arr[$field];
875
        }
884
        }
876
        return null;
885
        return null;
877
    }
886
    }
878
 
887
 
879
    function getName()
888
    function getName()
880
    {
889
    {
881
        return $this->getPackage();
890
        return $this->getPackage();
882
    }
891
    }
883
 
892
 
884
    function getPackage()
893
    function getPackage()
885
    {
894
    {
886
        if (isset($this->_packageInfo['name'])) {
895
        if (isset($this->_packageInfo['name'])) {
887
            return $this->_packageInfo['name'];
896
            return $this->_packageInfo['name'];
888
        }
897
        }
889
        return false;
898
        return false;
890
    }
899
    }
891
 
900
 
892
    function getChannel()
901
    function getChannel()
893
    {
902
    {
894
        if (isset($this->_packageInfo['uri'])) {
903
        if (isset($this->_packageInfo['uri'])) {
895
            return '__uri';
904
            return '__uri';
896
        }
905
        }
897
        if (isset($this->_packageInfo['channel'])) {
906
        if (isset($this->_packageInfo['channel'])) {
898
            return strtolower($this->_packageInfo['channel']);
907
            return strtolower($this->_packageInfo['channel']);
899
        }
908
        }
900
        return false;
909
        return false;
901
    }
910
    }
902
 
911
 
903
    function getUri()
912
    function getUri()
904
    {
913
    {
905
        if (isset($this->_packageInfo['uri'])) {
914
        if (isset($this->_packageInfo['uri'])) {
906
            return $this->_packageInfo['uri'];
915
            return $this->_packageInfo['uri'];
907
        }
916
        }
908
        return false;
917
        return false;
909
    }
918
    }
910
 
919
 
911
    function getExtends()
920
    function getExtends()
912
    {
921
    {
913
        if (isset($this->_packageInfo['extends'])) {
922
        if (isset($this->_packageInfo['extends'])) {
914
            return $this->_packageInfo['extends'];
923
            return $this->_packageInfo['extends'];
915
        }
924
        }
916
        return false;
925
        return false;
917
    }
926
    }
918
 
927
 
919
    function getSummary()
928
    function getSummary()
920
    {
929
    {
921
        if (isset($this->_packageInfo['summary'])) {
930
        if (isset($this->_packageInfo['summary'])) {
922
            return $this->_packageInfo['summary'];
931
            return $this->_packageInfo['summary'];
923
        }
932
        }
924
        return false;
933
        return false;
925
    }
934
    }
926
 
935
 
927
    function getDescription()
936
    function getDescription()
928
    {
937
    {
929
        if (isset($this->_packageInfo['description'])) {
938
        if (isset($this->_packageInfo['description'])) {
930
            return $this->_packageInfo['description'];
939
            return $this->_packageInfo['description'];
931
        }
940
        }
932
        return false;
941
        return false;
933
    }
942
    }
934
 
943
 
935
    function getMaintainers($raw = false)
944
    function getMaintainers($raw = false)
936
    {
945
    {
937
        if (!isset($this->_packageInfo['lead'])) {
946
        if (!isset($this->_packageInfo['lead'])) {
938
            return false;
947
            return false;
939
        }
948
        }
940
        if ($raw) {
949
        if ($raw) {
941
            $ret = array('lead' => $this->_packageInfo['lead']);
950
            $ret = array('lead' => $this->_packageInfo['lead']);
942
            (isset($this->_packageInfo['developer'])) ?
951
            (isset($this->_packageInfo['developer'])) ?
943
                $ret['developer'] = $this->_packageInfo['developer'] :null;
952
                $ret['developer'] = $this->_packageInfo['developer'] :null;
944
            (isset($this->_packageInfo['contributor'])) ?
953
            (isset($this->_packageInfo['contributor'])) ?
945
                $ret['contributor'] = $this->_packageInfo['contributor'] :null;
954
                $ret['contributor'] = $this->_packageInfo['contributor'] :null;
946
            (isset($this->_packageInfo['helper'])) ?
955
            (isset($this->_packageInfo['helper'])) ?
947
                $ret['helper'] = $this->_packageInfo['helper'] :null;
956
                $ret['helper'] = $this->_packageInfo['helper'] :null;
948
            return $ret;
957
            return $ret;
949
        } else {
958
        } else {
950
            $ret = array();
959
            $ret = array();
951
            $leads = isset($this->_packageInfo['lead'][0]) ? $this->_packageInfo['lead'] :
960
            $leads = isset($this->_packageInfo['lead'][0]) ? $this->_packageInfo['lead'] :
952
                array($this->_packageInfo['lead']);
961
                array($this->_packageInfo['lead']);
953
            foreach ($leads as $lead) {
962
            foreach ($leads as $lead) {
954
                $s = $lead;
963
                $s = $lead;
955
                $s['handle'] = $s['user'];
964
                $s['handle'] = $s['user'];
956
                unset($s['user']);
965
                unset($s['user']);
957
                $s['role'] = 'lead';
966
                $s['role'] = 'lead';
958
                $ret[] = $s;
967
                $ret[] = $s;
959
            }
968
            }
960
            if (isset($this->_packageInfo['developer'])) {
969
            if (isset($this->_packageInfo['developer'])) {
961
                $leads = isset($this->_packageInfo['developer'][0]) ?
970
                $leads = isset($this->_packageInfo['developer'][0]) ?
962
                    $this->_packageInfo['developer'] :
971
                    $this->_packageInfo['developer'] :
963
                    array($this->_packageInfo['developer']);
972
                    array($this->_packageInfo['developer']);
964
                foreach ($leads as $maintainer) {
973
                foreach ($leads as $maintainer) {
965
                    $s = $maintainer;
974
                    $s = $maintainer;
966
                    $s['handle'] = $s['user'];
975
                    $s['handle'] = $s['user'];
967
                    unset($s['user']);
976
                    unset($s['user']);
968
                    $s['role'] = 'developer';
977
                    $s['role'] = 'developer';
969
                    $ret[] = $s;
978
                    $ret[] = $s;
970
                }
979
                }
971
            }
980
            }
972
            if (isset($this->_packageInfo['contributor'])) {
981
            if (isset($this->_packageInfo['contributor'])) {
973
                $leads = isset($this->_packageInfo['contributor'][0]) ?
982
                $leads = isset($this->_packageInfo['contributor'][0]) ?
974
                    $this->_packageInfo['contributor'] :
983
                    $this->_packageInfo['contributor'] :
975
                    array($this->_packageInfo['contributor']);
984
                    array($this->_packageInfo['contributor']);
976
                foreach ($leads as $maintainer) {
985
                foreach ($leads as $maintainer) {
977
                    $s = $maintainer;
986
                    $s = $maintainer;
978
                    $s['handle'] = $s['user'];
987
                    $s['handle'] = $s['user'];
979
                    unset($s['user']);
988
                    unset($s['user']);
980
                    $s['role'] = 'contributor';
989
                    $s['role'] = 'contributor';
981
                    $ret[] = $s;
990
                    $ret[] = $s;
982
                }
991
                }
983
            }
992
            }
984
            if (isset($this->_packageInfo['helper'])) {
993
            if (isset($this->_packageInfo['helper'])) {
985
                $leads = isset($this->_packageInfo['helper'][0]) ?
994
                $leads = isset($this->_packageInfo['helper'][0]) ?
986
                    $this->_packageInfo['helper'] :
995
                    $this->_packageInfo['helper'] :
987
                    array($this->_packageInfo['helper']);
996
                    array($this->_packageInfo['helper']);
988
                foreach ($leads as $maintainer) {
997
                foreach ($leads as $maintainer) {
989
                    $s = $maintainer;
998
                    $s = $maintainer;
990
                    $s['handle'] = $s['user'];
999
                    $s['handle'] = $s['user'];
991
                    unset($s['user']);
1000
                    unset($s['user']);
992
                    $s['role'] = 'helper';
1001
                    $s['role'] = 'helper';
993
                    $ret[] = $s;
1002
                    $ret[] = $s;
994
                }
1003
                }
995
            }
1004
            }
996
            return $ret;
1005
            return $ret;
997
        }
1006
        }
998
        return false;
1007
        return false;
999
    }
1008
    }
1000
 
1009
 
1001
    function getLeads()
1010
    function getLeads()
1002
    {
1011
    {
1003
        if (isset($this->_packageInfo['lead'])) {
1012
        if (isset($this->_packageInfo['lead'])) {
1004
            return $this->_packageInfo['lead'];
1013
            return $this->_packageInfo['lead'];
1005
        }
1014
        }
1006
        return false;
1015
        return false;
1007
    }
1016
    }
1008
 
1017
 
1009
    function getDevelopers()
1018
    function getDevelopers()
1010
    {
1019
    {
1011
        if (isset($this->_packageInfo['developer'])) {
1020
        if (isset($this->_packageInfo['developer'])) {
1012
            return $this->_packageInfo['developer'];
1021
            return $this->_packageInfo['developer'];
1013
        }
1022
        }
1014
        return false;
1023
        return false;
1015
    }
1024
    }
1016
 
1025
 
1017
    function getContributors()
1026
    function getContributors()
1018
    {
1027
    {
1019
        if (isset($this->_packageInfo['contributor'])) {
1028
        if (isset($this->_packageInfo['contributor'])) {
1020
            return $this->_packageInfo['contributor'];
1029
            return $this->_packageInfo['contributor'];
1021
        }
1030
        }
1022
        return false;
1031
        return false;
1023
    }
1032
    }
1024
 
1033
 
1025
    function getHelpers()
1034
    function getHelpers()
1026
    {
1035
    {
1027
        if (isset($this->_packageInfo['helper'])) {
1036
        if (isset($this->_packageInfo['helper'])) {
1028
            return $this->_packageInfo['helper'];
1037
            return $this->_packageInfo['helper'];
1029
        }
1038
        }
1030
        return false;
1039
        return false;
1031
    }
1040
    }
1032
 
1041
 
1033
    function setDate($date)
1042
    function setDate($date)
1034
    {
1043
    {
1035
        if (!isset($this->_packageInfo['date'])) {
1044
        if (!isset($this->_packageInfo['date'])) {
1036
            // ensure that the extends tag is set up in the right location
1045
            // ensure that the extends tag is set up in the right location
1037
            $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
1046
            $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
1038
                array('time', 'version',
1047
                array('time', 'version',
1039
                    'stability', 'license', 'notes', 'contents', 'compatible',
1048
                    'stability', 'license', 'notes', 'contents', 'compatible',
1040
                    'dependencies', 'providesextension', 'srcpackage', 'srcuri',
1049
                    'dependencies', 'providesextension', 'srcpackage', 'srcuri',
1041
                    'phprelease', 'extsrcrelease', 'extbinrelease', 'zendextsrcrelease',
1050
                    'phprelease', 'extsrcrelease', 'extbinrelease', 'zendextsrcrelease',
1042
                    'zendextbinrelease', 'bundle', 'changelog'), array(), 'date');
1051
                    'zendextbinrelease', 'bundle', 'changelog'), array(), 'date');
1043
        }
1052
        }
1044
        $this->_packageInfo['date'] = $date;
1053
        $this->_packageInfo['date'] = $date;
1045
        $this->_isValid = 0;
1054
        $this->_isValid = 0;
1046
    }
1055
    }
1047
 
1056
 
1048
    function setTime($time)
1057
    function setTime($time)
1049
    {
1058
    {
1050
        $this->_isValid = 0;
1059
        $this->_isValid = 0;
1051
        if (!isset($this->_packageInfo['time'])) {
1060
        if (!isset($this->_packageInfo['time'])) {
1052
            // ensure that the time tag is set up in the right location
1061
            // ensure that the time tag is set up in the right location
1053
            $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
1062
            $this->_packageInfo = $this->_insertBefore($this->_packageInfo,
1054
                    array('version',
1063
                    array('version',
1055
                    'stability', 'license', 'notes', 'contents', 'compatible',
1064
                    'stability', 'license', 'notes', 'contents', 'compatible',
1056
                    'dependencies', 'providesextension', 'srcpackage', 'srcuri',
1065
                    'dependencies', 'providesextension', 'srcpackage', 'srcuri',
1057
                    'phprelease', 'extsrcrelease', 'extbinrelease', 'zendextsrcrelease',
1066
                    'phprelease', 'extsrcrelease', 'extbinrelease', 'zendextsrcrelease',
1058
                    'zendextbinrelease', 'bundle', 'changelog'), $time, 'time');
1067
                    'zendextbinrelease', 'bundle', 'changelog'), $time, 'time');
1059
        }
1068
        }
1060
        $this->_packageInfo['time'] = $time;
1069
        $this->_packageInfo['time'] = $time;
1061
    }
1070
    }
1062
 
1071
 
1063
    function getDate()
1072
    function getDate()
1064
    {
1073
    {
1065
        if (isset($this->_packageInfo['date'])) {
1074
        if (isset($this->_packageInfo['date'])) {
1066
            return $this->_packageInfo['date'];
1075
            return $this->_packageInfo['date'];
1067
        }
1076
        }
1068
        return false;
1077
        return false;
1069
    }
1078
    }
1070
 
1079
 
1071
    function getTime()
1080
    function getTime()
1072
    {
1081
    {
1073
        if (isset($this->_packageInfo['time'])) {
1082
        if (isset($this->_packageInfo['time'])) {
1074
            return $this->_packageInfo['time'];
1083
            return $this->_packageInfo['time'];
1075
        }
1084
        }
1076
        return false;
1085
        return false;
1077
    }
1086
    }
1078
 
1087
 
1079
    /**
1088
    /**
1080
     * @param package|api version category to return
1089
     * @param package|api version category to return
1081
     */
1090
     */
1082
    function getVersion($key = 'release')
1091
    function getVersion($key = 'release')
1083
    {
1092
    {
1084
        if (isset($this->_packageInfo['version'][$key])) {
1093
        if (isset($this->_packageInfo['version'][$key])) {
1085
            return $this->_packageInfo['version'][$key];
1094
            return $this->_packageInfo['version'][$key];
1086
        }
1095
        }
1087
        return false;
1096
        return false;
1088
    }
1097
    }
1089
 
1098
 
1090
    function getStability()
1099
    function getStability()
1091
    {
1100
    {
1092
        if (isset($this->_packageInfo['stability'])) {
1101
        if (isset($this->_packageInfo['stability'])) {
1093
            return $this->_packageInfo['stability'];
1102
            return $this->_packageInfo['stability'];
1094
        }
1103
        }
1095
        return false;
1104
        return false;
1096
    }
1105
    }
1097
 
1106
 
1098
    function getState($key = 'release')
1107
    function getState($key = 'release')
1099
    {
1108
    {
1100
        if (isset($this->_packageInfo['stability'][$key])) {
1109
        if (isset($this->_packageInfo['stability'][$key])) {
1101
            return $this->_packageInfo['stability'][$key];
1110
            return $this->_packageInfo['stability'][$key];
1102
        }
1111
        }
1103
        return false;
1112
        return false;
1104
    }
1113
    }
1105
 
1114
 
1106
    function getLicense($raw = false)
1115
    function getLicense($raw = false)
1107
    {
1116
    {
1108
        if (isset($this->_packageInfo['license'])) {
1117
        if (isset($this->_packageInfo['license'])) {
1109
            if ($raw) {
1118
            if ($raw) {
1110
                return $this->_packageInfo['license'];
1119
                return $this->_packageInfo['license'];
1111
            }
1120
            }
1112
            if (is_array($this->_packageInfo['license'])) {
1121
            if (is_array($this->_packageInfo['license'])) {
1113
                return $this->_packageInfo['license']['_content'];
1122
                return $this->_packageInfo['license']['_content'];
1114
            } else {
1123
            } else {
1115
                return $this->_packageInfo['license'];
1124
                return $this->_packageInfo['license'];
1116
            }
1125
            }
1117
        }
1126
        }
1118
        return false;
1127
        return false;
1119
    }
1128
    }
1120
 
1129
 
1121
    function getLicenseLocation()
1130
    function getLicenseLocation()
1122
    {
1131
    {
1123
        if (!isset($this->_packageInfo['license']) || !is_array($this->_packageInfo['license'])) {
1132
        if (!isset($this->_packageInfo['license']) || !is_array($this->_packageInfo['license'])) {
1124
            return false;
1133
            return false;
1125
        }
1134
        }
1126
        return $this->_packageInfo['license']['attribs'];
1135
        return $this->_packageInfo['license']['attribs'];
1127
    }
1136
    }
1128
 
1137
 
1129
    function getNotes()
1138
    function getNotes()
1130
    {
1139
    {
1131
        if (isset($this->_packageInfo['notes'])) {
1140
        if (isset($this->_packageInfo['notes'])) {
1132
            return $this->_packageInfo['notes'];
1141
            return $this->_packageInfo['notes'];
1133
        }
1142
        }
1134
        return false;
1143
        return false;
1135
    }
1144
    }
1136
 
1145
 
1137
    /**
1146
    /**
1138
     * Return the <usesrole> tag contents, if any
1147
     * Return the <usesrole> tag contents, if any
1139
     * @return array|false
1148
     * @return array|false
1140
     */
1149
     */
1141
    function getUsesrole()
1150
    function getUsesrole()
1142
    {
1151
    {
1143
        if (isset($this->_packageInfo['usesrole'])) {
1152
        if (isset($this->_packageInfo['usesrole'])) {
1144
            return $this->_packageInfo['usesrole'];
1153
            return $this->_packageInfo['usesrole'];
1145
        }
1154
        }
1146
        return false;
1155
        return false;
1147
    }
1156
    }
1148
 
1157
 
1149
    /**
1158
    /**
1150
     * Return the <usestask> tag contents, if any
1159
     * Return the <usestask> tag contents, if any
1151
     * @return array|false
1160
     * @return array|false
1152
     */
1161
     */
1153
    function getUsestask()
1162
    function getUsestask()
1154
    {
1163
    {
1155
        if (isset($this->_packageInfo['usestask'])) {
1164
        if (isset($this->_packageInfo['usestask'])) {
1156
            return $this->_packageInfo['usestask'];
1165
            return $this->_packageInfo['usestask'];
1157
        }
1166
        }
1158
        return false;
1167
        return false;
1159
    }
1168
    }
1160
 
1169
 
1161
    /**
1170
    /**
1162
     * This should only be used to retrieve filenames and install attributes
1171
     * This should only be used to retrieve filenames and install attributes
1163
     */
1172
     */
1164
    function getFilelist($preserve = false)
1173
    function getFilelist($preserve = false)
1165
    {
1174
    {
1166
        if (isset($this->_packageInfo['filelist']) && !$preserve) {
1175
        if (isset($this->_packageInfo['filelist']) && !$preserve) {
1167
            return $this->_packageInfo['filelist'];
1176
            return $this->_packageInfo['filelist'];
1168
        }
1177
        }
1169
        $this->flattenFilelist();
1178
        $this->flattenFilelist();
1170
        if ($contents = $this->getContents()) {
1179
        if ($contents = $this->getContents()) {
1171
            $ret = array();
1180
            $ret = array();
-
 
1181
            if (!isset($contents['dir'])) {
-
 
1182
                return false;
-
 
1183
            }
1172
            if (!isset($contents['dir']['file'][0])) {
1184
            if (!isset($contents['dir']['file'][0])) {
1173
                $contents['dir']['file'] = array($contents['dir']['file']);
1185
                $contents['dir']['file'] = array($contents['dir']['file']);
1174
            }
1186
            }
1175
            foreach ($contents['dir']['file'] as $file) {
1187
            foreach ($contents['dir']['file'] as $file) {
-
 
1188
                if (!isset($file['attribs']['name'])) {
-
 
1189
                    continue;
-
 
1190
                }
1176
                $name = $file['attribs']['name'];
1191
                $name = $file['attribs']['name'];
1177
                if (!$preserve) {
1192
                if (!$preserve) {
1178
                    $file = $file['attribs'];
1193
                    $file = $file['attribs'];
1179
                }
1194
                }
1180
                $ret[$name] = $file;
1195
                $ret[$name] = $file;
1181
            }
1196
            }
1182
            if (!$preserve) {
1197
            if (!$preserve) {
1183
                $this->_packageInfo['filelist'] = $ret;
1198
                $this->_packageInfo['filelist'] = $ret;
1184
            }
1199
            }
1185
            return $ret;
1200
            return $ret;
1186
        }
1201
        }
1187
        return false;
1202
        return false;
1188
    }
1203
    }
1189
 
1204
 
1190
    /**
1205
    /**
1191
     * Return configure options array, if any
1206
     * Return configure options array, if any
1192
     *
1207
     *
1193
     * @return array|false
1208
     * @return array|false
1194
     */
1209
     */
1195
    function getConfigureOptions()
1210
    function getConfigureOptions()
1196
    {
1211
    {
1197
        if ($this->getPackageType() != 'extsrc' && $this->getPackageType() != 'zendextsrc') {
1212
        if ($this->getPackageType() != 'extsrc' && $this->getPackageType() != 'zendextsrc') {
1198
            return false;
1213
            return false;
1199
        }
1214
        }
-
 
1215
 
1200
        $releases = $this->getReleases();
1216
        $releases = $this->getReleases();
1201
        if (isset($releases[0])) {
1217
        if (isset($releases[0])) {
1202
            $releases = $releases[0];
1218
            $releases = $releases[0];
1203
        }
1219
        }
-
 
1220
 
1204
        if (isset($releases['configureoption'])) {
1221
        if (isset($releases['configureoption'])) {
1205
            if (!isset($releases['configureoption'][0])) {
1222
            if (!isset($releases['configureoption'][0])) {
1206
                $releases['configureoption'] = array($releases['configureoption']);
1223
                $releases['configureoption'] = array($releases['configureoption']);
1207
            }
1224
            }
-
 
1225
 
1208
            for ($i = 0; $i < count($releases['configureoption']); $i++) {
1226
            for ($i = 0; $i < count($releases['configureoption']); $i++) {
1209
                $releases['configureoption'][$i] = $releases['configureoption'][$i]['attribs'];
1227
                $releases['configureoption'][$i] = $releases['configureoption'][$i]['attribs'];
1210
            }
1228
            }
-
 
1229
 
1211
            return $releases['configureoption'];
1230
            return $releases['configureoption'];
1212
        }
1231
        }
-
 
1232
 
1213
        return false;
1233
        return false;
1214
    }
1234
    }
1215
 
1235
 
1216
    /**
1236
    /**
1217
     * This is only used at install-time, after all serialization
1237
     * This is only used at install-time, after all serialization
1218
     * is over.
1238
     * is over.
1219
     */
1239
     */
1220
    function resetFilelist()
1240
    function resetFilelist()
1221
    {
1241
    {
1222
        $this->_packageInfo['filelist'] = array();
1242
        $this->_packageInfo['filelist'] = array();
1223
    }
1243
    }
1224
 
1244
 
1225
    /**
1245
    /**
1226
     * Retrieve a list of files that should be installed on this computer
1246
     * Retrieve a list of files that should be installed on this computer
1227
     * @return array
1247
     * @return array
1228
     */
1248
     */
1229
    function getInstallationFilelist($forfilecheck = false)
1249
    function getInstallationFilelist($forfilecheck = false)
1230
    {
1250
    {
1231
        $contents = $this->getFilelist(true);
1251
        $contents = $this->getFilelist(true);
1232
        if (isset($contents['dir']['attribs']['baseinstalldir'])) {
1252
        if (isset($contents['dir']['attribs']['baseinstalldir'])) {
1233
            $base = $contents['dir']['attribs']['baseinstalldir'];
1253
            $base = $contents['dir']['attribs']['baseinstalldir'];
1234
        }
1254
        }
1235
        if (isset($this->_packageInfo['bundle'])) {
1255
        if (isset($this->_packageInfo['bundle'])) {
1236
            return PEAR::raiseError(
1256
            return PEAR::raiseError(
1237
                'Exception: bundles should be handled in download code only');
1257
                'Exception: bundles should be handled in download code only');
1238
        }
1258
        }
1239
        $release = $this->getReleases();
1259
        $release = $this->getReleases();
1240
        if ($release) {
1260
        if ($release) {
1241
            if (!isset($release[0])) {
1261
            if (!isset($release[0])) {
1242
                if (!isset($release['installconditions']) && !isset($release['filelist'])) {
1262
                if (!isset($release['installconditions']) && !isset($release['filelist'])) {
1243
                    if ($forfilecheck) {
1263
                    if ($forfilecheck) {
1244
                        return $this->getFilelist();
1264
                        return $this->getFilelist();
1245
                    }
1265
                    }
1246
                    return $contents;
1266
                    return $contents;
1247
                }
1267
                }
1248
                $release = array($release);
1268
                $release = array($release);
1249
            }
1269
            }
1250
            $depchecker = &$this->getPEARDependency2($this->_config, array(),
1270
            $depchecker = &$this->getPEARDependency2($this->_config, array(),
1251
                array('channel' => $this->getChannel(), 'package' => $this->getPackage()),
1271
                array('channel' => $this->getChannel(), 'package' => $this->getPackage()),
1252
                PEAR_VALIDATE_INSTALLING);
1272
                PEAR_VALIDATE_INSTALLING);
1253
            foreach ($release as $instance) {
1273
            foreach ($release as $instance) {
1254
                if (isset($instance['installconditions'])) {
1274
                if (isset($instance['installconditions'])) {
1255
                    $installconditions = $instance['installconditions'];
1275
                    $installconditions = $instance['installconditions'];
1256
                    if (is_array($installconditions)) {
1276
                    if (is_array($installconditions)) {
1257
                        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
1277
                        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
1258
                        foreach ($installconditions as $type => $conditions) {
1278
                        foreach ($installconditions as $type => $conditions) {
1259
                            if (!isset($conditions[0])) {
1279
                            if (!isset($conditions[0])) {
1260
                                $conditions = array($conditions);
1280
                                $conditions = array($conditions);
1261
                            }
1281
                            }
1262
                            foreach ($conditions as $condition) {
1282
                            foreach ($conditions as $condition) {
1263
                                $ret = $depchecker->{"validate{$type}Dependency"}($condition);
1283
                                $ret = $depchecker->{"validate{$type}Dependency"}($condition);
1264
                                if (PEAR::isError($ret)) {
1284
                                if (PEAR::isError($ret)) {
1265
                                    PEAR::popErrorHandling();
1285
                                    PEAR::popErrorHandling();
1266
                                    continue 3; // skip this release
1286
                                    continue 3; // skip this release
1267
                                }
1287
                                }
1268
                            }
1288
                            }
1269
                        }
1289
                        }
1270
                        PEAR::popErrorHandling();
1290
                        PEAR::popErrorHandling();
1271
                    }
1291
                    }
1272
                }
1292
                }
1273
                // this is the release to use
1293
                // this is the release to use
1274
                if (isset($instance['filelist'])) {
1294
                if (isset($instance['filelist'])) {
1275
                    // ignore files
1295
                    // ignore files
1276
                    if (isset($instance['filelist']['ignore'])) {
1296
                    if (isset($instance['filelist']['ignore'])) {
1277
                        $ignore = isset($instance['filelist']['ignore'][0]) ?
1297
                        $ignore = isset($instance['filelist']['ignore'][0]) ?
1278
                            $instance['filelist']['ignore'] :
1298
                            $instance['filelist']['ignore'] :
1279
                            array($instance['filelist']['ignore']);
1299
                            array($instance['filelist']['ignore']);
1280
                        foreach ($ignore as $ig) {
1300
                        foreach ($ignore as $ig) {
1281
                            unset ($contents[$ig['attribs']['name']]);
1301
                            unset ($contents[$ig['attribs']['name']]);
1282
                        }
1302
                        }
1283
                    }
1303
                    }
1284
                    // install files as this name
1304
                    // install files as this name
1285
                    if (isset($instance['filelist']['install'])) {
1305
                    if (isset($instance['filelist']['install'])) {
1286
                        $installas = isset($instance['filelist']['install'][0]) ?
1306
                        $installas = isset($instance['filelist']['install'][0]) ?
1287
                            $instance['filelist']['install'] :
1307
                            $instance['filelist']['install'] :
1288
                            array($instance['filelist']['install']);
1308
                            array($instance['filelist']['install']);
1289
                        foreach ($installas as $as) {
1309
                        foreach ($installas as $as) {
1290
                            $contents[$as['attribs']['name']]['attribs']['install-as'] =
1310
                            $contents[$as['attribs']['name']]['attribs']['install-as'] =
1291
                                $as['attribs']['as'];
1311
                                $as['attribs']['as'];
1292
                        }
1312
                        }
1293
                    }
1313
                    }
1294
                }
1314
                }
1295
                if ($forfilecheck) {
1315
                if ($forfilecheck) {
1296
                    foreach ($contents as $file => $attrs) {
1316
                    foreach ($contents as $file => $attrs) {
1297
                        $contents[$file] = $attrs['attribs'];
1317
                        $contents[$file] = $attrs['attribs'];
1298
                    }
1318
                    }
1299
                }
1319
                }
1300
                return $contents;
1320
                return $contents;
1301
            }
1321
            }
1302
        } else { // simple release - no installconditions or install-as
1322
        } else { // simple release - no installconditions or install-as
1303
            if ($forfilecheck) {
1323
            if ($forfilecheck) {
1304
                return $this->getFilelist();
1324
                return $this->getFilelist();
1305
            }
1325
            }
1306
            return $contents;
1326
            return $contents;
1307
        }
1327
        }
1308
        // no releases matched
1328
        // no releases matched
1309
        return PEAR::raiseError('No releases in package.xml matched the existing operating ' .
1329
        return PEAR::raiseError('No releases in package.xml matched the existing operating ' .
1310
            'system, extensions installed, or architecture, cannot install');
1330
            'system, extensions installed, or architecture, cannot install');
1311
    }
1331
    }
1312
 
1332
 
1313
    /**
1333
    /**
1314
     * This is only used at install-time, after all serialization
1334
     * This is only used at install-time, after all serialization
1315
     * is over.
1335
     * is over.
1316
     * @param string file name
1336
     * @param string file name
1317
     * @param string installed path
1337
     * @param string installed path
1318
     */
1338
     */
1319
    function setInstalledAs($file, $path)
1339
    function setInstalledAs($file, $path)
1320
    {
1340
    {
1321
        if ($path) {
1341
        if ($path) {
1322
            return $this->_packageInfo['filelist'][$file]['installed_as'] = $path;
1342
            return $this->_packageInfo['filelist'][$file]['installed_as'] = $path;
1323
        }
1343
        }
1324
        unset($this->_packageInfo['filelist'][$file]['installed_as']);
1344
        unset($this->_packageInfo['filelist'][$file]['installed_as']);
1325
    }
1345
    }
1326
 
1346
 
1327
    function getInstalledLocation($file)
1347
    function getInstalledLocation($file)
1328
    {
1348
    {
1329
        if (isset($this->_packageInfo['filelist'][$file]['installed_as'])) {
1349
        if (isset($this->_packageInfo['filelist'][$file]['installed_as'])) {
1330
            return $this->_packageInfo['filelist'][$file]['installed_as'];
1350
            return $this->_packageInfo['filelist'][$file]['installed_as'];
1331
        }
1351
        }
1332
        return false;
1352
        return false;
1333
    }
1353
    }
1334
 
1354
 
1335
    /**
1355
    /**
1336
     * This is only used at install-time, after all serialization
1356
     * This is only used at install-time, after all serialization
1337
     * is over.
1357
     * is over.
1338
     */
1358
     */
1339
    function installedFile($file, $atts)
1359
    function installedFile($file, $atts)
1340
    {
1360
    {
1341
        if (isset($this->_packageInfo['filelist'][$file])) {
1361
        if (isset($this->_packageInfo['filelist'][$file])) {
1342
            $this->_packageInfo['filelist'][$file] =
1362
            $this->_packageInfo['filelist'][$file] =
1343
                array_merge($this->_packageInfo['filelist'][$file], $atts['attribs']);
1363
                array_merge($this->_packageInfo['filelist'][$file], $atts['attribs']);
1344
        } else {
1364
        } else {
1345
            $this->_packageInfo['filelist'][$file] = $atts['attribs'];
1365
            $this->_packageInfo['filelist'][$file] = $atts['attribs'];
1346
        }
1366
        }
1347
    }
1367
    }
1348
 
1368
 
1349
    /**
1369
    /**
1350
     * Retrieve the contents tag
1370
     * Retrieve the contents tag
1351
     */
1371
     */
1352
    function getContents()
1372
    function getContents()
1353
    {
1373
    {
1354
        if (isset($this->_packageInfo['contents'])) {
1374
        if (isset($this->_packageInfo['contents'])) {
1355
            return $this->_packageInfo['contents'];
1375
            return $this->_packageInfo['contents'];
1356
        }
1376
        }
1357
        return false;
1377
        return false;
1358
    }
1378
    }
1359
 
1379
 
1360
    /**
1380
    /**
1361
     * @param string full path to file
1381
     * @param string full path to file
1362
     * @param string attribute name
1382
     * @param string attribute name
1363
     * @param string attribute value
1383
     * @param string attribute value
1364
     * @param int risky but fast - use this to choose a file based on its position in the list
1384
     * @param int risky but fast - use this to choose a file based on its position in the list
1365
     *            of files.  Index is zero-based like PHP arrays.
1385
     *            of files.  Index is zero-based like PHP arrays.
1366
     * @return bool success of operation
1386
     * @return bool success of operation
1367
     */
1387
     */
1368
    function setFileAttribute($filename, $attr, $value, $index = false)
1388
    function setFileAttribute($filename, $attr, $value, $index = false)
1369
    {
1389
    {
1370
        $this->_isValid = 0;
1390
        $this->_isValid = 0;
1371
        if (in_array($attr, array('role', 'name', 'baseinstalldir'))) {
1391
        if (in_array($attr, array('role', 'name', 'baseinstalldir'))) {
1372
            $this->_filesValid = false;
1392
            $this->_filesValid = false;
1373
        }
1393
        }
1374
        if ($index !== false &&
1394
        if ($index !== false &&
1375
              isset($this->_packageInfo['contents']['dir']['file'][$index]['attribs'])) {
1395
              isset($this->_packageInfo['contents']['dir']['file'][$index]['attribs'])) {
1376
            $this->_packageInfo['contents']['dir']['file'][$index]['attribs'][$attr] = $value;
1396
            $this->_packageInfo['contents']['dir']['file'][$index]['attribs'][$attr] = $value;
1377
            return true;
1397
            return true;
1378
        }
1398
        }
1379
        if (!isset($this->_packageInfo['contents']['dir']['file'])) {
1399
        if (!isset($this->_packageInfo['contents']['dir']['file'])) {
1380
            return false;
1400
            return false;
1381
        }
1401
        }
1382
        $files = $this->_packageInfo['contents']['dir']['file'];
1402
        $files = $this->_packageInfo['contents']['dir']['file'];
1383
        if (!isset($files[0])) {
1403
        if (!isset($files[0])) {
1384
            $files = array($files);
1404
            $files = array($files);
1385
            $ind = false;
1405
            $ind = false;
1386
        } else {
1406
        } else {
1387
            $ind = true;
1407
            $ind = true;
1388
        }
1408
        }
1389
        foreach ($files as $i => $file) {
1409
        foreach ($files as $i => $file) {
1390
            if (isset($file['attribs'])) {
1410
            if (isset($file['attribs'])) {
1391
                if ($file['attribs']['name'] == $filename) {
1411
                if ($file['attribs']['name'] == $filename) {
1392
                    if ($ind) {
1412
                    if ($ind) {
1393
                        $this->_packageInfo['contents']['dir']['file'][$i]['attribs'][$attr] = $value;
1413
                        $this->_packageInfo['contents']['dir']['file'][$i]['attribs'][$attr] = $value;
1394
                    } else {
1414
                    } else {
1395
                        $this->_packageInfo['contents']['dir']['file']['attribs'][$attr] = $value;
1415
                        $this->_packageInfo['contents']['dir']['file']['attribs'][$attr] = $value;
1396
                    }
1416
                    }
1397
                    return true;
1417
                    return true;
1398
                }
1418
                }
1399
            }
1419
            }
1400
        }
1420
        }
1401
        return false;
1421
        return false;
1402
    }
1422
    }
1403
 
1423
 
1404
    function setDirtree($path)
1424
    function setDirtree($path)
1405
    {
1425
    {
1406
        if (!isset($this->_packageInfo['dirtree'])) {
1426
        if (!isset($this->_packageInfo['dirtree'])) {
1407
            $this->_packageInfo['dirtree'] = array();
1427
            $this->_packageInfo['dirtree'] = array();
1408
        }
1428
        }
1409
        $this->_packageInfo['dirtree'][$path] = true;
1429
        $this->_packageInfo['dirtree'][$path] = true;
1410
    }
1430
    }
1411
 
1431
 
1412
    function getDirtree()
1432
    function getDirtree()
1413
    {
1433
    {
1414
        if (isset($this->_packageInfo['dirtree']) && count($this->_packageInfo['dirtree'])) {
1434
        if (isset($this->_packageInfo['dirtree']) && count($this->_packageInfo['dirtree'])) {
1415
            return $this->_packageInfo['dirtree'];
1435
            return $this->_packageInfo['dirtree'];
1416
        }
1436
        }
1417
        return false;
1437
        return false;
1418
    }
1438
    }
1419
 
1439
 
1420
    function resetDirtree()
1440
    function resetDirtree()
1421
    {
1441
    {
1422
        unset($this->_packageInfo['dirtree']);
1442
        unset($this->_packageInfo['dirtree']);
1423
    }
1443
    }
1424
 
1444
 
1425
    /**
1445
    /**
1426
     * Determines whether this package claims it is compatible with the version of
1446
     * Determines whether this package claims it is compatible with the version of
1427
     * the package that has a recommended version dependency
1447
     * the package that has a recommended version dependency
1428
     * @param PEAR_PackageFile_v2|PEAR_PackageFile_v1|PEAR_Downloader_Package
1448
     * @param PEAR_PackageFile_v2|PEAR_PackageFile_v1|PEAR_Downloader_Package
1429
     * @return boolean
1449
     * @return boolean
1430
     */
1450
     */
1431
    function isCompatible($pf)
1451
    function isCompatible($pf)
1432
    {
1452
    {
1433
        if (!isset($this->_packageInfo['compatible'])) {
1453
        if (!isset($this->_packageInfo['compatible'])) {
1434
            return false;
1454
            return false;
1435
        }
1455
        }
1436
        if (!isset($this->_packageInfo['channel'])) {
1456
        if (!isset($this->_packageInfo['channel'])) {
1437
            return false;
1457
            return false;
1438
        }
1458
        }
1439
        $me = $pf->getVersion();
1459
        $me = $pf->getVersion();
1440
        $compatible = $this->_packageInfo['compatible'];
1460
        $compatible = $this->_packageInfo['compatible'];
1441
        if (!isset($compatible[0])) {
1461
        if (!isset($compatible[0])) {
1442
            $compatible = array($compatible);
1462
            $compatible = array($compatible);
1443
        }
1463
        }
1444
        $found = false;
1464
        $found = false;
1445
        foreach ($compatible as $info) {
1465
        foreach ($compatible as $info) {
1446
            if (strtolower($info['name']) == strtolower($pf->getPackage())) {
1466
            if (strtolower($info['name']) == strtolower($pf->getPackage())) {
1447
                if (strtolower($info['channel']) == strtolower($pf->getChannel())) {
1467
                if (strtolower($info['channel']) == strtolower($pf->getChannel())) {
1448
                    $found = true;
1468
                    $found = true;
1449
                    break;
1469
                    break;
1450
                }
1470
                }
1451
            }
1471
            }
1452
        }
1472
        }
1453
        if (!$found) {
1473
        if (!$found) {
1454
            return false;
1474
            return false;
1455
        }
1475
        }
1456
        if (isset($info['exclude'])) {
1476
        if (isset($info['exclude'])) {
1457
            if (!isset($info['exclude'][0])) {
1477
            if (!isset($info['exclude'][0])) {
1458
                $info['exclude'] = array($info['exclude']);
1478
                $info['exclude'] = array($info['exclude']);
1459
            }
1479
            }
1460
            foreach ($info['exclude'] as $exclude) {
1480
            foreach ($info['exclude'] as $exclude) {
1461
                if (version_compare($me, $exclude, '==')) {
1481
                if (version_compare($me, $exclude, '==')) {
1462
                    return false;
1482
                    return false;
1463
                }
1483
                }
1464
            }
1484
            }
1465
        }
1485
        }
1466
        if (version_compare($me, $info['min'], '>=') && version_compare($me, $info['max'], '<=')) {
1486
        if (version_compare($me, $info['min'], '>=') && version_compare($me, $info['max'], '<=')) {
1467
            return true;
1487
            return true;
1468
        }
1488
        }
1469
        return false;
1489
        return false;
1470
    }
1490
    }
1471
 
1491
 
1472
    /**
1492
    /**
1473
     * @return array|false
1493
     * @return array|false
1474
     */
1494
     */
1475
    function getCompatible()
1495
    function getCompatible()
1476
    {
1496
    {
1477
        if (isset($this->_packageInfo['compatible'])) {
1497
        if (isset($this->_packageInfo['compatible'])) {
1478
            return $this->_packageInfo['compatible'];
1498
            return $this->_packageInfo['compatible'];
1479
        }
1499
        }
1480
        return false;
1500
        return false;
1481
    }
1501
    }
1482
 
1502
 
1483
    function getDependencies()
1503
    function getDependencies()
1484
    {
1504
    {
1485
        if (isset($this->_packageInfo['dependencies'])) {
1505
        if (isset($this->_packageInfo['dependencies'])) {
1486
            return $this->_packageInfo['dependencies'];
1506
            return $this->_packageInfo['dependencies'];
1487
        }
1507
        }
1488
        return false;
1508
        return false;
1489
    }
1509
    }
1490
 
1510
 
1491
    function isSubpackageOf($p)
1511
    function isSubpackageOf($p)
1492
    {
1512
    {
1493
        return $p->isSubpackage($this);
1513
        return $p->isSubpackage($this);
1494
    }
1514
    }
1495
 
1515
 
1496
    /**
1516
    /**
1497
     * Determines whether the passed in package is a subpackage of this package.
1517
     * Determines whether the passed in package is a subpackage of this package.
1498
     *
1518
     *
1499
     * No version checking is done, only name verification.
1519
     * No version checking is done, only name verification.
1500
     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
1520
     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
1501
     * @return bool
1521
     * @return bool
1502
     */
1522
     */
1503
    function isSubpackage($p)
1523
    function isSubpackage($p)
1504
    {
1524
    {
1505
        $sub = array();
1525
        $sub = array();
1506
        if (isset($this->_packageInfo['dependencies']['required']['subpackage'])) {
1526
        if (isset($this->_packageInfo['dependencies']['required']['subpackage'])) {
1507
            $sub = $this->_packageInfo['dependencies']['required']['subpackage'];
1527
            $sub = $this->_packageInfo['dependencies']['required']['subpackage'];
1508
            if (!isset($sub[0])) {
1528
            if (!isset($sub[0])) {
1509
                $sub = array($sub);
1529
                $sub = array($sub);
1510
            }
1530
            }
1511
        }
1531
        }
1512
        if (isset($this->_packageInfo['dependencies']['optional']['subpackage'])) {
1532
        if (isset($this->_packageInfo['dependencies']['optional']['subpackage'])) {
1513
            $sub1 = $this->_packageInfo['dependencies']['optional']['subpackage'];
1533
            $sub1 = $this->_packageInfo['dependencies']['optional']['subpackage'];
1514
            if (!isset($sub1[0])) {
1534
            if (!isset($sub1[0])) {
1515
                $sub1 = array($sub1);
1535
                $sub1 = array($sub1);
1516
            }
1536
            }
1517
            $sub = array_merge($sub, $sub1);
1537
            $sub = array_merge($sub, $sub1);
1518
        }
1538
        }
1519
        if (isset($this->_packageInfo['dependencies']['group'])) {
1539
        if (isset($this->_packageInfo['dependencies']['group'])) {
1520
            $group = $this->_packageInfo['dependencies']['group'];
1540
            $group = $this->_packageInfo['dependencies']['group'];
1521
            if (!isset($group[0])) {
1541
            if (!isset($group[0])) {
1522
                $group = array($group);
1542
                $group = array($group);
1523
            }
1543
            }
1524
            foreach ($group as $deps) {
1544
            foreach ($group as $deps) {
1525
                if (isset($deps['subpackage'])) {
1545
                if (isset($deps['subpackage'])) {
1526
                    $sub2 = $deps['subpackage'];
1546
                    $sub2 = $deps['subpackage'];
1527
                    if (!isset($sub2[0])) {
1547
                    if (!isset($sub2[0])) {
1528
                        $sub2 = array($sub2);
1548
                        $sub2 = array($sub2);
1529
                    }
1549
                    }
1530
                    $sub = array_merge($sub, $sub2);
1550
                    $sub = array_merge($sub, $sub2);
1531
                }
1551
                }
1532
            }
1552
            }
1533
        }
1553
        }
1534
        foreach ($sub as $dep) {
1554
        foreach ($sub as $dep) {
1535
            if (strtolower($dep['name']) == strtolower($p->getPackage())) {
1555
            if (strtolower($dep['name']) == strtolower($p->getPackage())) {
1536
                if (isset($dep['channel'])) {
1556
                if (isset($dep['channel'])) {
1537
                    if (strtolower($dep['channel']) == strtolower($p->getChannel())) {
1557
                    if (strtolower($dep['channel']) == strtolower($p->getChannel())) {
1538
                        return true;
1558
                        return true;
1539
                    }
1559
                    }
1540
                } else {
1560
                } else {
1541
                    if ($dep['uri'] == $p->getURI()) {
1561
                    if ($dep['uri'] == $p->getURI()) {
1542
                        return true;
1562
                        return true;
1543
                    }
1563
                    }
1544
                }
1564
                }
1545
            }
1565
            }
1546
        }
1566
        }
1547
        return false;
1567
        return false;
1548
    }
1568
    }
1549
 
1569
 
1550
    function dependsOn($package, $channel)
1570
    function dependsOn($package, $channel)
1551
    {
1571
    {
1552
        if (!($deps = $this->getDependencies())) {
1572
        if (!($deps = $this->getDependencies())) {
1553
            return false;
1573
            return false;
1554
        }
1574
        }
1555
        foreach (array('package', 'subpackage') as $type) {
1575
        foreach (array('package', 'subpackage') as $type) {
1556
            foreach (array('required', 'optional') as $needed) {
1576
            foreach (array('required', 'optional') as $needed) {
1557
                if (isset($deps[$needed][$type])) {
1577
                if (isset($deps[$needed][$type])) {
1558
                    if (!isset($deps[$needed][$type][0])) {
1578
                    if (!isset($deps[$needed][$type][0])) {
1559
                        $deps[$needed][$type] = array($deps[$needed][$type]);
1579
                        $deps[$needed][$type] = array($deps[$needed][$type]);
1560
                    }
1580
                    }
1561
                    foreach ($deps[$needed][$type] as $dep) {
1581
                    foreach ($deps[$needed][$type] as $dep) {
1562
                        $depchannel = isset($dep['channel']) ? $dep['channel'] : '__uri';
1582
                        $depchannel = isset($dep['channel']) ? $dep['channel'] : '__uri';
1563
                        if (strtolower($dep['name']) == strtolower($package) &&
1583
                        if (strtolower($dep['name']) == strtolower($package) &&
1564
                              $depchannel == $channel) {
1584
                              $depchannel == $channel) {
1565
                            return true;
1585
                            return true;
1566
                        }  
1586
                        }
1567
                    }
1587
                    }
1568
                }
1588
                }
1569
            }
1589
            }
1570
            if (isset($deps['group'])) {
1590
            if (isset($deps['group'])) {
1571
                if (!isset($deps['group'][0])) {
1591
                if (!isset($deps['group'][0])) {
1572
                    $dep['group'] = array($deps['group']);
1592
                    $dep['group'] = array($deps['group']);
1573
                }
1593
                }
1574
                foreach ($deps['group'] as $group) {
1594
                foreach ($deps['group'] as $group) {
1575
                    if (isset($group[$type])) {
1595
                    if (isset($group[$type])) {
1576
                        if (!is_array($group[$type])) {
1596
                        if (!is_array($group[$type])) {
1577
                            $group[$type] = array($group[$type]);
1597
                            $group[$type] = array($group[$type]);
1578
                        }
1598
                        }
1579
                        foreach ($group[$type] as $dep) {
1599
                        foreach ($group[$type] as $dep) {
1580
                            $depchannel = isset($dep['channel']) ? $dep['channel'] : '__uri';
1600
                            $depchannel = isset($dep['channel']) ? $dep['channel'] : '__uri';
1581
                            if (strtolower($dep['name']) == strtolower($package) &&
1601
                            if (strtolower($dep['name']) == strtolower($package) &&
1582
                                  $depchannel == $channel) {
1602
                                  $depchannel == $channel) {
1583
                                return true;
1603
                                return true;
1584
                            }  
1604
                            }
1585
                        }
1605
                        }
1586
                    }
1606
                    }
1587
                }
1607
                }
1588
            }
1608
            }
1589
        }
1609
        }
1590
        return false;
1610
        return false;
1591
    }
1611
    }
1592
 
1612
 
1593
    /**
1613
    /**
1594
     * Get the contents of a dependency group
1614
     * Get the contents of a dependency group
1595
     * @param string
1615
     * @param string
1596
     * @return array|false
1616
     * @return array|false
1597
     */
1617
     */
1598
    function getDependencyGroup($name)
1618
    function getDependencyGroup($name)
1599
    {
1619
    {
1600
        $name = strtolower($name);
1620
        $name = strtolower($name);
1601
        if (!isset($this->_packageInfo['dependencies']['group'])) {
1621
        if (!isset($this->_packageInfo['dependencies']['group'])) {
1602
            return false;
1622
            return false;
1603
        }
1623
        }
1604
        $groups = $this->_packageInfo['dependencies']['group'];
1624
        $groups = $this->_packageInfo['dependencies']['group'];
1605
        if (!isset($groups[0])) {
1625
        if (!isset($groups[0])) {
1606
            $groups = array($groups);
1626
            $groups = array($groups);
1607
        }
1627
        }
1608
        foreach ($groups as $group) {
1628
        foreach ($groups as $group) {
1609
            if (strtolower($group['attribs']['name']) == $name) {
1629
            if (strtolower($group['attribs']['name']) == $name) {
1610
                return $group;
1630
                return $group;
1611
            }
1631
            }
1612
        }
1632
        }
1613
        return false;
1633
        return false;
1614
    }
1634
    }
1615
 
1635
 
1616
    /**
1636
    /**
1617
     * Retrieve a partial package.xml 1.0 representation of dependencies
1637
     * Retrieve a partial package.xml 1.0 representation of dependencies
1618
     *
1638
     *
1619
     * a very limited representation of dependencies is returned by this method.
1639
     * a very limited representation of dependencies is returned by this method.
1620
     * The <exclude> tag for excluding certain versions of a dependency is
1640
     * The <exclude> tag for excluding certain versions of a dependency is
1621
     * completely ignored.  In addition, dependency groups are ignored, with the
1641
     * completely ignored.  In addition, dependency groups are ignored, with the
1622
     * assumption that all dependencies in dependency groups are also listed in
1642
     * assumption that all dependencies in dependency groups are also listed in
1623
     * the optional group that work with all dependency groups
1643
     * the optional group that work with all dependency groups
1624
     * @param boolean return package.xml 2.0 <dependencies> tag
1644
     * @param boolean return package.xml 2.0 <dependencies> tag
1625
     * @return array|false
1645
     * @return array|false
1626
     */
1646
     */
1627
    function getDeps($raw = false, $nopearinstaller = false)
1647
    function getDeps($raw = false, $nopearinstaller = false)
1628
    {
1648
    {
1629
        if (isset($this->_packageInfo['dependencies'])) {
1649
        if (isset($this->_packageInfo['dependencies'])) {
1630
            if ($raw) {
1650
            if ($raw) {
1631
                return $this->_packageInfo['dependencies'];
1651
                return $this->_packageInfo['dependencies'];
1632
            }
1652
            }
1633
            $ret = array();
1653
            $ret = array();
1634
            $map = array(
1654
            $map = array(
1635
                'php' => 'php',
1655
                'php' => 'php',
1636
                'package' => 'pkg',
1656
                'package' => 'pkg',
1637
                'subpackage' => 'pkg',
1657
                'subpackage' => 'pkg',
1638
                'extension' => 'ext',
1658
                'extension' => 'ext',
1639
                'os' => 'os',
1659
                'os' => 'os',
1640
                'pearinstaller' => 'pkg',
1660
                'pearinstaller' => 'pkg',
1641
                );
1661
                );
1642
            foreach (array('required', 'optional') as $type) {
1662
            foreach (array('required', 'optional') as $type) {
1643
                $optional = ($type == 'optional') ? 'yes' : 'no';
1663
                $optional = ($type == 'optional') ? 'yes' : 'no';
1644
                if (!isset($this->_packageInfo['dependencies'][$type])) {
1664
                if (!isset($this->_packageInfo['dependencies'][$type])
-
 
1665
                    || empty($this->_packageInfo['dependencies'][$type])) {
1645
                    continue;
1666
                    continue;
1646
                }
1667
                }
1647
                foreach ($this->_packageInfo['dependencies'][$type] as $dtype => $deps) {
1668
                foreach ($this->_packageInfo['dependencies'][$type] as $dtype => $deps) {
1648
                    if ($dtype == 'pearinstaller' && $nopearinstaller) {
1669
                    if ($dtype == 'pearinstaller' && $nopearinstaller) {
1649
                        continue;
1670
                        continue;
1650
                    }
1671
                    }
1651
                    if (!isset($deps[0])) {
1672
                    if (!isset($deps[0])) {
1652
                        $deps = array($deps);
1673
                        $deps = array($deps);
1653
                    }
1674
                    }
1654
                    foreach ($deps as $dep) {
1675
                    foreach ($deps as $dep) {
1655
                        if (!isset($map[$dtype])) {
1676
                        if (!isset($map[$dtype])) {
1656
                            // no support for arch type
1677
                            // no support for arch type
1657
                            continue;
1678
                            continue;
1658
                        }
1679
                        }
1659
                        if ($dtype == 'pearinstaller') {
1680
                        if ($dtype == 'pearinstaller') {
1660
                            $dep['name'] = 'PEAR';
1681
                            $dep['name'] = 'PEAR';
1661
                            $dep['channel'] = 'pear.php.net';
1682
                            $dep['channel'] = 'pear.php.net';
1662
                        }
1683
                        }
1663
                        $s = array('type' => $map[$dtype]);
1684
                        $s = array('type' => $map[$dtype]);
1664
                        if (isset($dep['channel'])) {
1685
                        if (isset($dep['channel'])) {
1665
                            $s['channel'] = $dep['channel'];
1686
                            $s['channel'] = $dep['channel'];
1666
                        }
1687
                        }
1667
                        if (isset($dep['uri'])) {
1688
                        if (isset($dep['uri'])) {
1668
                            $s['uri'] = $dep['uri'];
1689
                            $s['uri'] = $dep['uri'];
1669
                        }
1690
                        }
1670
                        if (isset($dep['name'])) {
1691
                        if (isset($dep['name'])) {
1671
                            $s['name'] = $dep['name'];
1692
                            $s['name'] = $dep['name'];
1672
                        }
1693
                        }
1673
                        if (isset($dep['conflicts'])) {
1694
                        if (isset($dep['conflicts'])) {
1674
                            $s['rel'] = 'not';
1695
                            $s['rel'] = 'not';
1675
                        } else {
1696
                        } else {
1676
                            if (!isset($dep['min']) &&
1697
                            if (!isset($dep['min']) &&
1677
                                  !isset($dep['max'])) {
1698
                                  !isset($dep['max'])) {
1678
                                $s['rel'] = 'has';
1699
                                $s['rel'] = 'has';
1679
                                $s['optional'] = $optional;
1700
                                $s['optional'] = $optional;
1680
                            } elseif (isset($dep['min']) &&
1701
                            } elseif (isset($dep['min']) &&
1681
                                  isset($dep['max'])) {
1702
                                  isset($dep['max'])) {
1682
                                $s['rel'] = 'ge';
1703
                                $s['rel'] = 'ge';
1683
                                $s1 = $s;
1704
                                $s1 = $s;
1684
                                $s1['rel'] = 'le';
1705
                                $s1['rel'] = 'le';
1685
                                $s['version'] = $dep['min'];
1706
                                $s['version'] = $dep['min'];
1686
                                $s1['version'] = $dep['max'];
1707
                                $s1['version'] = $dep['max'];
1687
                                if (isset($dep['channel'])) {
1708
                                if (isset($dep['channel'])) {
1688
                                    $s1['channel'] = $dep['channel'];
1709
                                    $s1['channel'] = $dep['channel'];
1689
                                }
1710
                                }
1690
                                if ($dtype != 'php') {
1711
                                if ($dtype != 'php') {
1691
                                    $s['name'] = $dep['name'];
1712
                                    $s['name'] = $dep['name'];
1692
                                    $s1['name'] = $dep['name'];
1713
                                    $s1['name'] = $dep['name'];
1693
                                }
1714
                                }
1694
                                $s['optional'] = $optional;
1715
                                $s['optional'] = $optional;
1695
                                $s1['optional'] = $optional;
1716
                                $s1['optional'] = $optional;
1696
                                $ret[] = $s1;
1717
                                $ret[] = $s1;
1697
                            } elseif (isset($dep['min'])) {
1718
                            } elseif (isset($dep['min'])) {
1698
                                if (isset($dep['exclude']) &&
1719
                                if (isset($dep['exclude']) &&
1699
                                      $dep['exclude'] == $dep['min']) {
1720
                                      $dep['exclude'] == $dep['min']) {
1700
                                    $s['rel'] = 'gt';
1721
                                    $s['rel'] = 'gt';
1701
                                } else {
1722
                                } else {
1702
                                    $s['rel'] = 'ge';
1723
                                    $s['rel'] = 'ge';
1703
                                }
1724
                                }
1704
                                $s['version'] = $dep['min'];
1725
                                $s['version'] = $dep['min'];
1705
                                $s['optional'] = $optional;
1726
                                $s['optional'] = $optional;
1706
                                if ($dtype != 'php') {
1727
                                if ($dtype != 'php') {
1707
                                    $s['name'] = $dep['name'];
1728
                                    $s['name'] = $dep['name'];
1708
                                }
1729
                                }
1709
                            } elseif (isset($dep['max'])) {
1730
                            } elseif (isset($dep['max'])) {
1710
                                if (isset($dep['exclude']) &&
1731
                                if (isset($dep['exclude']) &&
1711
                                      $dep['exclude'] == $dep['max']) {
1732
                                      $dep['exclude'] == $dep['max']) {
1712
                                    $s['rel'] = 'lt';
1733
                                    $s['rel'] = 'lt';
1713
                                } else {
1734
                                } else {
1714
                                    $s['rel'] = 'le';
1735
                                    $s['rel'] = 'le';
1715
                                }
1736
                                }
1716
                                $s['version'] = $dep['max'];
1737
                                $s['version'] = $dep['max'];
1717
                                $s['optional'] = $optional;
1738
                                $s['optional'] = $optional;
1718
                                if ($dtype != 'php') {
1739
                                if ($dtype != 'php') {
1719
                                    $s['name'] = $dep['name'];
1740
                                    $s['name'] = $dep['name'];
1720
                                }
1741
                                }
1721
                            }
1742
                            }
1722
                        }
1743
                        }
1723
                        $ret[] = $s;
1744
                        $ret[] = $s;
1724
                    }
1745
                    }
1725
                }
1746
                }
1726
            }
1747
            }
1727
            if (count($ret)) {
1748
            if (count($ret)) {
1728
                return $ret;
1749
                return $ret;
1729
            }
1750
            }
1730
        }
1751
        }
1731
        return false;
1752
        return false;
1732
    }
1753
    }
1733
 
1754
 
1734
    /**
1755
    /**
1735
     * @return php|extsrc|extbin|zendextsrc|zendextbin|bundle|false
1756
     * @return php|extsrc|extbin|zendextsrc|zendextbin|bundle|false
1736
     */
1757
     */
1737
    function getPackageType()
1758
    function getPackageType()
1738
    {
1759
    {
1739
        if (isset($this->_packageInfo['phprelease'])) {
1760
        if (isset($this->_packageInfo['phprelease'])) {
1740
            return 'php';
1761
            return 'php';
1741
        }
1762
        }
1742
        if (isset($this->_packageInfo['extsrcrelease'])) {
1763
        if (isset($this->_packageInfo['extsrcrelease'])) {
1743
            return 'extsrc';
1764
            return 'extsrc';
1744
        }
1765
        }
1745
        if (isset($this->_packageInfo['extbinrelease'])) {
1766
        if (isset($this->_packageInfo['extbinrelease'])) {
1746
            return 'extbin';
1767
            return 'extbin';
1747
        }
1768
        }
1748
        if (isset($this->_packageInfo['zendextsrcrelease'])) {
1769
        if (isset($this->_packageInfo['zendextsrcrelease'])) {
1749
            return 'zendextsrc';
1770
            return 'zendextsrc';
1750
        }
1771
        }
1751
        if (isset($this->_packageInfo['zendextbinrelease'])) {
1772
        if (isset($this->_packageInfo['zendextbinrelease'])) {
1752
            return 'zendextbin';
1773
            return 'zendextbin';
1753
        }
1774
        }
1754
        if (isset($this->_packageInfo['bundle'])) {
1775
        if (isset($this->_packageInfo['bundle'])) {
1755
            return 'bundle';
1776
            return 'bundle';
1756
        }
1777
        }
1757
        return false;
1778
        return false;
1758
    }
1779
    }
1759
 
1780
 
1760
    /**
1781
    /**
1761
     * @return array|false
1782
     * @return array|false
1762
     */
1783
     */
1763
    function getReleases()
1784
    function getReleases()
1764
    {
1785
    {
1765
        $type = $this->getPackageType();
1786
        $type = $this->getPackageType();
1766
        if ($type != 'bundle') {
1787
        if ($type != 'bundle') {
1767
            $type .= 'release';
1788
            $type .= 'release';
1768
        }
1789
        }
1769
        if ($this->getPackageType() && isset($this->_packageInfo[$type])) {
1790
        if ($this->getPackageType() && isset($this->_packageInfo[$type])) {
1770
            return $this->_packageInfo[$type];
1791
            return $this->_packageInfo[$type];
1771
        }
1792
        }
1772
        return false;
1793
        return false;
1773
    }
1794
    }
1774
 
1795
 
1775
    /**
1796
    /**
1776
     * @return array
1797
     * @return array
1777
     */
1798
     */
1778
    function getChangelog()
1799
    function getChangelog()
1779
    {
1800
    {
1780
        if (isset($this->_packageInfo['changelog'])) {
1801
        if (isset($this->_packageInfo['changelog'])) {
1781
            return $this->_packageInfo['changelog'];
1802
            return $this->_packageInfo['changelog'];
1782
        }
1803
        }
1783
        return false;
1804
        return false;
1784
    }
1805
    }
1785
 
1806
 
1786
    function hasDeps()
1807
    function hasDeps()
1787
    {
1808
    {
1788
        return isset($this->_packageInfo['dependencies']);
1809
        return isset($this->_packageInfo['dependencies']);
1789
    }
1810
    }
1790
 
1811
 
1791
    function getPackagexmlVersion()
1812
    function getPackagexmlVersion()
1792
    {
1813
    {
1793
        if (isset($this->_packageInfo['zendextsrcrelease'])) {
1814
        if (isset($this->_packageInfo['zendextsrcrelease'])) {
1794
            return '2.1';
1815
            return '2.1';
1795
        }
1816
        }
1796
        if (isset($this->_packageInfo['zendextbinrelease'])) {
1817
        if (isset($this->_packageInfo['zendextbinrelease'])) {
1797
            return '2.1';
1818
            return '2.1';
1798
        }
1819
        }
1799
        return '2.0';
1820
        return '2.0';
1800
    }
1821
    }
1801
 
1822
 
1802
    /**
1823
    /**
1803
     * @return array|false
1824
     * @return array|false
1804
     */
1825
     */
1805
    function getSourcePackage()
1826
    function getSourcePackage()
1806
    {
1827
    {
1807
        if (isset($this->_packageInfo['extbinrelease']) ||
1828
        if (isset($this->_packageInfo['extbinrelease']) ||
1808
              isset($this->_packageInfo['zendextbinrelease'])) {
1829
              isset($this->_packageInfo['zendextbinrelease'])) {
1809
            return array('channel' => $this->_packageInfo['srcchannel'],
1830
            return array('channel' => $this->_packageInfo['srcchannel'],
1810
                         'package' => $this->_packageInfo['srcpackage']);
1831
                         'package' => $this->_packageInfo['srcpackage']);
1811
        }
1832
        }
1812
        return false;
1833
        return false;
1813
    }
1834
    }
1814
 
1835
 
1815
    function getBundledPackages()
1836
    function getBundledPackages()
1816
    {
1837
    {
1817
        if (isset($this->_packageInfo['bundle'])) {
1838
        if (isset($this->_packageInfo['bundle'])) {
1818
            return $this->_packageInfo['contents']['bundledpackage'];
1839
            return $this->_packageInfo['contents']['bundledpackage'];
1819
        }
1840
        }
1820
        return false;
1841
        return false;
1821
    }
1842
    }
1822
 
1843
 
1823
    function getLastModified()
1844
    function getLastModified()
1824
    {
1845
    {
1825
        if (isset($this->_packageInfo['_lastmodified'])) {
1846
        if (isset($this->_packageInfo['_lastmodified'])) {
1826
            return $this->_packageInfo['_lastmodified'];
1847
            return $this->_packageInfo['_lastmodified'];
1827
        }
1848
        }
1828
        return false;
1849
        return false;
1829
    }
1850
    }
1830
 
1851
 
1831
    /**
1852
    /**
1832
     * Get the contents of a file listed within the package.xml
1853
     * Get the contents of a file listed within the package.xml
1833
     * @param string
1854
     * @param string
1834
     * @return string
1855
     * @return string
1835
     */
1856
     */
1836
    function getFileContents($file)
1857
    function getFileContents($file)
1837
    {
1858
    {
1838
        if ($this->_archiveFile == $this->_packageFile) { // unpacked
1859
        if ($this->_archiveFile == $this->_packageFile) { // unpacked
1839
            $dir = dirname($this->_packageFile);
1860
            $dir = dirname($this->_packageFile);
1840
            $file = $dir . DIRECTORY_SEPARATOR . $file;
1861
            $file = $dir . DIRECTORY_SEPARATOR . $file;
1841
            $file = str_replace(array('/', '\\'),
1862
            $file = str_replace(array('/', '\\'),
1842
                array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $file);
1863
                array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $file);
1843
            if (file_exists($file) && is_readable($file)) {
1864
            if (file_exists($file) && is_readable($file)) {
1844
                return implode('', file($file));
1865
                return implode('', file($file));
1845
            }
1866
            }
1846
        } else { // tgz
1867
        } else { // tgz
1847
            $tar = &new Archive_Tar($this->_archiveFile);
1868
            $tar = new Archive_Tar($this->_archiveFile);
1848
            $tar->pushErrorHandling(PEAR_ERROR_RETURN);
1869
            $tar->pushErrorHandling(PEAR_ERROR_RETURN);
1849
            if ($file != 'package.xml' && $file != 'package2.xml') {
1870
            if ($file != 'package.xml' && $file != 'package2.xml') {
1850
                $file = $this->getPackage() . '-' . $this->getVersion() . '/' . $file;
1871
                $file = $this->getPackage() . '-' . $this->getVersion() . '/' . $file;
1851
            }
1872
            }
1852
            $file = $tar->extractInString($file);
1873
            $file = $tar->extractInString($file);
1853
            $tar->popErrorHandling();
1874
            $tar->popErrorHandling();
1854
            if (PEAR::isError($file)) {
1875
            if (PEAR::isError($file)) {
1855
                return PEAR::raiseError("Cannot locate file '$file' in archive");
1876
                return PEAR::raiseError("Cannot locate file '$file' in archive");
1856
            }
1877
            }
1857
            return $file;
1878
            return $file;
1858
        }
1879
        }
1859
    }
1880
    }
1860
 
1881
 
1861
    function &getRW()
1882
    function &getRW()
1862
    {
1883
    {
1863
        if (!class_exists('PEAR_PackageFile_v2_rw')) {
1884
        if (!class_exists('PEAR_PackageFile_v2_rw')) {
1864
            require_once 'PEAR/PackageFile/v2/rw.php';
1885
            require_once 'PEAR/PackageFile/v2/rw.php';
1865
        }
1886
        }
1866
        $a = new PEAR_PackageFile_v2_rw;
1887
        $a = new PEAR_PackageFile_v2_rw;
1867
        foreach (get_object_vars($this) as $name => $unused) {
1888
        foreach (get_object_vars($this) as $name => $unused) {
1868
            if (!isset($this->$name)) {
1889
            if (!isset($this->$name)) {
1869
                continue;
1890
                continue;
1870
            }
1891
            }
1871
            if ($name == '_config' || $name == '_logger'|| $name == '_registry' ||
1892
            if ($name == '_config' || $name == '_logger'|| $name == '_registry' ||
1872
                  $name == '_stack') {
1893
                  $name == '_stack') {
1873
                $a->$name = &$this->$name;
1894
                $a->$name = &$this->$name;
1874
            } else {
1895
            } else {
1875
                $a->$name = $this->$name;
1896
                $a->$name = $this->$name;
1876
            }
1897
            }
1877
        }
1898
        }
1878
        return $a;
1899
        return $a;
1879
    }
1900
    }
1880
 
1901
 
1881
    function &getDefaultGenerator()
1902
    function &getDefaultGenerator()
1882
    {
1903
    {
1883
        if (!class_exists('PEAR_PackageFile_Generator_v2')) {
1904
        if (!class_exists('PEAR_PackageFile_Generator_v2')) {
1884
            require_once 'PEAR/PackageFile/Generator/v2.php';
1905
            require_once 'PEAR/PackageFile/Generator/v2.php';
1885
        }
1906
        }
1886
        $a = &new PEAR_PackageFile_Generator_v2($this);
1907
        $a = new PEAR_PackageFile_Generator_v2($this);
1887
        return $a;
1908
        return $a;
1888
    }
1909
    }
1889
 
1910
 
1890
    function analyzeSourceCode($file, $string = false)
1911
    function analyzeSourceCode($file, $string = false)
1891
    {
1912
    {
1892
        if (!isset($this->_v2Validator) ||
1913
        if (!isset($this->_v2Validator) ||
1893
              !is_a($this->_v2Validator, 'PEAR_PackageFile_v2_Validator')) {
1914
              !is_a($this->_v2Validator, 'PEAR_PackageFile_v2_Validator')) {
1894
            if (!class_exists('PEAR_PackageFile_v2_Validator')) {
1915
            if (!class_exists('PEAR_PackageFile_v2_Validator')) {
1895
                require_once 'PEAR/PackageFile/v2/Validator.php';
1916
                require_once 'PEAR/PackageFile/v2/Validator.php';
1896
            }
1917
            }
1897
            $this->_v2Validator = new PEAR_PackageFile_v2_Validator;
1918
            $this->_v2Validator = new PEAR_PackageFile_v2_Validator;
1898
        }
1919
        }
1899
        return $this->_v2Validator->analyzeSourceCode($file, $string);
1920
        return $this->_v2Validator->analyzeSourceCode($file, $string);
1900
    }
1921
    }
1901
 
1922
 
1902
    function validate($state = PEAR_VALIDATE_NORMAL)
1923
    function validate($state = PEAR_VALIDATE_NORMAL)
1903
    {
1924
    {
1904
        if (!isset($this->_packageInfo) || !is_array($this->_packageInfo)) {
1925
        if (!isset($this->_packageInfo) || !is_array($this->_packageInfo)) {
1905
            return false;
1926
            return false;
1906
        }
1927
        }
1907
        if (!isset($this->_v2Validator) ||
1928
        if (!isset($this->_v2Validator) ||
1908
              !is_a($this->_v2Validator, 'PEAR_PackageFile_v2_Validator')) {
1929
              !is_a($this->_v2Validator, 'PEAR_PackageFile_v2_Validator')) {
1909
            if (!class_exists('PEAR_PackageFile_v2_Validator')) {
1930
            if (!class_exists('PEAR_PackageFile_v2_Validator')) {
1910
                require_once 'PEAR/PackageFile/v2/Validator.php';
1931
                require_once 'PEAR/PackageFile/v2/Validator.php';
1911
            }
1932
            }
1912
            $this->_v2Validator = new PEAR_PackageFile_v2_Validator;
1933
            $this->_v2Validator = new PEAR_PackageFile_v2_Validator;
1913
        }
1934
        }
1914
        if (isset($this->_packageInfo['xsdversion'])) {
1935
        if (isset($this->_packageInfo['xsdversion'])) {
1915
            unset($this->_packageInfo['xsdversion']);
1936
            unset($this->_packageInfo['xsdversion']);
1916
        }
1937
        }
1917
        return $this->_v2Validator->validate($this, $state);
1938
        return $this->_v2Validator->validate($this, $state);
1918
    }
1939
    }
1919
 
1940
 
1920
    function getTasksNs()
1941
    function getTasksNs()
1921
    {
1942
    {
1922
        if (!isset($this->_tasksNs)) {
1943
        if (!isset($this->_tasksNs)) {
1923
            if (isset($this->_packageInfo['attribs'])) {
1944
            if (isset($this->_packageInfo['attribs'])) {
1924
                foreach ($this->_packageInfo['attribs'] as $name => $value) {
1945
                foreach ($this->_packageInfo['attribs'] as $name => $value) {
1925
                    if ($value == 'http://pear.php.net/dtd/tasks-1.0') {
1946
                    if ($value == 'http://pear.php.net/dtd/tasks-1.0') {
1926
                        $this->_tasksNs = str_replace('xmlns:', '', $name);
1947
                        $this->_tasksNs = str_replace('xmlns:', '', $name);
1927
                        break;
1948
                        break;
1928
                    }
1949
                    }
1929
                }
1950
                }
1930
            }
1951
            }
1931
        }
1952
        }
1932
        return $this->_tasksNs;
1953
        return $this->_tasksNs;
1933
    }
1954
    }
1934
 
1955
 
1935
    /**
1956
    /**
1936
     * Determine whether a task name is a valid task.  Custom tasks may be defined
1957
     * Determine whether a task name is a valid task.  Custom tasks may be defined
1937
     * using subdirectories by putting a "-" in the name, as in <tasks:mycustom-task>
1958
     * using subdirectories by putting a "-" in the name, as in <tasks:mycustom-task>
1938
     *
1959
     *
1939
     * Note that this method will auto-load the task class file and test for the existence
1960
     * Note that this method will auto-load the task class file and test for the existence
1940
     * of the name with "-" replaced by "_" as in PEAR/Task/mycustom/task.php makes class
1961
     * of the name with "-" replaced by "_" as in PEAR/Task/mycustom/task.php makes class
1941
     * PEAR_Task_mycustom_task
1962
     * PEAR_Task_mycustom_task
1942
     * @param string
1963
     * @param string
1943
     * @return boolean
1964
     * @return boolean
1944
     */
1965
     */
1945
    function getTask($task)
1966
    function getTask($task)
1946
    {
1967
    {
1947
        $this->getTasksNs();
1968
        $this->getTasksNs();
1948
        // transform all '-' to '/' and 'tasks:' to '' so tasks:replace becomes replace
1969
        // transform all '-' to '/' and 'tasks:' to '' so tasks:replace becomes replace
1949
        $task = str_replace(array($this->_tasksNs . ':', '-'), array('', ' '), $task);
1970
        $task = str_replace(array($this->_tasksNs . ':', '-'), array('', ' '), $task);
1950
        $task = str_replace(' ', '/', ucwords($task));
1971
        $taskfile = str_replace(' ', '/', ucwords($task));
1951
        $ps = (strtolower(substr(PHP_OS, 0, 3)) == 'win') ? ';' : ':';
1972
        $task = str_replace(array(' ', '/'), '_', ucwords($task));
1952
        foreach (explode($ps, ini_get('include_path')) as $path) {
1973
        if (class_exists("PEAR_Task_$task")) {
1953
            if (file_exists($path . "/PEAR/Task/$task.php")) {
1974
            return "PEAR_Task_$task";
-
 
1975
        }
1954
                include_once "PEAR/Task/$task.php";
1976
        $fp = @fopen("PEAR/Task/$taskfile.php", 'r', true);
1955
                $task = str_replace('/', '_', $task);
1977
        if ($fp) {
1956
                if (class_exists("PEAR_Task_$task")) {
1978
            fclose($fp);
1957
                    return "PEAR_Task_$task";
1979
            require_once "PEAR/Task/$taskfile.php";
1958
                }
1980
            return "PEAR_Task_$task";
1959
            }
-
 
1960
        }
1981
        }
1961
        return false;
1982
        return false;
1962
    }
1983
    }
1963
 
1984
 
1964
    /**
1985
    /**
1965
     * Key-friendly array_splice
1986
     * Key-friendly array_splice
1966
     * @param tagname to splice a value in before
1987
     * @param tagname to splice a value in before
1967
     * @param mixed the value to splice in
1988
     * @param mixed the value to splice in
1968
     * @param string the new tag name
1989
     * @param string the new tag name
1969
     */
1990
     */
1970
    function _ksplice($array, $key, $value, $newkey)
1991
    function _ksplice($array, $key, $value, $newkey)
1971
    {
1992
    {
1972
        $offset = array_search($key, array_keys($array));
1993
        $offset = array_search($key, array_keys($array));
1973
        $after = array_slice($array, $offset);
1994
        $after = array_slice($array, $offset);
1974
        $before = array_slice($array, 0, $offset);
1995
        $before = array_slice($array, 0, $offset);
1975
        $before[$newkey] = $value;
1996
        $before[$newkey] = $value;
1976
        return array_merge($before, $after);
1997
        return array_merge($before, $after);
1977
    }
1998
    }
1978
 
1999
 
1979
    /**
2000
    /**
1980
     * @param array a list of possible keys, in the order they may occur
2001
     * @param array a list of possible keys, in the order they may occur
1981
     * @param mixed contents of the new package.xml tag
2002
     * @param mixed contents of the new package.xml tag
1982
     * @param string tag name
2003
     * @param string tag name
1983
     * @access private
2004
     * @access private
1984
     */
2005
     */
1985
    function _insertBefore($array, $keys, $contents, $newkey)
2006
    function _insertBefore($array, $keys, $contents, $newkey)
1986
    {
2007
    {
1987
        foreach ($keys as $key) {
2008
        foreach ($keys as $key) {
1988
            if (isset($array[$key])) {
2009
            if (isset($array[$key])) {
1989
                return $array = $this->_ksplice($array, $key, $contents, $newkey);
2010
                return $array = $this->_ksplice($array, $key, $contents, $newkey);
1990
            }
2011
            }
1991
        }
2012
        }
1992
        $array[$newkey] = $contents;
2013
        $array[$newkey] = $contents;
1993
        return $array;
2014
        return $array;
1994
    }
2015
    }
1995
 
2016
 
1996
    /**
2017
    /**
1997
     * @param subsection of {@link $_packageInfo}
2018
     * @param subsection of {@link $_packageInfo}
1998
     * @param array|string tag contents
2019
     * @param array|string tag contents
1999
     * @param array format:
2020
     * @param array format:
2000
     * <pre>
2021
     * <pre>
2001
     * array(
2022
     * array(
2002
     *   tagname => array(list of tag names that follow this one),
2023
     *   tagname => array(list of tag names that follow this one),
2003
     *   childtagname => array(list of child tag names that follow this one),
2024
     *   childtagname => array(list of child tag names that follow this one),
2004
     * )
2025
     * )
2005
     * </pre>
2026
     * </pre>
2006
     *
2027
     *
2007
     * This allows construction of nested tags
2028
     * This allows construction of nested tags
2008
     * @access private
2029
     * @access private
2009
     */
2030
     */
2010
    function _mergeTag($manip, $contents, $order)
2031
    function _mergeTag($manip, $contents, $order)
2011
    {
2032
    {
2012
        if (count($order)) {
2033
        if (count($order)) {
2013
            foreach ($order as $tag => $curorder) {
2034
            foreach ($order as $tag => $curorder) {
2014
                if (!isset($manip[$tag])) {
2035
                if (!isset($manip[$tag])) {
2015
                    // ensure that the tag is set up
2036
                    // ensure that the tag is set up
2016
                    $manip = $this->_insertBefore($manip, $curorder, array(), $tag);
2037
                    $manip = $this->_insertBefore($manip, $curorder, array(), $tag);
2017
                }
2038
                }
2018
                if (count($order) > 1) {
2039
                if (count($order) > 1) {
2019
                    $manip[$tag] = $this->_mergeTag($manip[$tag], $contents, array_slice($order, 1));
2040
                    $manip[$tag] = $this->_mergeTag($manip[$tag], $contents, array_slice($order, 1));
2020
                    return $manip;
2041
                    return $manip;
2021
                }
2042
                }
2022
            }
2043
            }
2023
        } else {
2044
        } else {
2024
            return $manip;
2045
            return $manip;
2025
        }
2046
        }
2026
        if (is_array($manip[$tag]) && !empty($manip[$tag]) && isset($manip[$tag][0])) {
2047
        if (is_array($manip[$tag]) && !empty($manip[$tag]) && isset($manip[$tag][0])) {
2027
            $manip[$tag][] = $contents;
2048
            $manip[$tag][] = $contents;
2028
        } else {
2049
        } else {
2029
            if (!count($manip[$tag])) {
2050
            if (!count($manip[$tag])) {
2030
                $manip[$tag] = $contents;
2051
                $manip[$tag] = $contents;
2031
            } else {
2052
            } else {
2032
                $manip[$tag] = array($manip[$tag]);
2053
                $manip[$tag] = array($manip[$tag]);
2033
                $manip[$tag][] = $contents;
2054
                $manip[$tag][] = $contents;
2034
            }
2055
            }
2035
        }
2056
        }
2036
        return $manip;
2057
        return $manip;
2037
    }
2058
    }
2038
}
2059
}
2039
?>
2060
?>