Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| WikibaseRepoEntitySearchHelperCallbacksHookHandler | |
92.31% |
12 / 13 |
|
50.00% |
1 / 2 |
4.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| onWikibaseRepoEntitySearchHelperCallbacks | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
2.03 | |||
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1 ); |
| 4 | |
| 5 | namespace EntitySchema\Wikibase\Hooks; |
| 6 | |
| 7 | use EntitySchema\Wikibase\Search\EntitySchemaSearchHelperFactory; |
| 8 | use MediaWiki\Context\RequestContext; |
| 9 | use MediaWiki\Request\WebRequest; |
| 10 | use Wikimedia\Assert\Assert; |
| 11 | |
| 12 | /** |
| 13 | * @license GPL-2.0-or-later |
| 14 | */ |
| 15 | class WikibaseRepoEntitySearchHelperCallbacksHookHandler { |
| 16 | |
| 17 | private bool $entitySchemaIsRepo; |
| 18 | private ?EntitySchemaSearchHelperFactory $factory; |
| 19 | |
| 20 | public function __construct( |
| 21 | bool $entitySchemaIsRepo, |
| 22 | ?EntitySchemaSearchHelperFactory $factory |
| 23 | ) { |
| 24 | $this->entitySchemaIsRepo = $entitySchemaIsRepo; |
| 25 | $this->factory = $factory; |
| 26 | if ( $entitySchemaIsRepo ) { |
| 27 | Assert::parameterType( |
| 28 | EntitySchemaSearchHelperFactory::class, |
| 29 | $factory, |
| 30 | '$factory' |
| 31 | ); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @inheritDoc |
| 37 | */ |
| 38 | public function onWikibaseRepoEntitySearchHelperCallbacks( array &$callbacks ): void { |
| 39 | if ( !$this->entitySchemaIsRepo ) { |
| 40 | return; |
| 41 | } |
| 42 | $callbacks[EntitySchemaSearchHelperFactory::ENTITY_TYPE] = function ( WebRequest $request ) { |
| 43 | // TODO would be nice if Wikibase injected the context for us |
| 44 | // ($request is unfortunately not very useful) |
| 45 | return $this->factory->newForContext( RequestContext::getMain() ); |
| 46 | }; |
| 47 | } |
| 48 | |
| 49 | } |