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_Validate
3
 * PEAR_Validate
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Greg Beaver <cellog@php.net>
9
 * @author     Greg Beaver <cellog@php.net>
16
 * @copyright  1997-2006 The PHP Group
10
 * @copyright  1997-2009 The Authors
17
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
11
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
18
 * @version    CVS: $Id: Validate.php,v 1.50 2006/09/25 05:12:21 cellog Exp $
-
 
19
 * @link       http://pear.php.net/package/PEAR
12
 * @link       http://pear.php.net/package/PEAR
20
 * @since      File available since Release 1.4.0a1
13
 * @since      File available since Release 1.4.0a1
21
 */
14
 */
22
/**#@+
15
/**#@+
23
 * Constants for install stage
16
 * Constants for install stage
Line 34... Line 27...
34
/**
27
/**
35
 * Validation class for package.xml - channel-level advanced validation
28
 * Validation class for package.xml - channel-level advanced validation
36
 * @category   pear
29
 * @category   pear
37
 * @package    PEAR
30
 * @package    PEAR
38
 * @author     Greg Beaver <cellog@php.net>
31
 * @author     Greg Beaver <cellog@php.net>
39
 * @copyright  1997-2006 The PHP Group
32
 * @copyright  1997-2009 The Authors
40
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
33
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
41
 * @version    Release: 1.5.1
34
 * @version    Release: 1.10.1
42
 * @link       http://pear.php.net/package/PEAR
35
 * @link       http://pear.php.net/package/PEAR
43
 * @since      Class available since Release 1.4.0a1
36
 * @since      Class available since Release 1.4.0a1
44
 */
37
 */
