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_v1, package.xml version 1.0
3
 * PEAR_PackageFile_v1, package.xml version 1.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: v1.php,v 1.72 2006/10/31 02:54:41 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
/**
20
/**
28
 * Error code if parsing is attempted with no xml extension
21
 * Error code if parsing is attempted with no xml extension
29
 */
22
 */
30
define('PEAR_PACKAGEFILE_ERROR_NO_XML_EXT', 3);
23
define('PEAR_PACKAGEFILE_ERROR_NO_XML_EXT', 3);
31
 
24
 
32
/**
25
/**
33
 * Error code if creating the xml parser resource fails
26
 * Error code if creating the xml parser resource fails
34
 */
27
 */
35
define('PEAR_PACKAGEFILE_ERROR_CANT_MAKE_PARSER', 4);
28
define('PEAR_PACKAGEFILE_ERROR_CANT_MAKE_PARSER', 4);
36
 
29
 
37
/**
30
/**
38
 * Error code used for all sax xml parsing errors
31
 * Error code used for all sax xml parsing errors
39
 */
32
 */
40
define('PEAR_PACKAGEFILE_ERROR_PARSER_ERROR', 5);
33
define('PEAR_PACKAGEFILE_ERROR_PARSER_ERROR', 5);
41
 
34
 
42
/**
35
/**
43
 * Error code used when there is no name
36
 * Error code used when there is no name
44
 */
37
 */
45
define('PEAR_PACKAGEFILE_ERROR_NO_NAME', 6);
38
define('PEAR_PACKAGEFILE_ERROR_NO_NAME', 6);
46
 
39
 
47
/**
40
/**
48
 * Error code when a package name is not valid
41
 * Error code when a package name is not valid
49
 */
42
 */
50
define('PEAR_PACKAGEFILE_ERROR_INVALID_NAME', 7);
43
define('PEAR_PACKAGEFILE_ERROR_INVALID_NAME', 7);
51
 
44
 
52
/**
45
/**
53
 * Error code used when no summary is parsed
46
 * Error code used when no summary is parsed
54
 */
47
 */
55
define('PEAR_PACKAGEFILE_ERROR_NO_SUMMARY', 8);
48
define('PEAR_PACKAGEFILE_ERROR_NO_SUMMARY', 8);
56
 
49
 
57
/**
50
/**
58
 * Error code for summaries that are more than 1 line
51
 * Error code for summaries that are more than 1 line
59
 */
52
 */
60
define('PEAR_PACKAGEFILE_ERROR_MULTILINE_SUMMARY', 9);
53
define('PEAR_PACKAGEFILE_ERROR_MULTILINE_SUMMARY', 9);
61
 
54
 
62
/**
55
/**
63
 * Error code used when no description is present
56
 * Error code used when no description is present
64
 */
57
 */
65
define('PEAR_PACKAGEFILE_ERROR_NO_DESCRIPTION', 10);
58
define('PEAR_PACKAGEFILE_ERROR_NO_DESCRIPTION', 10);
66
 
59
 
67
/**
60
/**
68
 * Error code used when no license is present
61
 * Error code used when no license is present
69
 */
62
 */
70
define('PEAR_PACKAGEFILE_ERROR_NO_LICENSE', 11);
63
define('PEAR_PACKAGEFILE_ERROR_NO_LICENSE', 11);
71
 
64
 
72
/**
65
/**
73
 * Error code used when a <version> version number is not present
66
 * Error code used when a <version> version number is not present
74
 */
67
 */
75
define('PEAR_PACKAGEFILE_ERROR_NO_VERSION', 12);
68
define('PEAR_PACKAGEFILE_ERROR_NO_VERSION', 12);
76
 
69
 
77
/**
70
/**
78
 * Error code used when a <version> version number is invalid
71
 * Error code used when a <version> version number is invalid
79
 */
72
 */
80
define('PEAR_PACKAGEFILE_ERROR_INVALID_VERSION', 13);
73
define('PEAR_PACKAGEFILE_ERROR_INVALID_VERSION', 13);
81
 
74
 
82
/**
75
/**
83
 * Error code when release state is missing
76
 * Error code when release state is missing
84
 */
77
 */
85
define('PEAR_PACKAGEFILE_ERROR_NO_STATE', 14);
78
define('PEAR_PACKAGEFILE_ERROR_NO_STATE', 14);
86
 
79
 
87
/**
80
/**
88
 * Error code when release state is invalid
81
 * Error code when release state is invalid
89
 */
82
 */
90
define('PEAR_PACKAGEFILE_ERROR_INVALID_STATE', 15);
83
define('PEAR_PACKAGEFILE_ERROR_INVALID_STATE', 15);
91
 
84
 
92
/**
85
/**
93
 * Error code when release state is missing
86
 * Error code when release state is missing
94
 */
87
 */
95
define('PEAR_PACKAGEFILE_ERROR_NO_DATE', 16);
88
define('PEAR_PACKAGEFILE_ERROR_NO_DATE', 16);
96
 
89
 
97
/**
90
/**
98
 * Error code when release state is invalid
91
 * Error code when release state is invalid
99
 */
92
 */
100
define('PEAR_PACKAGEFILE_ERROR_INVALID_DATE', 17);
93
define('PEAR_PACKAGEFILE_ERROR_INVALID_DATE', 17);
101
 
94
 
102
/**
95
/**
103
 * Error code when no release notes are found
96
 * Error code when no release notes are found
104
 */
97
 */
105
define('PEAR_PACKAGEFILE_ERROR_NO_NOTES', 18);
98
define('PEAR_PACKAGEFILE_ERROR_NO_NOTES', 18);
106
 
99
 
107
/**
100
/**
108
 * Error code when no maintainers are found
101
 * Error code when no maintainers are found
109
 */
102
 */
110
define('PEAR_PACKAGEFILE_ERROR_NO_MAINTAINERS', 19);
103
define('PEAR_PACKAGEFILE_ERROR_NO_MAINTAINERS', 19);
111
 
104
 
112
/**
105
/**
113
 * Error code when a maintainer has no handle
106
 * Error code when a maintainer has no handle
114
 */
107
 */
115
define('PEAR_PACKAGEFILE_ERROR_NO_MAINTHANDLE', 20);
108
define('PEAR_PACKAGEFILE_ERROR_NO_MAINTHANDLE', 20);
116
 
109
 
117
/**
110
/**
118
 * Error code when a maintainer has no handle
111
 * Error code when a maintainer has no handle
119
 */
112
 */
120
define('PEAR_PACKAGEFILE_ERROR_NO_MAINTROLE', 21);
113
define('PEAR_PACKAGEFILE_ERROR_NO_MAINTROLE', 21);
121
 
114
 
122
/**
115
/**
123
 * Error code when a maintainer has no name
116
 * Error code when a maintainer has no name
124
 */
117
 */
125
define('PEAR_PACKAGEFILE_ERROR_NO_MAINTNAME', 22);
118
define('PEAR_PACKAGEFILE_ERROR_NO_MAINTNAME', 22);
126
 
119
 
127
/**
120
/**
128
 * Error code when a maintainer has no email
121
 * Error code when a maintainer has no email
129
 */
122
 */
130
define('PEAR_PACKAGEFILE_ERROR_NO_MAINTEMAIL', 23);
123
define('PEAR_PACKAGEFILE_ERROR_NO_MAINTEMAIL', 23);
131
 
124
 
132
/**
125
/**
133
 * Error code when a maintainer has no handle
126
 * Error code when a maintainer has no handle
134
 */
127
 */
135
define('PEAR_PACKAGEFILE_ERROR_INVALID_MAINTROLE', 24);
128
define('PEAR_PACKAGEFILE_ERROR_INVALID_MAINTROLE', 24);
136
 
129
 
137
/**
130
/**
138
 * Error code when a dependency is not a PHP dependency, but has no name
131
 * Error code when a dependency is not a PHP dependency, but has no name
139
 */
132
 */
140
define('PEAR_PACKAGEFILE_ERROR_NO_DEPNAME', 25);
133
define('PEAR_PACKAGEFILE_ERROR_NO_DEPNAME', 25);
141
 
134
 
142
/**
135
/**
143
 * Error code when a dependency has no type (pkg, php, etc.)
136
 * Error code when a dependency has no type (pkg, php, etc.)
144
 */
137
 */
145
define('PEAR_PACKAGEFILE_ERROR_NO_DEPTYPE', 26);
138
define('PEAR_PACKAGEFILE_ERROR_NO_DEPTYPE', 26);
146
 
139
 
147
/**
140
/**
148
 * Error code when a dependency has no relation (lt, ge, has, etc.)
141
 * Error code when a dependency has no relation (lt, ge, has, etc.)
149
 */
142
 */
150
define('PEAR_PACKAGEFILE_ERROR_NO_DEPREL', 27);
143
define('PEAR_PACKAGEFILE_ERROR_NO_DEPREL', 27);
151
 
144
 
152
/**
145
/**
153
 * Error code when a dependency is not a 'has' relation, but has no version
146
 * Error code when a dependency is not a 'has' relation, but has no version
154
 */
147
 */
155
define('PEAR_PACKAGEFILE_ERROR_NO_DEPVERSION', 28);
148
define('PEAR_PACKAGEFILE_ERROR_NO_DEPVERSION', 28);
156
 
149
 
157
/**
150
/**
158
 * Error code when a dependency has an invalid relation
151
 * Error code when a dependency has an invalid relation
159
 */
152
 */
160
define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPREL', 29);
153
define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPREL', 29);
161
 
154
 
162
/**
155
/**
163
 * Error code when a dependency has an invalid type
156
 * Error code when a dependency has an invalid type
164
 */
157
 */
165
define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPTYPE', 30);
158
define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPTYPE', 30);
166
 
159
 
167
/**
160
/**
168
 * Error code when a dependency has an invalid optional option
161
 * Error code when a dependency has an invalid optional option
169
 */
162
 */
170
define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPOPTIONAL', 31);
163
define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPOPTIONAL', 31);
171
 
164
 
172
/**
165
/**
173
 * Error code when a dependency is a pkg dependency, and has an invalid package name
166
 * Error code when a dependency is a pkg dependency, and has an invalid package name
174
 */
167
 */
175
define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPNAME', 32);
168
define('PEAR_PACKAGEFILE_ERROR_INVALID_DEPNAME', 32);
176
 
169
 
177
/**
170
/**
178
 * Error code when a dependency has a channel="foo" attribute, and foo is not a registered channel
171
 * Error code when a dependency has a channel="foo" attribute, and foo is not a registered channel
179
 */
172
 */
180
define('PEAR_PACKAGEFILE_ERROR_UNKNOWN_DEPCHANNEL', 33);
173
define('PEAR_PACKAGEFILE_ERROR_UNKNOWN_DEPCHANNEL', 33);
181
 
174
 
182
/**
175
/**
183
 * Error code when rel="has" and version attribute is present.
176
 * Error code when rel="has" and version attribute is present.
184
 */
177
 */
185
define('PEAR_PACKAGEFILE_ERROR_DEPVERSION_IGNORED', 34);
178
define('PEAR_PACKAGEFILE_ERROR_DEPVERSION_IGNORED', 34);
186
 
179
 
187
/**
180
/**
188
 * Error code when type="php" and dependency name is present
181
 * Error code when type="php" and dependency name is present
189
 */
182
 */
190
define('PEAR_PACKAGEFILE_ERROR_DEPNAME_IGNORED', 35);
183
define('PEAR_PACKAGEFILE_ERROR_DEPNAME_IGNORED', 35);
191
 
184
 
192
/**
185
/**
193
 * Error code when a configure option has no name
186
 * Error code when a configure option has no name
194
 */
187
 */
195
define('PEAR_PACKAGEFILE_ERROR_NO_CONFNAME', 36);
188
define('PEAR_PACKAGEFILE_ERROR_NO_CONFNAME', 36);
196
 
189
 
197
/**
190
/**
198
 * Error code when a configure option has no name
191
 * Error code when a configure option has no name
199
 */
192
 */
200
define('PEAR_PACKAGEFILE_ERROR_NO_CONFPROMPT', 37);
193
define('PEAR_PACKAGEFILE_ERROR_NO_CONFPROMPT', 37);
201
 
194
 
202
/**
195
/**
203
 * Error code when a file in the filelist has an invalid role
196
 * Error code when a file in the filelist has an invalid role
204
 */
197
 */
205
define('PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE', 38);
198
define('PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE', 38);
206
 
199
 
207
/**
200
/**
208
 * Error code when a file in the filelist has no role
201
 * Error code when a file in the filelist has no role
209
 */
202
 */
210
define('PEAR_PACKAGEFILE_ERROR_NO_FILEROLE', 39);
203
define('PEAR_PACKAGEFILE_ERROR_NO_FILEROLE', 39);
211
 
204
 
212
/**
205
/**
213
 * Error code when analyzing a php source file that has parse errors
206
 * Error code when analyzing a php source file that has parse errors
214
 */
207
 */
215
define('PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE', 40);
208
define('PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE', 40);
216
 
209
 
217
/**
210
/**
218
 * Error code when analyzing a php source file reveals a source element
211
 * Error code when analyzing a php source file reveals a source element
219
 * without a package name prefix
212
 * without a package name prefix
220
 */
213
 */
221
define('PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX', 41);
214
define('PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX', 41);
222
 
215
 
223
/**
216
/**
224
 * Error code when an unknown channel is specified
217
 * Error code when an unknown channel is specified
225
 */
