Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
2
/**
2
/**
3
 * PEAR_Common, the base class for the PEAR Installer
3
 * PEAR_Common, the base class for the PEAR Installer
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     Stig Bakken <ssb@php.net>
9
 * @author     Stig Bakken <ssb@php.net>
16
 * @author     Tomas V. V. Cox <cox@idecnet.com>
10
 * @author     Tomas V. V. Cox <cox@idecnet.com>
17
 * @author     Greg Beaver <cellog@php.net>
11
 * @author     Greg Beaver <cellog@php.net>
18
 * @copyright  1997-2006 The PHP Group
12
 * @copyright  1997-2009 The Authors
19
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
13
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
20
 * @version    CVS: $Id: Common.php,v 1.157 2006/05/12 02:38:58 cellog Exp $
-
 
21
 * @link       http://pear.php.net/package/PEAR
14
 * @link       http://pear.php.net/package/PEAR
22
 * @since      File available since Release 0.1.0
15
 * @since      File available since Release 0.1.0
23
 * @deprecated File deprecated since Release 1.4.0a1
16
 * @deprecated File deprecated since Release 1.4.0a1
24
 */
17
 */
Line 25... Line 18...
25
 
18
 
26
/**
19
/**
27
 * Include error handling
20
 * Include error handling
28
 */
21
 */
Line 29... Line -...
29
require_once 'PEAR.php';
-
 
30
 
-
 
31
// {{{ constants and globals
22
require_once 'PEAR.php';
32
 
23
 
33
/**
24
/**
34
 * PEAR_Common error when an invalid PHP file is passed to PEAR_Common::analyzeSourceCode()
25
 * PEAR_Common error when an invalid PHP file is passed to PEAR_Common::analyzeSourceCode()
35
 */
26
 */