45
class PEAR_Validate
38
class PEAR_Validate
46
{
39
{
Line 66... Line 59...
66
     * @return bool
59
     * @return bool
67
     * @access protected
60
     * @access protected
68
     */
61
     */
69
    function _validPackageName($name)
62
    function _validPackageName($name)
70
    {
63
    {
71
        return (bool) preg_match('/^' . $this->packageregex . '$/', $name);
64
        return (bool) preg_match('/^' . $this->packageregex . '\\z/', $name);
72
    }
65
    }
Line 73... Line 66...
73
 
66
 
74
    /**
67
    /**
75
     * @param string package name to validate
68
     * @param string package name to validate
Line 78... Line 71...
78
     */
71
     */
79
    function validPackageName($name, $validatepackagename = false)
72
    function validPackageName($name, $validatepackagename = false)
80
    {
73
    {
81
        if ($validatepackagename) {
74
        if ($validatepackagename) {
82
            if (strtolower($name) == strtolower($validatepackagename)) {
75
            if (strtolower($name) == strtolower($validatepackagename)) {
83
                return (bool) preg_match('/^[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*$/', $name);
76
                return (bool) preg_match('/^[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*\\z/', $name);
84
            }
77
            }
85
        }
78
        }
86
        return $this->_validPackageName($name);
79
        return $this->_validPackageName($name);
87
    }
80
    }
Line 88... Line 81...
88
 
81
 
89
    /**
82
    /**
90
     * This validates a bundle name, and bundle names must conform
83
     * This validates a bundle name, and bundle names must conform
91
     * to the PEAR naming convention, so the method is final and static.
84
     * to the PEAR naming convention, so the method is final and static.
92
     * @param string
85
     * @param string
93
     * @final
-
 
94
     * @static
86
     * @final
95
     */
87
     */
96
    function validGroupName($name)
88
    public static function validGroupName($name)
97
    {
89
    {
98
        return (bool) preg_match('/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/', $name);
90
        return (bool) preg_match('/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '\\z/', $name);
Line 99... Line 91...
99
    }
91
    }
100
 
92
 
101
    /**
93
    /**
102
     * Determine whether $state represents a valid stability level
94
     * Determine whether $state represents a valid stability level
103
     * @param string
-
 
104
     * @return bool
95
     * @param string
105
     * @static
96
     * @return bool
106
     * @final
97
     * @final
107
     */
98
     */
108
    function validState($state)
99
    public static function validState($state)
109
    {
100
    {
Line 110... Line 101...
110
        return in_array($state, array('snapshot', 'devel', 'alpha', 'beta', 'stable'));
101
        return in_array($state, array('snapshot', 'devel', 'alpha', 'beta', 'stable'));
111
    }
102
    }
112
 
103
 
113
    /**
-
 
114
     * Get a list of valid stability levels
104
    /**
115
     * @return array
105
     * Get a list of valid stability levels
116
     * @static
106
     * @return array
117
     * @final
107
     * @final
118
     */
108
     */
119
    function getValidStates()
109
    public static function getValidStates()
Line 120... Line 110...
120
    {
110
    {
121
        return array('snapshot', 'devel', 'alpha', 'beta', 'stable');
111
        return array('snapshot', 'devel', 'alpha', 'beta', 'stable');
122
    }
112
    }
123
 
113
 
124
    /**
114
    /**
125
     * Determine whether a version is a properly formatted version number that can be used
-
 
126
     * by version_compare
115
     * Determine whether a version is a properly formatted version number that can be used
127
     * @param string
116
     * by version_compare
128
     * @return bool
117
     * @param string
129
     * @static
118
     * @return bool
130
     * @final
119
     * @final
131
     */
120
     */
Line 132... Line 121...
132
    function validVersion($ver)
121
    public static function validVersion($ver)
Line 211... Line 200...
211
            if (($this->_packagexml->getPackagexmlVersion() == '2.0' ||
200
            if (($this->_packagexml->getPackagexmlVersion() == '2.0' ||
212
                 $this->_packagexml->getPackagexmlVersion() == '2.1') &&
201
                 $this->_packagexml->getPackagexmlVersion() == '2.1') &&
213
                  $this->_packagexml->getExtends()) {
202
                  $this->_packagexml->getExtends()) {
214
                $version = $this->_packagexml->getVersion() . '';
203
                $version = $this->_packagexml->getVersion() . '';
215
                $name = $this->_packagexml->getPackage();
204
                $name = $this->_packagexml->getPackage();
216
                $test = array_shift($a = explode('.', $version));
205
                $a = explode('.', $version);
-
 
206
                $test = array_shift($a);
217
                if ($test == '0') {
207
                if ($test == '0') {
218
                    return true;
208
                    return true;
219
                }
209
                }
220
                $vlen = strlen($test);
210
                $vlen = strlen($test);
221
                $majver = substr($name, strlen($name) - $vlen);
211
                $majver = substr($name, strlen($name) - $vlen);
Line 456... Line 446...
456
                $this->_addFailure('date', 'invalid release date "' .
446
                $this->_addFailure('date', 'invalid release date "' .
457
                    $this->_packagexml->getDate() . '"');
447
                    $this->_packagexml->getDate() . '"');
458
                return false;
448
                return false;
459
            }
449
            }
Line 460... Line -...
460
 
-
 
461
 
450
 
462
            if ($this->_state == PEAR_VALIDATE_PACKAGING &&
451
            if ($this->_state == PEAR_VALIDATE_PACKAGING &&
463
                  $this->_packagexml->getDate() != date('Y-m-d')) {
452
                  $this->_packagexml->getDate() != date('Y-m-d')) {
464
                $this->_addWarning('date', 'Release Date "' .
453
                $this->_addWarning('date', 'Release Date "' .
465
                    $this->_packagexml->getDate() . '" is not today');
454
                    $this->_packagexml->getDate() . '" is not today');
Line 475... Line 464...
475
    {
464
    {
476
        if (!$this->_packagexml->getTime()) {
465
        if (!$this->_packagexml->getTime()) {
477
            // default of no time value set
466
            // default of no time value set
478
            return true;
467
            return true;
479
        }
468
        }
-
 
469
 
480
        // packager automatically sets time, so only validate if
470
        // packager automatically sets time, so only validate if pear validate is called
481
        // pear validate is called
-
 
482
        if ($this->_state = PEAR_VALIDATE_NORMAL) {
471
        if ($this->_state = PEAR_VALIDATE_NORMAL) {
483
            if (!preg_match('/\d\d:\d\d:\d\d/',
472
            if (!preg_match('/\d\d:\d\d:\d\d/',
484
                  $this->_packagexml->getTime())) {
473
                  $this->_packagexml->getTime())) {
485
                $this->_addFailure('time', 'invalid release time "' .
474
                $this->_addFailure('time', 'invalid release time "' .
486
                    $this->_packagexml->getTime() . '"');
475
                    $this->_packagexml->getTime() . '"');
487
                return false;
476
                return false;
488
            }
477
            }
-
 
478
 
489
            if (strtotime($this->_packagexml->getTime()) == -1) {
479
            $result = preg_match('|\d{2}\:\d{2}\:\d{2}|', $this->_packagexml->getTime(), $matches);
-
 
480
            if ($result === false || empty($matches)) {
490
                $this->_addFailure('time', 'invalid release time "' .
481
                $this->_addFailure('time', 'invalid release time "' .
491
                    $this->_packagexml->getTime() . '"');
482
                    $this->_packagexml->getTime() . '"');
492
                return false;
483
                return false;
493
            }
484
            }
494
        }
485
        }
-
 
486
 
495
        return true;
487
        return true;
496
    }
488
    }
Line 497... Line 489...
497
 
489
 
498
    /**
490
    /**
Line 628... Line 620...
628
     */
620
     */
629
    function validateDeps()
621
    function validateDeps()
630
    {
622
    {
631
        return true;
623
        return true;
632
    }
624
    }
633
}
625
}
634
?>
-
 
635
626