Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ProtectedHookAccessorTrait | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| getHookContainer | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHookRunner | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\HookContainer; |
| 4 | |
| 5 | use MediaWiki\MediaWikiServices; |
| 6 | |
| 7 | /** |
| 8 | * This trait provides an implementation of getHookContainer() and |
| 9 | * getHookRunner() for classes that do not use dependency injection. Its |
| 10 | * purpose is to provide a consistent API which can easily be maintained |
| 11 | * after the class has been migrated to dependency injection. |
| 12 | */ |
| 13 | trait ProtectedHookAccessorTrait { |
| 14 | /** |
| 15 | * Get a HookContainer, for running extension hooks or for hook metadata. |
| 16 | * |
| 17 | * @since 1.35 |
| 18 | * @return HookContainer |
| 19 | */ |
| 20 | protected function getHookContainer() { |
| 21 | return MediaWikiServices::getInstance()->getHookContainer(); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Get a HookRunner for running core hooks. |
| 26 | * |
| 27 | * @internal This is for use by core only. Hook interfaces may be removed |
| 28 | * without notice. |
| 29 | * @since 1.35 |
| 30 | * @return HookRunner |
| 31 | */ |
| 32 | protected function getHookRunner() { |
| 33 | return new HookRunner( $this->getHookContainer() ); |
| 34 | } |
| 35 | } |