36
define('PEAR_COMMON_ERROR_INVALIDPHP', 1);
27
define('PEAR_COMMON_ERROR_INVALIDPHP', 1);
Line 37... Line 28...
37
define('_PEAR_COMMON_PACKAGE_NAME_PREG', '[A-Za-z][a-zA-Z0-9_]+');
28
define('_PEAR_COMMON_PACKAGE_NAME_PREG', '[A-Za-z][a-zA-Z0-9_]+');
38
define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/');
29
define('PEAR_COMMON_PACKAGE_NAME_PREG', '/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '\\z/');
39
 
30
 
Line 40... Line 31...
40
// this should allow: 1, 1.0, 1.0RC1, 1.0dev, 1.0dev123234234234, 1.0a1, 1.0b1, 1.0pl1
31
// this should allow: 1, 1.0, 1.0RC1, 1.0dev, 1.0dev123234234234, 1.0a1, 1.0b1, 1.0pl1
41
define('_PEAR_COMMON_PACKAGE_VERSION_PREG', '\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?');
32
define('_PEAR_COMMON_PACKAGE_VERSION_PREG', '\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?');
42
define('PEAR_COMMON_PACKAGE_VERSION_PREG', '/^' . _PEAR_COMMON_PACKAGE_VERSION_PREG . '$/i');
33
define('PEAR_COMMON_PACKAGE_VERSION_PREG', '/^' . _PEAR_COMMON_PACKAGE_VERSION_PREG . '\\z/i');
43
 
34
 
44
// XXX far from perfect :-)
35
// XXX far from perfect :-)
Line 45... Line 36...
45
define('_PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '(' . _PEAR_COMMON_PACKAGE_NAME_PREG .
36
define('_PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '(' . _PEAR_COMMON_PACKAGE_NAME_PREG .
46
    ')(-([.0-9a-zA-Z]+))?');
37
    ')(-([.0-9a-zA-Z]+))?');
Line 47... Line 38...
47
define('PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '/^' . _PEAR_COMMON_PACKAGE_DOWNLOAD_PREG .
38
define('PEAR_COMMON_PACKAGE_DOWNLOAD_PREG', '/^' . _PEAR_COMMON_PACKAGE_DOWNLOAD_PREG .
48
    '$/');
39
    '\\z/');
49
 
40
 
Line 50... Line 41...
50
define('_PEAR_CHANNELS_NAME_PREG', '[A-Za-z][a-zA-Z0-9\.]+');
41
define('_PEAR_CHANNELS_NAME_PREG', '[A-Za-z][a-zA-Z0-9\.]+');
51
define('PEAR_CHANNELS_NAME_PREG', '/^' . _PEAR_CHANNELS_NAME_PREG . '$/');
42
define('PEAR_CHANNELS_NAME_PREG', '/^' . _PEAR_CHANNELS_NAME_PREG . '\\z/');
52
 
43
 
Line 53... Line 44...
53
// this should allow any dns or IP address, plus a path - NO UNDERSCORES ALLOWED
44
// this should allow any dns or IP address, plus a path - NO UNDERSCORES ALLOWED
54
define('_PEAR_CHANNELS_SERVER_PREG', '[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*(\/[a-zA-Z0-9\-]+)*');
45
define('_PEAR_CHANNELS_SERVER_PREG', '[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*(\/[a-zA-Z0-9\-]+)*');
55
define('PEAR_CHANNELS_SERVER_PREG', '/^' . _PEAR_CHANNELS_SERVER_PREG . '$/i');
46
define('PEAR_CHANNELS_SERVER_PREG', '/^' . _PEAR_CHANNELS_SERVER_PREG . '\\z/i');
Line 56... Line 47...
56
 
47
 
57
define('_PEAR_CHANNELS_PACKAGE_PREG',  '(' ._PEAR_CHANNELS_SERVER_PREG . ')\/('
48
define('_PEAR_CHANNELS_PACKAGE_PREG',  '(' ._PEAR_CHANNELS_SERVER_PREG . ')\/('
58
         . _PEAR_COMMON_PACKAGE_NAME_PREG . ')');
49
         . _PEAR_COMMON_PACKAGE_NAME_PREG . ')');
59
define('PEAR_CHANNELS_PACKAGE_PREG', '/^' . _PEAR_CHANNELS_PACKAGE_PREG . '$/i');
50
define('PEAR_CHANNELS_PACKAGE_PREG', '/^' . _PEAR_CHANNELS_PACKAGE_PREG . '\\z/i');
Line 115... Line 106...
115
 * Valid "provide" types
106
 * Valid "provide" types
116
 * @var array
107
 * @var array
117
 */
108
 */
118
$GLOBALS['_PEAR_Common_script_phases'] = array('pre-install', 'post-install', 'pre-uninstall', 'post-uninstall', 'pre-build', 'post-build', 'pre-configure', 'post-configure', 'pre-setup', 'post-setup');
109
$GLOBALS['_PEAR_Common_script_phases'] = array('pre-install', 'post-install', 'pre-uninstall', 'post-uninstall', 'pre-build', 'post-build', 'pre-configure', 'post-configure', 'pre-setup', 'post-setup');
Line 119... Line -...
119
 
-
 
120
// }}}
-
 
121
 
110
 
122
/**
111
/**
123
 * Class providing common functionality for PEAR administration classes.
112
 * Class providing common functionality for PEAR administration classes.
124
 * @category   pear
113
 * @category   pear
125
 * @package    PEAR
114
 * @package    PEAR
126
 * @author     Stig Bakken <ssb@php.net>
115
 * @author     Stig Bakken <ssb@php.net>
127
 * @author     Tomas V. V. Cox <cox@idecnet.com>
116
 * @author     Tomas V. V. Cox <cox@idecnet.com>
128
 * @author     Greg Beaver <cellog@php.net>
117
 * @author     Greg Beaver <cellog@php.net>
129
 * @copyright  1997-2006 The PHP Group
118
 * @copyright  1997-2009 The Authors
130
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
119
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
131
 * @version    Release: 1.5.1
120
 * @version    Release: 1.10.1
132
 * @link       http://pear.php.net/package/PEAR
121
 * @link       http://pear.php.net/package/PEAR
133
 * @since      Class available since Release 1.4.0a1
122
 * @since      Class available since Release 1.4.0a1
134
 * @deprecated This class will disappear, and its components will be spread
123
 * @deprecated This class will disappear, and its components will be spread
135
 *             into smaller classes, like the AT&T breakup, as of Release 1.4.0a1
124
 *             into smaller classes, like the AT&T breakup, as of Release 1.4.0a1
136
 */
125
 */
137
class PEAR_Common extends PEAR
126
class PEAR_Common extends PEAR
-
 
127
{
-
 
128
    /**
-
 
129
     * User Interface object (PEAR_Frontend_* class).  If null,
138
{
130
     * the log() method uses print.
-
 
131
     * @var object
-
 
132
     */
-
 
133
    var $ui = null;
-
 
134
 
-
 
135
    /**
-
 
136
     * Configuration object (PEAR_Config).
-
 
137
     * @var PEAR_Config
-
 
138
     */
Line 139... Line 139...
139
    // {{{ properties
139
    var $config = null;
140
 
140
 
Line 141... Line 141...
141
    /** stack of elements, gives some sort of XML context */
141
    /** stack of elements, gives some sort of XML context */
Line 148... Line 148...
148
    var $current_attributes = array();
148
    var $current_attributes = array();
Line 149... Line 149...
149
 
149
 
150
    /** assoc with information about a package */
150
    /** assoc with information about a package */
Line 151... Line -...
151
    var $pkginfo = array();
-
 
152
 
-
 
153
    /**
-
 
154
     * User Interface object (PEAR_Frontend_* class).  If null,
-
 
155
     * the log() method uses print.
-
 
156
     * @var object
-
 
157
     */
-
 
158
    var $ui = null;
-
 
159
 
-
 
160
    /**
-
 
161
     * Configuration object (PEAR_Config).
-
 
162
     * @var object
-
 
163
     */
-
 
164
    var $config = null;
151
    var $pkginfo = array();
Line 165... Line 152...
165
 
152
 
166
    var $current_path = null;
-
 
167
 
-
 
168
    /**
-
 
169
     * PEAR_SourceAnalyzer instance
-
 
170
     * @var object
-
 
171
     */
153
    var $current_path = null;
172
    var $source_analyzer = null;
154
 
173
    /**
155
    /**
174
     * Flag variable used to mark a valid package file
156
     * Flag variable used to mark a valid package file
175
     * @var boolean
157
     * @var boolean
Line 176... Line -...
176
     * @access private
-
 
177
     */
-
 
178
    var $_validPackageFile;
-
 
179
 
-
 
180
    // }}}
158
     * @access private
181
 
159
     */
182
    // {{{ constructor
160
    var $_validPackageFile;
183
 
161
 
184
    /**
162
    /**
185
     * PEAR_Common constructor
163
     * PEAR_Common constructor
186
     *
164
     *
187
     * @access public
165
     * @access public
188
     */
166
     */
189
    function PEAR_Common()
167
    function __construct()
190
    {
168
    {
Line 191... Line -...
191
        parent::PEAR();
-
 
192
        $this->config = &PEAR_Config::singleton();
-
 
193
        $this->debug = $this->config->get('verbose');
-
 
194
    }
169
        parent::__construct();
195
 
170
        $this->config = &PEAR_Config::singleton();
196
    // }}}
171
        $this->debug = $this->config->get('verbose');
197
    // {{{ destructor
172
    }
198
 
173
 
Line 209... Line 184...
209
        while ($file = array_shift($tempfiles)) {
184
        while ($file = array_shift($tempfiles)) {
210
            if (@is_dir($file)) {
185
            if (@is_dir($file)) {
211
                if (!class_exists('System')) {
186
                if (!class_exists('System')) {
212
                    require_once 'System.php';
187
                    require_once 'System.php';
213
                }
188
                }
-
 
189
 
214
                System::rm(array('-rf', $file));
190
                System::rm(array('-rf', $file));
215
            } elseif (file_exists($file)) {
191
            } elseif (file_exists($file)) {
216
                unlink($file);
192
                unlink($file);
217
            }
193
            }
218
        }
194
        }
219
    }
195
    }
Line 220... Line -...
220
 
-
 
221
    // }}}
-
 
222
    // {{{ addTempFile()
-
 
223
 
196
 
224
    /**
197
    /**
225
     * Register a temporary file or directory.  When the destructor is
198
     * Register a temporary file or directory.  When the destructor is
226
     * executed, all registered temporary files and directories are
199
     * executed, all registered temporary files and directories are
227
     * removed.
200
     * removed.
Line 238... Line 211...
238
            require_once 'PEAR/Frontend.php';
211
            require_once 'PEAR/Frontend.php';
239
        }
212
        }
240
        PEAR_Frontend::addTempFile($file);
213
        PEAR_Frontend::addTempFile($file);
241
    }
214
    }
Line 242... Line -...
242
 
-
 
243
    // }}}
-
 
244
    // {{{ mkDirHier()
-
 
245
 
215
 
246
    /**
216
    /**
247
     * Wrapper to System::mkDir(), creates a directory as well as
217
     * Wrapper to System::mkDir(), creates a directory as well as
248
     * any necessary parent directories.
218
     * any necessary parent directories.
249
     *
219
     *
Line 253... Line 223...
253
     *
223
     *
254
     * @access public
224
     * @access public
255
     */
225
     */
256
    function mkDirHier($dir)
226
    function mkDirHier($dir)
257
    {
227
    {
-
 
228
        // Only used in Installer - move it there ?
258
        $this->log(2, "+ create dir $dir");
229
        $this->log(2, "+ create dir $dir");
259
        if (!class_exists('System')) {
230
        if (!class_exists('System')) {
260
            require_once 'System.php';
231
            require_once 'System.php';
261
        }
232
        }
262
        return System::mkDir(array('-p', $dir));
233
        return System::mkDir(array('-p', $dir));
263
    }
234
    }
Line 264... Line -...
264
 
-
 
265
    // }}}
-
 
266
    // {{{ log()
-
 
267
 
235
 
268
    /**
236
    /**
269
     * Logging method.
237
     * Logging method.
270
     *
238
     *
271
     * @param int    $level  log level (0 is quiet, higher is noisier)
239
     * @param int    $level  log level (0 is quiet, higher is noisier)
272
     * @param string $msg    message to write to the log
240
     * @param string $msg    message to write to the log
273
     *
241
     *
274
     * @return void
-
 
275
     *
-
 
276
     * @access public
-
 
277
     * @static
242
     * @return void
278
     */
243
     */
279
    function log($level, $msg, $append_crlf = true)
244
    public function log($level, $msg, $append_crlf = true)
280
    {
245
    {
281
        if ($this->debug >= $level) {
246
        if ($this->debug >= $level) {
282
            if (!class_exists('PEAR_Frontend')) {
247
            if (!class_exists('PEAR_Frontend')) {
283
                require_once 'PEAR/Frontend.php';
248
                require_once 'PEAR/Frontend.php';
-
 
249
            }
284
            }
250
 
285
            $ui = &PEAR_Frontend::singleton();
251
            $ui = &PEAR_Frontend::singleton();
286
            if (is_a($ui, 'PEAR_Frontend')) {
252
            if (is_a($ui, 'PEAR_Frontend')) {
287
                $ui->log($msg, $append_crlf);
253
                $ui->log($msg, $append_crlf);
288
            } else {
254
            } else {
289
                print "$msg\n";
255
                print "$msg\n";
290
            }
256
            }
291
        }
257
        }
Line 292... Line -...
292
    }
-
 
293
 
-
 
294
    // }}}
-
 
295
    // {{{ mkTempDir()
258
    }
296
 
259
 
297
    /**
260
    /**
298
     * Create and register a temporary directory.
261
     * Create and register a temporary directory.
299
     *
262
     *
Line 305... Line 268...
305
     *
268
     *
306
     * @access public
269
     * @access public
307
     */
270
     */
308
    function mkTempDir($tmpdir = '')
271
    function mkTempDir($tmpdir = '')
309
    {
272
    {
310
        if ($tmpdir) {
-
 
311
            $topt = array('-t', $tmpdir);
273
        $topt = $tmpdir ? array('-t', $tmpdir) : array();
312
        } else {
-
 
313
            $topt = array();
-
 
314
        }
-
 
315
        $topt = array_merge($topt, array('-d', 'pear'));
274
        $topt = array_merge($topt, array('-d', 'pear'));
316
        if (!class_exists('System')) {
275
        if (!class_exists('System')) {
317
            require_once 'System.php';
276
            require_once 'System.php';
318
        }
277
        }
-
 
278
 
319
        if (!$tmpdir = System::mktemp($topt)) {
279
        if (!$tmpdir = System::mktemp($topt)) {
320
            return false;
280
            return false;
321
        }
281
        }
-
 
282
 
322
        $this->addTempFile($tmpdir);
283
        $this->addTempFile($tmpdir);
323
        return $tmpdir;
284
        return $tmpdir;
324
    }
285
    }
Line 325... Line -...
325
 
-
 
326
    // }}}
-
 
327
    // {{{ setFrontendObject()
-
 
328
 
286
 
329
    /**
287
    /**
330
     * Set object that represents the frontend to be used.
288
     * Set object that represents the frontend to be used.
331
     *
289
     *
332
     * @param  object Reference of the frontend object
290
     * @param  object Reference of the frontend object
Line 336... Line 294...
336
    function setFrontendObject(&$ui)
294
    function setFrontendObject(&$ui)
337
    {
295
    {
338
        $this->ui = &$ui;
296
        $this->ui = &$ui;
339
    }
297
    }
Line -... Line 298...
-
 
298
 
-
 
299
    /**
-
 
300
     * Return an array containing all of the states that are more stable than
-
 
301
     * or equal to the passed in state
-
 
302
     *
-
 
303
     * @param string Release state
-
 
304
     * @param boolean Determines whether to include $state in the list
-
 
305
     * @return false|array False if $state is not a valid release state
-
 
306
     */
-
 
307
    function betterStates($state, $include = false)
-
 
308
    {
-
 
309
        static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable');
-
 
310
        $i = array_search($state, $states);
-
 
311
        if ($i === false) {
-
 
312
            return false;
-
 
313
        }
-
 
314
        if ($include) {
340
 
315
            $i--;
-
 
316
        }
-
 
317
        return array_slice($states, $i + 1);
Line -... Line 318...
-
 
318
    }
-
 
319
 
-
 
320
    /**
-
 
321
     * Get the valid roles for a PEAR package maintainer
-
 
322
     *
-
 
323
     * @return array
-
 
324
     */
-
 
325
    public static function getUserRoles()
-
 
326
    {
-
 
327
        return $GLOBALS['_PEAR_Common_maintainer_roles'];
-
 
328
    }
-
 
329
 
-
 
330
    /**
-
 
331
     * Get the valid package release states of packages
-
 
332
     *
-
 
333
     * @return array
-
 
334
     */
-
 
335
    public static function getReleaseStates()
-
 
336
    {
-
 
337
        return $GLOBALS['_PEAR_Common_release_states'];
-
 
338
    }
-
 
339
 
-
 
340
    /**
-
 
341
     * Get the implemented dependency types (php, ext, pkg etc.)
-
 
342
     *
-
 
343
     * @return array
-
 
344
     */
-
 
345
    public static function getDependencyTypes()
-
 
346
    {
-
 
347
        return $GLOBALS['_PEAR_Common_dependency_types'];
-
 
348
    }
-
 
349
 
-
 
350
    /**
-
 
351
     * Get the implemented dependency relations (has, lt, ge etc.)
-
 
352
     *
-
 
353
     * @return array
-
 
354
     */
-
 
355
    public static function getDependencyRelations()
-
 
356
    {
-
 
357
        return $GLOBALS['_PEAR_Common_dependency_relations'];
-
 
358
    }
-
 
359
 
-
 
360
    /**
-
 
361
     * Get the implemented file roles
-
 
362
     *
-
 
363
     * @return array
-
 
364
     */
-
 
365
    public static function getFileRoles()
-
 
366
    {
-
 
367
        return $GLOBALS['_PEAR_Common_file_roles'];
-
 
368
    }
-
 
369
 
-
 
370
    /**
-
 
371
     * Get the implemented file replacement types in
-
 
372
     *
-
 
373
     * @return array
-
 
374
     */
-
 
375
    public static function getReplacementTypes()
-
 
376
    {
-
 
377
        return $GLOBALS['_PEAR_Common_replacement_types'];
-
 
378
    }
-
 
379
 
-
 
380
    /**
-
 
381
     * Get the implemented file replacement types in
-
 
382
     *
-
 
383
     * @return array
-
 
384
     */
-
 
385
    public static function getProvideTypes()
-
 
386
    {
-
 
387
        return $GLOBALS['_PEAR_Common_provide_types'];
-
 
388
    }
-
 
389
 
-
 
390
    /**
-
 
391
     * Get the implemented file replacement types in
-
 
392
     *
-
 
393
     * @return array
-
 
394
     */
-
 
395
    public static function getScriptPhases()
-
 
396
    {
-
 
397
        return $GLOBALS['_PEAR_Common_script_phases'];
-
 
398
    }
-
 
399
 
-
 
400
    /**
-
 
401
     * Test whether a string contains a valid package name.
-
 
402
     *
-
 
403
     * @param string $name the package name to test
-
 
404
     *
-
 
405
     * @return bool
-
 
406
     *
-
 
407
     * @access public
-
 
408
     */
-
 
409
    function validPackageName($name)
-
 
410
    {
-
 
411
        return (bool)preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $name);
-
 
412
    }
-
 
413
 
-
 
414
    /**
-
 
415
     * Test whether a string contains a valid package version.
-
 
416
     *
-
 
417
     * @param string $ver the package version to test
-
 
418
     *
-
 
419
     * @return bool
-
 
420
     *
-
 
421
     * @access public
-
 
422
     */
-
 
423
    function validPackageVersion($ver)
-
 
424
    {
-
 
425
        return (bool)preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver);
-
 
426
    }
