Merge "Move up devunt's name to Developers"
[lhc/web/wiklou.git] / includes / registration / CoreVersionChecker.php
1 <?php
2
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 use Composer\Semver\VersionParser;
21 use Composer\Semver\Constraint\Constraint;
22
23 /**
24 * @since 1.26
25 */
26 class CoreVersionChecker {
27
28 /**
29 * @var Constraint|bool representing $wgVersion
30 */
31 private $coreVersion = false;
32
33 /**
34 * @var VersionParser
35 */
36 private $versionParser;
37
38 /**
39 * @param string $coreVersion Current version of core
40 */
41 public function __construct( $coreVersion ) {
42 $this->versionParser = new VersionParser();
43 try {
44 $this->coreVersion = new Constraint(
45 '==',
46 $this->versionParser->normalize( $coreVersion )
47 );
48 } catch ( UnexpectedValueException $e ) {
49 // Non-parsable version, don't fatal.
50 }
51 }
52
53 /**
54 * Check that the provided constraint is compatible with the current version of core
55 *
56 * @param string $constraint Something like ">= 1.26"
57 * @return bool
58 */
59 public function check( $constraint ) {
60 if ( $this->coreVersion === false ) {
61 // Couldn't parse the core version, so we can't check anything
62 return true;
63 }
64
65 return $this->versionParser->parseConstraints( $constraint )
66 ->matches( $this->coreVersion );
67 }
68 }