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 1... Line 1...
1
<?php
1
<?php
2
//
2
/**
3
// +----------------------------------------------------------------------+
-
 
4
// | PHP Version 5                                                        |
-
 
5
// +----------------------------------------------------------------------+
-
 
6
// | Copyright (c) 1997-2004 The PHP Group                                |
-
 
7
// +----------------------------------------------------------------------+
-
 
8
// | This source file is subject to version 3.0 of the PHP license,       |
3
 * PEAR_PackageFile_v2, package.xml version 2.0, read/write version
-
 
4
 *
9
// | that is bundled with this package in the file LICENSE, and is        |
5
 * PHP versions 4 and 5
-
 
6
 *
10
// | available through the world-wide-web at the following url:           |
7
 * @category   pear
11
// | http://www.php.net/license/3_0.txt.                                  |
8
 * @package    PEAR
12
// | If you did not receive a copy of the PHP license and are unable to   |
9
 * @author     Greg Beaver <cellog@php.net>
13
// | obtain it through the world-wide-web, please send a note to          |
10
 * @copyright  1997-2009 The Authors
14
// | license@php.net so we can mail you a copy immediately.               |
11
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
15
// +----------------------------------------------------------------------+
-
 
16
// | Author: Greg Beaver <cellog@php.net>                                 |
12
 * @link       http://pear.php.net/package/PEAR
17
// |                                                                      |
13
 * @since      File available since Release 1.4.0a8
18
// +----------------------------------------------------------------------+
-
 
19
//
14
 */
20
// $Id: Validator.php,v 1.97 2007/02/10 05:56:18 cellog Exp $
-
 
21
/**
15
/**
22
 * Private validation class used by PEAR_PackageFile_v2 - do not use directly, its
16
 * Private validation class used by PEAR_PackageFile_v2 - do not use directly, its
23
 * sole purpose is to split up the PEAR/PackageFile/v2.php file to make it smaller
17
 * sole purpose is to split up the PEAR/PackageFile/v2.php file to make it smaller
-
 
18
 * @category   pear
-
 
19
 * @package    PEAR
24
 * @author Greg Beaver <cellog@php.net>
20
 * @author     Greg Beaver <cellog@php.net>
-
 
21
 * @copyright  1997-2009 The Authors
-
 
22
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
-
 
23
 * @version    Release: 1.10.1
-
 
24
 * @link       http://pear.php.net/package/PEAR
-
 
25
 * @since      Class available since Release 1.4.0a8
25
 * @access private
26
 * @access private
26
 */
27
 */