-
 
427
 
-
 
428
    /**
-
 
429
     * @param string $path relative or absolute include path
-
 
430
     * @return boolean
-
 
431
     */
-
 
432
    public static function isIncludeable($path)
-
 
433
    {
-
 
434
        if (file_exists($path) && is_readable($path)) {
-
 
435
            return true;
-
 
436
        }
-
 
437
 
-
 
438
        $ipath = explode(PATH_SEPARATOR, ini_get('include_path'));
-
 
439
        foreach ($ipath as $include) {
341
    // }}}
440
            $test = realpath($include . DIRECTORY_SEPARATOR . $path);
-
 
441
            if (file_exists($test) && is_readable($test)) {
-
 
442
                return true;
-
 
443
            }
-
 
444
        }
-
 
445
 
-
 
446
        return false;
-
 
447
    }
-
 
448
 
-
 
449
    function _postProcessChecks($pf)
-
 
450
    {
-
 
451
        if (!PEAR::isError($pf)) {
-
 
452
            return $this->_postProcessValidPackagexml($pf);
-
 
453
        }
-
 
454
 
-
 
455
        $errs = $pf->getUserinfo();
-
 
456
        if (is_array($errs)) {
-
 
457
            foreach ($errs as $error) {
-
 
458
                $e = $this->raiseError($error['message'], $error['code'], null, null, $error);
-
 
459
            }
-
 
460
        }
-
 
461
 
Line 342... Line 462...
342
 
462
        return $pf;
343
    // {{{ infoFromTgzFile()
463
    }
