Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RestrictedUserGroupCheckerFactory | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRestrictedUserGroupChecker | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /* |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\User; |
| 8 | |
| 9 | /** |
| 10 | * A service that helps to create RestrictedUserGroupChecker instances, either for the local or remote wikis. |
| 11 | * |
| 12 | * @since 1.46 |
| 13 | */ |
| 14 | class RestrictedUserGroupCheckerFactory { |
| 15 | |
| 16 | private array $instances = []; |
| 17 | |
| 18 | public function __construct( |
| 19 | private readonly RestrictedUserGroupConfigReader $configReader, |
| 20 | private readonly UserRequirementsConditionChecker $userRequirementsConditionChecker, |
| 21 | ) { |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Creates an instance of RestrictedUserGroupChecker for the specified wiki and scope. |
| 26 | * @param false|string $wiki Wiki ID for which the checker should be created. `false` means the current wiki. |
| 27 | * @param string $scope The scope for which the checker should be created. |
| 28 | * Only restrictions relevant for this scope will be considered. |
| 29 | * Defaults to {@see RestrictedUserGroupConfigReader::SCOPE_LOCAL}. |
| 30 | */ |
| 31 | public function getRestrictedUserGroupChecker( |
| 32 | false|string $wiki = false, |
| 33 | string $scope = RestrictedUserGroupConfigReader::SCOPE_LOCAL |
| 34 | ): RestrictedUserGroupChecker { |
| 35 | $key = $wiki . ':' . $scope; |
| 36 | if ( !isset( $this->instances[$key] ) ) { |
| 37 | $config = $this->configReader->getConfig( $wiki, $scope ); |
| 38 | $this->instances[$key] = new RestrictedUserGroupChecker( |
| 39 | $config, |
| 40 | $this->userRequirementsConditionChecker, |
| 41 | ); |
| 42 | } |
| 43 | return $this->instances[$key]; |
| 44 | } |
| 45 | } |