Move MemcachedBagOStuff b/c logic to ObjectCache
[mediawiki.git] / includes / registration / CoreVersionChecker.php
blobf64d826da0d4b38bad79aabbe8456d80d09be1c3
1 <?php
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.
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.
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
20 use Composer\Semver\VersionParser;
21 use Composer\Semver\Constraint\Constraint;
23 /**
24 * @since 1.26
26 class CoreVersionChecker {
28 /**
29 * @var Constraint|bool representing $wgVersion
31 private $coreVersion = false;
33 /**
34 * @var VersionParser
36 private $versionParser;
38 /**
39 * @param string $coreVersion Current version of core
41 public function __construct( $coreVersion ) {
42 $this->versionParser = new VersionParser();
43 try {
44 $this->coreVersion = new Constraint(
45 '==',
46 $this->versionParser->normalize( $coreVersion )
48 } catch ( UnexpectedValueException $e ) {
49 // Non-parsable version, don't fatal.
53 /**
54 * Check that the provided constraint is compatible with the current version of core
56 * @param string $constraint Something like ">= 1.26"
57 * @return bool
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;
65 return $this->versionParser->parseConstraints( $constraint )
66 ->matches( $this->coreVersion );