| 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 | */ |
| 21 | |
| 22 | namespace MediaWiki\Block; |
| 23 | |
| 24 | use MediaWiki\Config\ServiceOptions; |
| 25 | use MediaWiki\Permissions\Authority; |
| 26 | use MediaWiki\User\UserIdentity; |
| 27 | |
| 28 | /** |
| 29 | * Factory class for BlockPermissionChecker |
| 30 | * |
| 31 | * @since 1.35 |
| 32 | */ |
| 33 | class BlockPermissionCheckerFactory { |
| 34 | /** |
| 35 | * @internal only to be used by ServiceWiring |
| 36 | */ |
| 37 | public const CONSTRUCTOR_OPTIONS = BlockPermissionChecker::CONSTRUCTOR_OPTIONS; |
| 38 | |
| 39 | private ServiceOptions $options; |
| 40 | private BlockUtils $blockUtils; |
| 41 | |
| 42 | public function __construct( |
| 43 | ServiceOptions $options, |
| 44 | BlockUtils $blockUtils |
| 45 | ) { |
| 46 | $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
| 47 | $this->options = $options; |
| 48 | $this->blockUtils = $blockUtils; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param UserIdentity|string|null $target Target of the validated block; may be null if unknown |
| 53 | * @param Authority $performer Performer of the validated block |
| 54 | * |
| 55 | * @return BlockPermissionChecker |
| 56 | */ |
| 57 | public function newBlockPermissionChecker( |
| 58 | $target, |
| 59 | Authority $performer |
| 60 | ) { |
| 61 | return new BlockPermissionChecker( |
| 62 | $this->options, |
| 63 | $this->blockUtils, |
| 64 | $target, |
| 65 | $performer |
| 66 | ); |
| 67 | } |
| 68 | } |