218
 */
226
define('PEAR_PACKAGEFILE_ERROR_UNKNOWN_CHANNEL', 42);
219
define('PEAR_PACKAGEFILE_ERROR_UNKNOWN_CHANNEL', 42);
227
 
220
 
228
/**
221
/**
229
 * Error code when no files are found in the filelist
222
 * Error code when no files are found in the filelist
230
 */
223
 */
231
define('PEAR_PACKAGEFILE_ERROR_NO_FILES', 43);
224
define('PEAR_PACKAGEFILE_ERROR_NO_FILES', 43);
232
 
225
 
233
/**
226
/**
234
 * Error code when a file is not valid php according to _analyzeSourceCode()
227
 * Error code when a file is not valid php according to _analyzeSourceCode()
235
 */
228
 */
236
define('PEAR_PACKAGEFILE_ERROR_INVALID_FILE', 44);
229
define('PEAR_PACKAGEFILE_ERROR_INVALID_FILE', 44);
237
 
230
 
238
/**
231
/**
239
 * Error code when the channel validator returns an error or warning
232
 * Error code when the channel validator returns an error or warning
240
 */
233
 */
241
define('PEAR_PACKAGEFILE_ERROR_CHANNELVAL', 45);
234
define('PEAR_PACKAGEFILE_ERROR_CHANNELVAL', 45);
242
 
235
 
243
/**
236
/**
244
 * Error code when a php5 package is packaged in php4 (analysis doesn't work)
237
 * Error code when a php5 package is packaged in php4 (analysis doesn't work)
245
 */
238
 */
246
define('PEAR_PACKAGEFILE_ERROR_PHP5', 46);
239
define('PEAR_PACKAGEFILE_ERROR_PHP5', 46);
247
 
240
 
248
/**
241
/**
249
 * Error code when a file is listed in package.xml but does not exist
242
 * Error code when a file is listed in package.xml but does not exist
250
 */
243
 */
251
define('PEAR_PACKAGEFILE_ERROR_FILE_NOTFOUND', 47);
244
define('PEAR_PACKAGEFILE_ERROR_FILE_NOTFOUND', 47);
252
 
245
 
253
/**
246
/**
254
 * Error code when a <dep type="php" rel="not"... is encountered (use rel="ne")
247
 * Error code when a <dep type="php" rel="not"... is encountered (use rel="ne")
255
 */
248
 */
256
define('PEAR_PACKAGEFILE_PHP_NO_NOT', 48);
249
define('PEAR_PACKAGEFILE_PHP_NO_NOT', 48);
257
 
250
 
258
/**
251
/**
259
 * Error code when a package.xml contains non-ISO-8859-1 characters
252
 * Error code when a package.xml contains non-ISO-8859-1 characters
260
 */
253
 */
261
define('PEAR_PACKAGEFILE_ERROR_NON_ISO_CHARS', 49);
254
define('PEAR_PACKAGEFILE_ERROR_NON_ISO_CHARS', 49);
262
 
255
 
263
/**
256
/**
264
 * Error code when a dependency is not a 'has' relation, but has no version
257
 * Error code when a dependency is not a 'has' relation, but has no version
265
 */
258
 */
266
define('PEAR_PACKAGEFILE_ERROR_NO_DEPPHPVERSION', 50);
259
define('PEAR_PACKAGEFILE_ERROR_NO_DEPPHPVERSION', 50);
267
 
260
 
268
/**
261
/**
269
 * Error code when a package has no lead developer
262
 * Error code when a package has no lead developer
270
 */
263
 */
271
define('PEAR_PACKAGEFILE_ERROR_NO_LEAD', 51);
264
define('PEAR_PACKAGEFILE_ERROR_NO_LEAD', 51);
272
 
265
 
273
/**
266
/**
274
 * Error code when a filename begins with "."
267
 * Error code when a filename begins with "."
275
 */
268
 */
276
define('PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME', 52);
269
define('PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME', 52);
277
/**
270
/**
278
 * package.xml encapsulator
271
 * package.xml encapsulator
279
 * @category   pear
272
 * @category   pear
280
 * @package    PEAR
273
 * @package    PEAR
281
 * @author     Greg Beaver <cellog@php.net>
274
 * @author     Greg Beaver <cellog@php.net>
282
 * @copyright  1997-2006 The PHP Group
275
 * @copyright  1997-2009 The Authors
283
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
276
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
284
 * @version    Release: 1.5.1
277
 * @version    Release: 1.10.1
285
 * @link       http://pear.php.net/package/PEAR
278
 * @link       http://pear.php.net/package/PEAR
286
 * @since      Class available since Release 1.4.0a1
279
 * @since      Class available since Release 1.4.0a1
287
 */
280
 */
