Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
WikibaseClientDataTypesHandler | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onWikibaseClientDataTypes | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace EntitySchema\Wikibase\Hooks; |
6 | |
7 | use EntitySchema\Wikibase\DataValues\EntitySchemaValueParser; |
8 | use MediaWiki\Config\Config; |
9 | use ValueFormatters\ValueFormatter; |
10 | |
11 | /** |
12 | * @license GPL-2.0-or-later |
13 | */ |
14 | class WikibaseClientDataTypesHandler { |
15 | |
16 | private Config $settings; |
17 | |
18 | public function __construct( |
19 | Config $settings |
20 | ) { |
21 | $this->settings = $settings; |
22 | } |
23 | |
24 | public function onWikibaseClientDataTypes( array &$dataTypeDefinitions ) { |
25 | if ( !$this->settings->get( 'EntitySchemaEnableDatatype' ) ) { |
26 | return; |
27 | } |
28 | $dataTypeDefinitions = array_merge( |
29 | $dataTypeDefinitions, |
30 | [ |
31 | 'PT:entity-schema' => [ |
32 | 'value-type' => 'wikibase-entityid', |
33 | 'parser-factory-callback' => fn () => new EntitySchemaValueParser(), |
34 | 'formatter-factory-callback' => fn () => new class implements ValueFormatter { |
35 | /** @inheritDoc */ |
36 | public function format( $value ) { |
37 | return "Entity schema not supported yet ({$value->getSchemaId()})"; |
38 | } |
39 | }, |
40 | ], |
41 | ] |
42 | ); |
43 | } |
44 | |
45 | } |