27
class PEAR_PackageFile_v2_Validator
28
class PEAR_PackageFile_v2_Validator
28
{
29
{
29
    /**
30
    /**
Line 69... Line 70...
69
        if (!isset($this->_packageInfo) || !is_array($this->_packageInfo)) {
70
        if (!isset($this->_packageInfo) || !is_array($this->_packageInfo)) {
70
            return false;
71
            return false;
71
        }
72
        }
72
        if (!isset($this->_packageInfo['attribs']['version']) ||
73
        if (!isset($this->_packageInfo['attribs']['version']) ||
73
              ($this->_packageInfo['attribs']['version'] != '2.0' &&
74
              ($this->_packageInfo['attribs']['version'] != '2.0' &&
74
               $this->_packageInfo['attribs']['version'] != '2.1')) {
75
               $this->_packageInfo['attribs']['version'] != '2.1')
-
 
76
        ) {
75
            $this->_noPackageVersion();
77
            $this->_noPackageVersion();
76
        }
78
        }
77
        $structure =
79
        $structure =
78
        array(
80
        array(
79
            'name',
81
            'name',
Line 107... Line 109...
107
        $test = $this->_packageInfo;
109
        $test = $this->_packageInfo;
108
        if (isset($test['dependencies']) &&
110
        if (isset($test['dependencies']) &&
109
              isset($test['dependencies']['required']) &&
111
              isset($test['dependencies']['required']) &&
110
              isset($test['dependencies']['required']['pearinstaller']) &&
112
              isset($test['dependencies']['required']['pearinstaller']) &&
111
              isset($test['dependencies']['required']['pearinstaller']['min']) &&
113
              isset($test['dependencies']['required']['pearinstaller']['min']) &&
-
 
114
              '1.10.1' != '@package' . '_version@' &&
112
              version_compare('1.5.1',
115
              version_compare('1.10.1',
113
                $test['dependencies']['required']['pearinstaller']['min'], '<')) {
116
                $test['dependencies']['required']['pearinstaller']['min'], '<')
-
 
117
        ) {
114
            $this->_pearVersionTooLow($test['dependencies']['required']['pearinstaller']['min']);
118
            $this->_pearVersionTooLow($test['dependencies']['required']['pearinstaller']['min']);
115
            return false;
119
            return false;
116
        }
120
        }
117
        // ignore post-installation array fields
121
        // ignore post-installation array fields
118
        if (array_key_exists('filelist', $test)) {
122
        if (array_key_exists('filelist', $test)) {
Line 128... Line 132...
128
            unset($test['old']);
132
            unset($test['old']);
129
        }
133
        }
130
        if (array_key_exists('_lastversion', $test)) {
134
        if (array_key_exists('_lastversion', $test)) {
131
            unset($test['_lastversion']);
135
            unset($test['_lastversion']);
132
        }
136
        }
133
        if (!$this->_stupidSchemaValidate($structure,
137
        if (!$this->_stupidSchemaValidate($structure, $test, '<package>')) {
134
                                          $test, '<package>')) {
-
 
135
            return false;
138
            return false;
136
        }
139
        }
137
        if (empty($this->_packageInfo['name'])) {
140
        if (empty($this->_packageInfo['name'])) {
138
            $this->_tagCannotBeEmpty('name');
141
            $this->_tagCannotBeEmpty('name');
139
        }
142
        }
140
        if (isset($this->_packageInfo['uri'])) {
143
        $test = isset($this->_packageInfo['uri']) ? 'uri' :'channel';
141
            $test = 'uri';
-
 
142
        } else {
-
 
143
            $test = 'channel';
-
 
144
        }
-
 
145
        if (empty($this->_packageInfo[$test])) {
144
        if (empty($this->_packageInfo[$test])) {
146
            $this->_tagCannotBeEmpty($test);
145
            $this->_tagCannotBeEmpty($test);
147
        }
146
        }
148
        if (is_array($this->_packageInfo['license']) &&
147
        if (is_array($this->_packageInfo['license']) &&
149
              (!isset($this->_packageInfo['license']['_content']) ||
148
              (!isset($this->_packageInfo['license']['_content']) ||
Line 231... Line 230...
231
                        $fail = true;
230
                        $fail = true;
232
                    }
231
                    }
233
                }
232
                }
234
            }
233
            }
235
        }
234
        }
-
 
235
 
236
        if ($fail) {
236
        if ($fail) {
237
            return false;
237
            return false;
238
        }
238
        }
-
 
239
 
239
        $list = $this->_packageInfo['contents'];
240
        $list = $this->_packageInfo['contents'];
240
        if (isset($list['dir']) && is_array($list['dir']) && isset($list['dir'][0])) {
241
        if (isset($list['dir']) && is_array($list['dir']) && isset($list['dir'][0])) {
241
            $this->_multipleToplevelDirNotAllowed();
242
            $this->_multipleToplevelDirNotAllowed();
242
            return $this->_isValid = 0;
243
            return $this->_isValid = 0;
243
        }
244
        }
-
 
245
 
244
        $this->_validateFilelist();
246
        $this->_validateFilelist();
245
        $this->_validateRelease();
247
        $this->_validateRelease();
246
        if (!$this->_stack->hasErrors()) {
248
        if (!$this->_stack->hasErrors()) {
247
            $chan = $this->_pf->_registry->getChannel($this->_pf->getChannel(), true);
249
            $chan = $this->_pf->_registry->getChannel($this->_pf->getChannel(), true);
248
            if (PEAR::isError($chan)) {
250
            if (PEAR::isError($chan)) {
Line 252... Line 254...
252
                // for channel validator packages, always use the default PEAR validator.
254
                // for channel validator packages, always use the default PEAR validator.
253
                // otherwise, they can't be installed or packaged
255
                // otherwise, they can't be installed or packaged
254
                $validator = $chan->getValidationObject($this->_pf->getPackage());
256
                $validator = $chan->getValidationObject($this->_pf->getPackage());
255
                if (!$validator) {
257
                if (!$validator) {
256
                    $this->_stack->push(__FUNCTION__, 'error',
258
                    $this->_stack->push(__FUNCTION__, 'error',
257
                        array_merge(
-
 
258
                            array('channel' => $chan->getName(),
259
                        array('channel' => $chan->getName(),
259
                                  'package' => $this->_pf->getPackage()),
260
                              'package' => $this->_pf->getPackage(),
260
                              $valpack
261
                              'name'    => $valpack['_content'],
261
                            ),
262
                              'version' => $valpack['attribs']['version']),
262
                        'package "%channel%/%package%" cannot be properly validated without ' .
263
                        'package "%channel%/%package%" cannot be properly validated without ' .
263
                        'validation package "%channel%/%name%-%version%"');
264
                        'validation package "%channel%/%name%-%version%"');
264
                    return $this->_isValid = 0;
265
                    return $this->_isValid = 0;
265
                }
266
                }
266
                $validator->setPackageFile($this->_pf);
267
                $validator->setPackageFile($this->_pf);
Line 274... Line 275...
274
                    $this->_stack->push(__FUNCTION__, 'warning', $warning,
275
                    $this->_stack->push(__FUNCTION__, 'warning', $warning,
275
                        'Channel validator warning: field "%field%" - %reason%');
276
                        'Channel validator warning: field "%field%" - %reason%');
276
                }
277
                }
277
            }
278
            }
278
        }
279
        }
-
 
280
 
279
        $this->_pf->_isValid = $this->_isValid = !$this->_stack->hasErrors('error');
281
        $this->_pf->_isValid = $this->_isValid = !$this->_stack->hasErrors('error');
280
        if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$this->_filesValid) {
282
        if ($this->_isValid && $state == PEAR_VALIDATE_PACKAGING && !$this->_filesValid) {
281
            if ($this->_pf->getPackageType() == 'bundle') {
283
            if ($this->_pf->getPackageType() == 'bundle') {
282
                if ($this->_analyzeBundledPackages()) {
284
                if ($this->_analyzeBundledPackages()) {
283
                    $this->_filesValid = $this->_pf->_filesValid = true;
285
                    $this->_filesValid = $this->_pf->_filesValid = true;
Line 290... Line 292...
290
                } else {
292
                } else {
291
                    $this->_filesValid = $this->_pf->_filesValid = true;
293
                    $this->_filesValid = $this->_pf->_filesValid = true;
292
                }
294
                }
293
            }
295
            }
294
        }
296
        }
-
 
297
 
295
        if ($this->_isValid) {
298
        if ($this->_isValid) {
296
            return $this->_pf->_isValid = $this->_isValid = $state;
299
            return $this->_pf->_isValid = $this->_isValid = $state;
297
        }
300
        }
-
 
301
 
298
        return $this->_pf->_isValid = $this->_isValid = 0;
302
        return $this->_pf->_isValid = $this->_isValid = 0;
299
    }
303
    }
Line 300... Line 304...
300
 
304
 
301
    function _stupidSchemaValidate($structure, $xml, $root)
305
    function _stupidSchemaValidate($structure, $xml, $root)
Line 464... Line 468...
464
    {
468
    {
465
        $structure = array('release', 'api');
469
        $structure = array('release', 'api');
466
        $a = $this->_stupidSchemaValidate($structure, $this->_packageInfo['version'], '<version>');
470
        $a = $this->_stupidSchemaValidate($structure, $this->_packageInfo['version'], '<version>');
467
        $a &= $this->_stupidSchemaValidate($structure, $this->_packageInfo['stability'], '<stability>');
471
        $a &= $this->_stupidSchemaValidate($structure, $this->_packageInfo['stability'], '<stability>');
468
        if ($a) {
472
        if ($a) {
469
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
473
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
470
                  $this->_packageInfo['version']['release'])) {
474
                  $this->_packageInfo['version']['release'])) {
471
                $this->_invalidVersion('release', $this->_packageInfo['version']['release']);
475
                $this->_invalidVersion('release', $this->_packageInfo['version']['release']);
472
            }
476
            }
473
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
477
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
474
                  $this->_packageInfo['version']['api'])) {
478
                  $this->_packageInfo['version']['api'])) {
475
                $this->_invalidVersion('api', $this->_packageInfo['version']['api']);
479
                $this->_invalidVersion('api', $this->_packageInfo['version']['api']);
476
            }
480
            }
477
            if (!in_array($this->_packageInfo['stability']['release'],
481
            if (!in_array($this->_packageInfo['stability']['release'],
478
                  array('snapshot', 'devel', 'alpha', 'beta', 'stable'))) {
482
                  array('snapshot', 'devel', 'alpha', 'beta', 'stable'))) {
479
                $this->_invalidState('release', $this->_packageinfo['stability']['release']);
483
                $this->_invalidState('release', $this->_packageInfo['stability']['release']);
480
            }
484
            }
481
            if (!in_array($this->_packageInfo['stability']['api'],
485
            if (!in_array($this->_packageInfo['stability']['api'],
482
                  array('devel', 'alpha', 'beta', 'stable'))) {
486
                  array('devel', 'alpha', 'beta', 'stable'))) {
483
                $this->_invalidState('api', $this->_packageinfo['stability']['api']);
487
                $this->_invalidState('api', $this->_packageInfo['stability']['api']);
484
            }
488
            }
485
        }
489
        }
486
    }
490
    }
Line 487... Line 491...
487
 
491
 
Line 517... Line 521...
517
            '*exclude',
521
            '*exclude',
518
        );
522
        );
519
        $type = $installcondition ? '<installcondition><php>' : '<dependencies><required><php>';
523
        $type = $installcondition ? '<installcondition><php>' : '<dependencies><required><php>';
520
        $this->_stupidSchemaValidate($structure, $dep, $type);
524
        $this->_stupidSchemaValidate($structure, $dep, $type);
521
        if (isset($dep['min'])) {
525
        if (isset($dep['min'])) {
522
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?$/',
526
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?\\z/',
523
                  $dep['min'])) {
527
                  $dep['min'])) {
524
                $this->_invalidVersion($type . '<min>', $dep['min']);
528
                $this->_invalidVersion($type . '<min>', $dep['min']);
525
            }
529
            }
526
        }
530
        }
527
        if (isset($dep['max'])) {
531
        if (isset($dep['max'])) {
528
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?$/',
532
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?\\z/',
529
                  $dep['max'])) {
533
                  $dep['max'])) {
530
                $this->_invalidVersion($type . '<max>', $dep['max']);
534
                $this->_invalidVersion($type . '<max>', $dep['max']);
531
            }
535
            }
532
        }
536
        }
533
        if (isset($dep['exclude'])) {
537
        if (isset($dep['exclude'])) {
534
            if (!is_array($dep['exclude'])) {
538
            if (!is_array($dep['exclude'])) {
535
                $dep['exclude'] = array($dep['exclude']);
539
                $dep['exclude'] = array($dep['exclude']);
536
            }
540
            }
537
            foreach ($dep['exclude'] as $exclude) {
541
            foreach ($dep['exclude'] as $exclude) {
538
                if (!preg_match(
542
                if (!preg_match(
539
                     '/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?$/',
543
                     '/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?(?:-[a-zA-Z0-9]+)?\\z/',
540
                     $exclude)) {
544
                     $exclude)) {
541
                    $this->_invalidVersion($type . '<exclude>', $exclude);
545
                    $this->_invalidVersion($type . '<exclude>', $exclude);
542
                }
546
                }
543
            }
547
            }
544
        }
548
        }
Line 552... Line 556...
552
            '*recommended',
556
            '*recommended',
553
            '*exclude',
557
            '*exclude',
554
        );
558
        );
555
        $this->_stupidSchemaValidate($structure, $dep, '<dependencies><required><pearinstaller>');
559
        $this->_stupidSchemaValidate($structure, $dep, '<dependencies><required><pearinstaller>');
556
        if (isset($dep['min'])) {
560
        if (isset($dep['min'])) {
557
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
561
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
558
                  $dep['min'])) {
562
                  $dep['min'])) {
559
                $this->_invalidVersion('<dependencies><required><pearinstaller><min>',
563
                $this->_invalidVersion('<dependencies><required><pearinstaller><min>',
560
                    $dep['min']);
564
                    $dep['min']);
561
            }
565
            }
562
        }
566
        }
563
        if (isset($dep['max'])) {
567
        if (isset($dep['max'])) {
564
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
568
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
565
                  $dep['max'])) {
569
                  $dep['max'])) {
566
                $this->_invalidVersion('<dependencies><required><pearinstaller><max>',
570
                $this->_invalidVersion('<dependencies><required><pearinstaller><max>',
567
                    $dep['max']);
571
                    $dep['max']);
568
            }
572
            }
569
        }
573
        }
570
        if (isset($dep['recommended'])) {
574
        if (isset($dep['recommended'])) {
571
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
575
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
572
                  $dep['recommended'])) {
576
                  $dep['recommended'])) {
573
                $this->_invalidVersion('<dependencies><required><pearinstaller><recommended>',
577
                $this->_invalidVersion('<dependencies><required><pearinstaller><recommended>',
574
                    $dep['recommended']);
578
                    $dep['recommended']);
575
            }
579
            }
576
        }
580
        }
577
        if (isset($dep['exclude'])) {
581
        if (isset($dep['exclude'])) {
578
            if (!is_array($dep['exclude'])) {
582
            if (!is_array($dep['exclude'])) {
579
                $dep['exclude'] = array($dep['exclude']);
583
                $dep['exclude'] = array($dep['exclude']);
580
            }
584
            }
581
            foreach ($dep['exclude'] as $exclude) {
585
            foreach ($dep['exclude'] as $exclude) {
582
                if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
586
                if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
583
                      $exclude)) {
587
                      $exclude)) {
584
                    $this->_invalidVersion('<dependencies><required><pearinstaller><exclude>',
588
                    $this->_invalidVersion('<dependencies><required><pearinstaller><exclude>',
585
                        $exclude);
589
                        $exclude);
586
                }
590
                }
587
            }
591
            }
Line 639... Line 643...
639
        }
643
        }
640
        if (isset($dep['channel']) && strtolower($dep['channel']) == '__uri') {
644
        if (isset($dep['channel']) && strtolower($dep['channel']) == '__uri') {
641
            $this->_DepchannelCannotBeUri('<dependencies>' . $group . $type);
645
            $this->_DepchannelCannotBeUri('<dependencies>' . $group . $type);
642
        }
646
        }
643
        if (isset($dep['min'])) {
647
        if (isset($dep['min'])) {
644
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
648
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
645
                  $dep['min'])) {
649
                  $dep['min'])) {
646
                $this->_invalidVersion('<dependencies>' . $group . $type . '<min>', $dep['min']);
650
                $this->_invalidVersion('<dependencies>' . $group . $type . '<min>', $dep['min']);
647
            }
651
            }
648
        }
652
        }
649
        if (isset($dep['max'])) {
653
        if (isset($dep['max'])) {
650
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
654
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
651
                  $dep['max'])) {
655
                  $dep['max'])) {
652
                $this->_invalidVersion('<dependencies>' . $group . $type . '<max>', $dep['max']);
656
                $this->_invalidVersion('<dependencies>' . $group . $type . '<max>', $dep['max']);
653
            }
657
            }
654
        }
658
        }
655
        if (isset($dep['recommended'])) {
659
        if (isset($dep['recommended'])) {
656
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
660
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
657
                  $dep['recommended'])) {
661
                  $dep['recommended'])) {
658
                $this->_invalidVersion('<dependencies>' . $group . $type . '<recommended>',
662
                $this->_invalidVersion('<dependencies>' . $group . $type . '<recommended>',
659
                    $dep['recommended']);
663
                    $dep['recommended']);
660
            }
664
            }
661
        }
665
        }
662
        if (isset($dep['exclude'])) {
666
        if (isset($dep['exclude'])) {
663
            if (!is_array($dep['exclude'])) {
667
            if (!is_array($dep['exclude'])) {
664
                $dep['exclude'] = array($dep['exclude']);
668
                $dep['exclude'] = array($dep['exclude']);
665
            }
669
            }
666
            foreach ($dep['exclude'] as $exclude) {
670
            foreach ($dep['exclude'] as $exclude) {
667
                if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
671
                if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
668
                      $exclude)) {
672
                      $exclude)) {
669
                    $this->_invalidVersion('<dependencies>' . $group . $type . '<exclude>',
673
                    $this->_invalidVersion('<dependencies>' . $group . $type . '<exclude>',
670
                        $exclude);
674
                        $exclude);
671
                }
675
                }
672
            }
676
            }
Line 711... Line 715...
711
        if (isset($dep['name'])) {
715
        if (isset($dep['name'])) {
712
            $type .= '<name>' . $dep['name'] . '</name>';
716
            $type .= '<name>' . $dep['name'] . '</name>';
713
        }
717
        }
714
        $this->_stupidSchemaValidate($structure, $dep, $type);
718
        $this->_stupidSchemaValidate($structure, $dep, $type);
715
        if (isset($dep['min'])) {
719
        if (isset($dep['min'])) {
716
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
720
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
717
                  $dep['min'])) {
721
                  $dep['min'])) {
718
                $this->_invalidVersion(substr($type, 1) . '<min', $dep['min']);
722
                $this->_invalidVersion(substr($type, 1) . '<min', $dep['min']);
719
            }
723
            }
720
        }
724
        }
721
        if (isset($dep['max'])) {
725
        if (isset($dep['max'])) {
722
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
726
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
723
                  $dep['max'])) {
727
                  $dep['max'])) {
724
                $this->_invalidVersion(substr($type, 1) . '<max', $dep['max']);
728
                $this->_invalidVersion(substr($type, 1) . '<max', $dep['max']);
725
            }
729
            }
726
        }
730
        }
727
        if (isset($dep['recommended'])) {
731
        if (isset($dep['recommended'])) {
728
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
732
            if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
729
                  $dep['recommended'])) {
733
                  $dep['recommended'])) {
730
                $this->_invalidVersion(substr($type, 1) . '<recommended', $dep['recommended']);
734
                $this->_invalidVersion(substr($type, 1) . '<recommended', $dep['recommended']);
731
            }
735
            }
732
        }
736
        }
733
        if (isset($dep['exclude'])) {
737
        if (isset($dep['exclude'])) {
734
            if (!is_array($dep['exclude'])) {
738
            if (!is_array($dep['exclude'])) {
735
                $dep['exclude'] = array($dep['exclude']);
739
                $dep['exclude'] = array($dep['exclude']);
736
            }
740
            }
737
            foreach ($dep['exclude'] as $exclude) {
741
            foreach ($dep['exclude'] as $exclude) {
738
                if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
742
                if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
739
                      $exclude)) {
743
                      $exclude)) {
740
                    $this->_invalidVersion(substr($type, 1) . '<exclude', $exclude);
744
                    $this->_invalidVersion(substr($type, 1) . '<exclude', $exclude);
741
                }
745
                }
742
            }
746
            }
743
        }
747
        }
Line 930... Line 934...
930
            if (is_array($package) && array_key_exists('name', $package)) {
934
            if (is_array($package) && array_key_exists('name', $package)) {
931
                $type .= '<name>' . $package['name'] . '</name>';
935
                $type .= '<name>' . $package['name'] . '</name>';
932
            }
936
            }
933
            $this->_stupidSchemaValidate($required, $package, $type);
937
            $this->_stupidSchemaValidate($required, $package, $type);
934
            if (is_array($package) && array_key_exists('min', $package)) {
938
            if (is_array($package) && array_key_exists('min', $package)) {
935
                if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
939
                if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
936
                      $package['min'])) {
940
                      $package['min'])) {
937
                    $this->_invalidVersion(substr($type, 1) . '<min', $package['min']);
941
                    $this->_invalidVersion(substr($type, 1) . '<min', $package['min']);
938
                }
942
                }
939
            }
943
            }
940
            if (is_array($package) && array_key_exists('max', $package)) {
944
            if (is_array($package) && array_key_exists('max', $package)) {
941
                if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
945
                if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
942
                      $package['max'])) {
946
                      $package['max'])) {
943
                    $this->_invalidVersion(substr($type, 1) . '<max', $package['max']);
947
                    $this->_invalidVersion(substr($type, 1) . '<max', $package['max']);
944
                }
948
                }
945
            }
949
            }
946
            if (is_array($package) && array_key_exists('exclude', $package)) {
950
            if (is_array($package) && array_key_exists('exclude', $package)) {
947
                if (!is_array($package['exclude'])) {
951
                if (!is_array($package['exclude'])) {
948
                    $package['exclude'] = array($package['exclude']);
952
                    $package['exclude'] = array($package['exclude']);
949
                }
953
                }
950
                foreach ($package['exclude'] as $exclude) {
954
                foreach ($package['exclude'] as $exclude) {
951
                    if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?$/',
955
                    if (!preg_match('/^\d+(?:\.\d+)*(?:[a-zA-Z]+\d*)?\\z/',
952
                          $exclude)) {
956
                          $exclude)) {
953
                        $this->_invalidVersion(substr($type, 1) . '<exclude', $exclude);
957
                        $this->_invalidVersion(substr($type, 1) . '<exclude', $exclude);
954
                    }
958
                    }
955
                }
959
                }
956
            }
960
            }
Line 1005... Line 1009...
1005
        if (!isset($list['attribs']) || !isset($list['attribs']['name'])) {
1009
        if (!isset($list['attribs']) || !isset($list['attribs']['name'])) {
1006
            $unknown = $allowignore ? '<filelist>' : '<dir name="*unknown*">';
1010
            $unknown = $allowignore ? '<filelist>' : '<dir name="*unknown*">';
1007
            $dirname = $iscontents ? '<contents>' : $unknown;
1011
            $dirname = $iscontents ? '<contents>' : $unknown;
1008
        } else {
1012
        } else {
1009
            $dirname = '<dir name="' . $list['attribs']['name'] . '">';
1013
            $dirname = '<dir name="' . $list['attribs']['name'] . '">';
-
 
1014
            if (preg_match('~/\.\.?(/|\\z)|^\.\.?/~',
-
 
1015
                          str_replace('\\', '/', $list['attribs']['name']))) {
-
 
1016
                // file contains .. parent directory or . cur directory
-
 
1017
                $this->_invalidDirName($list['attribs']['name']);
-
 
1018
            }
1010
        }
1019
        }
1011
        $res = $this->_stupidSchemaValidate($struc, $list, $dirname);
1020
        $res = $this->_stupidSchemaValidate($struc, $list, $dirname);
1012
        if ($allowignore && $res) {
1021
        if ($allowignore && $res) {
1013
            $ignored_or_installed = array();
1022
            $ignored_or_installed = array();
1014
            $this->_pf->getFilelist();
1023
            $this->_pf->getFilelist();
Line 1034... Line 1043...
1034
                    }
1043
                    }
1035
                    if (!isset($ignored_or_installed[$file['attribs']['name']])) {
1044
                    if (!isset($ignored_or_installed[$file['attribs']['name']])) {
1036
                        $ignored_or_installed[$file['attribs']['name']] = array();
1045
                        $ignored_or_installed[$file['attribs']['name']] = array();
1037
                    }
1046
                    }
1038
                    $ignored_or_installed[$file['attribs']['name']][] = 1;
1047
                    $ignored_or_installed[$file['attribs']['name']][] = 1;
-
 
1048
                    if (preg_match('~/\.\.?(/|\\z)|^\.\.?/~',
-
 
1049
                                  str_replace('\\', '/', $file['attribs']['as']))) {
-
 
1050
                        // file contains .. parent directory or . cur directory references
-
 
1051
                        $this->_invalidFileInstallAs($file['attribs']['name'],
-
 
1052
                            $file['attribs']['as']);
-
 
1053
                    }
1039
                }
1054
                }
1040
            }
1055
            }
1041
            if (isset($list['ignore'])) {
1056
            if (isset($list['ignore'])) {
1042
                if (!isset($list['ignore'][0])) {
1057
                if (!isset($list['ignore'][0])) {
1043
                    $list['ignore'] = array($list['ignore']);
1058
                    $list['ignore'] = array($list['ignore']);
Line 1052... Line 1067...
1052
                    }
1067
                    }
1053
                }
1068
                }
1054
            }
1069
            }
1055
        }
1070
        }
1056
        if (!$allowignore && isset($list['file'])) {
1071
        if (!$allowignore && isset($list['file'])) {
-
 
1072
            if (is_string($list['file'])) {
-
 
1073
                $this->_oldStyleFileNotAllowed();
-
 
1074
                return false;
-
 
1075
            }
1057
            if (!isset($list['file'][0])) {
1076
            if (!isset($list['file'][0])) {
1058
                // single file
1077
                // single file
1059
                $list['file'] = array($list['file']);
1078
                $list['file'] = array($list['file']);
1060
            }
1079
            }
1061
            foreach ($list['file'] as $i => $file)
1080
            foreach ($list['file'] as $i => $file)
1062
            {
1081
            {
1063
                if (isset($file['attribs']) && isset($file['attribs']['name']) &&
1082
                if (isset($file['attribs']) && isset($file['attribs']['name'])) {
1064
                      $file['attribs']['name']{0} == '.' &&
1083
                    if ($file['attribs']['name']{0} == '.' &&
1065
                        $file['attribs']['name']{1} == '/') {
1084
                          $file['attribs']['name']{1} == '/') {
1066
                    // name is something like "./doc/whatever.txt"
1085
                        // name is something like "./doc/whatever.txt"
-
 
1086
                        $this->_invalidFileName($file['attribs']['name'], $dirname);
-
 
1087
                    }
-
 
1088
                    if (preg_match('~/\.\.?(/|\\z)|^\.\.?/~',
-
 
1089
                                  str_replace('\\', '/', $file['attribs']['name']))) {
-
 
1090
                        // file contains .. parent directory or . cur directory
1067
                    $this->_invalidFileName($file['attribs']['name']);
1091
                        $this->_invalidFileName($file['attribs']['name'], $dirname);
-
 
1092
                    }
1068
                }
1093
                }
1069
                if (isset($file['attribs']) && isset($file['attribs']['role'])) {
1094
                if (isset($file['attribs']) && isset($file['attribs']['role'])) {
1070
                    if (!$this->_validateRole($file['attribs']['role'])) {
1095
                    if (!$this->_validateRole($file['attribs']['role'])) {
1071
                        if (isset($this->_packageInfo['usesrole'])) {
1096
                        if (isset($this->_packageInfo['usesrole'])) {
1072
                            $roles = $this->_packageInfo['usesrole'];
1097
                            $roles = $this->_packageInfo['usesrole'];
Line 1302... Line 1327...
1302
                $this->_validateInstallConditions($rel['installconditions'],
1327
                $this->_validateInstallConditions($rel['installconditions'],
1303
                    "<$release><installconditions>");
1328
                    "<$release><installconditions>");
1304
            }
1329
            }
1305
            if (is_array($rel) && array_key_exists('filelist', $rel)) {
1330
            if (is_array($rel) && array_key_exists('filelist', $rel)) {
1306
                if ($rel['filelist']) {
1331
                if ($rel['filelist']) {
1307
                    
1332
 
1308
                    $this->_validateFilelist($rel['filelist'], true);
1333
                    $this->_validateFilelist($rel['filelist'], true);
1309
                }
1334
                }
1310
            }
1335
            }
1311
        }
1336
        }
1312
    }
1337
    }
Line 1323... Line 1348...
1323
    function _pearVersionTooLow($version)
1348
    function _pearVersionTooLow($version)
1324
    {
1349
    {
1325
        $this->_stack->push(__FUNCTION__, 'error',
1350
        $this->_stack->push(__FUNCTION__, 'error',
1326
            array('version' => $version),
1351
            array('version' => $version),
1327
            'This package.xml requires PEAR version %version% to parse properly, we are ' .
1352
            'This package.xml requires PEAR version %version% to parse properly, we are ' .
1328
            'version 1.5.1');
1353
            'version 1.10.1');
1329
    }
1354
    }
Line 1330... Line 1355...
1330
 
1355
 
1331
    function _invalidTagOrder($oktags, $actual, $root)
1356
    function _invalidTagOrder($oktags, $actual, $root)
1332
    {
1357
    {
Line 1347... Line 1372...
1347
        $this->_stack->push(__FUNCTION__, 'error', array('type' => $type),
1372
        $this->_stack->push(__FUNCTION__, 'error', array('type' => $type),
1348
            '<%type%> is not allowed inside release <filelist>, only inside ' .
1373
            '<%type%> is not allowed inside release <filelist>, only inside ' .
1349
            '<contents>, use <ignore> and <install> only');
1374
            '<contents>, use <ignore> and <install> only');
1350
    }
1375
    }
Line -... Line 1376...
-
 
1376
 
-
 
1377
    function _oldStyleFileNotAllowed()
-
 
1378
    {
-
 
1379
        $this->_stack->push(__FUNCTION__, 'error', array(),
-
 
1380
            'Old-style <file>name</file> is not allowed.  Use' .
-
 
1381
            '<file name="name" role="role"/>');
-
 
1382
    }
1351
 
1383
 
1352
    function _tagMissingAttribute($tag, $attr, $context)
1384
    function _tagMissingAttribute($tag, $attr, $context)
1353
    {
1385
    {
1354
        $this->_stack->push(__FUNCTION__, 'error', array('tag' => $tag,
1386
        $this->_stack->push(__FUNCTION__, 'error', array('tag' => $tag,
1355
            'attribute' => $attr, 'context' => $context),
1387
            'attribute' => $attr, 'context' => $context),
Line 1379... Line 1411...
1379
 
1411
 
1380
    function _invalidFileName($file, $dir)
1412
    function _invalidFileName($file, $dir)
1381
    {
1413
    {
1382
        $this->_stack->push(__FUNCTION__, 'error', array(
1414
        $this->_stack->push(__FUNCTION__, 'error', array(
-
 
1415
            'file' => $file),
-
 
1416
            'File "%file%" in directory "%dir%" cannot begin with "./" or contain ".."');
-
 
1417
    }
-
 
1418
 
-
 
1419
    function _invalidFileInstallAs($file, $as)
-
 
1420
    {
-
 
1421
        $this->_stack->push(__FUNCTION__, 'error', array(
-
 
1422
            'file' => $file, 'as' => $as),
-
 
1423
            'File "%file%" <install as="%as%"/> cannot contain "./" or contain ".."');
-
 
1424
    }
-
 
1425
 
-
 
1426
    function _invalidDirName($dir)
-
 
1427
    {
-
 
1428
        $this->_stack->push(__FUNCTION__, 'error', array(
1383
            'file' => $file),
1429
            'dir' => $file),
1384
            'File "%file%" cannot begin with "."');
1430
            'Directory "%dir%" cannot begin with "./" or contain ".."');
Line 1385... Line 1431...
1385
    }
1431
    }
1386
 
1432
 
1387
    function _filelistCannotContainFile($filelist)
1433
    function _filelistCannotContainFile($filelist)
Line 1623... Line 1669...
1623
    }
1669
    }
Line 1624... Line 1670...
1624
 
1670
 
1625
    function _usesroletaskMustHaveChannelOrUri($role, $tag)
1671
    function _usesroletaskMustHaveChannelOrUri($role, $tag)
1626
    {
1672
    {
1627
        $this->_stack->push(__FUNCTION__, 'error', array('role' => $role, 'tag' => $tag),
1673
        $this->_stack->push(__FUNCTION__, 'error', array('role' => $role, 'tag' => $tag),
1628
            '<%tag%> must contain either <uri>, or <channel> and <package>');
1674
            '<%tag%> for role "%role%" must contain either <uri>, or <channel> and <package>');
Line 1629... Line 1675...
1629
    }
1675
    }
1630
 
1676
 
1631
    function _usesroletaskMustHavePackage($role, $tag)
1677
    function _usesroletaskMustHavePackage($role, $tag)
1632
    {
1678
    {
1633
        $this->_stack->push(__FUNCTION__, 'error', array('role' => $role, 'tag' => $tag),
1679
        $this->_stack->push(__FUNCTION__, 'error', array('role' => $role, 'tag' => $tag),
Line 1634... Line 1680...
1634
            '<%tag%> must contain <package>');
1680
            '<%tag%> for role "%role%" must contain <package>');
1635
    }
1681
    }
1636
 
1682
 
Line 1646... Line 1692...
1646
            '%tag% cannot conflict with all OSes');
1692
            '%tag% cannot conflict with all OSes');
1647
    }
1693
    }
Line 1648... Line 1694...
1648
 
1694
 
1649
    function _invalidDepGroupName($name)
1695
    function _invalidDepGroupName($name)
1650
    {
1696
    {
1651
        $this->_stack->push(__FUNCTION__, 'error', array('group' => $name),
1697
        $this->_stack->push(__FUNCTION__, 'error', array('name' => $name),
1652
            'Invalid dependency group name "%name%"');
1698
            'Invalid dependency group name "%name%"');
Line 1653... Line 1699...
1653
    }
1699
    }
1654
 
1700
 
Line 1681... Line 1727...
1681
        }
1727
        }
1682
        if (!isset($this->_pf->_packageFile)) {
1728
        if (!isset($this->_pf->_packageFile)) {
1683
            return false;
1729
            return false;
1684
        }
1730
        }
1685
        $dir_prefix = dirname($this->_pf->_packageFile);
1731
        $dir_prefix = dirname($this->_pf->_packageFile);
-
 
1732
        $common = new PEAR_Common;
1686
        $log = isset($this->_pf->_logger) ? array(&$this->_pf->_logger, 'log') :
1733
        $log = isset($this->_pf->_logger) ? array(&$this->_pf->_logger, 'log') :
1687
            array('PEAR_Common', 'log');
1734
            array($common, 'log');
1688
        $info = $this->_pf->getContents();
1735
        $info = $this->_pf->getContents();
1689
        $info = $info['bundledpackage'];
1736
        $info = $info['bundledpackage'];
1690
        if (!is_array($info)) {
1737
        if (!is_array($info)) {
1691
            $info = array($info);
1738
            $info = array($info);
1692
        }
1739
        }
1693
        $pkg = &new PEAR_PackageFile($this->_pf->_config);
1740
        $pkg = new PEAR_PackageFile($this->_pf->_config);
1694
        foreach ($info as $package) {
1741
        foreach ($info as $package) {
1695
            if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $package)) {
1742
            if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $package)) {
1696
                $this->_fileNotFound($dir_prefix . DIRECTORY_SEPARATOR . $package);
1743
                $this->_fileNotFound($dir_prefix . DIRECTORY_SEPARATOR . $package);
1697
                $this->_isValid = 0;
1744
                $this->_isValid = 0;
1698
                continue;
1745
                continue;
Line 1796... Line 1843...
1796
        if (!function_exists("token_get_all")) {
1843
        if (!function_exists("token_get_all")) {
1797
            $this->_stack->push(__FUNCTION__, 'error', array('file' => $file),
1844
            $this->_stack->push(__FUNCTION__, 'error', array('file' => $file),
1798
                'Parser error: token_get_all() function must exist to analyze source code, PHP may have been compiled with --disable-tokenizer');
1845
                'Parser error: token_get_all() function must exist to analyze source code, PHP may have been compiled with --disable-tokenizer');
1799
            return false;
1846
            return false;
1800
        }
1847
        }
-
 
1848
 
1801
        if (!defined('T_DOC_COMMENT')) {
1849
        if (!defined('T_DOC_COMMENT')) {
1802
            define('T_DOC_COMMENT', T_COMMENT);
1850
            define('T_DOC_COMMENT', T_COMMENT);
1803
        }
1851
        }
-
 
1852
 
1804
        if (!defined('T_INTERFACE')) {
1853
        if (!defined('T_INTERFACE')) {
1805
            define('T_INTERFACE', -1);
1854
            define('T_INTERFACE', -1);
1806
        }
1855
        }
-
 
1856
 
1807
        if (!defined('T_IMPLEMENTS')) {
1857
        if (!defined('T_IMPLEMENTS')) {
1808
            define('T_IMPLEMENTS', -1);
1858
            define('T_IMPLEMENTS', -1);
1809
        }
1859
        }
-
 
1860
 
1810
        if ($string) {
1861
        if ($string) {
1811
            $contents = $file;
1862
            $contents = $file;
1812
        } else {
1863
        } else {
1813
            if (!$fp = @fopen($file, "r")) {
1864
            if (!$fp = @fopen($file, "r")) {
1814
                return false;
1865
                return false;
1815
            }
1866
            }
1816
            fclose($fp);
1867
            fclose($fp);
1817
            $contents = file_get_contents($file);
1868
            $contents = file_get_contents($file);
1818
        }
1869
        }
-
 
1870
 
-
 
1871
        // Silence this function so we can catch PHP Warnings and show our own custom message
1819
        $tokens = token_get_all($contents);
1872
        $tokens = @token_get_all($contents);
-
 
1873
        if (isset($php_errormsg)) {
-
 
1874
            if (isset($this->_stack)) {
-
 
1875
                $pn = $this->_pf->getPackage();
-
 
1876
                $this->_stack->push(__FUNCTION__, 'warning',
-
 
1877
                        array('file' => $file, 'package' => $pn),
-
 
1878
                        'in %file%: Could not process file for unknown reasons,' .
-
 
1879
                        ' possibly a PHP parse error in %file% from %package%');
-
 
1880
            }
-
 
1881
        }
1820
/*
1882
/*
1821
        for ($i = 0; $i < sizeof($tokens); $i++) {
1883
        for ($i = 0; $i < sizeof($tokens); $i++) {
1822
            @list($token, $data) = $tokens[$i];
1884
            @list($token, $data) = $tokens[$i];
1823
            if (is_string($token)) {
1885
            if (is_string($token)) {
1824
                var_dump($token);
1886
                var_dump($token);
Line 1854... Line 1916...
1854
                list($token, $data) = $tokens[$i];
1916
                list($token, $data) = $tokens[$i];
1855
            } else {
1917
            } else {
1856
                $token = $tokens[$i];
1918
                $token = $tokens[$i];
1857
                $data = '';
1919
                $data = '';
1858
            }
1920
            }
-
 
1921
 
1859
            if ($inquote) {
1922
            if ($inquote) {
1860
                if ($token != '"' && $token != T_END_HEREDOC) {
1923
                if ($token != '"' && $token != T_END_HEREDOC) {
1861
                    continue;
1924
                    continue;
1862
                } else {
1925
                } else {
1863
                    $inquote = false;
1926
                    $inquote = false;
1864
                    continue;
1927
                    continue;
1865
                }
1928
                }
1866
            }
1929
            }
-
 
1930
 
1867
            switch ($token) {
1931
            switch ($token) {
1868
                case T_WHITESPACE :
1932
                case T_WHITESPACE :
1869
                    continue;
1933
                    continue;
1870
                case ';':
1934
                case ';':
1871
                    if ($interface) {
1935
                    if ($interface) {
Line 1897... Line 1961...
1897
                case ')': $paren_level--;   continue 2;
1961
                case ')': $paren_level--;   continue 2;
1898
                case T_INTERFACE:
1962
                case T_INTERFACE:
1899
                    $interface = true;
1963
                    $interface = true;
1900
                case T_CLASS:
1964
                case T_CLASS:
1901
                    if (($current_class_level != -1) || ($current_function_level != -1)) {
1965
                    if (($current_class_level != -1) || ($current_function_level != -1)) {
-
 
1966
                        if (isset($this->_stack)) {
1902
                        $this->_stack->push(__FUNCTION__, 'error', array('file' => $file),
1967
                            $this->_stack->push(__FUNCTION__, 'error', array('file' => $file),
1903
                        'Parser error: invalid PHP found in file "%file%"');
1968
                            'Parser error: invalid PHP found in file "%file%"');
-
 
1969
                        } else {
-
 
1970
                            PEAR::raiseError("Parser error: invalid PHP found in file \"$file\"",
-
 
1971
                                PEAR_COMMON_ERROR_INVALIDPHP);
-
 
1972
                        }
-
 
1973
 
1904
                        return false;
1974
                        return false;
1905
                    }
1975
                    }
1906
                case T_FUNCTION:
1976
                case T_FUNCTION:
1907
                case T_NEW:
1977
                case T_NEW:
1908
                case T_EXTENDS:
1978
                case T_EXTENDS:
1909
                case T_IMPLEMENTS:
1979
                case T_IMPLEMENTS:
1910
                    $look_for = $token;
1980
                    $look_for = $token;
1911
                    continue 2;
1981
                    continue 2;
1912
                case T_STRING:
1982
                case T_STRING:
1913
                    if (version_compare(zend_version(), '2.0', '<')) {
-
 
1914
                        if (in_array(strtolower($data),
-
 
1915
                            array('public', 'private', 'protected', 'abstract',
-
 
1916
                                  'interface', 'implements', 'throw') 
-
 
1917
                                 )) {
-
 
1918
                            $this->_stack->push(__FUNCTION__, 'warning', array(
-
 
1919
                                'file' => $file),
-
 
1920
                                'Error, PHP5 token encountered in %file%,' .
-
 
1921
                                ' analysis should be in PHP5');
-
 
1922
                        }
-
 
1923
                    }
-
 
1924
                    if ($look_for == T_CLASS) {
1983
                    if ($look_for == T_CLASS) {
1925
                        $current_class = $data;
1984
                        $current_class = $data;
1926
                        $current_class_level = $brace_level;
1985
                        $current_class_level = $brace_level;
1927
                        $declared_classes[] = $current_class;
1986
                        $declared_classes[] = $current_class;
1928
                    } elseif ($look_for == T_INTERFACE) {
1987
                    } elseif ($look_for == T_INTERFACE) {
Line 1942... Line 2001...
1942
                            $declared_methods[$current_interface][] = $data;
2001
                            $declared_methods[$current_interface][] = $data;
1943
                        } else {
2002
                        } else {
1944
                            $current_function = $data;
2003
                            $current_function = $data;
1945
                            $declared_functions[] = $current_function;
2004
                            $declared_functions[] = $current_function;
1946
                        }
2005
                        }
-
 
2006
 
1947
                        $current_function_level = $brace_level;
2007
                        $current_function_level = $brace_level;
1948
                        $m = array();
2008
                        $m = array();
1949
                    } elseif ($look_for == T_NEW) {
2009
                    } elseif ($look_for == T_NEW) {
1950
                        $used_classes[$data] = true;
2010
                        $used_classes[$data] = true;
1951
                    }
2011
                    }
-
 
2012
 
1952
                    $look_for = 0;
2013
                    $look_for = 0;
1953
                    continue 2;
2014
                    continue 2;
1954
                case T_VARIABLE:
2015
                case T_VARIABLE:
1955
                    $look_for = 0;
2016
                    $look_for = 0;
1956
                    continue 2;
2017
                    continue 2;
Line 1962... Line 2023...
1962
                            $nodeps = array_merge($nodeps, $m[1]);
2023
                            $nodeps = array_merge($nodeps, $m[1]);
1963
                        }
2024
                        }
1964
                    }
2025
                    }
1965
                    continue 2;
2026
                    continue 2;
1966
                case T_DOUBLE_COLON:
2027
                case T_DOUBLE_COLON:
-
 
2028
                    $token = $tokens[$i - 1][0];
1967
                    if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
2029
                    if (!($token == T_WHITESPACE || $token == T_STRING || $token == T_STATIC || $token == T_VARIABLE)) {
-
 
2030
                        if (isset($this->_stack)) {
1968
                        $this->_stack->push(__FUNCTION__, 'warning', array('file' => $file),
2031
                            $this->_stack->push(__FUNCTION__, 'warning', array('file' => $file),
1969
                            'Parser error: invalid PHP found in file "%file%"');
2032
                                'Parser error: invalid PHP found in file "%file%"');
-
 
2033
                        } else {
-
 
2034
                            PEAR::raiseError("Parser error: invalid PHP found in file \"$file\"",
-
 
2035
                                PEAR_COMMON_ERROR_INVALIDPHP);
-
 
2036
                        }
-
 
2037
 
1970
                        return false;
2038
                        return false;
1971
                    }
2039
                    }
-
 
2040
 
1972
                    $class = $tokens[$i - 1][1];
2041
                    $class = $tokens[$i - 1][1];
1973
                    if (strtolower($class) != 'parent') {
2042
                    if (strtolower($class) != 'parent') {
1974
                        $used_classes[$class] = true;
2043
                        $used_classes[$class] = true;
1975
                    }
2044
                    }
-
 
2045
 
1976
                    continue 2;
2046
                    continue 2;
1977
            }
2047
            }
1978
        }
2048
        }
-
 
2049
 
1979
        return array(
2050
        return array(
1980
            "source_file" => $file,
2051
            "source_file" => $file,
1981
            "declared_classes" => $declared_classes,
2052
            "declared_classes" => $declared_classes,
1982
            "declared_interfaces" => $declared_interfaces,
2053
            "declared_interfaces" => $declared_interfaces,
1983
            "declared_methods" => $declared_methods,
2054
            "declared_methods" => $declared_methods,
1984
            "declared_functions" => $declared_functions,
2055
            "declared_functions" => $declared_functions,
1985
            "used_classes" => array_diff(array_keys($used_classes), $nodeps),
2056
            "used_classes" => array_diff(array_keys($used_classes), $nodeps),
1986
            "inheritance" => $extends,
2057
            "inheritance" => $extends,
1987
            "implements" => $implements,
2058
            "implements" => $implements,
1988
            );
2059
        );
1989
    }
2060
    }
Line 1990... Line 2061...
1990
 
2061
 
1991
    /**
2062
    /**
1992
     * Build a "provides" array from data returned by
2063
     * Build a "provides" array from data returned by
Line 2010... Line 2081...
2010
    function _buildProvidesArray($srcinfo)
2081
    function _buildProvidesArray($srcinfo)
2011
    {
2082
    {
2012
        if (!$this->_isValid) {
2083
        if (!$this->_isValid) {
2013
            return array();
2084
            return array();
2014
        }
2085
        }
-
 
2086
 
2015
        $providesret = array();
2087
        $providesret = array();
2016
        $file = basename($srcinfo['source_file']);
2088
        $file        = basename($srcinfo['source_file']);
2017
        $pn = $this->_pf->getPackage();
2089
        $pn          = isset($this->_pf) ? $this->_pf->getPackage() : '';
2018
        $pnl = strlen($pn);
2090
        $pnl         = strlen($pn);
2019
        foreach ($srcinfo['declared_classes'] as $class) {
2091
        foreach ($srcinfo['declared_classes'] as $class) {
2020
            $key = "class;$class";
2092
            $key = "class;$class";
2021
            if (isset($providesret[$key])) {
2093
            if (isset($providesret[$key])) {
2022
                continue;
2094
                continue;
2023
            }
2095
            }
-
 
2096
 
2024
            $providesret[$key] =
2097
            $providesret[$key] =
2025
                array('file'=> $file, 'type' => 'class', 'name' => $class);
2098
                array('file'=> $file, 'type' => 'class', 'name' => $class);
2026
            if (isset($srcinfo['inheritance'][$class])) {
2099
            if (isset($srcinfo['inheritance'][$class])) {
2027
                $providesret[$key]['extends'] =
2100
                $providesret[$key]['extends'] =
2028
                    $srcinfo['inheritance'][$class];
2101
                    $srcinfo['inheritance'][$class];
2029
            }
2102
            }
2030
        }
2103
        }
-
 
2104
 
2031
        foreach ($srcinfo['declared_methods'] as $class => $methods) {
2105
        foreach ($srcinfo['declared_methods'] as $class => $methods) {
2032
            foreach ($methods as $method) {
2106
            foreach ($methods as $method) {
2033
                $function = "$class::$method";
2107
                $function = "$class::$method";
2034
                $key = "function;$function";
2108
                $key = "function;$function";
2035
                if ($method{0} == '_' || !strcasecmp($method, $class) ||
2109
                if ($method{0} == '_' || !strcasecmp($method, $class) ||
2036
                    isset($providesret[$key])) {
2110
                    isset($providesret[$key])) {
2037
                    continue;
2111
                    continue;
2038
                }
2112
                }
-
 
2113
 
2039
                $providesret[$key] =
2114
                $providesret[$key] =
2040
                    array('file'=> $file, 'type' => 'function', 'name' => $function);
2115
                    array('file'=> $file, 'type' => 'function', 'name' => $function);
2041
            }
2116
            }
2042
        }
2117
        }
Line 2043... Line 2118...
2043
 
2118
 
2044
        foreach ($srcinfo['declared_functions'] as $function) {
2119
        foreach ($srcinfo['declared_functions'] as $function) {
2045
            $key = "function;$function";
2120
            $key = "function;$function";
2046
            if ($function{0} == '_' || isset($providesret[$key])) {
2121
            if ($function{0} == '_' || isset($providesret[$key])) {
2047
                continue;
2122
                continue;
-
 
2123
            }
2048
            }
2124
 
2049
            if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {
2125
            if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) {
2050
                $warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";
2126
                $warnings[] = "in1 " . $file . ": function \"$function\" not prefixed with package name \"$pn\"";
-
 
2127
            }
2051
            }
2128
 
2052
            $providesret[$key] =
2129
            $providesret[$key] =
2053
                array('file'=> $file, 'type' => 'function', 'name' => $function);
2130
                array('file'=> $file, 'type' => 'function', 'name' => $function);
-
 
2131
        }
2054
        }
2132
 
2055
        return $providesret;
2133
        return $providesret;
2056
    }
2134
    }
2057
}
-
 
2058
?>
2135
}