288
class PEAR_PackageFile_v1
281
class PEAR_PackageFile_v1
289
{
282
{
290
    /**
283
    /**
291
     * @access private
284
     * @access private
292
     * @var PEAR_ErrorStack
285
     * @var PEAR_ErrorStack
293
     * @access private
286
     * @access private
294
     */
287
     */
295
    var $_stack;
288
    var $_stack;
296
 
289
 
297
    /**
290
    /**
298
     * A registry object, used to access the package name validation regex for non-standard channels
291
     * A registry object, used to access the package name validation regex for non-standard channels
299
     * @var PEAR_Registry
292
     * @var PEAR_Registry
300
     * @access private
293
     * @access private
301
     */
294
     */
302
    var $_registry;
295
    var $_registry;
303
 
296
 
304
    /**
297
    /**
305
     * An object that contains a log method that matches PEAR_Common::log's signature
298
     * An object that contains a log method that matches PEAR_Common::log's signature
306
     * @var object
299
     * @var object
307
     * @access private
300
     * @access private
308
     */
301
     */
309
    var $_logger;
302
    var $_logger;
310
 
303
 
311
    /**
304
    /**
312
     * Parsed package information
305
     * Parsed package information
313
     * @var array
306
     * @var array
314
     * @access private
307
     * @access private
315
     */
308
     */
316
    var $_packageInfo;
309
    var $_packageInfo;
317
 
310
 
318
    /**
311
    /**
319
     * path to package.xml
312
     * path to package.xml
320
     * @var string
313
     * @var string
321
     * @access private
314
     * @access private
322
     */
315
     */
323
    var $_packageFile;
316
    var $_packageFile;
324
 
317
 
325
    /**
318
    /**
326
     * path to package .tgz or false if this is a local/extracted package.xml
319
     * path to package .tgz or false if this is a local/extracted package.xml
327
     * @var string
320
     * @var string
328
     * @access private
321
     * @access private
329
     */
322
     */
330
    var $_archiveFile;
323
    var $_archiveFile;
331
 
324
 
332
    /**
325
    /**
333
     * @var int
326
     * @var int
334
     * @access private
327
     * @access private
335
     */
328
     */
336
    var $_isValid = 0;
329
    var $_isValid = 0;
337
 
330
 
338
    /**
331
    /**
339
     * Determines whether this packagefile was initialized only with partial package info
332
     * Determines whether this packagefile was initialized only with partial package info
340
     *
333
     *
341
     * If this package file was constructed via parsing REST, it will only contain
334
     * If this package file was constructed via parsing REST, it will only contain
342
     *
335
     *
343
     * - package name
336
     * - package name
344
     * - channel name
337
     * - channel name
345
     * - dependencies 
338
     * - dependencies 
346
     * @var boolean
339
     * @var boolean
347
     * @access private
340
     * @access private
348
     */
341
     */
349
    var $_incomplete = true;
342
    var $_incomplete = true;
350
 
343
 
351
    /**
344
    /**
352
     * @param bool determines whether to return a PEAR_Error object, or use the PEAR_ErrorStack
345
     * @param bool determines whether to return a PEAR_Error object, or use the PEAR_ErrorStack
353
     * @param string Name of Error Stack class to use.
346
     * @param string Name of Error Stack class to use.
354
     */
347
     */
355
    function PEAR_PackageFile_v1()
348
    function __construct()
356
    {
349
    {
357
        $this->_stack = &new PEAR_ErrorStack('PEAR_PackageFile_v1');
350
        $this->_stack = new PEAR_ErrorStack('PEAR_PackageFile_v1');
358
        $this->_stack->setErrorMessageTemplate($this->_getErrorMessage());
351
        $this->_stack->setErrorMessageTemplate($this->_getErrorMessage());
359
        $this->_isValid = 0;
352
        $this->_isValid = 0;
360
    }
353
    }
361
 
354
 
362
    function installBinary($installer)
355
    function installBinary($installer)
363
    {
356
    {
364
        return false;
357
        return false;
365
    }
358
    }
366
 
359
 
367
    function isExtension($name)
360
    function isExtension($name)
368
    {
361
    {
369
        return false;
362
        return false;
370
    }
363
    }
371
 
364
 
372
    function setConfig(&$config)
365
    function setConfig(&$config)
373
    {
366
    {
374
        $this->_config = &$config;
367
        $this->_config = &$config;
375
        $this->_registry = &$config->getRegistry();
368
        $this->_registry = &$config->getRegistry();
376
    }
369
    }
377
 
370
 
378
    function setRequestedGroup()
371
    function setRequestedGroup()
379
    {
372
    {
380
        // placeholder
373
        // placeholder
381
    }
374
    }
382
 
375
 
383
    /**
376
    /**
384
     * For saving in the registry.
377
     * For saving in the registry.
385
     *
378
     *
386
     * Set the last version that was installed
379
     * Set the last version that was installed
387
     * @param string
380
     * @param string
388
     */
381
     */
389
    function setLastInstalledVersion($version)
382
    function setLastInstalledVersion($version)
390
    {
383
    {
391
        $this->_packageInfo['_lastversion'] = $version;
384
        $this->_packageInfo['_lastversion'] = $version;
392
    }
385
    }
393
 
386
 
394
    /**
387
    /**
395
     * @return string|false
388
     * @return string|false
396
     */
389
     */
397
    function getLastInstalledVersion()
390
    function getLastInstalledVersion()
398
    {
391
    {
399
        if (isset($this->_packageInfo['_lastversion'])) {
392
        if (isset($this->_packageInfo['_lastversion'])) {
400
            return $this->_packageInfo['_lastversion'];
393
            return $this->_packageInfo['_lastversion'];
401
        }
394
        }
402
        return false;
395
        return false;
403
    }
396
    }
404
 
397
 
405
    function getInstalledBinary()
398
    function getInstalledBinary()
406
    {
399
    {
407
        return false;
400
        return false;
408
    }
401
    }
409
 
402
 
410
    function listPostinstallScripts()
403
    function listPostinstallScripts()
411
    {
404
    {
412
        return false;
405
        return false;
413
    }
406
    }
414
 
407
 
415
    function initPostinstallScripts()
408
    function initPostinstallScripts()
416
    {
409
    {
417
        return false;
410
        return false;
418
    }
411
    }
419
 
412
 
420
    function setLogger(&$logger)
413
    function setLogger(&$logger)
421
    {
414
    {
422
        if ($logger && (!is_object($logger) || !method_exists($logger, 'log'))) {
415
        if ($logger && (!is_object($logger) || !method_exists($logger, 'log'))) {
423
            return PEAR::raiseError('Logger must be compatible with PEAR_Common::log');
416
            return PEAR::raiseError('Logger must be compatible with PEAR_Common::log');
424
        }
417
        }
425
        $this->_logger = &$logger;
418
        $this->_logger = &$logger;
426
    }
419
    }
427
 
420
 
428
    function setPackagefile($file, $archive = false)
421
    function setPackagefile($file, $archive = false)
429
    {
422
    {
430
        $this->_packageFile = $file;
423
        $this->_packageFile = $file;
431
        $this->_archiveFile = $archive ? $archive : $file;
424
        $this->_archiveFile = $archive ? $archive : $file;
432
    }
425
    }
433
 
426
 
434
    function getPackageFile()
427
    function getPackageFile()
435
    {
428
    {
436
        return isset($this->_packageFile) ? $this->_packageFile : false;
429
        return isset($this->_packageFile) ? $this->_packageFile : false;
437
    }
430
    }
438
 
431
 
439
    function getPackageType()
432
    function getPackageType()
440
    {
433
    {
441
        return 'php';
434
        return 'php';
442
    }
435
    }
443
 
436
 
444
    function getArchiveFile()
437
    function getArchiveFile()
445
    {
438
    {
446
        return $this->_archiveFile;
439
        return $this->_archiveFile;
447
    }
440
    }
448
 
441
 
449
    function packageInfo($field)
442
    function packageInfo($field)
450
    {
443
    {
451
        if (!is_string($field) || empty($field) ||
444
        if (!is_string($field) || empty($field) ||
452
            !isset($this->_packageInfo[$field])) {
445
            !isset($this->_packageInfo[$field])) {
453
            return false;
446
            return false;
454
        }
447
        }
455
        return $this->_packageInfo[$field];
448
        return $this->_packageInfo[$field];
456
    }
449
    }
457
 
450
 
458
    function setDirtree($path)
451
    function setDirtree($path)
459
    {
452
    {
460
        if (!isset($this->_packageInfo['dirtree'])) {
453
        if (!isset($this->_packageInfo['dirtree'])) {
461
            $this->_packageInfo['dirtree'] = array();
454
            $this->_packageInfo['dirtree'] = array();
462
        }
455
        }
463
        $this->_packageInfo['dirtree'][$path] = true;
456
        $this->_packageInfo['dirtree'][$path] = true;
464
    }
457
    }
465
 
458
 
466
    function getDirtree()
459
    function getDirtree()
467
    {
460
    {
468
        if (isset($this->_packageInfo['dirtree']) && count($this->_packageInfo['dirtree'])) {
461
        if (isset($this->_packageInfo['dirtree']) && count($this->_packageInfo['dirtree'])) {
469
            return $this->_packageInfo['dirtree'];
462
            return $this->_packageInfo['dirtree'];
470
        }
463
        }
471
        return false;
464
        return false;
472
    }
465
    }
473
 
466
 
474
    function resetDirtree()
467
    function resetDirtree()
475
    {
468
    {
476
        unset($this->_packageInfo['dirtree']);
469
        unset($this->_packageInfo['dirtree']);
477
    }
470
    }
478
 
471
 
479
    function fromArray($pinfo)
472
    function fromArray($pinfo)
480
    {
473
    {
481
        $this->_incomplete = false;
474
        $this->_incomplete = false;
482
        $this->_packageInfo = $pinfo;
475
        $this->_packageInfo = $pinfo;
483
    }
476
    }
484
 
477
 
485
    function isIncomplete()
478
    function isIncomplete()
486
    {
479
    {
487
        return $this->_incomplete;
480
        return $this->_incomplete;
488
    }
481
    }
489
 
482
 
490
    function getChannel()
483
    function getChannel()
491
    {
484
    {
492
        return 'pear.php.net';
485
        return 'pear.php.net';
493
    }
486
    }
494
 
487
 
495
    function getUri()
488
    function getUri()
496
    {
489
    {
497
        return false;
490
        return false;
498
    }
491
    }
499
 
492
 
500
    function getTime()
493
    function getTime()
501
    {
494
    {
502
        return false;
495
        return false;
503
    }
496
    }
504
 
497
 
505
    function getExtends()
498
    function getExtends()
506
    {
499
    {
507
        if (isset($this->_packageInfo['extends'])) {
500
        if (isset($this->_packageInfo['extends'])) {
508
            return $this->_packageInfo['extends'];
501
            return $this->_packageInfo['extends'];
509
        }
502
        }
510
        return false;
503
        return false;
511
    }
504
    }
512
 
505
 
513
    /**
506
    /**
514
     * @return array
507
     * @return array
515
     */
508
     */
516
    function toArray()
509
    function toArray()
517
    {
510
    {
518
        if (!$this->validate(PEAR_VALIDATE_NORMAL)) {
511
        if (!$this->validate(PEAR_VALIDATE_NORMAL)) {
519
            return false;
512
            return false;
520
        }
513
        }
521
        return $this->getArray();
514
        return $this->getArray();
522
    }
515
    }
523
 
516
 
524
    function getArray()
517
    function getArray()
525
    {
518
    {
526
        return $this->_packageInfo;
519
        return $this->_packageInfo;
527
    }
520
    }
528
 
521
 
529
    function getName()
522
    function getName()
530
    {
523
    {
531
        return $this->getPackage();
524
        return $this->getPackage();
532
    }
525
    }
533
 
526
 
534
    function getPackage()
527
    function getPackage()
535
    {
528
    {
536
        if (isset($this->_packageInfo['package'])) {
529
        if (isset($this->_packageInfo['package'])) {
537
            return $this->_packageInfo['package'];
530
            return $this->_packageInfo['package'];
538
        }
531
        }
539
        return false;
532
        return false;
540
    }
533
    }
541
 
534
 
542
    /**
535
    /**
543
     * WARNING - don't use this unless you know what you are doing
536
     * WARNING - don't use this unless you know what you are doing
544
     */
537
     */
545
    function setRawPackage($package)
538
    function setRawPackage($package)
546
    {
539
    {
547
        $this->_packageInfo['package'] = $package;
540
        $this->_packageInfo['package'] = $package;
548
    }
541
    }
549
 
542
 
550
    function setPackage($package)
543
    function setPackage($package)
551
    {
544
    {
552
        $this->_packageInfo['package'] = $package;
545
        $this->_packageInfo['package'] = $package;
553
        $this->_isValid = false;
546
        $this->_isValid = false;
554
    }
547
    }
555
 
548
 
556
    function getVersion()
549
    function getVersion()
557
    {
550
    {
558
        if (isset($this->_packageInfo['version'])) {
551
        if (isset($this->_packageInfo['version'])) {
559
            return $this->_packageInfo['version'];
552
            return $this->_packageInfo['version'];
560
        }
553
        }
561
        return false;
554
        return false;
562
    }
555
    }
563
 
556
 
564
    function setVersion($version)
557
    function setVersion($version)
565
    {
558
    {
566
        $this->_packageInfo['version'] = $version;
559
        $this->_packageInfo['version'] = $version;
567
        $this->_isValid = false;
560
        $this->_isValid = false;
568
    }
561
    }
569
 
562
 
570
    function clearMaintainers()
563
    function clearMaintainers()
571
    {
564
    {
572
        unset($this->_packageInfo['maintainers']);
565
        unset($this->_packageInfo['maintainers']);
573
    }
566
    }
574
 
567
 
575
    function getMaintainers()
568
    function getMaintainers()
576
    {
569
    {
577
        if (isset($this->_packageInfo['maintainers'])) {
570
        if (isset($this->_packageInfo['maintainers'])) {
578
            return $this->_packageInfo['maintainers'];
571
            return $this->_packageInfo['maintainers'];
579
        }
572
        }
580
        return false;
573
        return false;
581
    }
574
    }
582
 
575
 
583
    /**
576
    /**
584
     * Adds a new maintainer - no checking of duplicates is performed, use
577
     * Adds a new maintainer - no checking of duplicates is performed, use
585
     * updatemaintainer for that purpose.
578
     * updatemaintainer for that purpose.
586
     */
579
     */
587
    function addMaintainer($role, $handle, $name, $email)
580
    function addMaintainer($role, $handle, $name, $email)
588
    {
581
    {
589
        $this->_packageInfo['maintainers'][] =
582
        $this->_packageInfo['maintainers'][] =
590
            array('handle' => $handle, 'role' => $role, 'email' => $email, 'name' => $name);
583
            array('handle' => $handle, 'role' => $role, 'email' => $email, 'name' => $name);
591
        $this->_isValid = false;
584
        $this->_isValid = false;
592
    }
585
    }
593
 
586
 
594
    function updateMaintainer($role, $handle, $name, $email)
587
    function updateMaintainer($role, $handle, $name, $email)
595
    {
588
    {
596
        $found = false;
589
        $found = false;
597
        if (!isset($this->_packageInfo['maintainers']) ||
590
        if (!isset($this->_packageInfo['maintainers']) ||
598
              !is_array($this->_packageInfo['maintainers'])) {
591
              !is_array($this->_packageInfo['maintainers'])) {
599
            return $this->addMaintainer($role, $handle, $name, $email);
592
            return $this->addMaintainer($role, $handle, $name, $email);
600
        }
593
        }
601
        foreach ($this->_packageInfo['maintainers'] as $i => $maintainer) {
594
        foreach ($this->_packageInfo['maintainers'] as $i => $maintainer) {
602
            if ($maintainer['handle'] == $handle) {
595
            if ($maintainer['handle'] == $handle) {
603
                $found = $i;
596
                $found = $i;
604
                break;
597
                break;
605
            }
598
            }
606
        }
599
        }
607
        if ($found !== false) {
600
        if ($found !== false) {
608
            unset($this->_packageInfo['maintainers'][$found]);
601
            unset($this->_packageInfo['maintainers'][$found]);
609
            $this->_packageInfo['maintainers'] =
602
            $this->_packageInfo['maintainers'] =
610
                array_values($this->_packageInfo['maintainers']);
603
                array_values($this->_packageInfo['maintainers']);
611
        }
604
        }
612
        $this->addMaintainer($role, $handle, $name, $email);
605
        $this->addMaintainer($role, $handle, $name, $email);
613
    }
606
    }
614
 
607
 
615
    function deleteMaintainer($handle)
608
    function deleteMaintainer($handle)
616
    {
609
    {
617
        $found = false;
610
        $found = false;
618
        foreach ($this->_packageInfo['maintainers'] as $i => $maintainer) {
611
        foreach ($this->_packageInfo['maintainers'] as $i => $maintainer) {
619
            if ($maintainer['handle'] == $handle) {
612
            if ($maintainer['handle'] == $handle) {
620
                $found = $i;
613
                $found = $i;
621
                break;
614
                break;
622
            }
615
            }
623
        }
616
        }
624
        if ($found !== false) {
617
        if ($found !== false) {
625
            unset($this->_packageInfo['maintainers'][$found]);
618
            unset($this->_packageInfo['maintainers'][$found]);
626
            $this->_packageInfo['maintainers'] =
619
            $this->_packageInfo['maintainers'] =
627
                array_values($this->_packageInfo['maintainers']);
620
                array_values($this->_packageInfo['maintainers']);
628
            return true;
621
            return true;
629
        }
622
        }
630
        return false;
623
        return false;
631
    }
624
    }
632
 
625
 
633
    function getState()
626
    function getState()
634
    {
627
    {
635
        if (isset($this->_packageInfo['release_state'])) {
628
        if (isset($this->_packageInfo['release_state'])) {
636
            return $this->_packageInfo['release_state'];
629
            return $this->_packageInfo['release_state'];
637
        }
630
        }
638
        return false;
631
        return false;
639
    }
632
    }
640
 
633
 
641
    function setRawState($state)
634
    function setRawState($state)
642
    {
635
    {
643
        $this->_packageInfo['release_state'] = $state;
636
        $this->_packageInfo['release_state'] = $state;
644
    }
637
    }
645
 
638
 
646
    function setState($state)
639
    function setState($state)
647
    {
640
    {
648
        $this->_packageInfo['release_state'] = $state;
641
        $this->_packageInfo['release_state'] = $state;
649
        $this->_isValid = false;
642
        $this->_isValid = false;
650
    }
643
    }
651
 
644
 
652
    function getDate()
645
    function getDate()
653
    {
646
    {
654
        if (isset($this->_packageInfo['release_date'])) {
647
        if (isset($this->_packageInfo['release_date'])) {
655
            return $this->_packageInfo['release_date'];
648
            return $this->_packageInfo['release_date'];
656
        }
649
        }
657
        return false;
650
        return false;
658
    }
651
    }
659
 
652
 
660
    function setDate($date)
653
    function setDate($date)
661
    {
654
    {
662
        $this->_packageInfo['release_date'] = $date;
655
        $this->_packageInfo['release_date'] = $date;
663
        $this->_isValid = false;
656
        $this->_isValid = false;
664
    }
657
    }
665
 
658
 
666
    function getLicense()
659
    function getLicense()
667
    {
660
    {
668
        if (isset($this->_packageInfo['release_license'])) {
661
        if (isset($this->_packageInfo['release_license'])) {
669
            return $this->_packageInfo['release_license'];
662
            return $this->_packageInfo['release_license'];
670
        }
663
        }
671
        return false;
664
        return false;
672
    }
665
    }
673
 
666
 
674
    function setLicense($date)
667
    function setLicense($date)
675
    {
668
    {
676
        $this->_packageInfo['release_license'] = $date;
669
        $this->_packageInfo['release_license'] = $date;
677
        $this->_isValid = false;
670
        $this->_isValid = false;
678
    }
671
    }
679
 
672
 
680
    function getSummary()
673
    function getSummary()
681
    {
674
    {
682
        if (isset($this->_packageInfo['summary'])) {
675
        if (isset($this->_packageInfo['summary'])) {
683
            return $this->_packageInfo['summary'];
676
            return $this->_packageInfo['summary'];
684
        }
677
        }
685
        return false;
678
        return false;
686
    }
679
    }
687
 
680
 
688
    function setSummary($summary)
681
    function setSummary($summary)
689
    {
682
    {
690
        $this->_packageInfo['summary'] = $summary;
683
        $this->_packageInfo['summary'] = $summary;
691
        $this->_isValid = false;
684
        $this->_isValid = false;
692
    }
685
    }
693
 
686
 
694
    function getDescription()
687
    function getDescription()
695
    {
688
    {
696
        if (isset($this->_packageInfo['description'])) {
689
        if (isset($this->_packageInfo['description'])) {
697
            return $this->_packageInfo['description'];
690
            return $this->_packageInfo['description'];
698
        }
691
        }
699
        return false;
692
        return false;
700
    }
693
    }
701
 
694
 
702
    function setDescription($desc)
695
    function setDescription($desc)
703
    {
696
    {
704
        $this->_packageInfo['description'] = $desc;
697
        $this->_packageInfo['description'] = $desc;
705
        $this->_isValid = false;
698
        $this->_isValid = false;
706
    }
699
    }
707
 
700
 
708
    function getNotes()
701
    function getNotes()
709
    {
702
    {
710
        if (isset($this->_packageInfo['release_notes'])) {
703
        if (isset($this->_packageInfo['release_notes'])) {
711
            return $this->_packageInfo['release_notes'];
704
            return $this->_packageInfo['release_notes'];
712
        }
705
        }
713
        return false;
706
        return false;
714
    }
707
    }
715
 
708
 
716
    function setNotes($notes)
709
    function setNotes($notes)
717
    {
710
    {
718
        $this->_packageInfo['release_notes'] = $notes;
711
        $this->_packageInfo['release_notes'] = $notes;
719
        $this->_isValid = false;
712
        $this->_isValid = false;
720
    }
713
    }
721
 
714
 
722
    function getDeps()
715
    function getDeps()
723
    {
716
    {
724
        if (isset($this->_packageInfo['release_deps'])) {
717
        if (isset($this->_packageInfo['release_deps'])) {
725
            return $this->_packageInfo['release_deps'];
718
            return $this->_packageInfo['release_deps'];
726
        }
719
        }
727
        return false;
720
        return false;
728
    }
721
    }
729
 
722
 
730
    /**
723
    /**
731
     * Reset dependencies prior to adding new ones
724
     * Reset dependencies prior to adding new ones
732
     */
725
     */
733
    function clearDeps()
726
    function clearDeps()
734
    {
727
    {
735
        unset($this->_packageInfo['release_deps']);
728
        unset($this->_packageInfo['release_deps']);
736
    }
729
    }
737
 
730
 
738
    function addPhpDep($version, $rel)
731
    function addPhpDep($version, $rel)
739
    {
732
    {
740
        $this->_isValid = false;
733
        $this->_isValid = false;
741
        $this->_packageInfo['release_deps'][] =
734
        $this->_packageInfo['release_deps'][] =
742
            array('type' => 'php',
735
            array('type' => 'php',
743
                  'rel' => $rel,
736
                  'rel' => $rel,
744
                  'version' => $version);
737
                  'version' => $version);
745
    }
738
    }
746
 
739
 
747
    function addPackageDep($name, $version, $rel, $optional = 'no')
740
    function addPackageDep($name, $version, $rel, $optional = 'no')
748
    {
741
    {
749
        $this->_isValid = false;
742
        $this->_isValid = false;
750
        $dep =
743
        $dep =
751
            array('type' => 'pkg',
744
            array('type' => 'pkg',
752
                  'name' => $name,
745
                  'name' => $name,
753
                  'rel' => $rel,
746
                  'rel' => $rel,
754
                  'optional' => $optional);
747
                  'optional' => $optional);
755
        if ($rel != 'has' && $rel != 'not') {
748
        if ($rel != 'has' && $rel != 'not') {
756
            $dep['version'] = $version;
749
            $dep['version'] = $version;
757
        }
750
        }
758
        $this->_packageInfo['release_deps'][] = $dep;
751
        $this->_packageInfo['release_deps'][] = $dep;
759
    }
752
    }
760
 
753
 
761
    function addExtensionDep($name, $version, $rel, $optional = 'no')
754
    function addExtensionDep($name, $version, $rel, $optional = 'no')
762
    {
755
    {
763
        $this->_isValid = false;
756
        $this->_isValid = false;
764
        $this->_packageInfo['release_deps'][] =
757
        $this->_packageInfo['release_deps'][] =
765
            array('type' => 'ext',
758
            array('type' => 'ext',
766
                  'name' => $name,
759
                  'name' => $name,
767
                  'rel' => $rel,
760
                  'rel' => $rel,
768
                  'version' => $version,
761
                  'version' => $version,
769
                  'optional' => $optional);
762
                  'optional' => $optional);
770
    }
763
    }
771
 
764
 
772
    /**
765
    /**
773
     * WARNING - do not use this function directly unless you know what you're doing
766
     * WARNING - do not use this function directly unless you know what you're doing
774
     */
767
     */
775
    function setDeps($deps)
768
    function setDeps($deps)
776
    {
769
    {
777
        $this->_packageInfo['release_deps'] = $deps;
770
        $this->_packageInfo['release_deps'] = $deps;
778
    }
771
    }
779
 
772
 
780
    function hasDeps()
773
    function hasDeps()
781
    {
774
    {
782
        return isset($this->_packageInfo['release_deps']) &&
775
        return isset($this->_packageInfo['release_deps']) &&
783
            count($this->_packageInfo['release_deps']);
776
            count($this->_packageInfo['release_deps']);
784
    }
777
    }
785
 
778
 
786
    function getDependencyGroup($group)
779
    function getDependencyGroup($group)
787
    {
780
    {
788
        return false;
781
        return false;
789
    }
782
    }
790
 
783
 
791
    function isCompatible($pf)
784
    function isCompatible($pf)
792
    {
785
    {
793
        return false;
786
        return false;
794
    }
787
    }
795
 
788
 
796
    function isSubpackageOf($p)
789
    function isSubpackageOf($p)
797
    {
790
    {
798
        return $p->isSubpackage($this);
791
        return $p->isSubpackage($this);
799
    }
792
    }
800
 
793
 
801
    function isSubpackage($p)
794
    function isSubpackage($p)
802
    {
795
    {
803
        return false;
796
        return false;
804
    }
797
    }
805
 
798
 
806
    function dependsOn($package, $channel)
799
    function dependsOn($package, $channel)
807
    {
800
    {
808
        if (strtolower($channel) != 'pear.php.net') {
801
        if (strtolower($channel) != 'pear.php.net') {
809
            return false;
802
            return false;
810
        }
803
        }
811
        if (!($deps = $this->getDeps())) {
804
        if (!($deps = $this->getDeps())) {
812
            return false;
805
            return false;
813
        }
806
        }
814
        foreach ($deps as $dep) {
807
        foreach ($deps as $dep) {
815
            if ($dep['type'] != 'pkg') {
808
            if ($dep['type'] != 'pkg') {
816
                continue;
809
                continue;
817
            }
810
            }
818
            if (strtolower($dep['name']) == strtolower($package)) {
811
            if (strtolower($dep['name']) == strtolower($package)) {
819
                return true;
812
                return true;
820
            }
813
            }
821
        }
814
        }
822
        return false;
815
        return false;
823
    }
816
    }
824
 
817
 
825
    function getConfigureOptions()
818
    function getConfigureOptions()
826
    {
819
    {
827
        if (isset($this->_packageInfo['configure_options'])) {
820
        if (isset($this->_packageInfo['configure_options'])) {
828
            return $this->_packageInfo['configure_options'];
821
            return $this->_packageInfo['configure_options'];
829
        }
822
        }
830
        return false;
823
        return false;
831
    }
824
    }
832
 
825
 
833
    function hasConfigureOptions()
826
    function hasConfigureOptions()
834
    {
827
    {
835
        return isset($this->_packageInfo['configure_options']) &&
828
        return isset($this->_packageInfo['configure_options']) &&
836
            count($this->_packageInfo['configure_options']);
829
            count($this->_packageInfo['configure_options']);
837
    }
830
    }
838
 
831
 
839
    function addConfigureOption($name, $prompt, $default = false)
832
    function addConfigureOption($name, $prompt, $default = false)
840
    {
833
    {
841
        $o = array('name' => $name, 'prompt' => $prompt);
834
        $o = array('name' => $name, 'prompt' => $prompt);
842
        if ($default !== false) {
835
        if ($default !== false) {
843
            $o['default'] = $default;
836
            $o['default'] = $default;
844
        }
837
        }
845
        if (!isset($this->_packageInfo['configure_options'])) {
838
        if (!isset($this->_packageInfo['configure_options'])) {
846
            $this->_packageInfo['configure_options'] = array();
839
            $this->_packageInfo['configure_options'] = array();
847
        }
840
        }
848
        $this->_packageInfo['configure_options'][] = $o;
841
        $this->_packageInfo['configure_options'][] = $o;
849
    }
842
    }
850
 
843
 
851
    function clearConfigureOptions()
844
    function clearConfigureOptions()
852
    {
845
    {
853
        unset($this->_packageInfo['configure_options']);
846
        unset($this->_packageInfo['configure_options']);
854
    }
847
    }
855
 
848
 
856
    function getProvides()
849
    function getProvides()
857
    {
850
    {
858
        if (isset($this->_packageInfo['provides'])) {
851
        if (isset($this->_packageInfo['provides'])) {
859
            return $this->_packageInfo['provides'];
852
            return $this->_packageInfo['provides'];
860
        }
853
        }
861
        return false;
854
        return false;
862
    }
855
    }
863
 
856
 
864
    function getProvidesExtension()
857
    function getProvidesExtension()
865
    {
858
    {
866
        return false;
859
        return false;
867
    }
860
    }
868
 
861
 
869
    function addFile($dir, $file, $attrs)
862
    function addFile($dir, $file, $attrs)
870
    {
863
    {
871
        $dir = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'), $dir);
864
        $dir = preg_replace(array('!\\\\+!', '!/+!'), array('/', '/'), $dir);
872
        if ($dir == '/' || $dir == '') {
865
        if ($dir == '/' || $dir == '') {
873
            $dir = '';
866
            $dir = '';
874
        } else {
867
        } else {
875
            $dir .= '/';
868
            $dir .= '/';
876
        }
869
        }
877
        $file = $dir . $file;
870
        $file = $dir . $file;
878
        $file = preg_replace('![\\/]+!', '/', $file);
871
        $file = preg_replace('![\\/]+!', '/', $file);
879
        $this->_packageInfo['filelist'][$file] = $attrs;
872
        $this->_packageInfo['filelist'][$file] = $attrs;
880
    }
873
    }
881
 
874
 
882
    function getInstallationFilelist()
875
    function getInstallationFilelist()
883
    {
876
    {
884
        return $this->getFilelist();
877
        return $this->getFilelist();
885
    }
878
    }
886
 
879
 
887
    function getFilelist()
880
    function getFilelist()
888
    {
881
    {
889
        if (isset($this->_packageInfo['filelist'])) {
882
        if (isset($this->_packageInfo['filelist'])) {
890
            return $this->_packageInfo['filelist'];
883
            return $this->_packageInfo['filelist'];
891
        }
884
        }
892
        return false;
885
        return false;
893
    }
886
    }
894
 
887
 
895
    function setFileAttribute($file, $attr, $value)
888
    function setFileAttribute($file, $attr, $value)
896
    {
889
    {
897
        $this->_packageInfo['filelist'][$file][$attr] = $value;
890
        $this->_packageInfo['filelist'][$file][$attr] = $value;
898
    }
891
    }
899
 
892
 
900
    function resetFilelist()
893
    function resetFilelist()
901
    {
894
    {
902
        $this->_packageInfo['filelist'] = array();
895
        $this->_packageInfo['filelist'] = array();
903
    }
896
    }
904
 
897
 
905
    function setInstalledAs($file, $path)
898
    function setInstalledAs($file, $path)
906
    {
899
    {
907
        if ($path) {
900
        if ($path) {
908
            return $this->_packageInfo['filelist'][$file]['installed_as'] = $path;
901
            return $this->_packageInfo['filelist'][$file]['installed_as'] = $path;
909
        }
902
        }
910
        unset($this->_packageInfo['filelist'][$file]['installed_as']);
903
        unset($this->_packageInfo['filelist'][$file]['installed_as']);
911
    }
904
    }
912
 
905
 
913
    function installedFile($file, $atts)
906
    function installedFile($file, $atts)
914
    {
907
    {
915
        if (isset($this->_packageInfo['filelist'][$file])) {
908
        if (isset($this->_packageInfo['filelist'][$file])) {
916
            $this->_packageInfo['filelist'][$file] =
909
            $this->_packageInfo['filelist'][$file] =
917
                array_merge($this->_packageInfo['filelist'][$file], $atts);
910
                array_merge($this->_packageInfo['filelist'][$file], $atts);
918
        } else {
911
        } else {
919
            $this->_packageInfo['filelist'][$file] = $atts;
912
            $this->_packageInfo['filelist'][$file] = $atts;
920
        }
913
        }
921
    }
914
    }
922
 
915
 
923
    function getChangelog()
916
    function getChangelog()
924
    {
917
    {
925
        if (isset($this->_packageInfo['changelog'])) {
918
        if (isset($this->_packageInfo['changelog'])) {
926
            return $this->_packageInfo['changelog'];
919
            return $this->_packageInfo['changelog'];
927
        }
920
        }
928
        return false;
921
        return false;
929
    }
922
    }
930
 
923
 
931
    function getPackagexmlVersion()
924
    function getPackagexmlVersion()
932
    {
925
    {
933
        return '1.0';
926
        return '1.0';
934
    }
927
    }
935
 
928
 
936
    /**
929
    /**
937
     * Wrapper to {@link PEAR_ErrorStack::getErrors()}
930
     * Wrapper to {@link PEAR_ErrorStack::getErrors()}
938
     * @param boolean determines whether to purge the error stack after retrieving
931
     * @param boolean determines whether to purge the error stack after retrieving
939
     * @return array
932
     * @return array
940
     */
933
     */
941
    function getValidationWarnings($purge = true)
934
    function getValidationWarnings($purge = true)
942
    {
935
    {
943
        return $this->_stack->getErrors($purge);
936
        return $this->_stack->getErrors($purge);
944
    }
937
    }
945
 
938
 
946
    // }}}
939
    // }}}
947
    /**
940
    /**
948
     * Validation error.  Also marks the object contents as invalid
941
     * Validation error.  Also marks the object contents as invalid
949
     * @param error code
942
     * @param error code
950
     * @param array error information
943
     * @param array error information
951
     * @access private
944
     * @access private
952
     */
945
     */
953
    function _validateError($code, $params = array())
946
    function _validateError($code, $params = array())
954
    {
947
    {
955
        $this->_stack->push($code, 'error', $params, false, false, debug_backtrace());
948
        $this->_stack->push($code, 'error', $params, false, false, debug_backtrace());
956
        $this->_isValid = false;
949
        $this->_isValid = false;
957
    }
950
    }
958
 
951
 
959
    /**
952
    /**
960
     * Validation warning.  Does not mark the object contents invalid.
953
     * Validation warning.  Does not mark the object contents invalid.
961
     * @param error code
954
     * @param error code
962
     * @param array error information
955
     * @param array error information
963
     * @access private
956
     * @access private
964
     */
957
     */
965
    function _validateWarning($code, $params = array())
958
    function _validateWarning($code, $params = array())
966
    {
959
    {
967
        $this->_stack->push($code, 'warning', $params, false, false, debug_backtrace());
960
        $this->_stack->push($code, 'warning', $params, false, false, debug_backtrace());
968
    }
961
    }
969
 
962
 
970
    /**
963
    /**
971
     * @param integer error code
964
     * @param integer error code
972
     * @access protected
965
     * @access protected
973
     */
966
     */
974
    function _getErrorMessage()
967
    function _getErrorMessage()
975
    {
968
    {
976
        return array(
969
        return array(
977
                PEAR_PACKAGEFILE_ERROR_NO_NAME =>
970
                PEAR_PACKAGEFILE_ERROR_NO_NAME =>
978
                    'Missing Package Name',
971
                    'Missing Package Name',
979
                PEAR_PACKAGEFILE_ERROR_NO_SUMMARY =>
972
                PEAR_PACKAGEFILE_ERROR_NO_SUMMARY =>
980
                    'No summary found',
973
                    'No summary found',
981
                PEAR_PACKAGEFILE_ERROR_MULTILINE_SUMMARY =>
974
                PEAR_PACKAGEFILE_ERROR_MULTILINE_SUMMARY =>
982
                    'Summary should be on one line',
975
                    'Summary should be on one line',
983
                PEAR_PACKAGEFILE_ERROR_NO_DESCRIPTION =>
976
                PEAR_PACKAGEFILE_ERROR_NO_DESCRIPTION =>
984
                    'Missing description',
977
                    'Missing description',
985
                PEAR_PACKAGEFILE_ERROR_NO_LICENSE =>
978
                PEAR_PACKAGEFILE_ERROR_NO_LICENSE =>
986
                    'Missing license',
979
                    'Missing license',
987
                PEAR_PACKAGEFILE_ERROR_NO_VERSION =>
980
                PEAR_PACKAGEFILE_ERROR_NO_VERSION =>
988
                    'No release version found',
981
                    'No release version found',
989
                PEAR_PACKAGEFILE_ERROR_NO_STATE =>
982
                PEAR_PACKAGEFILE_ERROR_NO_STATE =>
990
                    'No release state found',
983
                    'No release state found',
991
                PEAR_PACKAGEFILE_ERROR_NO_DATE =>
984
                PEAR_PACKAGEFILE_ERROR_NO_DATE =>
992
                    'No release date found',
985
                    'No release date found',
993
                PEAR_PACKAGEFILE_ERROR_NO_NOTES =>
986
                PEAR_PACKAGEFILE_ERROR_NO_NOTES =>
994
                    'No release notes found',
987
                    'No release notes found',
995
                PEAR_PACKAGEFILE_ERROR_NO_LEAD =>
988
                PEAR_PACKAGEFILE_ERROR_NO_LEAD =>
996
                    'Package must have at least one lead maintainer',
989
                    'Package must have at least one lead maintainer',
997
                PEAR_PACKAGEFILE_ERROR_NO_MAINTAINERS =>
990
                PEAR_PACKAGEFILE_ERROR_NO_MAINTAINERS =>
998
                    'No maintainers found, at least one must be defined',
991
                    'No maintainers found, at least one must be defined',
999
                PEAR_PACKAGEFILE_ERROR_NO_MAINTHANDLE =>
992
                PEAR_PACKAGEFILE_ERROR_NO_MAINTHANDLE =>
1000
                    'Maintainer %index% has no handle (user ID at channel server)',
993
                    'Maintainer %index% has no handle (user ID at channel server)',
1001
                PEAR_PACKAGEFILE_ERROR_NO_MAINTROLE =>
994
                PEAR_PACKAGEFILE_ERROR_NO_MAINTROLE =>
1002
                    'Maintainer %index% has no role',
995
                    'Maintainer %index% has no role',
1003
                PEAR_PACKAGEFILE_ERROR_NO_MAINTNAME =>
996
                PEAR_PACKAGEFILE_ERROR_NO_MAINTNAME =>
1004
                    'Maintainer %index% has no name',
997
                    'Maintainer %index% has no name',
1005
                PEAR_PACKAGEFILE_ERROR_NO_MAINTEMAIL =>
998
                PEAR_PACKAGEFILE_ERROR_NO_MAINTEMAIL =>
1006
                    'Maintainer %index% has no email',
999
                    'Maintainer %index% has no email',
1007
                PEAR_PACKAGEFILE_ERROR_NO_DEPNAME =>
1000
                PEAR_PACKAGEFILE_ERROR_NO_DEPNAME =>
1008
                    'Dependency %index% is not a php dependency, and has no name',
1001
                    'Dependency %index% is not a php dependency, and has no name',
1009
                PEAR_PACKAGEFILE_ERROR_NO_DEPREL =>
1002
                PEAR_PACKAGEFILE_ERROR_NO_DEPREL =>
1010
                    'Dependency %index% has no relation (rel)',
1003
                    'Dependency %index% has no relation (rel)',
1011
                PEAR_PACKAGEFILE_ERROR_NO_DEPTYPE =>
1004
                PEAR_PACKAGEFILE_ERROR_NO_DEPTYPE =>
1012
                    'Dependency %index% has no type',
1005
                    'Dependency %index% has no type',
1013
                PEAR_PACKAGEFILE_ERROR_DEPNAME_IGNORED =>
1006
                PEAR_PACKAGEFILE_ERROR_DEPNAME_IGNORED =>
1014
                    'PHP Dependency %index% has a name attribute of "%name%" which will be' .
1007
                    'PHP Dependency %index% has a name attribute of "%name%" which will be' .
1015
                        ' ignored!',
1008
                        ' ignored!',
1016
                PEAR_PACKAGEFILE_ERROR_NO_DEPVERSION =>
1009
                PEAR_PACKAGEFILE_ERROR_NO_DEPVERSION =>
1017
                    'Dependency %index% is not a rel="has" or rel="not" dependency, ' .
1010
                    'Dependency %index% is not a rel="has" or rel="not" dependency, ' .
1018
                        'and has no version',
1011
                        'and has no version',
1019
                PEAR_PACKAGEFILE_ERROR_NO_DEPPHPVERSION =>
1012
                PEAR_PACKAGEFILE_ERROR_NO_DEPPHPVERSION =>
1020
                    'Dependency %index% is a type="php" dependency, ' .
1013
                    'Dependency %index% is a type="php" dependency, ' .
1021
                        'and has no version',
1014
                        'and has no version',
1022
                PEAR_PACKAGEFILE_ERROR_DEPVERSION_IGNORED =>
1015
                PEAR_PACKAGEFILE_ERROR_DEPVERSION_IGNORED =>
1023
                    'Dependency %index% is a rel="%rel%" dependency, versioning is ignored',
1016
                    'Dependency %index% is a rel="%rel%" dependency, versioning is ignored',
1024
                PEAR_PACKAGEFILE_ERROR_INVALID_DEPOPTIONAL =>
1017
                PEAR_PACKAGEFILE_ERROR_INVALID_DEPOPTIONAL =>
1025
                    'Dependency %index% has invalid optional value "%opt%", should be yes or no',
1018
                    'Dependency %index% has invalid optional value "%opt%", should be yes or no',
1026
                PEAR_PACKAGEFILE_PHP_NO_NOT =>
1019
                PEAR_PACKAGEFILE_PHP_NO_NOT =>
1027
                    'Dependency %index%: php dependencies cannot use "not" rel, use "ne"' .
1020
                    'Dependency %index%: php dependencies cannot use "not" rel, use "ne"' .
1028
                        ' to exclude specific versions',
1021
                        ' to exclude specific versions',
1029
                PEAR_PACKAGEFILE_ERROR_NO_CONFNAME =>
1022
                PEAR_PACKAGEFILE_ERROR_NO_CONFNAME =>
1030
                    'Configure Option %index% has no name',
1023
                    'Configure Option %index% has no name',
1031
                PEAR_PACKAGEFILE_ERROR_NO_CONFPROMPT =>
1024
                PEAR_PACKAGEFILE_ERROR_NO_CONFPROMPT =>
1032
                    'Configure Option %index% has no prompt',
1025
                    'Configure Option %index% has no prompt',
1033
                PEAR_PACKAGEFILE_ERROR_NO_FILES =>
1026
                PEAR_PACKAGEFILE_ERROR_NO_FILES =>
1034
                    'No files in <filelist> section of package.xml',
1027
                    'No files in <filelist> section of package.xml',
1035
                PEAR_PACKAGEFILE_ERROR_NO_FILEROLE =>
1028
                PEAR_PACKAGEFILE_ERROR_NO_FILEROLE =>
1036
                    'File "%file%" has no role, expecting one of "%roles%"',
1029
                    'File "%file%" has no role, expecting one of "%roles%"',
1037
                PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE =>
1030
                PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE =>
1038
                    'File "%file%" has invalid role "%role%", expecting one of "%roles%"',
1031
                    'File "%file%" has invalid role "%role%", expecting one of "%roles%"',
1039
                PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME =>
1032
                PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME =>
1040
                    'File "%file%" cannot start with ".", cannot package or install',
1033
                    'File "%file%" cannot start with ".", cannot package or install',
1041
                PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE =>
1034
                PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE =>
1042
                    'Parser error: invalid PHP found in file "%file%"',
1035
                    'Parser error: invalid PHP found in file "%file%"',
1043
                PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX =>
1036
                PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX =>
1044
                    'in %file%: %type% "%name%" not prefixed with package name "%package%"',
1037
                    'in %file%: %type% "%name%" not prefixed with package name "%package%"',
1045
                PEAR_PACKAGEFILE_ERROR_INVALID_FILE =>
1038
                PEAR_PACKAGEFILE_ERROR_INVALID_FILE =>
1046
                    'Parser error: invalid PHP file "%file%"',
1039
                    'Parser error: invalid PHP file "%file%"',
1047
                PEAR_PACKAGEFILE_ERROR_CHANNELVAL =>
1040
                PEAR_PACKAGEFILE_ERROR_CHANNELVAL =>
1048
                    'Channel validator error: field "%field%" - %reason%',
1041
                    'Channel validator error: field "%field%" - %reason%',
1049
                PEAR_PACKAGEFILE_ERROR_PHP5 =>
1042
                PEAR_PACKAGEFILE_ERROR_PHP5 =>
1050
                    'Error, PHP5 token encountered in %file%, analysis should be in PHP5',
1043
                    'Error, PHP5 token encountered in %file%, analysis should be in PHP5',
1051
                PEAR_PACKAGEFILE_ERROR_FILE_NOTFOUND =>
1044
                PEAR_PACKAGEFILE_ERROR_FILE_NOTFOUND =>
1052
                    'File "%file%" in package.xml does not exist',
1045
                    'File "%file%" in package.xml does not exist',
1053
                PEAR_PACKAGEFILE_ERROR_NON_ISO_CHARS =>
1046
                PEAR_PACKAGEFILE_ERROR_NON_ISO_CHARS =>
1054
                    'Package.xml contains non-ISO-8859-1 characters, and may not validate',
1047
                    'Package.xml contains non-ISO-8859-1 characters, and may not validate',
1055
            );
1048
            );
1056
    }
1049
    }
1057
 
1050
 
1058
    /**
1051
    /**
1059
     * Validate XML package definition file.
1052
     * Validate XML package definition file.
1060
     *
1053
     *
1061
     * @access public
1054
     * @access public
1062
     * @return boolean
1055
     * @return boolean
1063
     */
1056
     */
1064
    function validate($state = PEAR_VALIDATE_NORMAL, $nofilechecking = false)
1057
    function validate($state = PEAR_VALIDATE_NORMAL, $nofilechecking = false)
1065
    {
1058
    {
1066
        if (($this->_isValid & $state) == $state) {
1059
        if (($this->_isValid & $state) == $state) {
1067
            return true;
1060
            return true;
1068
        }
1061
        }
1069
        $this->_isValid = true;
1062
        $this->_isValid = true;
1070
        $info = $this->_packageInfo;
1063
        $info = $this->_packageInfo;
1071
        if (empty($info['package'])) {
1064
        if (empty($info['package'])) {
1072
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_NAME);
1065
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_NAME);
1073
            $this->_packageName = $pn = 'unknown';
1066
            $this->_packageName = $pn = 'unknown';
1074
        } else {
1067
        } else {
1075
            $this->_packageName = $pn = $info['package'];
1068
            $this->_packageName = $pn = $info['package'];
1076
        }
1069
        }
1077
 
1070
 
1078
        if (empty($info['summary'])) {
1071
        if (empty($info['summary'])) {
1079
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_SUMMARY);
1072
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_SUMMARY);
1080
        } elseif (strpos(trim($info['summary']), "\n") !== false) {
1073
        } elseif (strpos(trim($info['summary']), "\n") !== false) {
1081
            $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_MULTILINE_SUMMARY,
1074
            $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_MULTILINE_SUMMARY,
1082
                array('summary' => $info['summary']));
1075
                array('summary' => $info['summary']));
