Debian Codegraph @

includes/preferences/SignatureValidatorFactory.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @author Derick Alangi
20 */
21
22 namespace MediaWiki\Preferences;
23
24 use MediaWiki\Config\ServiceOptions;
25 use MediaWiki\Parser\ParserOptions;
26 use MediaWiki\SpecialPage\SpecialPageFactory;
27 use MediaWiki\Title\TitleFactory;
28 use MediaWiki\User\UserIdentity;
29 use MessageLocalizer;
30
31 /**
32 * @since 1.38
33 */
34 class SignatureValidatorFactory {
35 /** @var ServiceOptions */
36 private $serviceOptions;
37
38 /** @var callable */
39 private $parserFactoryClosure;
40
41 /** @var callable */
42 private $lintErrorCheckerClosure;
43
44 /** @var SpecialPageFactory */
45 private $specialPageFactory;
46
47 /** @var TitleFactory */
48 private $titleFactory;
49
50 /**
51 * @param ServiceOptions $options
52 * @param callable $parserFactoryClosure A function which returns a ParserFactory.
53 * We use this instead of an actual ParserFactory to avoid a circular dependency,
54 * since Parser also needs a SignatureValidatorFactory for signature formatting.
55 * @param callable $lintErrorCheckerClosure A function which returns a LintErrorChecker, same as above.
56 * @param SpecialPageFactory $specialPageFactory
57 * @param TitleFactory $titleFactory
58 */
59 public function __construct(
60 ServiceOptions $options,
61 callable $parserFactoryClosure,
62 callable $lintErrorCheckerClosure,
63 SpecialPageFactory $specialPageFactory,
64 TitleFactory $titleFactory
65 ) {
66 // Configuration
67 $this->serviceOptions = $options;
68 $this->serviceOptions->assertRequiredOptions( SignatureValidator::CONSTRUCTOR_OPTIONS );
69 $this->parserFactoryClosure = $parserFactoryClosure;
70 $this->lintErrorCheckerClosure = $lintErrorCheckerClosure;
71 $this->specialPageFactory = $specialPageFactory;
72 $this->titleFactory = $titleFactory;
73 }
74
75 /**
76 * @param UserIdentity $user
77 * @param MessageLocalizer|null $localizer
78 * @param ParserOptions $popts
79 * @return SignatureValidator
80 */
81 public function newSignatureValidator(
82 UserIdentity $user,
83 ?MessageLocalizer $localizer,
84 ParserOptions $popts
85 ): SignatureValidator {
86 return new SignatureValidator(
87 $this->serviceOptions,
88 $user,
89 $localizer,
90 $popts,
91 ( $this->parserFactoryClosure )(),
92 ( $this->lintErrorCheckerClosure )(),
93 $this->specialPageFactory,
94 $this->titleFactory,
95 );
96 }
97 }