344
 
464
 
345
    /**
465
    /**
Line 354... Line 474...
354
     * @deprecated use PEAR_PackageFile->fromTgzFile() instead
474
     * @deprecated use PEAR_PackageFile->fromTgzFile() instead
355
     *
475
     *
356
     */
476
     */
357
    function infoFromTgzFile($file)
477
    function infoFromTgzFile($file)
358
    {
478
    {
359
        $packagefile = &new PEAR_PackageFile($this->config);
479
        $packagefile = new PEAR_PackageFile($this->config);
360
        $pf = &$packagefile->fromTgzFile($file, PEAR_VALIDATE_NORMAL);
480
        $pf = &$packagefile->fromTgzFile($file, PEAR_VALIDATE_NORMAL);
361
        if (PEAR::isError($pf)) {
-
 
362
            $errs = $pf->getUserinfo();
-
 
363
            if (is_array($errs)) {
-
 
364
                foreach ($errs as $error) {
-
 
365
                    $e = $this->raiseError($error['message'], $error['code'], null, null, $error);
-
 
366
                }
-
 
367
            }
-
 
368
            return $pf;
-
 
369
        }
-
 
370
        return $this->_postProcessValidPackagexml($pf);
481
        return $this->_postProcessChecks($pf);
371
    }
482
    }
Line 372... Line -...
372
 
-
 
373
    // }}}
-
 
374
    // {{{ infoFromDescriptionFile()
-
 
375
 
483
 
376
    /**
484
    /**
377
     * Returns information about a package file.  Expects the name of
485
     * Returns information about a package file.  Expects the name of
378
     * a package xml file as input.
486
     * a package xml file as input.
379
     *
487
     *
Line 385... Line 493...
385
     * @deprecated use PEAR_PackageFile->fromPackageFile() instead
493
     * @deprecated use PEAR_PackageFile->fromPackageFile() instead
386
     *
494
     *
387
     */
495
     */
388
    function infoFromDescriptionFile($descfile)
496
    function infoFromDescriptionFile($descfile)
389
    {
497
    {
390
        $packagefile = &new PEAR_PackageFile($this->config);
498
        $packagefile = new PEAR_PackageFile($this->config);
391
        $pf = &$packagefile->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
499
        $pf = &$packagefile->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
392
        if (PEAR::isError($pf)) {
-
 
393
            $errs = $pf->getUserinfo();
-
 
394
            if (is_array($errs)) {
-
 
395
                foreach ($errs as $error) {
-
 
396
                    $e = $this->raiseError($error['message'], $error['code'], null, null, $error);
-
 
397
                }
-
 
398
            }
-
 
399
            return $pf;
-
 
400
        }
-
 
401
        return $this->_postProcessValidPackagexml($pf);
500
        return $this->_postProcessChecks($pf);
402
    }
501
    }
Line 403... Line -...
403
 
-
 
404
    // }}}
-
 
405
    // {{{ infoFromString()
-
 
406
 
502
 
407
    /**
503
    /**
408
     * Returns information about a package file.  Expects the contents
504
     * Returns information about a package file.  Expects the contents
409
     * of a package xml file as input.
505
     * of a package xml file as input.
410
     *
506
     *
Line 416... Line 512...
416
     * @deprecated use PEAR_PackageFile->fromXmlstring() instead
512
     * @deprecated use PEAR_PackageFile->fromXmlstring() instead
417
     *
513
     *
418
     */
514
     */
419
    function infoFromString($data)
515
    function infoFromString($data)
420
    {
516
    {
421
        $packagefile = &new PEAR_PackageFile($this->config);
517
        $packagefile = new PEAR_PackageFile($this->config);
422
        $pf = &$packagefile->fromXmlString($data, PEAR_VALIDATE_NORMAL, false);
518
        $pf = &$packagefile->fromXmlString($data, PEAR_VALIDATE_NORMAL, false);
423
        if (PEAR::isError($pf)) {
-
 
424
            $errs = $pf->getUserinfo();
-
 
425
            if (is_array($errs)) {
-
 
426
                foreach ($errs as $error) {
-
 
427
                    $e = $this->raiseError($error['message'], $error['code'], null, null, $error);
-
 
428
                }
-
 
429
            }
-
 
430
            return $pf;
-
 
431
        }
-
 
432
        return $this->_postProcessValidPackagexml($pf);
519
        return $this->_postProcessChecks($pf);
433
    }
520
    }
434
    // }}}
-
 
Line 435... Line 521...
435
 
521
 
436
    /**
522
    /**
437
     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
523
     * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
438
     * @return array
524
     * @return array
439
     */
525
     */
440
    function _postProcessValidPackagexml(&$pf)
526
    function _postProcessValidPackagexml(&$pf)
441
    {
527
    {
442
        if (is_a($pf, 'PEAR_PackageFile_v2')) {
-
 
443
            // sort of make this into a package.xml 1.0-style array
-
 
444
            // changelog is not converted to old format.
-
 
445
            $arr = $pf->toArray(true);
-
 
446
            $arr = array_merge($arr, $arr['old']);
-
 
447
            unset($arr['old']);
-
 
448
            unset($arr['xsdversion']);
-
 
449
            unset($arr['contents']);
-
 
450
            unset($arr['compatible']);
-
 
451
            unset($arr['channel']);
-
 
452
            unset($arr['uri']);
-
 
453
            unset($arr['dependencies']);
-
 
454
            unset($arr['phprelease']);
-
 
455
            unset($arr['extsrcrelease']);
-
 
456
            unset($arr['zendextsrcrelease']);
-
 
457
            unset($arr['extbinrelease']);
-
 
458
            unset($arr['zendextbinrelease']);
-
 
459
            unset($arr['bundle']);
-
 
460
            unset($arr['lead']);
-
 
461
            unset($arr['developer']);
-
 
462
            unset($arr['helper']);
-
 
463
            unset($arr['contributor']);
-
 
464
            $arr['filelist'] = $pf->getFilelist();
-
 
465
            $this->pkginfo = $arr;
-
 
466
            return $arr;
-
 
467
        } else {
528
        if (!is_a($pf, 'PEAR_PackageFile_v2')) {
468
            $this->pkginfo = $pf->toArray();
529
            $this->pkginfo = $pf->toArray();
469
            return $this->pkginfo;
530
            return $this->pkginfo;
-
 
531
        }
-
 
532
 
-
 
533
        // sort of make this into a package.xml 1.0-style array
-
 
534
        // changelog is not converted to old format.
-
 
535
        $arr = $pf->toArray(true);
-
 
536
        $arr = array_merge($arr, $arr['old']);
-
 
537
        unset($arr['old'], $arr['xsdversion'], $arr['contents'], $arr['compatible'],
-
 
538
              $arr['channel'], $arr['uri'], $arr['dependencies'], $arr['phprelease'],
-
 
539
              $arr['extsrcrelease'], $arr['zendextsrcrelease'], $arr['extbinrelease'],
-
 
540
              $arr['zendextbinrelease'], $arr['bundle'], $arr['lead'], $arr['developer'],
-
 
541
              $arr['helper'], $arr['contributor']);
-
 
542
        $arr['filelist'] = $pf->getFilelist();
-
 
543
        $this->pkginfo = $arr;
470
        }
544
        return $arr;
471
    }
-
 
Line 472... Line 545...
472
    // {{{ infoFromAny()
545
    }
473
 
546
 
474
    /**
547
    /**
475
     * Returns package information from different sources
548
     * Returns package information from different sources
Line 483... Line 556...
483
     * @deprecated use PEAR_PackageFile->fromAnyFile() instead
556
     * @deprecated use PEAR_PackageFile->fromAnyFile() instead
484
     */
557
     */
485
    function infoFromAny($info)
558
    function infoFromAny($info)