1083
        }
1076
        }
1084
        if (empty($info['description'])) {
1077
        if (empty($info['description'])) {
1085
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DESCRIPTION);
1078
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DESCRIPTION);
1086
        }
1079
        }
1087
        if (empty($info['release_license'])) {
1080
        if (empty($info['release_license'])) {
1088
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_LICENSE);
1081
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_LICENSE);
1089
        }
1082
        }
1090
        if (empty($info['version'])) {
1083
        if (empty($info['version'])) {
1091
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_VERSION);
1084
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_VERSION);
1092
        }
1085
        }
1093
        if (empty($info['release_state'])) {
1086
        if (empty($info['release_state'])) {
1094
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_STATE);
1087
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_STATE);
1095
        }
1088
        }
1096
        if (empty($info['release_date'])) {
1089
        if (empty($info['release_date'])) {
1097
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DATE);
1090
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DATE);
1098
        }
1091
        }
1099
        if (empty($info['release_notes'])) {
1092
        if (empty($info['release_notes'])) {
1100
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_NOTES);
1093
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_NOTES);
1101
        }
1094
        }
1102
        if (empty($info['maintainers'])) {
1095
        if (empty($info['maintainers'])) {
1103
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTAINERS);
1096
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTAINERS);
1104
        } else {
1097
        } else {
1105
            $haslead = false;
1098
            $haslead = false;
1106
            $i = 1;
1099
            $i = 1;
1107
            foreach ($info['maintainers'] as $m) {
1100
            foreach ($info['maintainers'] as $m) {
1108
                if (empty($m['handle'])) {
1101
                if (empty($m['handle'])) {
1109
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTHANDLE,
1102
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTHANDLE,
1110
                        array('index' => $i));
1103
                        array('index' => $i));
1111
                }
1104
                }
1112
                if (empty($m['role'])) {
1105
                if (empty($m['role'])) {
1113
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTROLE,
1106
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTROLE,
1114
                        array('index' => $i, 'roles' => PEAR_Common::getUserRoles()));
1107
                        array('index' => $i, 'roles' => PEAR_Common::getUserRoles()));
1115
                } elseif ($m['role'] == 'lead') {
1108
                } elseif ($m['role'] == 'lead') {
1116
                    $haslead = true;
1109
                    $haslead = true;
1117
                }
