Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
81.82% |
9 / 11 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
| AbstractAuthenticationProvider | |
81.82% |
9 / 11 |
|
60.00% |
3 / 5 |
5.15 | |
0.00% |
0 / 1 |
| init | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| postInitSetup | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUniqueId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHookContainer | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getHookRunner | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Auth; |
| 8 | |
| 9 | use MediaWiki\Config\Config; |
| 10 | use MediaWiki\HookContainer\HookContainer; |
| 11 | use MediaWiki\HookContainer\HookRunner; |
| 12 | use MediaWiki\User\UserNameUtils; |
| 13 | use Psr\Log\LoggerInterface; |
| 14 | |
| 15 | /** |
| 16 | * A base class that implements some of the boilerplate for an AuthenticationProvider |
| 17 | * |
| 18 | * @stable to extend |
| 19 | * @ingroup Auth |
| 20 | * @since 1.27 |
| 21 | */ |
| 22 | abstract class AbstractAuthenticationProvider implements AuthenticationProvider { |
| 23 | protected LoggerInterface $logger; |
| 24 | protected AuthManager $manager; |
| 25 | protected Config $config; |
| 26 | private HookContainer $hookContainer; |
| 27 | private HookRunner $hookRunner; |
| 28 | protected UserNameUtils $userNameUtils; |
| 29 | |
| 30 | /** |
| 31 | * Initialise with dependencies of an AuthenticationProvider |
| 32 | * |
| 33 | * @since 1.37 |
| 34 | * @internal In production code AuthManager will initialize the |
| 35 | * AbstractAuthenticationProvider, in tests |
| 36 | * AuthenticationProviderTestTrait must be used. |
| 37 | */ |
| 38 | public function init( |
| 39 | LoggerInterface $logger, |
| 40 | AuthManager $manager, |
| 41 | HookContainer $hookContainer, |
| 42 | Config $config, |
| 43 | UserNameUtils $userNameUtils |
| 44 | ) { |
| 45 | $this->logger = $logger; |
| 46 | $this->manager = $manager; |
| 47 | $this->hookContainer = $hookContainer; |
| 48 | $this->hookRunner = new HookRunner( $hookContainer ); |
| 49 | $this->config = $config; |
| 50 | $this->userNameUtils = $userNameUtils; |
| 51 | $this->postInitSetup(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * A provider can override this to do any necessary setup after init() |
| 56 | * is called. |
| 57 | * |
| 58 | * @since 1.37 |
| 59 | * @stable to override |
| 60 | */ |
| 61 | protected function postInitSetup() { |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @inheritDoc |
| 66 | * @note Override this if it makes sense to support more than one instance |
| 67 | */ |
| 68 | public function getUniqueId() { |
| 69 | return static::class; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @since 1.35 |
| 74 | * @return HookContainer |
| 75 | */ |
| 76 | protected function getHookContainer(): HookContainer { |
| 77 | return $this->hookContainer; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @internal This is for use by core only. Hook interfaces may be removed |
| 82 | * without notice. |
| 83 | * @since 1.35 |
| 84 | * @return HookRunner |
| 85 | */ |
| 86 | protected function getHookRunner(): HookRunner { |
| 87 | return $this->hookRunner; |
| 88 | } |
| 89 | } |