@@ -10,51 +10,51 @@ |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | return array( |
13 | - 'zend-engine-2' => '>=5.0.0', |
|
14 | - 'oop' => '>=5.0.0', |
|
15 | - 'classes' => '>=5.0.0', |
|
16 | - 'object-model' => '>=5.0.0', |
|
17 | - 'pdo' => '>=5.1.0', |
|
18 | - 'native-json' => '>=5.2.0', |
|
19 | - 'namespaces' => '>=5.3.0', |
|
20 | - 'late-static-bindings' => '>=5.3.0', |
|
21 | - 'jump-labels' => '>=5.3.0', |
|
22 | - 'closures' => '>=5.3.0', |
|
23 | - 'php-archives' => '>=5.3.0', |
|
24 | - 'phar' => '>=5.3.0', |
|
25 | - 'circular-garbage-collection' => '>=5.3.0', |
|
26 | - 'sqlite3' => '>=5.3.0', |
|
27 | - 'mysqlnd' => '>=5.3.0', |
|
28 | - 'fileinfo' => '>=5.3.0', |
|
29 | - 'traits' => '>=5.4.0', |
|
30 | - 'short-array-syntax' => '>=5.4.0', |
|
31 | - '[]' => '>=5.4.0', |
|
32 | - 'built-in-web-server' => '>=5.4.0', |
|
33 | - 'generators' => '>=5.5.0', |
|
34 | - 'finally' => '>=5.5.0', |
|
35 | - 'opcache' => '>=5.5.0', |
|
36 | - 'constant-scalars' => '>=5.6.0', |
|
37 | - 'variadic-functions' => '>=5.6.0', |
|
38 | - 'argument-unpacking' => '>=5.6.0', |
|
39 | - 'exponentiation-operator' => '>=5.6.0', |
|
40 | - 'phpdbg' => '>=5.6.0', |
|
41 | - 'zend-engine-3' => '>=7.0.0', |
|
42 | - 'uniform-variable-syntax' => '>=7.0.0', |
|
43 | - 'ast-based-compilation' => '>=7.0.0', |
|
44 | - 'closure-call' => '>=7.0.0', |
|
45 | - 'null-coalesce-operator' => '>=7.0.0', |
|
46 | - '??' => '>=7.0.0', |
|
47 | - 'return-type-declarations' => '>=7.0.0', |
|
48 | - 'scalar-type-declarations' => '>=7.0.0', |
|
49 | - 'spaceship-operator' => '>=7.0.0', |
|
50 | - 'three-way-comparison-operator' => '>=7.0.0', |
|
51 | - '<=>' => '>=7.0.0', |
|
52 | - 'generator-delegation' => '>=7.0.0', |
|
53 | - 'anonymous-classes' => '>=7.0.0', |
|
54 | - 'multiple-namespace-import' => '>=7.0.0', |
|
55 | - 'pcre-8.38' => '>=7.0.3', |
|
56 | - 'http-451' => '>=7.0.3', |
|
57 | - 'libzip-1.1.2' => '>=7.0.5', |
|
58 | - 'void-return-type' => '>=7.1.0', |
|
59 | - 'constant-visibility-modifiers' => '>=7.1.0', |
|
13 | + 'zend-engine-2' => '>=5.0.0', |
|
14 | + 'oop' => '>=5.0.0', |
|
15 | + 'classes' => '>=5.0.0', |
|
16 | + 'object-model' => '>=5.0.0', |
|
17 | + 'pdo' => '>=5.1.0', |
|
18 | + 'native-json' => '>=5.2.0', |
|
19 | + 'namespaces' => '>=5.3.0', |
|
20 | + 'late-static-bindings' => '>=5.3.0', |
|
21 | + 'jump-labels' => '>=5.3.0', |
|
22 | + 'closures' => '>=5.3.0', |
|
23 | + 'php-archives' => '>=5.3.0', |
|
24 | + 'phar' => '>=5.3.0', |
|
25 | + 'circular-garbage-collection' => '>=5.3.0', |
|
26 | + 'sqlite3' => '>=5.3.0', |
|
27 | + 'mysqlnd' => '>=5.3.0', |
|
28 | + 'fileinfo' => '>=5.3.0', |
|
29 | + 'traits' => '>=5.4.0', |
|
30 | + 'short-array-syntax' => '>=5.4.0', |
|
31 | + '[]' => '>=5.4.0', |
|
32 | + 'built-in-web-server' => '>=5.4.0', |
|
33 | + 'generators' => '>=5.5.0', |
|
34 | + 'finally' => '>=5.5.0', |
|
35 | + 'opcache' => '>=5.5.0', |
|
36 | + 'constant-scalars' => '>=5.6.0', |
|
37 | + 'variadic-functions' => '>=5.6.0', |
|
38 | + 'argument-unpacking' => '>=5.6.0', |
|
39 | + 'exponentiation-operator' => '>=5.6.0', |
|
40 | + 'phpdbg' => '>=5.6.0', |
|
41 | + 'zend-engine-3' => '>=7.0.0', |
|
42 | + 'uniform-variable-syntax' => '>=7.0.0', |
|
43 | + 'ast-based-compilation' => '>=7.0.0', |
|
44 | + 'closure-call' => '>=7.0.0', |
|
45 | + 'null-coalesce-operator' => '>=7.0.0', |
|
46 | + '??' => '>=7.0.0', |
|
47 | + 'return-type-declarations' => '>=7.0.0', |
|
48 | + 'scalar-type-declarations' => '>=7.0.0', |
|
49 | + 'spaceship-operator' => '>=7.0.0', |
|
50 | + 'three-way-comparison-operator' => '>=7.0.0', |
|
51 | + '<=>' => '>=7.0.0', |
|
52 | + 'generator-delegation' => '>=7.0.0', |
|
53 | + 'anonymous-classes' => '>=7.0.0', |
|
54 | + 'multiple-namespace-import' => '>=7.0.0', |
|
55 | + 'pcre-8.38' => '>=7.0.3', |
|
56 | + 'http-451' => '>=7.0.3', |
|
57 | + 'libzip-1.1.2' => '>=7.0.5', |
|
58 | + 'void-return-type' => '>=7.1.0', |
|
59 | + 'constant-visibility-modifiers' => '>=7.1.0', |
|
60 | 60 | ); |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * FeatureInterface Interface. |
|
4 | - * |
|
5 | - * @package brightnucleus/phpfeature |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * FeatureInterface Interface. |
|
4 | + * |
|
5 | + * @package brightnucleus/phpfeature |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Interface FeatureInterface. |
@@ -22,33 +22,33 @@ discard block |
||
22 | 22 | interface FeatureInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Check whether a feature or a collection of features is supported. |
|
27 | - * |
|
28 | - * Accepts either a string or an array of strings. Returns true if all the passed-in features are supported, or |
|
29 | - * false if at least one of them is not. |
|
30 | - * |
|
31 | - * @since 0.1.0 |
|
32 | - * |
|
33 | - * @param string|array $features What features to check the support of. |
|
34 | - * |
|
35 | - * @return bool Whether the set of features as a whole is supported. |
|
36 | - */ |
|
37 | - public function isSupported($features); |
|
25 | + /** |
|
26 | + * Check whether a feature or a collection of features is supported. |
|
27 | + * |
|
28 | + * Accepts either a string or an array of strings. Returns true if all the passed-in features are supported, or |
|
29 | + * false if at least one of them is not. |
|
30 | + * |
|
31 | + * @since 0.1.0 |
|
32 | + * |
|
33 | + * @param string|array $features What features to check the support of. |
|
34 | + * |
|
35 | + * @return bool Whether the set of features as a whole is supported. |
|
36 | + */ |
|
37 | + public function isSupported($features); |
|
38 | 38 | |
39 | - /** |
|
40 | - * Get the minimum required version that supports all of the requested features. |
|
41 | - * |
|
42 | - * Accepts either a string or an array of strings. Returns a SemanticVersion object for the version number that is |
|
43 | - * known to support all the passed-in features, or false if at least one of them is not supported by any known |
|
44 | - * version. |
|
45 | - * |
|
46 | - * @since 0.2.0 |
|
47 | - * |
|
48 | - * @param string|array $features What features to check the support of. |
|
49 | - * |
|
50 | - * @return SemanticVersion|false SemanticVersion object for the version number that is known to support all the |
|
51 | - * passed-in features, false if none. |
|
52 | - */ |
|
53 | - public function getMinimumRequired($features); |
|
39 | + /** |
|
40 | + * Get the minimum required version that supports all of the requested features. |
|
41 | + * |
|
42 | + * Accepts either a string or an array of strings. Returns a SemanticVersion object for the version number that is |
|
43 | + * known to support all the passed-in features, or false if at least one of them is not supported by any known |
|
44 | + * version. |
|
45 | + * |
|
46 | + * @since 0.2.0 |
|
47 | + * |
|
48 | + * @param string|array $features What features to check the support of. |
|
49 | + * |
|
50 | + * @return SemanticVersion|false SemanticVersion object for the version number that is known to support all the |
|
51 | + * passed-in features, false if none. |
|
52 | + */ |
|
53 | + public function getMinimumRequired($features); |
|
54 | 54 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * PHPFeature_SemanticVersion Class. |
|
4 | - * |
|
5 | - * @package brightnucleus/phpfeature |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * PHPFeature_SemanticVersion Class. |
|
4 | + * |
|
5 | + * @package brightnucleus/phpfeature |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Class PHPFeature_SemanticVersion. |
@@ -21,239 +21,239 @@ discard block |
||
21 | 21 | class PHPFeature_SemanticVersion |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * RegEx pattern that matches the different version components. |
|
26 | - * |
|
27 | - * @since 0.1.0 |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - const VERSION_PATTERN = '/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z-]*))?(?:\+([0-9A-Za-z-]*))?$/'; |
|
24 | + /** |
|
25 | + * RegEx pattern that matches the different version components. |
|
26 | + * |
|
27 | + * @since 0.1.0 |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + const VERSION_PATTERN = '/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z-]*))?(?:\+([0-9A-Za-z-]*))?$/'; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Version that is used. |
|
35 | - * |
|
36 | - * @since 0.1.0 |
|
37 | - * |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected $version; |
|
33 | + /** |
|
34 | + * Version that is used. |
|
35 | + * |
|
36 | + * @since 0.1.0 |
|
37 | + * |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected $version; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Different components of the version that is used. |
|
44 | - * |
|
45 | - * @since 0.1.0 |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $components; |
|
42 | + /** |
|
43 | + * Different components of the version that is used. |
|
44 | + * |
|
45 | + * @since 0.1.0 |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $components; |
|
50 | 50 | |
51 | - /** |
|
52 | - * Instantiate a PHPFeature_SemanticVersion object. |
|
53 | - * |
|
54 | - * @since 0.1.0 |
|
55 | - * |
|
56 | - * @param string|null $version Optional. The version to use. Defaults to the current PHP interpreter's version. |
|
57 | - * @param bool $partial Optional. Whether to accept a partial version number. If true, the missing |
|
58 | - * components will default to `0` instead of throwing an exception. |
|
59 | - * |
|
60 | - * @throws RuntimeException When the version fails to validate. |
|
61 | - */ |
|
62 | - public function __construct($version = null, $partial = false) |
|
63 | - { |
|
51 | + /** |
|
52 | + * Instantiate a PHPFeature_SemanticVersion object. |
|
53 | + * |
|
54 | + * @since 0.1.0 |
|
55 | + * |
|
56 | + * @param string|null $version Optional. The version to use. Defaults to the current PHP interpreter's version. |
|
57 | + * @param bool $partial Optional. Whether to accept a partial version number. If true, the missing |
|
58 | + * components will default to `0` instead of throwing an exception. |
|
59 | + * |
|
60 | + * @throws RuntimeException When the version fails to validate. |
|
61 | + */ |
|
62 | + public function __construct($version = null, $partial = false) |
|
63 | + { |
|
64 | 64 | |
65 | - if (null === $version) { |
|
66 | - $version = '0.0.0'; |
|
67 | - } |
|
65 | + if (null === $version) { |
|
66 | + $version = '0.0.0'; |
|
67 | + } |
|
68 | 68 | |
69 | - $version = $this->validate($version, $partial); |
|
69 | + $version = $this->validate($version, $partial); |
|
70 | 70 | |
71 | - $this->version = $version; |
|
72 | - } |
|
71 | + $this->version = $version; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Get the version that is used. |
|
76 | - * |
|
77 | - * @since 0.1.0 |
|
78 | - * |
|
79 | - * @return string The version that is used. '0.0.0' if not defined. |
|
80 | - */ |
|
81 | - public function getVersion() |
|
82 | - { |
|
83 | - return (string)isset($this->version) ? $this->version : '0.0.0'; |
|
84 | - } |
|
74 | + /** |
|
75 | + * Get the version that is used. |
|
76 | + * |
|
77 | + * @since 0.1.0 |
|
78 | + * |
|
79 | + * @return string The version that is used. '0.0.0' if not defined. |
|
80 | + */ |
|
81 | + public function getVersion() |
|
82 | + { |
|
83 | + return (string)isset($this->version) ? $this->version : '0.0.0'; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get the major version number. |
|
88 | - * |
|
89 | - * @since 0.1.0 |
|
90 | - * |
|
91 | - * @return int The major version that is used. 0 if not defined. |
|
92 | - */ |
|
93 | - public function getMajor() |
|
94 | - { |
|
95 | - return (int)$this->getComponent('major') ?: 0; |
|
96 | - } |
|
86 | + /** |
|
87 | + * Get the major version number. |
|
88 | + * |
|
89 | + * @since 0.1.0 |
|
90 | + * |
|
91 | + * @return int The major version that is used. 0 if not defined. |
|
92 | + */ |
|
93 | + public function getMajor() |
|
94 | + { |
|
95 | + return (int)$this->getComponent('major') ?: 0; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Get the minor version number. |
|
100 | - * |
|
101 | - * @since 0.1.0 |
|
102 | - * |
|
103 | - * @return int The minor version that is used. 0 if not defined. |
|
104 | - */ |
|
105 | - public function getMinor() |
|
106 | - { |
|
107 | - return (int)$this->getComponent('minor') ?: 0; |
|
108 | - } |
|
98 | + /** |
|
99 | + * Get the minor version number. |
|
100 | + * |
|
101 | + * @since 0.1.0 |
|
102 | + * |
|
103 | + * @return int The minor version that is used. 0 if not defined. |
|
104 | + */ |
|
105 | + public function getMinor() |
|
106 | + { |
|
107 | + return (int)$this->getComponent('minor') ?: 0; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Get the patch version number. |
|
112 | - * |
|
113 | - * @since 0.1.0 |
|
114 | - * |
|
115 | - * @return int The patch version that is used. 0 if not defined. |
|
116 | - */ |
|
117 | - public function getPatch() |
|
118 | - { |
|
119 | - return (int)$this->getComponent('patch') ?: 0; |
|
120 | - } |
|
110 | + /** |
|
111 | + * Get the patch version number. |
|
112 | + * |
|
113 | + * @since 0.1.0 |
|
114 | + * |
|
115 | + * @return int The patch version that is used. 0 if not defined. |
|
116 | + */ |
|
117 | + public function getPatch() |
|
118 | + { |
|
119 | + return (int)$this->getComponent('patch') ?: 0; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Get the pre-release label. |
|
124 | - * |
|
125 | - * @since 0.1.0 |
|
126 | - * |
|
127 | - * @return string The patch version that is used. Empty string if not defined. |
|
128 | - */ |
|
129 | - public function getPreRelease() |
|
130 | - { |
|
131 | - return (string)$this->getComponent('pre-release') ?: ''; |
|
132 | - } |
|
122 | + /** |
|
123 | + * Get the pre-release label. |
|
124 | + * |
|
125 | + * @since 0.1.0 |
|
126 | + * |
|
127 | + * @return string The patch version that is used. Empty string if not defined. |
|
128 | + */ |
|
129 | + public function getPreRelease() |
|
130 | + { |
|
131 | + return (string)$this->getComponent('pre-release') ?: ''; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Get the build metadata. |
|
136 | - * |
|
137 | - * @since 0.1.0 |
|
138 | - * |
|
139 | - * @return string The build metadata for the version that is used. Empty string if not defined. |
|
140 | - */ |
|
141 | - public function getBuild() |
|
142 | - { |
|
143 | - return (string)$this->getComponent('build') ?: ''; |
|
144 | - } |
|
134 | + /** |
|
135 | + * Get the build metadata. |
|
136 | + * |
|
137 | + * @since 0.1.0 |
|
138 | + * |
|
139 | + * @return string The build metadata for the version that is used. Empty string if not defined. |
|
140 | + */ |
|
141 | + public function getBuild() |
|
142 | + { |
|
143 | + return (string)$this->getComponent('build') ?: ''; |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Get a string representation of the object. |
|
148 | - * |
|
149 | - * @since 0.2.0 |
|
150 | - * |
|
151 | - * @return string String representation of the version. |
|
152 | - */ |
|
153 | - public function __toString() |
|
154 | - { |
|
155 | - return (string)$this->getVersion(); |
|
156 | - } |
|
146 | + /** |
|
147 | + * Get a string representation of the object. |
|
148 | + * |
|
149 | + * @since 0.2.0 |
|
150 | + * |
|
151 | + * @return string String representation of the version. |
|
152 | + */ |
|
153 | + public function __toString() |
|
154 | + { |
|
155 | + return (string)$this->getVersion(); |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Validate the version and assert it is in SemVer format. |
|
160 | - * |
|
161 | - * @since 0.1.0 |
|
162 | - * |
|
163 | - * @param string $version The version to validate. |
|
164 | - * @param bool $partial Optional. Whether to accept a partial version number. If true, the missing components |
|
165 | - * will default to `0` instead of throwing an exception. |
|
166 | - * |
|
167 | - * @return string Validated version string. |
|
168 | - * @throws RuntimeException When the version fails to validate. |
|
169 | - */ |
|
170 | - protected function validate($version, $partial = false) |
|
171 | - { |
|
158 | + /** |
|
159 | + * Validate the version and assert it is in SemVer format. |
|
160 | + * |
|
161 | + * @since 0.1.0 |
|
162 | + * |
|
163 | + * @param string $version The version to validate. |
|
164 | + * @param bool $partial Optional. Whether to accept a partial version number. If true, the missing components |
|
165 | + * will default to `0` instead of throwing an exception. |
|
166 | + * |
|
167 | + * @return string Validated version string. |
|
168 | + * @throws RuntimeException When the version fails to validate. |
|
169 | + */ |
|
170 | + protected function validate($version, $partial = false) |
|
171 | + { |
|
172 | 172 | |
173 | - $version = trim($version); |
|
174 | - $pattern = self::VERSION_PATTERN; |
|
173 | + $version = trim($version); |
|
174 | + $pattern = self::VERSION_PATTERN; |
|
175 | 175 | |
176 | - $components = array(); |
|
177 | - $result = preg_match($pattern, $version, $components); |
|
176 | + $components = array(); |
|
177 | + $result = preg_match($pattern, $version, $components); |
|
178 | 178 | |
179 | - if ( ! $result) { |
|
180 | - throw new RuntimeException(sprintf( |
|
181 | - 'Failed to validate version "%1$s".', |
|
182 | - (string)$version |
|
183 | - )); |
|
184 | - } |
|
179 | + if ( ! $result) { |
|
180 | + throw new RuntimeException(sprintf( |
|
181 | + 'Failed to validate version "%1$s".', |
|
182 | + (string)$version |
|
183 | + )); |
|
184 | + } |
|
185 | 185 | |
186 | - if ( ! $partial && ( ! isset($components[2]) || ! isset($components[3]))) { |
|
187 | - throw new RuntimeException(sprintf( |
|
188 | - 'Could not accept partial version "%1$s", requested full versions only.', |
|
189 | - (string)$version |
|
190 | - )); |
|
191 | - } |
|
186 | + if ( ! $partial && ( ! isset($components[2]) || ! isset($components[3]))) { |
|
187 | + throw new RuntimeException(sprintf( |
|
188 | + 'Could not accept partial version "%1$s", requested full versions only.', |
|
189 | + (string)$version |
|
190 | + )); |
|
191 | + } |
|
192 | 192 | |
193 | - $this->setComponent('major', isset($components[1]) ? (int)$components[1] : 0); |
|
194 | - $this->setComponent('minor', isset($components[2]) ? (int)$components[2] : 0); |
|
195 | - $this->setComponent('patch', isset($components[3]) ? (int)$components[3] : 0); |
|
196 | - $this->setComponent('pre-release', isset($components[4]) ? (string)$components[4] : ''); |
|
197 | - $this->setComponent('build', isset($components[5]) ? (string)$components[5] : ''); |
|
193 | + $this->setComponent('major', isset($components[1]) ? (int)$components[1] : 0); |
|
194 | + $this->setComponent('minor', isset($components[2]) ? (int)$components[2] : 0); |
|
195 | + $this->setComponent('patch', isset($components[3]) ? (int)$components[3] : 0); |
|
196 | + $this->setComponent('pre-release', isset($components[4]) ? (string)$components[4] : ''); |
|
197 | + $this->setComponent('build', isset($components[5]) ? (string)$components[5] : ''); |
|
198 | 198 | |
199 | - $version = $this->getVersionFromComponents(); |
|
199 | + $version = $this->getVersionFromComponents(); |
|
200 | 200 | |
201 | - return $version; |
|
202 | - } |
|
201 | + return $version; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Build and return a version from the separated components. |
|
206 | - * |
|
207 | - * @since 0.1.0 |
|
208 | - * |
|
209 | - * @return string String representation of the component's version. |
|
210 | - */ |
|
211 | - protected function getVersionFromComponents() |
|
212 | - { |
|
204 | + /** |
|
205 | + * Build and return a version from the separated components. |
|
206 | + * |
|
207 | + * @since 0.1.0 |
|
208 | + * |
|
209 | + * @return string String representation of the component's version. |
|
210 | + */ |
|
211 | + protected function getVersionFromComponents() |
|
212 | + { |
|
213 | 213 | |
214 | - $pre_release = $this->getPreRelease() ? '-' . $this->getPreRelease() : ''; |
|
215 | - $build = $this->getBuild() ? '+' . $this->getBuild() : ''; |
|
214 | + $pre_release = $this->getPreRelease() ? '-' . $this->getPreRelease() : ''; |
|
215 | + $build = $this->getBuild() ? '+' . $this->getBuild() : ''; |
|
216 | 216 | |
217 | - $version = sprintf( |
|
218 | - '%1$s.%2$s.%3$s%4$s%5$s', |
|
219 | - $this->getMajor(), |
|
220 | - $this->getMinor(), |
|
221 | - $this->getPatch(), |
|
222 | - $pre_release, |
|
223 | - $build |
|
224 | - ); |
|
217 | + $version = sprintf( |
|
218 | + '%1$s.%2$s.%3$s%4$s%5$s', |
|
219 | + $this->getMajor(), |
|
220 | + $this->getMinor(), |
|
221 | + $this->getPatch(), |
|
222 | + $pre_release, |
|
223 | + $build |
|
224 | + ); |
|
225 | 225 | |
226 | - return $version; |
|
227 | - } |
|
226 | + return $version; |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Get a component of the version. |
|
231 | - * |
|
232 | - * @since 0.1.0 |
|
233 | - * |
|
234 | - * @param string $level What level of component to get. |
|
235 | - * Possible values: 'major', 'minor', 'patch' |
|
236 | - * |
|
237 | - * @return int The requested version component. null if not defined. |
|
238 | - */ |
|
239 | - protected function getComponent($level) |
|
240 | - { |
|
241 | - return array_key_exists($level, $this->components) |
|
242 | - ? $this->components[$level] |
|
243 | - : null; |
|
244 | - } |
|
229 | + /** |
|
230 | + * Get a component of the version. |
|
231 | + * |
|
232 | + * @since 0.1.0 |
|
233 | + * |
|
234 | + * @param string $level What level of component to get. |
|
235 | + * Possible values: 'major', 'minor', 'patch' |
|
236 | + * |
|
237 | + * @return int The requested version component. null if not defined. |
|
238 | + */ |
|
239 | + protected function getComponent($level) |
|
240 | + { |
|
241 | + return array_key_exists($level, $this->components) |
|
242 | + ? $this->components[$level] |
|
243 | + : null; |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * Set a component of the version. |
|
248 | - * |
|
249 | - * @since 0.1.0 |
|
250 | - * |
|
251 | - * @param string $level What level of component to set. |
|
252 | - * Possible values: 'major', 'minor', 'patch' |
|
253 | - * @param int $version What version to set that component to. |
|
254 | - */ |
|
255 | - protected function setComponent($level, $version) |
|
256 | - { |
|
257 | - $this->components[$level] = $version; |
|
258 | - } |
|
246 | + /** |
|
247 | + * Set a component of the version. |
|
248 | + * |
|
249 | + * @since 0.1.0 |
|
250 | + * |
|
251 | + * @param string $level What level of component to set. |
|
252 | + * Possible values: 'major', 'minor', 'patch' |
|
253 | + * @param int $version What version to set that component to. |
|
254 | + */ |
|
255 | + protected function setComponent($level, $version) |
|
256 | + { |
|
257 | + $this->components[$level] = $version; |
|
258 | + } |
|
259 | 259 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function getVersion() |
82 | 82 | { |
83 | - return (string)isset($this->version) ? $this->version : '0.0.0'; |
|
83 | + return (string) isset($this->version) ? $this->version : '0.0.0'; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function getMajor() |
94 | 94 | { |
95 | - return (int)$this->getComponent('major') ?: 0; |
|
95 | + return (int) $this->getComponent('major') ?: 0; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function getMinor() |
106 | 106 | { |
107 | - return (int)$this->getComponent('minor') ?: 0; |
|
107 | + return (int) $this->getComponent('minor') ?: 0; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function getPatch() |
118 | 118 | { |
119 | - return (int)$this->getComponent('patch') ?: 0; |
|
119 | + return (int) $this->getComponent('patch') ?: 0; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function getPreRelease() |
130 | 130 | { |
131 | - return (string)$this->getComponent('pre-release') ?: ''; |
|
131 | + return (string) $this->getComponent('pre-release') ?: ''; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function getBuild() |
142 | 142 | { |
143 | - return (string)$this->getComponent('build') ?: ''; |
|
143 | + return (string) $this->getComponent('build') ?: ''; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function __toString() |
154 | 154 | { |
155 | - return (string)$this->getVersion(); |
|
155 | + return (string) $this->getVersion(); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -179,22 +179,22 @@ discard block |
||
179 | 179 | if ( ! $result) { |
180 | 180 | throw new RuntimeException(sprintf( |
181 | 181 | 'Failed to validate version "%1$s".', |
182 | - (string)$version |
|
182 | + (string) $version |
|
183 | 183 | )); |
184 | 184 | } |
185 | 185 | |
186 | 186 | if ( ! $partial && ( ! isset($components[2]) || ! isset($components[3]))) { |
187 | 187 | throw new RuntimeException(sprintf( |
188 | 188 | 'Could not accept partial version "%1$s", requested full versions only.', |
189 | - (string)$version |
|
189 | + (string) $version |
|
190 | 190 | )); |
191 | 191 | } |
192 | 192 | |
193 | - $this->setComponent('major', isset($components[1]) ? (int)$components[1] : 0); |
|
194 | - $this->setComponent('minor', isset($components[2]) ? (int)$components[2] : 0); |
|
195 | - $this->setComponent('patch', isset($components[3]) ? (int)$components[3] : 0); |
|
196 | - $this->setComponent('pre-release', isset($components[4]) ? (string)$components[4] : ''); |
|
197 | - $this->setComponent('build', isset($components[5]) ? (string)$components[5] : ''); |
|
193 | + $this->setComponent('major', isset($components[1]) ? (int) $components[1] : 0); |
|
194 | + $this->setComponent('minor', isset($components[2]) ? (int) $components[2] : 0); |
|
195 | + $this->setComponent('patch', isset($components[3]) ? (int) $components[3] : 0); |
|
196 | + $this->setComponent('pre-release', isset($components[4]) ? (string) $components[4] : ''); |
|
197 | + $this->setComponent('build', isset($components[5]) ? (string) $components[5] : ''); |
|
198 | 198 | |
199 | 199 | $version = $this->getVersionFromComponents(); |
200 | 200 | |
@@ -211,8 +211,8 @@ discard block |
||
211 | 211 | protected function getVersionFromComponents() |
212 | 212 | { |
213 | 213 | |
214 | - $pre_release = $this->getPreRelease() ? '-' . $this->getPreRelease() : ''; |
|
215 | - $build = $this->getBuild() ? '+' . $this->getBuild() : ''; |
|
214 | + $pre_release = $this->getPreRelease() ? '-'.$this->getPreRelease() : ''; |
|
215 | + $build = $this->getBuild() ? '+'.$this->getBuild() : ''; |
|
216 | 216 | |
217 | 217 | $version = sprintf( |
218 | 218 | '%1$s.%2$s.%3$s%4$s%5$s', |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | // TODO: Better way to bootstrap this while still allowing DI? |
78 | 78 | if ( ! $config) { |
79 | - $config = new Config(include(dirname(__FILE__) . '/../config/known_features.php')); |
|
79 | + $config = new Config(include(dirname(__FILE__).'/../config/known_features.php')); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $this->config = $config; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | if (is_int($phpVersion)) { |
89 | - $phpVersion = (string)$phpVersion; |
|
89 | + $phpVersion = (string) $phpVersion; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | if (is_string($phpVersion)) { |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | |
129 | 129 | while ($isSupported && count($features) > 0) { |
130 | 130 | $feature = array_pop($features); |
131 | - $isSupported &= (bool)$this->checkSupport($feature); |
|
131 | + $isSupported &= (bool) $this->checkSupport($feature); |
|
132 | 132 | } |
133 | 133 | |
134 | - return (bool)$isSupported; |
|
134 | + return (bool) $isSupported; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | while (count($features) > 0) { |
171 | 171 | $feature = array_pop($features); |
172 | - $isSupported &= (bool)$this->checkSupport($feature, $minimumRequired); |
|
172 | + $isSupported &= (bool) $this->checkSupport($feature, $minimumRequired); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | return $minimumRequired !== '0.0.0' ? new SemanticVersion($minimumRequired, true) : false; |
@@ -193,16 +193,16 @@ discard block |
||
193 | 193 | return false; |
194 | 194 | } |
195 | 195 | |
196 | - $requirements = (array)$this->config->getKey($feature); |
|
196 | + $requirements = (array) $this->config->getKey($feature); |
|
197 | 197 | |
198 | 198 | $isSupported = true; |
199 | 199 | |
200 | 200 | while (($isSupported || null !== $minimumRequired) && count($requirements) > 0) { |
201 | 201 | $requirement = array_pop($requirements); |
202 | - $isSupported &= (bool)$this->checkRequirement($requirement, $minimumRequired); |
|
202 | + $isSupported &= (bool) $this->checkRequirement($requirement, $minimumRequired); |
|
203 | 203 | } |
204 | 204 | |
205 | - return (bool)$isSupported; |
|
205 | + return (bool) $isSupported; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -228,14 +228,14 @@ discard block |
||
228 | 228 | if ( ! $result || ! isset($arguments[1]) || ! isset($arguments[2])) { |
229 | 229 | throw new RuntimeException(sprintf( |
230 | 230 | 'Could not parse the requirement "%1$s".', |
231 | - (string)$requirement |
|
231 | + (string) $requirement |
|
232 | 232 | )); |
233 | 233 | } |
234 | 234 | |
235 | - $operator = isset($arguments[1]) ? (string)$arguments[1] : '>='; |
|
236 | - $milestone = isset($arguments[2]) ? (string)$arguments[2] : '0.0.0'; |
|
235 | + $operator = isset($arguments[1]) ? (string) $arguments[1] : '>='; |
|
236 | + $milestone = isset($arguments[2]) ? (string) $arguments[2] : '0.0.0'; |
|
237 | 237 | |
238 | - $isSupported = (bool)version_compare($this->version->getVersion(), $milestone, $operator); |
|
238 | + $isSupported = (bool) version_compare($this->version->getVersion(), $milestone, $operator); |
|
239 | 239 | |
240 | 240 | if (null !== $minimumRequired) { |
241 | 241 | $requiredVersion = $this->getRequiredVersion($milestone, $operator); |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * PHPFeature Class. |
|
4 | - * |
|
5 | - * @package brightnucleus/phpfeature |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license MIT |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * PHPFeature Class. |
|
4 | + * |
|
5 | + * @package brightnucleus/phpfeature |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license MIT |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | use BrightNucleus_Config as Config; |
13 | 13 | use BrightNucleus_ConfigInterface as ConfigInterface; |
@@ -25,366 +25,366 @@ discard block |
||
25 | 25 | class PHPFeature implements FeatureInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * RegEx pattern that matches the comparison string. |
|
30 | - * |
|
31 | - * @since 0.1.0 |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - const COMPARISON_PATTERN = '/^(?:(<=|lt|<|le|>=|gt|>|ge|=|==|eq|!=|<>|ne))([0-9].*)$/'; |
|
36 | - |
|
37 | - /** |
|
38 | - * Reference to the Configuration object. |
|
39 | - * |
|
40 | - * @since 0.1.0 |
|
41 | - * |
|
42 | - * @var ConfigInterface |
|
43 | - */ |
|
44 | - protected $config; |
|
45 | - |
|
46 | - /** |
|
47 | - * Reference to the Version object. |
|
48 | - * |
|
49 | - * @since 0.1.0 |
|
50 | - * |
|
51 | - * @var SemanticVersion |
|
52 | - */ |
|
53 | - protected $version; |
|
54 | - |
|
55 | - /** |
|
56 | - * Reference to the PHP releases. |
|
57 | - * |
|
58 | - * @since 0.2.4 |
|
59 | - * |
|
60 | - * @var PHPReleases |
|
61 | - */ |
|
62 | - protected $releases; |
|
63 | - |
|
64 | - /** |
|
65 | - * Instantiate a PHPFeature object. |
|
66 | - * |
|
67 | - * @since 0.1.0 |
|
68 | - * |
|
69 | - * @param SemanticVersion|string|int|null $phpVersion Version of PHP to check the features for. |
|
70 | - * @param ConfigInterface|null $config Configuration that contains the known features. |
|
71 | - * |
|
72 | - * @throws RuntimeException If the PHP version could not be validated. |
|
73 | - */ |
|
74 | - public function __construct($phpVersion = null, ConfigInterface $config = null) |
|
75 | - { |
|
76 | - |
|
77 | - // TODO: Better way to bootstrap this while still allowing DI? |
|
78 | - if ( ! $config) { |
|
79 | - $config = new Config(include(dirname(__FILE__) . '/../config/known_features.php')); |
|
80 | - } |
|
81 | - |
|
82 | - $this->config = $config; |
|
83 | - |
|
84 | - if (null === $phpVersion) { |
|
85 | - $phpVersion = phpversion(); |
|
86 | - } |
|
87 | - |
|
88 | - if (is_int($phpVersion)) { |
|
89 | - $phpVersion = (string)$phpVersion; |
|
90 | - } |
|
91 | - |
|
92 | - if (is_string($phpVersion)) { |
|
93 | - $phpVersion = new SemanticVersion($phpVersion, true); |
|
94 | - } |
|
95 | - |
|
96 | - $this->version = $phpVersion; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Check whether a feature or a collection of features is supported. |
|
101 | - * |
|
102 | - * Accepts either a string or an array of strings. Returns true if all the passed-in features are supported, or |
|
103 | - * false if at least one of them is not. |
|
104 | - * |
|
105 | - * @since 0.1.0 |
|
106 | - * |
|
107 | - * @param string|array $features What features to check the support of. |
|
108 | - * |
|
109 | - * @return bool Whether the set of features as a whole is supported. |
|
110 | - * @throws InvalidArgumentException If the wrong type of argument is passed in. |
|
111 | - * @throws RuntimeException If a requirement could not be parsed. |
|
112 | - */ |
|
113 | - public function isSupported($features) |
|
114 | - { |
|
115 | - |
|
116 | - if (is_string($features)) { |
|
117 | - $features = array($features); |
|
118 | - } |
|
119 | - |
|
120 | - if ( ! is_array($features)) { |
|
121 | - throw new InvalidArgumentException(sprintf( |
|
122 | - 'Wrong type of argument passed in to is_supported(): "%1$s".', |
|
123 | - gettype($features) |
|
124 | - )); |
|
125 | - } |
|
126 | - |
|
127 | - $isSupported = true; |
|
128 | - |
|
129 | - while ($isSupported && count($features) > 0) { |
|
130 | - $feature = array_pop($features); |
|
131 | - $isSupported &= (bool)$this->checkSupport($feature); |
|
132 | - } |
|
133 | - |
|
134 | - return (bool)$isSupported; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Get the minimum required version that supports all of the requested features. |
|
139 | - * |
|
140 | - * Accepts either a string or an array of strings. Returns a SemanticVersion object for the version number that is |
|
141 | - * known to support all the passed-in features, or false if at least one of them is not supported by any known |
|
142 | - * version. |
|
143 | - * |
|
144 | - * @since 0.2.0 |
|
145 | - * |
|
146 | - * @param string|array $features What features to check the support of. |
|
147 | - * |
|
148 | - * @return SemanticVersion|false SemanticVersion object for the version number that is known to support all the |
|
149 | - * passed-in features, false if none. |
|
150 | - * @throws InvalidArgumentException If the wrong type of argument is passed in. |
|
151 | - * @throws RuntimeException If a requirement could not be parsed. |
|
152 | - */ |
|
153 | - public function getMinimumRequired($features) |
|
154 | - { |
|
155 | - |
|
156 | - if (is_string($features)) { |
|
157 | - $features = array($features); |
|
158 | - } |
|
159 | - |
|
160 | - if ( ! is_array($features)) { |
|
161 | - throw new InvalidArgumentException(sprintf( |
|
162 | - 'Wrong type of argument passed in to get_minimum_required(): "%1$s".', |
|
163 | - gettype($features) |
|
164 | - )); |
|
165 | - } |
|
166 | - |
|
167 | - $minimumRequired = '0.0.0'; |
|
168 | - $isSupported = true; |
|
169 | - |
|
170 | - while (count($features) > 0) { |
|
171 | - $feature = array_pop($features); |
|
172 | - $isSupported &= (bool)$this->checkSupport($feature, $minimumRequired); |
|
173 | - } |
|
174 | - |
|
175 | - return $minimumRequired !== '0.0.0' ? new SemanticVersion($minimumRequired, true) : false; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Check whether a single feature is supported. |
|
180 | - * |
|
181 | - * @since 0.1.0 |
|
182 | - * |
|
183 | - * @param string $feature The feature to check. |
|
184 | - * @param string|null $minimumRequired Optional. Minimum required version that supports all features. |
|
185 | - * |
|
186 | - * @return bool Whether the requested feature is supported. |
|
187 | - * @throws RuntimeException If the requirement could not be parsed. |
|
188 | - */ |
|
189 | - protected function checkSupport($feature, &$minimumRequired = null) |
|
190 | - { |
|
191 | - |
|
192 | - if ( ! $this->config->hasKey($feature)) { |
|
193 | - return false; |
|
194 | - } |
|
195 | - |
|
196 | - $requirements = (array)$this->config->getKey($feature); |
|
197 | - |
|
198 | - $isSupported = true; |
|
199 | - |
|
200 | - while (($isSupported || null !== $minimumRequired) && count($requirements) > 0) { |
|
201 | - $requirement = array_pop($requirements); |
|
202 | - $isSupported &= (bool)$this->checkRequirement($requirement, $minimumRequired); |
|
203 | - } |
|
204 | - |
|
205 | - return (bool)$isSupported; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Check whether a single requirement is met. |
|
210 | - * |
|
211 | - * @since 0.1.0 |
|
212 | - * |
|
213 | - * @param string $requirement A requirement that is composed of an operator and a version milestone. |
|
214 | - * @param string|null $minimumRequired Optional. Minimum required version that supports all features. |
|
215 | - * |
|
216 | - * @return bool Whether the requirement is met. |
|
217 | - * @throws RuntimeException If the requirement could not be parsed. |
|
218 | - */ |
|
219 | - protected function checkRequirement($requirement, &$minimumRequired = null) |
|
220 | - { |
|
221 | - |
|
222 | - $requirement = trim($requirement); |
|
223 | - $pattern = self::COMPARISON_PATTERN; |
|
224 | - |
|
225 | - $arguments = array(); |
|
226 | - $result = preg_match($pattern, $requirement, $arguments); |
|
227 | - |
|
228 | - if ( ! $result || ! isset($arguments[1]) || ! isset($arguments[2])) { |
|
229 | - throw new RuntimeException(sprintf( |
|
230 | - 'Could not parse the requirement "%1$s".', |
|
231 | - (string)$requirement |
|
232 | - )); |
|
233 | - } |
|
234 | - |
|
235 | - $operator = isset($arguments[1]) ? (string)$arguments[1] : '>='; |
|
236 | - $milestone = isset($arguments[2]) ? (string)$arguments[2] : '0.0.0'; |
|
237 | - |
|
238 | - $isSupported = (bool)version_compare($this->version->getVersion(), $milestone, $operator); |
|
239 | - |
|
240 | - if (null !== $minimumRequired) { |
|
241 | - $requiredVersion = $this->getRequiredVersion($milestone, $operator); |
|
242 | - if (version_compare($requiredVersion, $minimumRequired, '>')) { |
|
243 | - $minimumRequired = $requiredVersion; |
|
244 | - } |
|
245 | - } |
|
246 | - |
|
247 | - return $isSupported; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Get the required version for a single requirement. |
|
252 | - * |
|
253 | - * @todo The entire algorithm is only an approximation. A 5.2 SemVer library is needed. |
|
254 | - * |
|
255 | - * @since 0.2.0 |
|
256 | - * |
|
257 | - * @param string $milestone A version milestone that is used to define the requirement. |
|
258 | - * @param string $operator An operator that gets applied to the milestone. |
|
259 | - * Possible values: '<=', 'lt', '<', 'le', '>=', 'gt', '>', 'ge', '=', '==', 'eq', '!=', |
|
260 | - * '<>', 'ne' |
|
261 | - * |
|
262 | - * @return string Version string that meets a single requirement. |
|
263 | - * @throws RuntimeException If the requirement could not be satisfied. |
|
264 | - * @throws RuntimeException If the NotEqual is used. |
|
265 | - */ |
|
266 | - protected function getRequiredVersion($milestone, $operator) |
|
267 | - { |
|
268 | - if (null === $this->releases) { |
|
269 | - $this->releases = new PHPReleases(); |
|
270 | - } |
|
271 | - |
|
272 | - switch ($operator) { |
|
273 | - case '>': |
|
274 | - case 'gt': |
|
275 | - return $this->getGreaterThanVersion($milestone); |
|
276 | - case '<': |
|
277 | - case 'lt': |
|
278 | - return $this->getLesserThanVersion($milestone); |
|
279 | - case '>=': |
|
280 | - case 'ge': |
|
281 | - return $this->getGreaterEqualVersion($milestone); |
|
282 | - case '<=': |
|
283 | - case 'le': |
|
284 | - return $this->getLesserEqualVersion($milestone); |
|
285 | - case '!=': |
|
286 | - case '<>': |
|
287 | - case 'ne': |
|
288 | - throw new RuntimeException('NotEqual operator is not implemented.'); |
|
289 | - } |
|
290 | - |
|
291 | - return $milestone; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Get a version greater than the milestone. |
|
296 | - * |
|
297 | - * @since 0.2.4 |
|
298 | - * |
|
299 | - * @param string $milestone A version milestone that is used to define the requirement. |
|
300 | - * |
|
301 | - * @return string Version number that meets the requirement. |
|
302 | - * @throws RuntimeException If the requirement could not be satisfied. |
|
303 | - */ |
|
304 | - protected function getGreaterThanVersion($milestone) |
|
305 | - { |
|
306 | - $data = $this->releases->getAll(); |
|
307 | - foreach ($data as $version => $date) { |
|
308 | - if (version_compare($version, $milestone, '>')) { |
|
309 | - return $version; |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - throw new RuntimeException('Could not satisfy version requirements.'); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Get a version lesser than the milestone. |
|
318 | - * |
|
319 | - * @since 0.2.4 |
|
320 | - * |
|
321 | - * @param string $milestone A version milestone that is used to define the requirement. |
|
322 | - * |
|
323 | - * @return string Version number that meets the requirement. |
|
324 | - * @throws RuntimeException If the requirement could not be satisfied. |
|
325 | - */ |
|
326 | - protected function getLesserThanVersion($milestone) |
|
327 | - { |
|
328 | - if (version_compare($this->version->getVersion(), $milestone, '<')) { |
|
329 | - return $this->version->getVersion(); |
|
330 | - } |
|
331 | - $data = array_reverse($this->releases->getAll()); |
|
332 | - foreach ($data as $version => $date) { |
|
333 | - if (version_compare($version, $milestone, '<')) { |
|
334 | - return $version; |
|
335 | - } |
|
336 | - } |
|
337 | - |
|
338 | - throw new RuntimeException('Could not satisfy version requirements.'); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Get a version greater or equal than the milestone. |
|
343 | - * |
|
344 | - * @since 0.2.4 |
|
345 | - * |
|
346 | - * @param string $milestone A version milestone that is used to define the requirement. |
|
347 | - * |
|
348 | - * @return string Version number that meets the requirement. |
|
349 | - */ |
|
350 | - protected function getGreaterEqualVersion($milestone) |
|
351 | - { |
|
352 | - if ($this->releases->exists($milestone)) { |
|
353 | - return $milestone; |
|
354 | - } |
|
355 | - |
|
356 | - $data = $this->releases->getAll(); |
|
357 | - foreach ($data as $version => $date) { |
|
358 | - if (version_compare($version, $milestone, '>=')) { |
|
359 | - return $version; |
|
360 | - } |
|
361 | - } |
|
362 | - |
|
363 | - throw new RuntimeException('Could not satisfy version requirements.'); |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Get a version lesser or equal than the milestone. |
|
368 | - * |
|
369 | - * @since 0.2.4 |
|
370 | - * |
|
371 | - * @param string $milestone A version milestone that is used to define the requirement. |
|
372 | - * |
|
373 | - * @return string Version number that meets the requirement. |
|
374 | - */ |
|
375 | - protected function getLesserEqualVersion($milestone) |
|
376 | - { |
|
377 | - if (version_compare($this->version->getVersion(), $milestone, '<=')) { |
|
378 | - return $this->version->getVersion(); |
|
379 | - } |
|
380 | - |
|
381 | - $data = array_reverse($this->releases->getAll()); |
|
382 | - foreach ($data as $version => $date) { |
|
383 | - if (version_compare($version, $milestone, '<=')) { |
|
384 | - return $version; |
|
385 | - } |
|
386 | - } |
|
387 | - |
|
388 | - throw new RuntimeException('Could not satisfy version requirements.'); |
|
389 | - } |
|
28 | + /** |
|
29 | + * RegEx pattern that matches the comparison string. |
|
30 | + * |
|
31 | + * @since 0.1.0 |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + const COMPARISON_PATTERN = '/^(?:(<=|lt|<|le|>=|gt|>|ge|=|==|eq|!=|<>|ne))([0-9].*)$/'; |
|
36 | + |
|
37 | + /** |
|
38 | + * Reference to the Configuration object. |
|
39 | + * |
|
40 | + * @since 0.1.0 |
|
41 | + * |
|
42 | + * @var ConfigInterface |
|
43 | + */ |
|
44 | + protected $config; |
|
45 | + |
|
46 | + /** |
|
47 | + * Reference to the Version object. |
|
48 | + * |
|
49 | + * @since 0.1.0 |
|
50 | + * |
|
51 | + * @var SemanticVersion |
|
52 | + */ |
|
53 | + protected $version; |
|
54 | + |
|
55 | + /** |
|
56 | + * Reference to the PHP releases. |
|
57 | + * |
|
58 | + * @since 0.2.4 |
|
59 | + * |
|
60 | + * @var PHPReleases |
|
61 | + */ |
|
62 | + protected $releases; |
|
63 | + |
|
64 | + /** |
|
65 | + * Instantiate a PHPFeature object. |
|
66 | + * |
|
67 | + * @since 0.1.0 |
|
68 | + * |
|
69 | + * @param SemanticVersion|string|int|null $phpVersion Version of PHP to check the features for. |
|
70 | + * @param ConfigInterface|null $config Configuration that contains the known features. |
|
71 | + * |
|
72 | + * @throws RuntimeException If the PHP version could not be validated. |
|
73 | + */ |
|
74 | + public function __construct($phpVersion = null, ConfigInterface $config = null) |
|
75 | + { |
|
76 | + |
|
77 | + // TODO: Better way to bootstrap this while still allowing DI? |
|
78 | + if ( ! $config) { |
|
79 | + $config = new Config(include(dirname(__FILE__) . '/../config/known_features.php')); |
|
80 | + } |
|
81 | + |
|
82 | + $this->config = $config; |
|
83 | + |
|
84 | + if (null === $phpVersion) { |
|
85 | + $phpVersion = phpversion(); |
|
86 | + } |
|
87 | + |
|
88 | + if (is_int($phpVersion)) { |
|
89 | + $phpVersion = (string)$phpVersion; |
|
90 | + } |
|
91 | + |
|
92 | + if (is_string($phpVersion)) { |
|
93 | + $phpVersion = new SemanticVersion($phpVersion, true); |
|
94 | + } |
|
95 | + |
|
96 | + $this->version = $phpVersion; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Check whether a feature or a collection of features is supported. |
|
101 | + * |
|
102 | + * Accepts either a string or an array of strings. Returns true if all the passed-in features are supported, or |
|
103 | + * false if at least one of them is not. |
|
104 | + * |
|
105 | + * @since 0.1.0 |
|
106 | + * |
|
107 | + * @param string|array $features What features to check the support of. |
|
108 | + * |
|
109 | + * @return bool Whether the set of features as a whole is supported. |
|
110 | + * @throws InvalidArgumentException If the wrong type of argument is passed in. |
|
111 | + * @throws RuntimeException If a requirement could not be parsed. |
|
112 | + */ |
|
113 | + public function isSupported($features) |
|
114 | + { |
|
115 | + |
|
116 | + if (is_string($features)) { |
|
117 | + $features = array($features); |
|
118 | + } |
|
119 | + |
|
120 | + if ( ! is_array($features)) { |
|
121 | + throw new InvalidArgumentException(sprintf( |
|
122 | + 'Wrong type of argument passed in to is_supported(): "%1$s".', |
|
123 | + gettype($features) |
|
124 | + )); |
|
125 | + } |
|
126 | + |
|
127 | + $isSupported = true; |
|
128 | + |
|
129 | + while ($isSupported && count($features) > 0) { |
|
130 | + $feature = array_pop($features); |
|
131 | + $isSupported &= (bool)$this->checkSupport($feature); |
|
132 | + } |
|
133 | + |
|
134 | + return (bool)$isSupported; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Get the minimum required version that supports all of the requested features. |
|
139 | + * |
|
140 | + * Accepts either a string or an array of strings. Returns a SemanticVersion object for the version number that is |
|
141 | + * known to support all the passed-in features, or false if at least one of them is not supported by any known |
|
142 | + * version. |
|
143 | + * |
|
144 | + * @since 0.2.0 |
|
145 | + * |
|
146 | + * @param string|array $features What features to check the support of. |
|
147 | + * |
|
148 | + * @return SemanticVersion|false SemanticVersion object for the version number that is known to support all the |
|
149 | + * passed-in features, false if none. |
|
150 | + * @throws InvalidArgumentException If the wrong type of argument is passed in. |
|
151 | + * @throws RuntimeException If a requirement could not be parsed. |
|
152 | + */ |
|
153 | + public function getMinimumRequired($features) |
|
154 | + { |
|
155 | + |
|
156 | + if (is_string($features)) { |
|
157 | + $features = array($features); |
|
158 | + } |
|
159 | + |
|
160 | + if ( ! is_array($features)) { |
|
161 | + throw new InvalidArgumentException(sprintf( |
|
162 | + 'Wrong type of argument passed in to get_minimum_required(): "%1$s".', |
|
163 | + gettype($features) |
|
164 | + )); |
|
165 | + } |
|
166 | + |
|
167 | + $minimumRequired = '0.0.0'; |
|
168 | + $isSupported = true; |
|
169 | + |
|
170 | + while (count($features) > 0) { |
|
171 | + $feature = array_pop($features); |
|
172 | + $isSupported &= (bool)$this->checkSupport($feature, $minimumRequired); |
|
173 | + } |
|
174 | + |
|
175 | + return $minimumRequired !== '0.0.0' ? new SemanticVersion($minimumRequired, true) : false; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Check whether a single feature is supported. |
|
180 | + * |
|
181 | + * @since 0.1.0 |
|
182 | + * |
|
183 | + * @param string $feature The feature to check. |
|
184 | + * @param string|null $minimumRequired Optional. Minimum required version that supports all features. |
|
185 | + * |
|
186 | + * @return bool Whether the requested feature is supported. |
|
187 | + * @throws RuntimeException If the requirement could not be parsed. |
|
188 | + */ |
|
189 | + protected function checkSupport($feature, &$minimumRequired = null) |
|
190 | + { |
|
191 | + |
|
192 | + if ( ! $this->config->hasKey($feature)) { |
|
193 | + return false; |
|
194 | + } |
|
195 | + |
|
196 | + $requirements = (array)$this->config->getKey($feature); |
|
197 | + |
|
198 | + $isSupported = true; |
|
199 | + |
|
200 | + while (($isSupported || null !== $minimumRequired) && count($requirements) > 0) { |
|
201 | + $requirement = array_pop($requirements); |
|
202 | + $isSupported &= (bool)$this->checkRequirement($requirement, $minimumRequired); |
|
203 | + } |
|
204 | + |
|
205 | + return (bool)$isSupported; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Check whether a single requirement is met. |
|
210 | + * |
|
211 | + * @since 0.1.0 |
|
212 | + * |
|
213 | + * @param string $requirement A requirement that is composed of an operator and a version milestone. |
|
214 | + * @param string|null $minimumRequired Optional. Minimum required version that supports all features. |
|
215 | + * |
|
216 | + * @return bool Whether the requirement is met. |
|
217 | + * @throws RuntimeException If the requirement could not be parsed. |
|
218 | + */ |
|
219 | + protected function checkRequirement($requirement, &$minimumRequired = null) |
|
220 | + { |
|
221 | + |
|
222 | + $requirement = trim($requirement); |
|
223 | + $pattern = self::COMPARISON_PATTERN; |
|
224 | + |
|
225 | + $arguments = array(); |
|
226 | + $result = preg_match($pattern, $requirement, $arguments); |
|
227 | + |
|
228 | + if ( ! $result || ! isset($arguments[1]) || ! isset($arguments[2])) { |
|
229 | + throw new RuntimeException(sprintf( |
|
230 | + 'Could not parse the requirement "%1$s".', |
|
231 | + (string)$requirement |
|
232 | + )); |
|
233 | + } |
|
234 | + |
|
235 | + $operator = isset($arguments[1]) ? (string)$arguments[1] : '>='; |
|
236 | + $milestone = isset($arguments[2]) ? (string)$arguments[2] : '0.0.0'; |
|
237 | + |
|
238 | + $isSupported = (bool)version_compare($this->version->getVersion(), $milestone, $operator); |
|
239 | + |
|
240 | + if (null !== $minimumRequired) { |
|
241 | + $requiredVersion = $this->getRequiredVersion($milestone, $operator); |
|
242 | + if (version_compare($requiredVersion, $minimumRequired, '>')) { |
|
243 | + $minimumRequired = $requiredVersion; |
|
244 | + } |
|
245 | + } |
|
246 | + |
|
247 | + return $isSupported; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Get the required version for a single requirement. |
|
252 | + * |
|
253 | + * @todo The entire algorithm is only an approximation. A 5.2 SemVer library is needed. |
|
254 | + * |
|
255 | + * @since 0.2.0 |
|
256 | + * |
|
257 | + * @param string $milestone A version milestone that is used to define the requirement. |
|
258 | + * @param string $operator An operator that gets applied to the milestone. |
|
259 | + * Possible values: '<=', 'lt', '<', 'le', '>=', 'gt', '>', 'ge', '=', '==', 'eq', '!=', |
|
260 | + * '<>', 'ne' |
|
261 | + * |
|
262 | + * @return string Version string that meets a single requirement. |
|
263 | + * @throws RuntimeException If the requirement could not be satisfied. |
|
264 | + * @throws RuntimeException If the NotEqual is used. |
|
265 | + */ |
|
266 | + protected function getRequiredVersion($milestone, $operator) |
|
267 | + { |
|
268 | + if (null === $this->releases) { |
|
269 | + $this->releases = new PHPReleases(); |
|
270 | + } |
|
271 | + |
|
272 | + switch ($operator) { |
|
273 | + case '>': |
|
274 | + case 'gt': |
|
275 | + return $this->getGreaterThanVersion($milestone); |
|
276 | + case '<': |
|
277 | + case 'lt': |
|
278 | + return $this->getLesserThanVersion($milestone); |
|
279 | + case '>=': |
|
280 | + case 'ge': |
|
281 | + return $this->getGreaterEqualVersion($milestone); |
|
282 | + case '<=': |
|
283 | + case 'le': |
|
284 | + return $this->getLesserEqualVersion($milestone); |
|
285 | + case '!=': |
|
286 | + case '<>': |
|
287 | + case 'ne': |
|
288 | + throw new RuntimeException('NotEqual operator is not implemented.'); |
|
289 | + } |
|
290 | + |
|
291 | + return $milestone; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Get a version greater than the milestone. |
|
296 | + * |
|
297 | + * @since 0.2.4 |
|
298 | + * |
|
299 | + * @param string $milestone A version milestone that is used to define the requirement. |
|
300 | + * |
|
301 | + * @return string Version number that meets the requirement. |
|
302 | + * @throws RuntimeException If the requirement could not be satisfied. |
|
303 | + */ |
|
304 | + protected function getGreaterThanVersion($milestone) |
|
305 | + { |
|
306 | + $data = $this->releases->getAll(); |
|
307 | + foreach ($data as $version => $date) { |
|
308 | + if (version_compare($version, $milestone, '>')) { |
|
309 | + return $version; |
|
310 | + } |
|
311 | + } |
|
312 | + |
|
313 | + throw new RuntimeException('Could not satisfy version requirements.'); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Get a version lesser than the milestone. |
|
318 | + * |
|
319 | + * @since 0.2.4 |
|
320 | + * |
|
321 | + * @param string $milestone A version milestone that is used to define the requirement. |
|
322 | + * |
|
323 | + * @return string Version number that meets the requirement. |
|
324 | + * @throws RuntimeException If the requirement could not be satisfied. |
|
325 | + */ |
|
326 | + protected function getLesserThanVersion($milestone) |
|
327 | + { |
|
328 | + if (version_compare($this->version->getVersion(), $milestone, '<')) { |
|
329 | + return $this->version->getVersion(); |
|
330 | + } |
|
331 | + $data = array_reverse($this->releases->getAll()); |
|
332 | + foreach ($data as $version => $date) { |
|
333 | + if (version_compare($version, $milestone, '<')) { |
|
334 | + return $version; |
|
335 | + } |
|
336 | + } |
|
337 | + |
|
338 | + throw new RuntimeException('Could not satisfy version requirements.'); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Get a version greater or equal than the milestone. |
|
343 | + * |
|
344 | + * @since 0.2.4 |
|
345 | + * |
|
346 | + * @param string $milestone A version milestone that is used to define the requirement. |
|
347 | + * |
|
348 | + * @return string Version number that meets the requirement. |
|
349 | + */ |
|
350 | + protected function getGreaterEqualVersion($milestone) |
|
351 | + { |
|
352 | + if ($this->releases->exists($milestone)) { |
|
353 | + return $milestone; |
|
354 | + } |
|
355 | + |
|
356 | + $data = $this->releases->getAll(); |
|
357 | + foreach ($data as $version => $date) { |
|
358 | + if (version_compare($version, $milestone, '>=')) { |
|
359 | + return $version; |
|
360 | + } |
|
361 | + } |
|
362 | + |
|
363 | + throw new RuntimeException('Could not satisfy version requirements.'); |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Get a version lesser or equal than the milestone. |
|
368 | + * |
|
369 | + * @since 0.2.4 |
|
370 | + * |
|
371 | + * @param string $milestone A version milestone that is used to define the requirement. |
|
372 | + * |
|
373 | + * @return string Version number that meets the requirement. |
|
374 | + */ |
|
375 | + protected function getLesserEqualVersion($milestone) |
|
376 | + { |
|
377 | + if (version_compare($this->version->getVersion(), $milestone, '<=')) { |
|
378 | + return $this->version->getVersion(); |
|
379 | + } |
|
380 | + |
|
381 | + $data = array_reverse($this->releases->getAll()); |
|
382 | + foreach ($data as $version => $date) { |
|
383 | + if (version_compare($version, $milestone, '<=')) { |
|
384 | + return $version; |
|
385 | + } |
|
386 | + } |
|
387 | + |
|
388 | + throw new RuntimeException('Could not satisfy version requirements.'); |
|
389 | + } |
|
390 | 390 | } |