1110
                }
1118
                if (empty($m['name'])) {
1111
                if (empty($m['name'])) {
1119
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTNAME,
1112
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTNAME,
1120
                        array('index' => $i));
1113
                        array('index' => $i));
1121
                }
1114
                }
1122
                if (empty($m['email'])) {
1115
                if (empty($m['email'])) {
1123
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTEMAIL,
1116
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_MAINTEMAIL,
1124
                        array('index' => $i));
1117
                        array('index' => $i));
1125
                }
1118
                }
1126
                $i++;
1119
                $i++;
1127
            }
1120
            }
1128
            if (!$haslead) {
1121
            if (!$haslead) {
1129
                $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_LEAD);
1122
                $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_LEAD);
1130
            }
1123
            }
1131
        }
1124
        }
1132
        if (!empty($info['release_deps'])) {
1125
        if (!empty($info['release_deps'])) {
1133
            $i = 1;
1126
            $i = 1;
1134
            foreach ($info['release_deps'] as $d) {
1127
            foreach ($info['release_deps'] as $d) {
1135
                if (!isset($d['type']) || empty($d['type'])) {
1128
                if (!isset($d['type']) || empty($d['type'])) {
1136
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPTYPE,
1129
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPTYPE,
1137
                        array('index' => $i, 'types' => PEAR_Common::getDependencyTypes()));
1130
                        array('index' => $i, 'types' => PEAR_Common::getDependencyTypes()));
1138
                    continue;
1131
                    continue;
1139
                }
1132
                }
1140
                if (!isset($d['rel']) || empty($d['rel'])) {
1133
                if (!isset($d['rel']) || empty($d['rel'])) {
1141
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPREL,
1134
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPREL,
1142
                        array('index' => $i, 'rels' => PEAR_Common::getDependencyRelations()));
1135
                        array('index' => $i, 'rels' => PEAR_Common::getDependencyRelations()));
1143
                    continue;
1136
                    continue;
1144
                }
1137
                }
