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    /** @var LoggerInterface */
38    protected $logger;
39
40    /** @var AuthManager */
41    protected $manager;
42
43    /** @var Config */
44    protected $config;
45
46    /** @var HookContainer */
47    private $hookContainer;
48
49    /** @var HookRunner */
50    private $hookRunner;
51
52    /** @var UserNameUtils */
53    protected $userNameUtils;
54
55    /**
56     * Initialise with dependencies of an AuthenticationProvider
57     *
58     * @since 1.37
59     * @internal In production code AuthManager will initialize the
60     * AbstractAuthenticationProvider, in tests
61     * AuthenticationProviderTestTrait must be used.
62     *
63     * @param LoggerInterface $logger
64     * @param AuthManager $manager
65     * @param HookContainer $hookContainer
66     * @param Config $config
67     * @param UserNameUtils $userNameUtils
68     */
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();
83    }
84
85    /**
86     * A provider can override this to do any necessary setup after init()
87     * is called.
88     *
89     * @since 1.37
90     * @stable to override
91     */
92    protected function postInitSetup() {
93    }
94
95    /**
96     * @inheritDoc
97     * @note Override this if it makes sense to support more than one instance
98     */
99    public function getUniqueId() {
100        return static::class;
101    }
102
103    /**
104     * @since 1.35
105     * @return HookContainer
106     */
107    protected function getHookContainer(): HookContainer {
108        return $this->hookContainer;
109    }
110
111    /**
112     * @internal This is for use by core only. Hook interfaces may be removed
113     *   without notice.
114     * @since 1.35
115     * @return HookRunner
116     */
117    protected function getHookRunner(): HookRunner {
118        return $this->hookRunner;
119    }
120}