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 * @file 20 * @since 1.35 21 */ 22 23namespace Vector\FeatureManagement\Requirements; 24 25use Vector\Constants; 26use Vector\FeatureManagement\Requirement; 27use Vector\SkinVersionLookup; 28 29/** 30 * Retrieve the skin version for the request and compare it with `Constants::SKIN_VERSION_LATEST`. 31 * This requirement is met if the two are equal. 32 * 33 * Skin version is evaluated in the following order: 34 * 35 * - `useskinversion` URL query parameter override. See `README.md`. 36 * 37 * - User preference. The `User` object for new and existing accounts are updated by hook according 38 * to the `VectorDefaultSkinVersionForNewAccounts` and 39 * `VectorDefaultSkinVersionForExistingAccounts` config values. See the `Vector\Hooks` class and 40 * `skin.json`. 41 * 42 * If the skin version is evaluated prior to `User` preference hook invocations, an incorrect 43 * version may be returned as only query parameter and site configuration will be known. 44 * 45 * - Site configuration default. The default is controlled by the `VectorDefaultSkinVersion` config 46 * value. This is used for anonymous users and as a fallback configuration. See `skin.json`. 47 * 48 * This majority of this class is taken from Stephen Niedzielski's `Vector\SkinVersionLookup` class, 49 * which was introduced in `d1072d0fdfb1`. 50 * 51 * @unstable 52 * 53 * @package Vector\FeatureManagement\Requirements 54 * @internal 55 */ 56final class LatestSkinVersionRequirement implements Requirement { 57 58 /** 59 * @var SkinVersionLookup 60 */ 61 private $skinVersionLookup; 62 63 /** 64 * This constructor accepts all dependencies needed to obtain the skin version. 65 * 66 * @param SkinVersionLookup $skinVersionLookup 67 */ 68 public function __construct( SkinVersionLookup $skinVersionLookup ) { 69 $this->skinVersionLookup = $skinVersionLookup; 70 } 71 72 /** 73 * @inheritDoc 74 */ 75 public function getName(): string { 76 return Constants::REQUIREMENT_LATEST_SKIN_VERSION; 77 } 78 79 /** 80 * @inheritDoc 81 * @throws \ConfigException 82 */ 83 public function isMet(): bool { 84 return $this->skinVersionLookup->getVersion() === Constants::SKIN_VERSION_LATEST; 85 } 86} 87