1145
                if (!empty($d['optional'])) {
1138
                if (!empty($d['optional'])) {
1146
                    if (!in_array($d['optional'], array('yes', 'no'))) {
1139
                    if (!in_array($d['optional'], array('yes', 'no'))) {
1147
                        $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_DEPOPTIONAL,
1140
                        $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_DEPOPTIONAL,
1148
                            array('index' => $i, 'opt' => $d['optional']));
1141
                            array('index' => $i, 'opt' => $d['optional']));
1149
                    }
1142
                    }
1150
                }
1143
                }
1151
                if ($d['rel'] != 'has' && $d['rel'] != 'not' && empty($d['version'])) {
1144
                if ($d['rel'] != 'has' && $d['rel'] != 'not' && empty($d['version'])) {
1152
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPVERSION,
1145
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPVERSION,
1153
                        array('index' => $i));
1146
                        array('index' => $i));
1154
                } elseif (($d['rel'] == 'has' || $d['rel'] == 'not') && !empty($d['version'])) {
1147
                } elseif (($d['rel'] == 'has' || $d['rel'] == 'not') && !empty($d['version'])) {
1155
                    $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_DEPVERSION_IGNORED,
1148
                    $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_DEPVERSION_IGNORED,
1156
                        array('index' => $i, 'rel' => $d['rel']));
1149
                        array('index' => $i, 'rel' => $d['rel']));
1157
                }
1150
                }
1158
                if ($d['type'] == 'php' && !empty($d['name'])) {
1151
                if ($d['type'] == 'php' && !empty($d['name'])) {
1159
                    $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_DEPNAME_IGNORED,
1152
                    $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_DEPNAME_IGNORED,
1160
                        array('index' => $i, 'name' => $d['name']));
1153
                        array('index' => $i, 'name' => $d['name']));
1161
                } elseif ($d['type'] != 'php' && empty($d['name'])) {
1154
                } elseif ($d['type'] != 'php' && empty($d['name'])) {
1162
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPNAME,
1155
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPNAME,
1163
                        array('index' => $i));
1156
                        array('index' => $i));
1164
                }
1157
                }
1165
                if ($d['type'] == 'php' && empty($d['version'])) {
1158
                if ($d['type'] == 'php' && empty($d['version'])) {
1166
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPPHPVERSION,
1159
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_DEPPHPVERSION,
1167
                        array('index' => $i));
1160
                        array('index' => $i));
1168
                }
1161
                }
1169
                if (($d['rel'] == 'not') && ($d['type'] == 'php')) {
1162
                if (($d['rel'] == 'not') && ($d['type'] == 'php')) {
1170
                    $this->_validateError(PEAR_PACKAGEFILE_PHP_NO_NOT,
1163
                    $this->_validateError(PEAR_PACKAGEFILE_PHP_NO_NOT,
1171
                        array('index' => $i));
1164
                        array('index' => $i));
1172
                }
1165
                }
1173
                $i++;
1166
                $i++;
1174
            }
1167
            }
1175
        }
1168
        }
1176
        if (!empty($info['configure_options'])) {
1169
        if (!empty($info['configure_options'])) {
1177
            $i = 1;
1170
            $i = 1;
1178
            foreach ($info['configure_options'] as $c) {
1171
            foreach ($info['configure_options'] as $c) {
1179
                if (empty($c['name'])) {
1172
                if (empty($c['name'])) {
1180
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_CONFNAME,
1173
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_CONFNAME,
1181
                        array('index' => $i));
1174
                        array('index' => $i));
1182
                }
1175
                }
1183
                if (empty($c['prompt'])) {
1176
                if (empty($c['prompt'])) {
1184
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_CONFPROMPT,
1177
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_CONFPROMPT,
1185
                        array('index' => $i));
1178
                        array('index' => $i));
1186
                }
1179
                }
1187
                $i++;
1180
                $i++;
1188
            }
1181
            }
1189
        }
1182
        }
1190
        if (empty($info['filelist'])) {
1183
        if (empty($info['filelist'])) {
1191
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_FILES);
1184
            $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_FILES);
1192
            $errors[] = 'no files';
1185
            $errors[] = 'no files';
1193
        } else {
1186
        } else {
1194
            foreach ($info['filelist'] as $file => $fa) {
1187
            foreach ($info['filelist'] as $file => $fa) {
1195
                if (empty($fa['role'])) {
1188
                if (empty($fa['role'])) {
1196
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_FILEROLE,
1189
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_NO_FILEROLE,
1197
                        array('file' => $file, 'roles' => PEAR_Common::getFileRoles()));
1190
                        array('file' => $file, 'roles' => PEAR_Common::getFileRoles()));
1198
                    continue;
1191
                    continue;
1199
                } elseif (!in_array($fa['role'], PEAR_Common::getFileRoles())) {
1192
                } elseif (!in_array($fa['role'], PEAR_Common::getFileRoles())) {
1200
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE,
1193
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILEROLE,
1201
                        array('file' => $file, 'role' => $fa['role'], 'roles' => PEAR_Common::getFileRoles()));
1194
                        array('file' => $file, 'role' => $fa['role'], 'roles' => PEAR_Common::getFileRoles()));
1202
                }
1195
                }
1203
                if ($file{0} == '.' && $file{1} == '/') {
1196
                if (preg_match('~/\.\.?(/|\\z)|^\.\.?/~', str_replace('\\', '/', $file))) {
-
 
1197
                    // file contains .. parent directory or . cur directory references
1204
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME,
1198
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME,
1205
                        array('file' => $file));
1199
                        array('file' => $file));
1206
                }
1200
                }
-
 
1201
                if (isset($fa['install-as']) &&
-
 
1202
                      preg_match('~/\.\.?(/|\\z)|^\.\.?/~', 
-
 
1203
                                 str_replace('\\', '/', $fa['install-as']))) {
-
 
1204
                    // install-as contains .. parent directory or . cur directory references
-
 
1205
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME,
-
 
1206
                        array('file' => $file . ' [installed as ' . $fa['install-as'] . ']'));
-
 
1207
                }
-
 
1208
                if (isset($fa['baseinstalldir']) &&
-
 
1209
                      preg_match('~/\.\.?(/|\\z)|^\.\.?/~', 
-
 
1210
                                 str_replace('\\', '/', $fa['baseinstalldir']))) {
-
 
1211
                    // install-as contains .. parent directory or . cur directory references
-
 
1212
                    $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_FILENAME,
-
 
1213
                        array('file' => $file . ' [baseinstalldir ' . $fa['baseinstalldir'] . ']'));
-
 
1214
                }
1207
            }
1215
            }
1208
        }
1216
        }
1209
        if (isset($this->_registry) && $this->_isValid) {
1217
        if (isset($this->_registry) && $this->_isValid) {
1210
            $chan = $this->_registry->getChannel('pear.php.net');
1218
            $chan = $this->_registry->getChannel('pear.php.net');
1211
            if (PEAR::isError($chan)) {
1219
            if (PEAR::isError($chan)) {
1212
                $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $chan->getMessage());
1220
                $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $chan->getMessage());
1213
                return $this->_isValid = 0;
1221
                return $this->_isValid = 0;
1214
            }
1222
            }
1215
            $validator = $chan->getValidationObject();
1223
            $validator = $chan->getValidationObject();
1216
            $validator->setPackageFile($this);
1224
            $validator->setPackageFile($this);
1217
            $validator->validate($state);
1225
            $validator->validate($state);
1218
            $failures = $validator->getFailures();
1226
            $failures = $validator->getFailures();
1219
            foreach ($failures['errors'] as $error) {
1227
            foreach ($failures['errors'] as $error) {
1220
                $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $error);
1228
                $this->_validateError(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $error);
1221
            }
1229
            }
1222
            foreach ($failures['warnings'] as $warning) {
1230
            foreach ($failures['warnings'] as $warning) {
1223
                $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $warning);
1231
                $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_CHANNELVAL, $warning);
1224
            }
1232
            }
1225
        }
1233
        }
1226
        if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$nofilechecking) {
1234
        if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$nofilechecking) {
1227
            if ($this->_analyzePhpFiles()) {
1235
            if ($this->_analyzePhpFiles()) {
1228
                $this->_isValid = true;
1236
                $this->_isValid = true;
1229
            }
1237
            }
1230
        }
1238
        }
1231
        if ($this->_isValid) {
1239
        if ($this->_isValid) {
1232
            return $this->_isValid = $state;
1240
            return $this->_isValid = $state;
1233
        }
1241
        }
1234
        return $this->_isValid = 0;
1242
        return $this->_isValid = 0;
1235
    }
1243
    }
1236
 
1244
 
1237
    function _analyzePhpFiles()
1245
    function _analyzePhpFiles()
1238
    {
1246
    {
1239
        if (!$this->_isValid) {
1247
        if (!$this->_isValid) {
1240
            return false;
1248
            return false;
1241
        }
1249
        }
1242
        if (!isset($this->_packageFile)) {
1250
        if (!isset($this->_packageFile)) {
1243
            return false;
1251
            return false;
1244
        }
1252
        }
1245
        $dir_prefix = dirname($this->_packageFile);
1253
        $dir_prefix = dirname($this->_packageFile);
1246
        $common = new PEAR_Common;
1254
        $common = new PEAR_Common;
1247
        $log = isset($this->_logger) ? array(&$this->_logger, 'log') :
1255
        $log = isset($this->_logger) ? array(&$this->_logger, 'log') :
1248
            array($common, 'log');
1256
            array($common, 'log');
1249
        $info = $this->getFilelist();
1257
        $info = $this->getFilelist();
1250
        foreach ($info as $file => $fa) {
1258
        foreach ($info as $file => $fa) {
1251
            if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $file)) {
1259
            if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $file)) {
1252
                $this->_validateError(PEAR_PACKAGEFILE_ERROR_FILE_NOTFOUND,
1260
                $this->_validateError(PEAR_PACKAGEFILE_ERROR_FILE_NOTFOUND,
1253
                    array('file' => realpath($dir_prefix) . DIRECTORY_SEPARATOR . $file));
1261
                    array('file' => realpath($dir_prefix) . DIRECTORY_SEPARATOR . $file));
1254
                continue;
1262
                continue;
1255
            }
1263
            }