486
    {
559
    {
487
        if (is_string($info) && file_exists($info)) {
560
        if (is_string($info) && file_exists($info)) {
488
            $packagefile = &new PEAR_PackageFile($this->config);
561
            $packagefile = new PEAR_PackageFile($this->config);
489
            $pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
562
            $pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
490
            if (PEAR::isError($pf)) {
563
            if (PEAR::isError($pf)) {
491
                $errs = $pf->getUserinfo();
564
                $errs = $pf->getUserinfo();
492
                if (is_array($errs)) {
565
                if (is_array($errs)) {
493
                    foreach ($errs as $error) {
566
                    foreach ($errs as $error) {
494
                        $e = $this->raiseError($error['message'], $error['code'], null, null, $error);
567
                        $e = $this->raiseError($error['message'], $error['code'], null, null, $error);
495
                    }
568
                    }
496
                }
569
                }
-
 
570
 
497
                return $pf;
571
                return $pf;
498
            }
572
            }
-
 
573
 
499
            return $this->_postProcessValidPackagexml($pf);
574
            return $this->_postProcessValidPackagexml($pf);
500
        }
575
        }
-
 
576
 
501
        return $info;
577
        return $info;
502
    }
578
    }
Line 503... Line -...
503
 
-
 
504
    // }}}
-
 
505
    // {{{ xmlFromInfo()
-
 
506
 
579
 
507
    /**
580
    /**
508
     * Return an XML document based on the package info (as returned
581
     * Return an XML document based on the package info (as returned
509
     * by the PEAR_Common::infoFrom* methods).
582
     * by the PEAR_Common::infoFrom* methods).
510
     *
583
     *
Line 515... Line 588...
515
     * @access public
588
     * @access public
516
     * @deprecated use a PEAR_PackageFile_v* object's generator instead
589
     * @deprecated use a PEAR_PackageFile_v* object's generator instead
517
     */
590
     */
518
    function xmlFromInfo($pkginfo)
591
    function xmlFromInfo($pkginfo)
519
    {
592
    {
520
        $config = &PEAR_Config::singleton();
593
        $config      = &PEAR_Config::singleton();
521
        $packagefile = &new PEAR_PackageFile($config);
594
        $packagefile = new PEAR_PackageFile($config);
522
        $pf = &$packagefile->fromArray($pkginfo);
595
        $pf = &$packagefile->fromArray($pkginfo);
523
        $gen = &$pf->getDefaultGenerator();
596
        $gen = &$pf->getDefaultGenerator();
524
        return $gen->toXml(PEAR_VALIDATE_PACKAGING);
597
        return $gen->toXml(PEAR_VALIDATE_PACKAGING);
525
    }
598
    }
Line 526... Line -...
526
 
-
 
527
    // }}}
-
 
528
    // {{{ validatePackageInfo()
-
 
529
 
599
 
530
    /**
600
    /**
531
     * Validate XML package definition file.
601
     * Validate XML package definition file.
532
     *
602
     *
533
     * @param  string $info Filename of the package archive or of the
603
     * @param  string $info Filename of the package archive or of the
Line 540... Line 610...
540
     * @return boolean
610
     * @return boolean
541
     * @deprecated use the validation of PEAR_PackageFile objects
611
     * @deprecated use the validation of PEAR_PackageFile objects
542
     */
612
     */
543
    function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '')
613
    function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '')
544
    {
614
    {
545
        $config = &PEAR_Config::singleton();
615
        $config      = &PEAR_Config::singleton();
546
        $packagefile = &new PEAR_PackageFile($config);
616
        $packagefile = new PEAR_PackageFile($config);
547
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
617
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
548
        if (strpos($info, '<?xml') !== false) {
618
        if (strpos($info, '<?xml') !== false) {
549
            $pf = &$packagefile->fromXmlString($info, PEAR_VALIDATE_NORMAL, '');
619
            $pf = &$packagefile->fromXmlString($info, PEAR_VALIDATE_NORMAL, '');
550
        } else {
620
        } else {
551
            $pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
621
            $pf = &$packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL);
552
        }
622
        }
-
 
623
 
553
        PEAR::staticPopErrorHandling();
624
        PEAR::staticPopErrorHandling();
554
        if (PEAR::isError($pf)) {
625
        if (PEAR::isError($pf)) {
555
            $errs = $pf->getUserinfo();
626
            $errs = $pf->getUserinfo();
556
            if (is_array($errs)) {
627
            if (is_array($errs)) {
557
                foreach ($errs as $error) {
628
                foreach ($errs as $error) {
Line 560... Line 631...
560
                    } else {
631
                    } else {
561
                        $warnings[] = $error['message'];
632
                        $warnings[] = $error['message'];
562
                    }
633
                    }
563
                }
634
                }
564
            }
635
            }
-
 
636
 
565
            return false;
637
            return false;
566
        }
638
        }
-
 
639
 
567
        return true;
640
        return true;
568
    }
641
    }
Line 569... Line -...
569
 
-
 
570
    // }}}
-
 
571
    // {{{ buildProvidesArray()
-
 
572
 
642
 
573
    /**
643
    /**
574
     * Build a "provides" array from data returned by
644
     * Build a "provides" array from data returned by
575
     * analyzeSourceCode().  The format of the built array is like
645
     * analyzeSourceCode().  The format of the built array is like
576
     * this:
646
     * this:
Line 594... Line 664...
594
        $file = basename($srcinfo['source_file']);
664
        $file = basename($srcinfo['source_file']);
595
        $pn = '';
665
        $pn = '';
596
        if (isset($this->_packageName)) {
666
        if (isset($this->_packageName)) {
597
            $pn = $this->_packageName;
667
            $pn = $this->_packageName;
598
        }
668
        }
-
 
669
 
599
        $pnl = strlen($pn);
670
        $pnl = strlen($pn);
600
        foreach ($srcinfo['declared_classes'] as $class) {
671
        foreach ($srcinfo['declared_classes'] as $class) {
601
            $key = "class;$class";
672
            $key = "class;$class";
602
            if (isset($this->pkginfo['provides'][$key])) {
673
            if (isset($this->pkginfo['provides'][$key])) {
603
                continue;
674
                continue;
604
            }
675
            }
-
 
676
 
605
            $this->pkginfo['provides'][$key] =
677
            $this->pkginfo['provides'][$key] =
606
                array('file'=> $file, 'type' => 'class', 'name' => $class);
678
                array('file'=> $file, 'type' => 'class', 'name' => $class);
607
            if (isset($srcinfo['inheritance'][$class])) {
679
            if (isset($srcinfo['inheritance'][$class])) {
608
                $this->pkginfo['provides'][$key]['extends'] =
680
                $this->pkginfo['provides'][$key]['extends'] =
609
                    $srcinfo['inheritance'][$class];
681
                    $srcinfo['inheritance'][$class];
610
            }
682
            }
611
        }
683
        }
-
 
684
 
612
        foreach ($srcinfo['declared_methods'] as $class => $methods) {
685
        foreach ($srcinfo['declared_methods'] as $class => $methods) {
613
            foreach ($methods as $method) {
686
            foreach ($methods as $method) {
614
                $function = "$class::$method";
687
                $function = "$class::$method";
615
                $key = "function;$function";
688
                $key = "function;$function";
616
                if ($method{0} == '_' || !strcasecmp($method, $class) ||
689
                if ($method{0} == '_' || !strcasecmp($method, $class) ||
617
                    isset($this->pkginfo['provides'][$key])) {
690
                    isset($this->pkginfo['provides'][$key])) {
618
                    continue;
691
                    continue;
619
                }
692
                }
-
 
693
 
620
                $this->pkginfo['provides'][$key] =
694
                $this->pkginfo['provides'][$key] =
621
                    array('file'=> $file, 'type' => 'function', 'name' => $function);
695
                    array('file'=> $file, 'type' => 'function', 'name' => $function);
622
            }
696
            }
623
        }
697
        }
Line 624... Line 698...
624
 
698
 
625
        foreach ($srcinfo['declared_functions'] as $function) {
699
        foreach ($srcinfo['declared_functions'] as $function) {
626
            $key = "function;$function";
700
            $key = "function;$function";
627
            if ($function{0} == '_' || isset($this->pkginfo['provides'][$key])) {
701
            if ($function{0} == '_' || isset($this->pkginfo['provides'][$key])) {
628
                continue;
702
                continue;
-
 
703
            }
629
            }
704
 
630
            if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {
705
            if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {
631
                $warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";
706
                $warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";
-
 
707
            }
632
            }
708
 
633
            $this->pkginfo['provides'][$key] =
709
            $this->pkginfo['provides'][$key] =
634
                array('file'=> $file, 'type' => 'function', 'name' => $function);
710
                array('file'=> $file, 'type' => 'function', 'name' => $function);
635
        }
711
        }
Line 636... Line -...
636
    }
-
 
637
 
-
 
638
    // }}}
-
 
639
    // {{{ analyzeSourceCode()
712
    }
640
 
713
 
641
    /**
714
    /**
642
     * Analyze the source code of the given PHP file
715
     * Analyze the source code of the given PHP file
643
     *
716
     *
644
     * @param  string Filename of the PHP file
717
     * @param  string Filename of the PHP file
645
     * @return mixed
718
     * @return mixed
646
     * @access public
719
     * @access public
647
     */
