Update git submodules
[mediawiki.git] / includes / auth / AbstractAuthenticationProvider.php
blobd18adc57d4b5dbae12272ee297dae1a928c3aa9f
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.
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.
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
18 * @file
19 * @ingroup Auth
22 namespace MediaWiki\Auth;
24 use MediaWiki\Config\Config;
25 use MediaWiki\HookContainer\HookContainer;
26 use MediaWiki\HookContainer\HookRunner;
27 use MediaWiki\User\UserNameUtils;
28 use Psr\Log\LoggerInterface;
30 /**
31 * A base class that implements some of the boilerplate for an AuthenticationProvider
32 * @stable to extend
33 * @ingroup Auth
34 * @since 1.27
36 abstract class AbstractAuthenticationProvider implements AuthenticationProvider {
37 /** @var LoggerInterface */
38 protected $logger;
40 /** @var AuthManager */
41 protected $manager;
43 /** @var Config */
44 protected $config;
46 /** @var HookContainer */
47 private $hookContainer;
49 /** @var HookRunner */
50 private $hookRunner;
52 /** @var UserNameUtils */
53 protected $userNameUtils;
55 /**
56 * Initialise with dependencies of an AuthenticationProvider
58 * @since 1.37
59 * @internal In production code AuthManager will initialize the
60 * AbstractAuthenticationProvider, in tests
61 * AuthenticationProviderTestTrait must be used.
63 * @param LoggerInterface $logger
64 * @param AuthManager $manager
65 * @param HookContainer $hookContainer
66 * @param Config $config
67 * @param UserNameUtils $userNameUtils
69 public function init(
70 LoggerInterface $logger,
71 AuthManager $manager,
72 HookContainer $hookContainer,
73 Config $config,
74 UserNameUtils $userNameUtils
75 ) {
76 $this->logger = $logger;
77 $this->manager = $manager;
78 $this->hookContainer = $hookContainer;
79 $this->hookRunner = new HookRunner( $hookContainer );
80 $this->config = $config;
81 $this->userNameUtils = $userNameUtils;
82 $this->postInitSetup();
85 /**
86 * A provider can override this to do any necessary setup after init()
87 * is called.
89 * @since 1.37
90 * @stable to override
92 protected function postInitSetup() {
95 /**
96 * @inheritDoc
97 * @note Override this if it makes sense to support more than one instance
99 public function getUniqueId() {
100 return static::class;
104 * @since 1.35
105 * @return HookContainer
107 protected function getHookContainer(): HookContainer {
108 return $this->hookContainer;
112 * @internal This is for use by core only. Hook interfaces may be removed
113 * without notice.
114 * @since 1.35
115 * @return HookRunner
117 protected function getHookRunner(): HookRunner {
118 return $this->hookRunner;