1256
            if ($fa['role'] == 'php' && $dir_prefix) {
1264
            if ($fa['role'] == 'php' && $dir_prefix) {
1257
                call_user_func_array($log, array(1, "Analyzing $file"));
1265
                call_user_func_array($log, array(1, "Analyzing $file"));
1258
                $srcinfo = $this->_analyzeSourceCode($dir_prefix . DIRECTORY_SEPARATOR . $file);
1266
                $srcinfo = $this->_analyzeSourceCode($dir_prefix . DIRECTORY_SEPARATOR . $file);
1259
                if ($srcinfo) {
1267
                if ($srcinfo) {
1260
                    $this->_buildProvidesArray($srcinfo);
1268
                    $this->_buildProvidesArray($srcinfo);
1261
                }
1269
                }
1262
            }
1270
            }
1263
        }
1271
        }
1264
        $this->_packageName = $pn = $this->getPackage();
1272
        $this->_packageName = $pn = $this->getPackage();
1265
        $pnl = strlen($pn);
1273
        $pnl = strlen($pn);
1266
        if (isset($this->_packageInfo['provides'])) {
1274
        if (isset($this->_packageInfo['provides'])) {
1267
            foreach ((array) $this->_packageInfo['provides'] as $key => $what) {
1275
            foreach ((array) $this->_packageInfo['provides'] as $key => $what) {
1268
                if (isset($what['explicit'])) {
1276
                if (isset($what['explicit'])) {
1269
                    // skip conformance checks if the provides entry is
1277
                    // skip conformance checks if the provides entry is
1270
                    // specified in the package.xml file
1278
                    // specified in the package.xml file
1271
                    continue;
1279
                    continue;
1272
                }
1280
                }
1273
                extract($what);
1281
                extract($what);
1274
                if ($type == 'class') {
1282
                if ($type == 'class') {
1275
                    if (!strncasecmp($name, $pn, $pnl)) {
1283
                    if (!strncasecmp($name, $pn, $pnl)) {
1276
                        continue;
1284
                        continue;
1277
                    }
1285
                    }
1278
                    $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX,
1286
                    $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX,
1279
                        array('file' => $file, 'type' => $type, 'name' => $name, 'package' => $pn));
1287
                        array('file' => $file, 'type' => $type, 'name' => $name, 'package' => $pn));
1280
                } elseif ($type == 'function') {
1288
                } elseif ($type == 'function') {
1281
                    if (strstr($name, '::') || !strncasecmp($name, $pn, $pnl)) {
1289
                    if (strstr($name, '::') || !strncasecmp($name, $pn, $pnl)) {
1282
                        continue;
1290
                        continue;
1283
                    }
1291
                    }
1284
                    $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX,
1292
                    $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_NO_PNAME_PREFIX,
1285
                        array('file' => $file, 'type' => $type, 'name' => $name, 'package' => $pn));
1293
                        array('file' => $file, 'type' => $type, 'name' => $name, 'package' => $pn));
1286
                }
1294
                }
1287
            }
1295
            }
1288
        }
1296
        }
1289
        return $this->_isValid;
1297
        return $this->_isValid;
1290
    }
1298
    }
1291
 
1299
 
1292
    /**
1300
    /**
1293
     * Get the default xml generator object
1301
     * Get the default xml generator object
1294
     *
1302
     *
1295
     * @return PEAR_PackageFile_Generator_v1
1303
     * @return PEAR_PackageFile_Generator_v1
1296
     */
1304
     */
1297
    function &getDefaultGenerator()
1305
    function &getDefaultGenerator()
1298
    {
1306
    {
1299
        if (!class_exists('PEAR_PackageFile_Generator_v1')) {
1307
        if (!class_exists('PEAR_PackageFile_Generator_v1')) {
1300
            require_once 'PEAR/PackageFile/Generator/v1.php';
1308
            require_once 'PEAR/PackageFile/Generator/v1.php';
1301
        }
1309
        }
1302
        $a = &new PEAR_PackageFile_Generator_v1($this);
1310
        $a = new PEAR_PackageFile_Generator_v1($this);
1303
        return $a;
1311
        return $a;
1304
    }
1312
    }
1305
 
1313
 
1306
    /**
1314
    /**
1307
     * Get the contents of a file listed within the package.xml
1315
     * Get the contents of a file listed within the package.xml
1308
     * @param string
1316
     * @param string
1309
     * @return string
1317
     * @return string
1310
     */
1318
     */
1311
    function getFileContents($file)
1319
    function getFileContents($file)
1312
    {
1320
    {
1313
        if ($this->_archiveFile == $this->_packageFile) { // unpacked
1321
        if ($this->_archiveFile == $this->_packageFile) { // unpacked
1314
            $dir = dirname($this->_packageFile);
1322
            $dir = dirname($this->_packageFile);
1315
            $file = $dir . DIRECTORY_SEPARATOR . $file;
1323
            $file = $dir . DIRECTORY_SEPARATOR . $file;
1316
            $file = str_replace(array('/', '\\'),
1324
            $file = str_replace(array('/', '\\'),
1317
                array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $file);
1325
                array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $file);
1318
            if (file_exists($file) && is_readable($file)) {
1326
            if (file_exists($file) && is_readable($file)) {
1319
                return implode('', file($file));
1327
                return implode('', file($file));
1320
            }
1328
            }
1321
        } else { // tgz
1329
        } else { // tgz
1322
            if (!class_exists('Archive_Tar')) {
1330
            if (!class_exists('Archive_Tar')) {
1323
                require_once 'Archive/Tar.php';
1331
                require_once 'Archive/Tar.php';
1324
            }
1332
            }
1325
            $tar = &new Archive_Tar($this->_archiveFile);
1333
            $tar = new Archive_Tar($this->_archiveFile);
1326
            $tar->pushErrorHandling(PEAR_ERROR_RETURN);
1334
            $tar->pushErrorHandling(PEAR_ERROR_RETURN);
1327
            if ($file != 'package.xml' && $file != 'package2.xml') {
1335
            if ($file != 'package.xml' && $file != 'package2.xml') {
1328
                $file = $this->getPackage() . '-' . $this->getVersion() . '/' . $file;
1336
                $file = $this->getPackage() . '-' . $this->getVersion() . '/' . $file;
1329
            }
1337
            }
1330
            $file = $tar->extractInString($file);
1338
            $file = $tar->extractInString($file);
1331
            $tar->popErrorHandling();
1339
            $tar->popErrorHandling();
1332
            if (PEAR::isError($file)) {
1340
            if (PEAR::isError($file)) {
1333
                return PEAR::raiseError("Cannot locate file '$file' in archive");
1341
                return PEAR::raiseError("Cannot locate file '$file' in archive");
1334
            }
1342
            }
1335
            return $file;
1343
            return $file;
1336
        }
1344
        }
1337
    }
1345
    }
1338
 
1346
 
1339
    // {{{ analyzeSourceCode()
1347
    // {{{ analyzeSourceCode()
1340
    /**
1348
    /**
1341
     * Analyze the source code of the given PHP file
1349
     * Analyze the source code of the given PHP file
1342
     *
1350
     *
1343
     * @param  string Filename of the PHP file
1351
     * @param  string Filename of the PHP file
1344
     * @return mixed
1352
     * @return mixed
1345
     * @access private
1353
     * @access private
1346
     */
1354
     */
1347
    function _analyzeSourceCode($file)
1355
    function _analyzeSourceCode($file)