720
     */
648
    function analyzeSourceCode($file)
721
    function analyzeSourceCode($file)
649
    {
-
 
650
        if (!function_exists("token_get_all")) {
-
 
651
            return false;
-
 
652
        }
722
    {
653
        if (!defined('T_DOC_COMMENT')) {
-
 
654
            define('T_DOC_COMMENT', T_COMMENT);
-
 
655
        }
-
 
656
        if (!defined('T_INTERFACE')) {
-
 
657
            define('T_INTERFACE', -1);
-
 
658
        }
-
 
659
        if (!defined('T_IMPLEMENTS')) {
723
        if (!class_exists('PEAR_PackageFile_v2_Validator')) {
660
            define('T_IMPLEMENTS', -1);
-
 
661
        }
-
 
662
        if (!$fp = @fopen($file, "r")) {
-
 
663
            return false;
-
 
664
        }
-
 
665
        fclose($fp);
-
 
666
        $contents = file_get_contents($file);
-
 
667
        $tokens = token_get_all($contents);
-
 
668
/*
-
 
669
        for ($i = 0; $i < sizeof($tokens); $i++) {
-
 
670
            @list($token, $data) = $tokens[$i];
-
 
671
            if (is_string($token)) {
-
 
672
                var_dump($token);
-
 
673
            } else {
-
 
674
                print token_name($token) . ' ';
-
 
675
                var_dump(rtrim($data));
-
 
676
            }
-
 
677
        }
-
 
678
*/
-
 
679
        $look_for = 0;
-
 
680
        $paren_level = 0;
-
 
681
        $bracket_level = 0;
-
 
682
        $brace_level = 0;
-
 
683
        $lastphpdoc = '';
-
 
684
        $current_class = '';
-
 
685
        $current_interface = '';
-
 
686
        $current_class_level = -1;
-
 
687
        $current_function = '';
-
 
688
        $current_function_level = -1;
-
 
689
        $declared_classes = array();
-
 
690
        $declared_interfaces = array();
-
 
691
        $declared_functions = array();
-
 
692
        $declared_methods = array();
-
 
693
        $used_classes = array();
-
 
694
        $used_functions = array();
-
 
695
        $extends = array();
-
 
696
        $implements = array();
-
 
697
        $nodeps = array();
-
 
698
        $inquote = false;
-
 
699
        $interface = false;
-
 
700
        for ($i = 0; $i < sizeof($tokens); $i++) {
-
 
701
            if (is_array($tokens[$i])) {
-
 
702
                list($token, $data) = $tokens[$i];
-
 
703
            } else {
-
 
704
                $token = $tokens[$i];
-
 
705
                $data = '';
-
 
706
            }
-
 
707
            if ($inquote) {
-
 
708
                if ($token != '"') {
-
 
709
                    continue;
-
 
710
                } else {
-
 
711
                    $inquote = false;
-
 
712
                    continue;
-
 
713
                }
-
 
714
            }
-
 
715
            switch ($token) {
-
 
716
                case T_WHITESPACE:
-
 
717
                    continue;
-
 
718
                case ';':
-
 
719
                    if ($interface) {
-
 
720
                        $current_function = '';
-
 
721
                        $current_function_level = -1;
-
 
722
                    }
-
 
723
                    break;
-
 
724
                case '"':
-
 
725
                    $inquote = true;
-
 
726
                    break;
-
 
727
                case T_CURLY_OPEN:
-
 
728
                case T_DOLLAR_OPEN_CURLY_BRACES:
-
 
729
                case '{': $brace_level++; continue 2;
-
 
730
                case '}':
-
 
731
                    $brace_level--;
-
 
732
                    if ($current_class_level == $brace_level) {
-
 
733
                        $current_class = '';
-
 
734
                        $current_class_level = -1;
-
 
735
                    }
-
 
736
                    if ($current_function_level == $brace_level) {
-
 
737
                        $current_function = '';
-
 
738
                        $current_function_level = -1;
-
 
739
                    }
-
 
740
                    continue 2;
-
 
741
                case '[': $bracket_level++; continue 2;
-
 
742
                case ']': $bracket_level--; continue 2;
-
 
743
                case '(': $paren_level++;   continue 2;
-
 
744
                case ')': $paren_level--;   continue 2;
-
 
745
                case T_INTERFACE:
-
 
746
                    $interface = true;
-
 
747
                case T_CLASS:
-
 
748
                    if (($current_class_level != -1) || ($current_function_level != -1)) {
-
 
749
                        PEAR::raiseError("Parser error: invalid PHP found in file \"$file\"",
-
 
750
                            PEAR_COMMON_ERROR_INVALIDPHP);
-
 
751
                        return false;
-
 
752
                    }
-
 
753
                case T_FUNCTION:
-
 
754
                case T_NEW:
-
 
755
                case T_EXTENDS:
-
 
756
                case T_IMPLEMENTS:
-
 
757
                    $look_for = $token;
-
 
758
                    continue 2;
-
 
759
                case T_STRING:
-
 
760
                    if (version_compare(zend_version(), '2.0', '<')) {
-
 
761
                        if (in_array(strtolower($data),
-
 
762
                            array('public', 'private', 'protected', 'abstract',
-
 
763
                                  'interface', 'implements', 'throw') 
-
 
764
                                 )) {
-
 
765
                            PEAR::raiseError('Error: PHP5 token encountered in ' . $file . 
-
 
766
                            'packaging should be done in PHP 5');
-
 
767
                            return false;
-
 
768
                        }
-
 
769
                    }
-
 
770
                    if ($look_for == T_CLASS) {
-
 
771
                        $current_class = $data;
-
 
772
                        $current_class_level = $brace_level;
-
 
773
                        $declared_classes[] = $current_class;
-
 
774
                    } elseif ($look_for == T_INTERFACE) {
-
 
775
                        $current_interface = $data;
-
 
776
                        $current_class_level = $brace_level;
-
 
777
                        $declared_interfaces[] = $current_interface;
-
 
778
                    } elseif ($look_for == T_IMPLEMENTS) {
-
 
779
                        $implements[$current_class] = $data;
-
 
780
                    } elseif ($look_for == T_EXTENDS) {
-
 
781
                        $extends[$current_class] = $data;
-
 
782
                    } elseif ($look_for == T_FUNCTION) {
-
 
783
                        if ($current_class) {
-
 
784
                            $current_function = "$current_class::$data";
-
 
785
                            $declared_methods[$current_class][] = $data;
-
 
786
                        } elseif ($current_interface) {
-
 
787
                            $current_function = "$current_interface::$data";
-
 
788
                            $declared_methods[$current_interface][] = $data;
-
 
789
                        } else {
-
 
790
                            $current_function = $data;
-
 
791
                            $declared_functions[] = $current_function;
-
 
792
                        }
-
 
793
                        $current_function_level = $brace_level;
-
 
794
                        $m = array();
-
 
795
                    } elseif ($look_for == T_NEW) {
-
 
796
                        $used_classes[$data] = true;
-
 
797
                    }
-
 
798
                    $look_for = 0;
-
 
799
                    continue 2;
-
 
800
                case T_VARIABLE:
-
 
801
                    $look_for = 0;
-
 
802
                    continue 2;
-
 
803
                case T_DOC_COMMENT:
-
 
804
                case T_COMMENT:
-
 
805
                    if (preg_match('!^/\*\*\s!', $data)) {
-
 
806
                        $lastphpdoc = $data;
-
 
807
                        if (preg_match_all('/@nodep\s+(\S+)/', $lastphpdoc, $m)) {
-
 
808
                            $nodeps = array_merge($nodeps, $m[1]);
-
 
809
                        }
-
 
810
                    }
-
 
811
                    continue 2;
-
 
812
                case T_DOUBLE_COLON:
-
 
813
                    if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
-
 
814
                        PEAR::raiseError("Parser error: invalid PHP found in file \"$file\"",
-
 
815
                            PEAR_COMMON_ERROR_INVALIDPHP);
-
 
816
                        return false;
-
 
817
                    }
-
 
818
                    $class = $tokens[$i - 1][1];
-
 
819
                    if (strtolower($class) != 'parent') {
-
 
820
                        $used_classes[$class] = true;
-
 
821
                    }
-
 
822
                    continue 2;
-
 
823
            }
-
 
824
        }
-
 
825
        return array(
-
 
826
            "source_file" => $file,
-
 
827
            "declared_classes" => $declared_classes,
-
 
828
            "declared_interfaces" => $declared_interfaces,
-
 
829
            "declared_methods" => $declared_methods,
-
 
830
            "declared_functions" => $declared_functions,
-
 
831
            "used_classes" => array_diff(array_keys($used_classes), $nodeps),
-
 
832
            "inheritance" => $extends,
-
 
833
            "implements" => $implements,
-
 
Line 834... Line -...
834
            );
-
 
835
    }
-
 
836
 
-
 
837
    // }}}
-
 
838
    // {{{  betterStates()
-
 
839
 
-
 
840
    /**
-
 
841
     * Return an array containing all of the states that are more stable than
-
 
842
     * or equal to the passed in state
-
 
843
     *
-
 
844
     * @param string Release state
-
 
845
     * @param boolean Determines whether to include $state in the list
-
 
846
     * @return false|array False if $state is not a valid release state
-
 
847
     */
-
 
848
    function betterStates($state, $include = false)
724
            require_once 'PEAR/PackageFile/v2/Validator.php';
849
    {
-
 
850
        static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable');
-
 
851
        $i = array_search($state, $states);
-
 
852
        if ($i === false) {
-
 
853
            return false;
-
 
854
        }
-
 
855
        if ($include) {
725
        }
856
            $i--;
726
 
Line 857... Line -...
857
        }
-
 
858
        return array_slice($states, $i + 1);
-
 
859
    }
