Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
81.82% covered (warning)
81.82%
9 / 11
60.00% covered (warning)
60.00%
3 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbstractAuthenticationProvider
81.82% covered (warning)
81.82%
9 / 11
60.00% covered (warning)
60.00%
3 / 5
5.15
0.00% covered (danger)
0.00%
0 / 1
 init
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 postInitSetup
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUniqueId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getHookContainer
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHookRunner
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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 * @ingroup Auth
20 */
21
22namespace MediaWiki\Auth;
23
24use MediaWiki\Config\Config;
25use MediaWiki\HookContainer\HookContainer;
26use MediaWiki\HookContainer\HookRunner;
27use MediaWiki\User\UserNameUtils;
28use Psr\Log\LoggerInterface;
29
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
35 */
36abstract class AbstractAuthenticationProvider implements AuthenticationProvider {
37    protected LoggerInterface $logger;
38    protected AuthManager $manager;
39    protected Config $config;
40    private HookContainer $hookContainer;
41    private HookRunner $hookRunner;
42    protected UserNameUtils $userNameUtils;
43
44    /**
45     * Initialise with dependencies of an AuthenticationProvider
46     *
47     * @since 1.37
48     * @internal In production code AuthManager will initialize the
49     * AbstractAuthenticationProvider, in tests
50     * AuthenticationProviderTestTrait must be used.
51     */
52    public function init(
53        LoggerInterface $logger,
54        AuthManager $manager,
55        HookContainer $hookContainer,
56        Config $config,
57        UserNameUtils $userNameUtils
58    ) {
59        $this->logger = $logger;
60        $this->manager = $manager;
61        $this->hookContainer = $hookContainer;
62        $this->hookRunner = new HookRunner( $hookContainer );
63        $this->config = $config;
64        $this->userNameUtils = $userNameUtils;
65        $this->postInitSetup();
66    }
67
68    /**
69     * A provider can override this to do any necessary setup after init()
70     * is called.
71     *
72     * @since 1.37
73     * @stable to override
74     */
75    protected function postInitSetup() {
76    }
77
78    /**
79     * @inheritDoc
80     * @note Override this if it makes sense to support more than one instance
81     */
82    public function getUniqueId() {
83        return static::class;
84    }
85
86    /**
87     * @since 1.35
88     * @return HookContainer
89     */
90    protected function getHookContainer(): HookContainer {
91        return $this->hookContainer;
92    }
93
94    /**
95     * @internal This is for use by core only. Hook interfaces may be removed
96     *   without notice.
97     * @since 1.35
98     * @return HookRunner
99     */
100    protected function getHookRunner(): HookRunner {
101        return $this->hookRunner;
102    }
103}