Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SchemaDataResolvingLabelLookup | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getLabelForTitle | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1 ); |
| 4 | |
| 5 | namespace EntitySchema\DataAccess; |
| 6 | |
| 7 | use MediaWiki\Page\PageIdentity; |
| 8 | use Wikibase\DataModel\Term\TermFallback; |
| 9 | |
| 10 | /** |
| 11 | * Lookup for EntitySchema labels, with language fallbacks applied. |
| 12 | * Resolves the EntitySchema data from a PageTitle |
| 13 | * |
| 14 | * @license GPL-2.0-or-later |
| 15 | */ |
| 16 | class SchemaDataResolvingLabelLookup { |
| 17 | |
| 18 | private FullViewSchemaDataLookup $fullViewSchemaDataLookup; |
| 19 | private LabelLookup $labelLookup; |
| 20 | |
| 21 | public function __construct( |
| 22 | FullViewSchemaDataLookup $fullViewSchemaDataLookup, |
| 23 | LabelLookup $labelLookup |
| 24 | ) { |
| 25 | $this->fullViewSchemaDataLookup = $fullViewSchemaDataLookup; |
| 26 | $this->labelLookup = $labelLookup; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Look up the label of the EntitySchema with the given title, if any. |
| 31 | * Language fallbacks are applied based on the given language code. |
| 32 | * |
| 33 | * @param PageIdentity $title |
| 34 | * @param string $langCode |
| 35 | * @return TermFallback|null The label, or null if no label or EntitySchema was found. |
| 36 | */ |
| 37 | public function getLabelForTitle( PageIdentity $title, string $langCode ): ?TermFallback { |
| 38 | $schemaData = $this->fullViewSchemaDataLookup->getFullViewSchemaDataForTitle( $title ); |
| 39 | if ( $schemaData === null ) { |
| 40 | return null; |
| 41 | } |
| 42 | return $this->labelLookup->getLabelForSchemaData( $schemaData, $langCode ); |
| 43 | } |
| 44 | } |