-
 
860
 
727
        $a = new PEAR_PackageFile_v2_Validator;
861
    // }}}
728
        return $a->analyzeSourceCode($file);
862
    // {{{ detectDependencies()
729
    }
863
 
730
 
864
    function detectDependencies($any, $status_callback = null)
731
    function detectDependencies($any, $status_callback = null)
-
 
732
    {
865
    {
733
        if (!function_exists("token_get_all")) {
866
        if (!function_exists("token_get_all")) {
734
            return false;
867
            return false;
735
        }
-
 
736
 
868
        }
737
        if (PEAR::isError($info = $this->infoFromAny($any))) {
869
        if (PEAR::isError($info = $this->infoFromAny($any))) {
738
            return $this->raiseError($info);
870
            return $this->raiseError($info);
739
        }
-
 
740
 
871
        }
741
        if (!is_array($info)) {
872
        if (!is_array($info)) {
742
            return false;
873
            return false;
743
        }
874
        }
744
 
875
        $deps = array();
745
        $deps = array();
876
        $used_c = $decl_c = $decl_f = $decl_m = array();
746
        $used_c = $decl_c = $decl_f = $decl_m = array();
877
        foreach ($info['filelist'] as $file => $fa) {
747
        foreach ($info['filelist'] as $file => $fa) {
878
            $tmp = $this->analyzeSourceCode($file);
748
            $tmp = $this->analyzeSourceCode($file);
879
            $used_c = @array_merge($used_c, $tmp['used_classes']);
749
            $used_c = @array_merge($used_c, $tmp['used_classes']);
880
            $decl_c = @array_merge($decl_c, $tmp['declared_classes']);
750
            $decl_c = @array_merge($decl_c, $tmp['declared_classes']);
-
 
751
            $decl_f = @array_merge($decl_f, $tmp['declared_functions']);
881
            $decl_f = @array_merge($decl_f, $tmp['declared_functions']);
752
            $decl_m = @array_merge($decl_m, $tmp['declared_methods']);
882
            $decl_m = @array_merge($decl_m, $tmp['declared_methods']);
753
            $inheri = @array_merge($inheri, $tmp['inheritance']);
883
            $inheri = @array_merge($inheri, $tmp['inheritance']);
754
        }
-
 
755
 
884
        }
756
        $used_c = array_unique($used_c);
885
        $used_c = array_unique($used_c);
757
        $decl_c = array_unique($decl_c);
886
        $decl_c = array_unique($decl_c);
758
        $undecl_c = array_diff($used_c, $decl_c);
887
        $undecl_c = array_diff($used_c, $decl_c);
759
 
888
        return array('used_classes' => $used_c,
760
        return array('used_classes' => $used_c,
889
                     'declared_classes' => $decl_c,
761
                     'declared_classes' => $decl_c,
890
                     'declared_methods' => $decl_m,
762
                     'declared_methods' => $decl_m,
891
                     'declared_functions' => $decl_f,
763
                     'declared_functions' => $decl_f,
Line 892... Line -...
892
                     'undeclared_classes' => $undecl_c,
-
 
893
                     'inheritance' => $inheri,
-
 
894
                     );
-
 
895
    }
-
 
896
 
-
 
897
    // }}}
-
 
898
    // {{{ getUserRoles()
-
 
899
 
-
 
900
    /**
-
 
901
     * Get the valid roles for a PEAR package maintainer
-
 
902
     *
-
 
903
     * @return array
-
 
904
     * @static
-
 
905
     */
-
 
906
    function getUserRoles()
-
 
907
    {
-
 
908
        return $GLOBALS['_PEAR_Common_maintainer_roles'];
-
 
909
    }
-
 
910
 
-
 
911
    // }}}
-
 
912
    // {{{ getReleaseStates()
-
 
913
 
-
 
914
    /**
-
 
915
     * Get the valid package release states of packages
-
 
916
     *
-
 
917
     * @return array
-
 
918
     * @static
-
 
919
     */
-
 
920
    function getReleaseStates()
-
 
921
    {
-
 
922
        return $GLOBALS['_PEAR_Common_release_states'];
-
 
923
    }
-
 
924
 
-
 
925
    // }}}
-
 
926
    // {{{ getDependencyTypes()
-
 
927
 
-
 
928
    /**
-
 
929
     * Get the implemented dependency types (php, ext, pkg etc.)
-
 
930
     *
-
 
931
     * @return array
-
 
932
     * @static
-
 
933
     */
-
 
934
    function getDependencyTypes()
-
 
935
    {
-
 
936
        return $GLOBALS['_PEAR_Common_dependency_types'];
-
 
937
    }
-
 
938
 
-
 
939
    // }}}
-
 
940
    // {{{ getDependencyRelations()
-
 
941
 
-
 
942
    /**
-
 
943
     * Get the implemented dependency relations (has, lt, ge etc.)
-
 
944
     *
-
 
945
     * @return array
-
 
946
     * @static
-
 
947
     */
-
 
948
    function getDependencyRelations()
-
 
949
    {
-
 
950
        return $GLOBALS['_PEAR_Common_dependency_relations'];
-
 
951
    }
-
 
952
 
-
 
953
    // }}}
-
 
954
    // {{{ getFileRoles()
-
 
955
 
-
 
956
    /**
-
 
957
     * Get the implemented file roles
-
 
958
     *
-
 
959
     * @return array
-
 
960
     * @static
-
 
961
     */
-
 
962
    function getFileRoles()
-
 
963
    {
-
 
964
        return $GLOBALS['_PEAR_Common_file_roles'];
-
 
965
    }
-
 
966
 
-
 
967
    // }}}
-
 
968
    // {{{ getReplacementTypes()
-
 
969
 
-
 
970
    /**
-
 
971
     * Get the implemented file replacement types in
-
 
972
     *
-
 
973
     * @return array
-
 
974
     * @static
-
 
975
     */
-
 
976
    function getReplacementTypes()
-
 
977
    {
-
 
978
        return $GLOBALS['_PEAR_Common_replacement_types'];
-
 
979
    }
-
 
980
 
-
 
981
    // }}}
-
 
982
    // {{{ getProvideTypes()
-
 
983
 
-
 
984
    /**
-
 
985
     * Get the implemented file replacement types in
-
 
986
     *
-
 
987
     * @return array
-
 
988
     * @static
-
 
989
     */
-
 
990
    function getProvideTypes()
-
 
991
    {
-
 
992
        return $GLOBALS['_PEAR_Common_provide_types'];
-
 
993
    }
-
 
994
 
-
 
995
    // }}}
-
 
996
    // {{{ getScriptPhases()
-
 
997
 
-
 
998
    /**
-
 
999
     * Get the implemented file replacement types in
-
 
1000
     *
-
 
1001
     * @return array
-
 
1002
     * @static
-
 
1003
     */
-
 
1004
    function getScriptPhases()
-
 
1005
    {
-
 
1006
        return $GLOBALS['_PEAR_Common_script_phases'];
-
 
1007
    }
-
 
1008
 
-
 
1009
    // }}}
-
 
1010
    // {{{ validPackageName()
-
 
1011
 
-
 
1012
    /**
-
 
1013
     * Test whether a string contains a valid package name.
-
 
1014
     *
-
 
1015
     * @param string $name the package name to test
-
 
1016
     *
-
 
1017
     * @return bool
-
 
1018
     *
-
 
1019
     * @access public
-
 
1020
     */
-
 
1021
    function validPackageName($name)
-
 
1022
    {
-
 
1023
        return (bool)preg_match(PEAR_COMMON_PACKAGE_NAME_PREG, $name);
-
 
1024
    }
-
 
1025
 
-
 
1026
 
-
 
1027
    // }}}
-
 
1028
    // {{{ validPackageVersion()
-
 
1029
 
-
 
1030
    /**
-
 
1031
     * Test whether a string contains a valid package version.
-
 
1032
     *
-
 
1033
     * @param string $ver the package version to test
-
 
1034
     *
-
 
1035
     * @return bool
-
 
1036
     *
-
 
1037
     * @access public
-
 
1038
     */
-
 
1039
    function validPackageVersion($ver)
-
 
1040
    {
-
 
1041
        return (bool)preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver);
-
 
1042
    }
-
 
1043
 
-
 
1044
 
764
                     'undeclared_classes' => $undecl_c,
1045
    // }}}
765
                     'inheritance' => $inheri,
1046
 
766
                     );