1348
    {
1356
    {
1349
        if (!function_exists("token_get_all")) {
1357
        if (!function_exists("token_get_all")) {
1350
            return false;
1358
            return false;
1351
        }
1359
        }
1352
        if (!defined('T_DOC_COMMENT')) {
1360
        if (!defined('T_DOC_COMMENT')) {
1353
            define('T_DOC_COMMENT', T_COMMENT);
1361
            define('T_DOC_COMMENT', T_COMMENT);
1354
        }
1362
        }
1355
        if (!defined('T_INTERFACE')) {
1363
        if (!defined('T_INTERFACE')) {
1356
            define('T_INTERFACE', -1);
1364
            define('T_INTERFACE', -1);
1357
        }
1365
        }
1358
        if (!defined('T_IMPLEMENTS')) {
1366
        if (!defined('T_IMPLEMENTS')) {
1359
            define('T_IMPLEMENTS', -1);
1367
            define('T_IMPLEMENTS', -1);
1360
        }
1368
        }
1361
        if (!$fp = @fopen($file, "r")) {
1369
        if (!$fp = @fopen($file, "r")) {
1362
            return false;
1370
            return false;
1363
        }
1371
        }
1364
        fclose($fp);
1372
        fclose($fp);
1365
        $contents = file_get_contents($file);
1373
        $contents = file_get_contents($file);
1366
        $tokens = token_get_all($contents);
1374
        $tokens = token_get_all($contents);
1367
/*
1375
/*
1368
        for ($i = 0; $i < sizeof($tokens); $i++) {
1376
        for ($i = 0; $i < sizeof($tokens); $i++) {
1369
            @list($token, $data) = $tokens[$i];
1377
            @list($token, $data) = $tokens[$i];
1370
            if (is_string($token)) {
1378
            if (is_string($token)) {
1371
                var_dump($token);
1379
                var_dump($token);
1372
            } else {
1380
            } else {
1373
                print token_name($token) . ' ';
1381
                print token_name($token) . ' ';
1374
                var_dump(rtrim($data));
1382
                var_dump(rtrim($data));
1375
            }
1383
            }
1376
        }
1384
        }
1377
*/
1385
*/
1378
        $look_for = 0;
1386
        $look_for = 0;
1379
        $paren_level = 0;
1387
        $paren_level = 0;
1380
        $bracket_level = 0;
1388
        $bracket_level = 0;
1381
        $brace_level = 0;
1389
        $brace_level = 0;
1382
        $lastphpdoc = '';
1390
        $lastphpdoc = '';
1383
        $current_class = '';
1391
        $current_class = '';
1384
        $current_interface = '';
1392
        $current_interface = '';
1385
        $current_class_level = -1;
1393
        $current_class_level = -1;
1386
        $current_function = '';
1394
        $current_function = '';
1387
        $current_function_level = -1;
1395
        $current_function_level = -1;
1388
        $declared_classes = array();
1396
        $declared_classes = array();
1389
        $declared_interfaces = array();
1397
        $declared_interfaces = array();
1390
        $declared_functions = array();
1398
        $declared_functions = array();
1391
        $declared_methods = array();
1399
        $declared_methods = array();
1392
        $used_classes = array();
1400
        $used_classes = array();
1393
        $used_functions = array();
1401
        $used_functions = array();
1394
        $extends = array();
1402
        $extends = array();
1395
        $implements = array();
1403
        $implements = array();
1396
        $nodeps = array();
1404
        $nodeps = array();
1397
        $inquote = false;
1405
        $inquote = false;
1398
        $interface = false;
1406
        $interface = false;
1399
        for ($i = 0; $i < sizeof($tokens); $i++) {
1407
        for ($i = 0; $i < sizeof($tokens); $i++) {
1400
            if (is_array($tokens[$i])) {
1408
            if (is_array($tokens[$i])) {
1401
                list($token, $data) = $tokens[$i];
1409
                list($token, $data) = $tokens[$i];
1402
            } else {
1410
            } else {
1403
                $token = $tokens[$i];
1411
                $token = $tokens[$i];
1404
                $data = '';
1412
                $data = '';
1405
            }
1413
            }
1406
            if ($inquote) {
1414
            if ($inquote) {
1407
                if ($token != '"' && $token != T_END_HEREDOC) {
1415
                if ($token != '"' && $token != T_END_HEREDOC) {
1408
                    continue;
1416
                    continue;
1409
                } else {
1417
                } else {
1410
                    $inquote = false;
1418
                    $inquote = false;
1411
                    continue;
1419
                    continue;
1412
                }
1420
                }
1413
            }
1421
            }
1414
            switch ($token) {
1422
            switch ($token) {
1415
                case T_WHITESPACE :
1423
                case T_WHITESPACE :
1416
                    continue;
1424
                    continue;
1417
                case ';':
1425
                case ';':
1418
                    if ($interface) {
1426
                    if ($interface) {
1419
                        $current_function = '';
1427
                        $current_function = '';
1420
                        $current_function_level = -1;
1428
                        $current_function_level = -1;
1421
                    }
1429
                    }
1422
                    break;
1430
                    break;
1423
                case '"':
1431
                case '"':
1424
                case T_START_HEREDOC:
1432
                case T_START_HEREDOC:
1425
                    $inquote = true;
1433
                    $inquote = true;
1426
                    break;
1434
                    break;
1427
                case T_CURLY_OPEN:
1435
                case T_CURLY_OPEN:
1428
                case T_DOLLAR_OPEN_CURLY_BRACES:
1436
                case T_DOLLAR_OPEN_CURLY_BRACES:
1429
                case '{': $brace_level++; continue 2;
1437
                case '{': $brace_level++; continue 2;
1430
                case '}':
1438
                case '}':
1431
                    $brace_level--;
1439
                    $brace_level--;
1432
                    if ($current_class_level == $brace_level) {
1440
                    if ($current_class_level == $brace_level) {
1433
                        $current_class = '';
1441
                        $current_class = '';
1434
                        $current_class_level = -1;
1442
                        $current_class_level = -1;
1435
                    }
1443
                    }
1436
                    if ($current_function_level == $brace_level) {
1444
                    if ($current_function_level == $brace_level) {
1437
                        $current_function = '';
1445
                        $current_function = '';
1438
                        $current_function_level = -1;
1446
                        $current_function_level = -1;
1439
                    }
1447
                    }
1440
                    continue 2;
1448
                    continue 2;
1441
                case '[': $bracket_level++; continue 2;
1449
                case '[': $bracket_level++; continue 2;
1442
                case ']': $bracket_level--; continue 2;
1450
                case ']': $bracket_level--; continue 2;
1443
                case '(': $paren_level++;   continue 2;
1451
                case '(': $paren_level++;   continue 2;
1444
                case ')': $paren_level--;   continue 2;
1452
                case ')': $paren_level--;   continue 2;
1445
                case T_INTERFACE:
1453
                case T_INTERFACE:
1446
                    $interface = true;
1454
                    $interface = true;
1447
                case T_CLASS:
1455
                case T_CLASS:
1448
                    if (($current_class_level != -1) || ($current_function_level != -1)) {
1456
                    if (($current_class_level != -1) || ($current_function_level != -1)) {
1449
                        $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE,
1457
                        $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE,
1450
                            array('file' => $file));
1458
                            array('file' => $file));
1451
                        return false;
1459
                        return false;
1452
                    }
1460
                    }
1453
                case T_FUNCTION:
1461
                case T_FUNCTION:
1454
                case T_NEW:
1462
                case T_NEW:
1455
                case T_EXTENDS:
1463
                case T_EXTENDS:
1456
                case T_IMPLEMENTS:
1464
                case T_IMPLEMENTS:
1457
                    $look_for = $token;
1465
                    $look_for = $token;
1458
                    continue 2;
1466
                    continue 2;
1459
                case T_STRING:
1467
                case T_STRING:
1460
                    if (version_compare(zend_version(), '2.0', '<')) {
-
 
1461
                        if (in_array(strtolower($data),
-
 
1462
                            array('public', 'private', 'protected', 'abstract',
-
 
1463
                                  'interface', 'implements', 'throw') 
-
 
1464
                                 )) {
-
 
1465
                            $this->_validateWarning(PEAR_PACKAGEFILE_ERROR_PHP5,
-
 
1466
                                array($file));
-
 
1467
                        }
-
 
1468
                    }
-
 
1469
                    if ($look_for == T_CLASS) {
1468
                    if ($look_for == T_CLASS) {
1470
                        $current_class = $data;
1469
                        $current_class = $data;
1471
                        $current_class_level = $brace_level;
1470
                        $current_class_level = $brace_level;
1472
                        $declared_classes[] = $current_class;
1471
                        $declared_classes[] = $current_class;
1473
                    } elseif ($look_for == T_INTERFACE) {
1472
                    } elseif ($look_for == T_INTERFACE) {
1474
                        $current_interface = $data;
1473
                        $current_interface = $data;
1475
                        $current_class_level = $brace_level;
1474
                        $current_class_level = $brace_level;
1476
                        $declared_interfaces[] = $current_interface;
1475
                        $declared_interfaces[] = $current_interface;
1477
                    } elseif ($look_for == T_IMPLEMENTS) {
1476
                    } elseif ($look_for == T_IMPLEMENTS) {
1478
                        $implements[$current_class] = $data;
1477
                        $implements[$current_class] = $data;
1479
                    } elseif ($look_for == T_EXTENDS) {
1478
                    } elseif ($look_for == T_EXTENDS) {
1480
                        $extends[$current_class] = $data;
1479
                        $extends[$current_class] = $data;
1481
                    } elseif ($look_for == T_FUNCTION) {
1480
                    } elseif ($look_for == T_FUNCTION) {
1482
                        if ($current_class) {
1481
                        if ($current_class) {
1483
                            $current_function = "$current_class::$data";
1482
                            $current_function = "$current_class::$data";
1484
                            $declared_methods[$current_class][] = $data;
1483
                            $declared_methods[$current_class][] = $data;
1485
                        } elseif ($current_interface) {
1484
                        } elseif ($current_interface) {
1486
                            $current_function = "$current_interface::$data";
1485
                            $current_function = "$current_interface::$data";
1487
                            $declared_methods[$current_interface][] = $data;
1486
                            $declared_methods[$current_interface][] = $data;
1488
                        } else {
1487
                        } else {
1489
                            $current_function = $data;
1488
                            $current_function = $data;
1490
                            $declared_functions[] = $current_function;
1489
                            $declared_functions[] = $current_function;
1491
                        }
1490
                        }
1492
                        $current_function_level = $brace_level;
1491
                        $current_function_level = $brace_level;
1493
                        $m = array();
1492
                        $m = array();
1494
                    } elseif ($look_for == T_NEW) {
1493
                    } elseif ($look_for == T_NEW) {
1495
                        $used_classes[$data] = true;
1494
                        $used_classes[$data] = true;
1496
                    }
1495
                    }
1497
                    $look_for = 0;
1496
                    $look_for = 0;
1498
                    continue 2;
1497
                    continue 2;
1499
                case T_VARIABLE:
1498
                case T_VARIABLE:
1500
                    $look_for = 0;
1499
                    $look_for = 0;
1501
                    continue 2;
1500
                    continue 2;
1502
                case T_DOC_COMMENT:
1501
                case T_DOC_COMMENT:
1503
                case T_COMMENT:
1502
                case T_COMMENT:
1504
                    if (preg_match('!^/\*\*\s!', $data)) {
1503
                    if (preg_match('!^/\*\*\s!', $data)) {
1505
                        $lastphpdoc = $data;
1504
                        $lastphpdoc = $data;
1506
                        if (preg_match_all('/@nodep\s+(\S+)/', $lastphpdoc, $m)) {
1505
                        if (preg_match_all('/@nodep\s+(\S+)/', $lastphpdoc, $m)) {
1507
                            $nodeps = array_merge($nodeps, $m[1]);
1506
                            $nodeps = array_merge($nodeps, $m[1]);
1508
                        }
1507
                        }
1509
                    }
1508
                    }
1510
                    continue 2;
1509
                    continue 2;
1511
                case T_DOUBLE_COLON:
1510
                case T_DOUBLE_COLON:
1512
                    if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
1511
                    if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
1513
                        $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE,
1512
                        $this->_validateError(PEAR_PACKAGEFILE_ERROR_INVALID_PHPFILE,
1514
                            array('file' => $file));
1513
                            array('file' => $file));
1515
                        return false;
1514
                        return false;
1516
                    }
1515
                    }
1517
                    $class = $tokens[$i - 1][1];
1516
                    $class = $tokens[$i - 1][1];
1518
                    if (strtolower($class) != 'parent') {
1517
                    if (strtolower($class) != 'parent') {
1519
                        $used_classes[$class] = true;
1518
                        $used_classes[$class] = true;
1520
                    }
1519
                    }
1521
                    continue 2;
1520
                    continue 2;
1522
            }
1521
            }
1523
        }
1522
        }
1524
        return array(
1523
        return array(
1525
            "source_file" => $file,
1524
            "source_file" => $file,
1526
            "declared_classes" => $declared_classes,
1525
            "declared_classes" => $declared_classes,
1527
            "declared_interfaces" => $declared_interfaces,
1526
            "declared_interfaces" => $declared_interfaces,
1528
            "declared_methods" => $declared_methods,
1527
            "declared_methods" => $declared_methods,
1529
            "declared_functions" => $declared_functions,
1528
            "declared_functions" => $declared_functions,
1530
            "used_classes" => array_diff(array_keys($used_classes), $nodeps),
1529
            "used_classes" => array_diff(array_keys($used_classes), $nodeps),
1531
            "inheritance" => $extends,
1530
            "inheritance" => $extends,
1532
            "implements" => $implements,
1531
            "implements" => $implements,
1533
            );
1532
            );
1534
    }
1533
    }
1535
 
1534
 
1536
    /**
1535
    /**
1537
     * Build a "provides" array from data returned by
1536
     * Build a "provides" array from data returned by
1538
     * analyzeSourceCode().  The format of the built array is like
1537
     * analyzeSourceCode().  The format of the built array is like
1539
     * this:
1538
     * this:
1540
     *
1539
     *
1541
     *  array(
1540
     *  array(
1542
     *    'class;MyClass' => 'array('type' => 'class', 'name' => 'MyClass'),
1541
     *    'class;MyClass' => 'array('type' => 'class', 'name' => 'MyClass'),
1543
     *    ...
1542
     *    ...
1544
     *  )
1543
     *  )
1545
     *
1544
     *
1546
     *
1545
     *
1547
     * @param array $srcinfo array with information about a source file
1546
     * @param array $srcinfo array with information about a source file
1548
     * as returned by the analyzeSourceCode() method.
1547
     * as returned by the analyzeSourceCode() method.
1549
     *
1548
     *
1550
     * @return void
1549
     * @return void
1551
     *
1550
     *
1552
     * @access private
1551
     * @access private
1553
     *
1552
     *
1554
     */
1553
     */
1555
    function _buildProvidesArray($srcinfo)
1554
    function _buildProvidesArray($srcinfo)
1556
    {
1555
    {
1557
        if (!$this->_isValid) {
1556
        if (!$this->_isValid) {
1558
            return false;
1557
            return false;
1559
        }
1558
        }
1560
        $file = basename($srcinfo['source_file']);
1559
        $file = basename($srcinfo['source_file']);
1561
        $pn = $this->getPackage();
1560
        $pn = $this->getPackage();
1562
        $pnl = strlen($pn);
1561
        $pnl = strlen($pn);
1563
        foreach ($srcinfo['declared_classes'] as $class) {
1562
        foreach ($srcinfo['declared_classes'] as $class) {
1564
            $key = "class;$class";
1563
            $key = "class;$class";
1565
            if (isset($this->_packageInfo['provides'][$key])) {
1564
            if (isset($this->_packageInfo['provides'][$key])) {
1566
                continue;
1565
                continue;
1567
            }
1566
            }
1568
            $this->_packageInfo['provides'][$key] =
1567
            $this->_packageInfo['provides'][$key] =
1569
                array('file'=> $file, 'type' => 'class', 'name' => $class);
1568
                array('file'=> $file, 'type' => 'class', 'name' => $class);
1570
            if (isset($srcinfo['inheritance'][$class])) {
1569
            if (isset($srcinfo['inheritance'][$class])) {
1571
                $this->_packageInfo['provides'][$key]['extends'] =
1570
                $this->_packageInfo['provides'][$key]['extends'] =
1572
                    $srcinfo['inheritance'][$class];
1571
                    $srcinfo['inheritance'][$class];
1573
            }
1572
            }
1574
        }
1573
        }
1575
        foreach ($srcinfo['declared_methods'] as $class => $methods) {
1574
        foreach ($srcinfo['declared_methods'] as $class => $methods) {
1576
            foreach ($methods as $method) {
1575
            foreach ($methods as $method) {
1577
                $function = "$class::$method";
1576
                $function = "$class::$method";
1578
                $key = "function;$function";
1577
                $key = "function;$function";
1579
                if ($method{0} == '_' || !strcasecmp($method, $class) ||
1578
                if ($method{0} == '_' || !strcasecmp($method, $class) ||
1580
                    isset($this->_packageInfo['provides'][$key])) {
1579
                    isset($this->_packageInfo['provides'][$key])) {
1581
                    continue;
1580
                    continue;
1582
                }
1581
                }
1583
                $this->_packageInfo['provides'][$key] =
1582
                $this->_packageInfo['provides'][$key] =
1584
                    array('file'=> $file, 'type' => 'function', 'name' => $function);
1583
                    array('file'=> $file, 'type' => 'function', 'name' => $function);
1585
            }
1584
            }
1586
        }
1585
        }
1587
 
1586
 
1588
        foreach ($srcinfo['declared_functions'] as $function) {
1587
        foreach ($srcinfo['declared_functions'] as $function) {
1589
            $key = "function;$function";
1588
            $key = "function;$function";
1590
            if ($function{0} == '_' || isset($this->_packageInfo['provides'][$key])) {
1589
            if ($function{0} == '_' || isset($this->_packageInfo['provides'][$key])) {
1591
                continue;
1590
                continue;
1592
            }
1591
            }
1593
            if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {
1592
            if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {
1594
                $warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";
1593
                $warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";
1595
            }
1594
            }
1596
            $this->_packageInfo['provides'][$key] =
1595
            $this->_packageInfo['provides'][$key] =
1597
                array('file'=> $file, 'type' => 'function', 'name' => $function);
1596
                array('file'=> $file, 'type' => 'function', 'name' => $function);
1598
        }
1597
        }
1599
    }
1598
    }
1600
 
1599
 
1601
    // }}}
1600
    // }}}
1602
}
1601
}
1603
?>
1602
?>