1047
    // {{{ downloadHttp()
767
    }
1048
 
768
 
Line 1079... Line 799...
1079
     * @param object  $ui        PEAR_Frontend_* instance
799
     * @param object  $ui        PEAR_Frontend_* instance
1080
     * @param object  $config    PEAR_Config instance
800
     * @param object  $config    PEAR_Config instance
1081
     * @param string  $save_dir  (optional) directory to save file in
801
     * @param string  $save_dir  (optional) directory to save file in
1082
     * @param mixed   $callback  (optional) function/method to call for status
802
     * @param mixed   $callback  (optional) function/method to call for status
1083
     *                           updates
803
     *                           updates
-
 
804
     * @param false|string|array $lastmodified header values to check against
-
 
805
     *                                         for caching
-
 
806
     *                                         use false to return the header
-
 
807
     *                                         values from this download
-
 
808
     * @param false|array        $accept       Accept headers to send
-
 
809
     * @param false|string       $channel      Channel to use for retrieving
-
 
810
     *                                         authentication
1084
     *
811
     *
1085
     * @return string  Returns the full path of the downloaded file or a PEAR
812
     * @return mixed  Returns the full path of the downloaded file or a PEAR
1086
     *                 error on failure.  If the error is caused by
813
     *                error on failure.  If the error is caused by
1087
     *                 socket-related errors, the error object will
814
     *                socket-related errors, the error object will
1088
     *                 have the fsockopen error code available through
815
     *                have the fsockopen error code available through
-
 
816
     *                getCode().  If caching is requested, then return the header
1089
     *                 getCode().
817
     *                values.
-
 
818
     *                If $lastmodified was given and the there are no changes,
-
 
819
     *                boolean false is returned.
1090
     *
820
     *
1091
     * @access public
821
     * @access public
1092
     * @deprecated in favor of PEAR_Downloader::downloadHttp()
-
 
1093
     */
822
     */
-
 
823
    function downloadHttp(
1094
    function downloadHttp($url, &$ui, $save_dir = '.', $callback = null)
824
        $url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null,
-
 
825
        $accept = false, $channel = false
1095
    {
826
    ) {
1096
        if (!class_exists('PEAR_Downloader')) {
827
        if (!class_exists('PEAR_Downloader')) {
1097
            require_once 'PEAR/Downloader.php';
828
            require_once 'PEAR/Downloader.php';
1098
        }
829
        }
1099
        return PEAR_Downloader::downloadHttp($url, $ui, $save_dir, $callback);
830
        return PEAR_Downloader::_downloadHttp(
1100
    }
-
 
1101
 
-
 
1102
    // }}}
-
 
1103
 
-
 
1104
    /**
-
 
1105
     * @param string $path relative or absolute include path
-
 
1106
     * @return boolean
-
 
1107
     * @static
-
 
1108
     */
-
 
1109
    function isIncludeable($path)
-
 
1110
    {
-
 
1111
        if (file_exists($path) && is_readable($path)) {
-
 
1112
            return true;
-
 
1113
        }
-
 
1114
        $ipath = explode(PATH_SEPARATOR, ini_get('include_path'));
-
 
1115
        foreach ($ipath as $include) {
-
 
1116
            $test = realpath($include . DIRECTORY_SEPARATOR . $path);
-
 
1117
            if (file_exists($test) && is_readable($test)) {
831
            $this, $url, $ui, $save_dir, $callback, $lastmodified,
1118
                return true;
832
            $accept, $channel
1119
            }
-
 
1120
        }
833
        );
1121
        return false;
-
 
1122
    }
834
    }
1123
}
835
}
-
 
836
 
1124
require_once 'PEAR/Config.php';
837
require_once 'PEAR/Config.php';
1125
require_once 'PEAR/PackageFile.php';
838
require_once 'PEAR/PackageFile.php';
1126
?>
-
 
1127
839