1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\EntityStore\Internal; |
4
|
|
|
|
5
|
|
|
use Wikibase\DataModel\Entity\EntityId; |
6
|
|
|
use Wikibase\DataModel\Entity\ItemId; |
7
|
|
|
use Wikibase\DataModel\Entity\PropertyId; |
8
|
|
|
use Wikibase\DataModel\Services\Lookup\EntityLookup; |
9
|
|
|
use Wikibase\DataModel\Services\Lookup\EntityLookupException; |
10
|
|
|
use Wikibase\DataModel\Services\Lookup\ItemLookup; |
11
|
|
|
use Wikibase\DataModel\Services\Lookup\ItemLookupException; |
12
|
|
|
use Wikibase\DataModel\Services\Lookup\PropertyLookup; |
13
|
|
|
use Wikibase\DataModel\Services\Lookup\PropertyLookupException; |
14
|
|
|
use Wikibase\EntityStore\EntityDocumentLookup; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Internal class |
18
|
|
|
* |
19
|
|
|
* @licence GPLv2+ |
20
|
|
|
* @author Thomas Pellissier Tanon |
21
|
|
|
*/ |
22
|
|
|
class DispatchingEntityLookup implements ItemLookup, PropertyLookup, EntityLookup, EntityDocumentLookup { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var EntityDocumentLookup |
26
|
|
|
*/ |
27
|
|
|
private $entityDocumentLookup; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param EntityDocumentLookup $entityDocumentLookup |
31
|
|
|
*/ |
32
|
11 |
|
public function __construct( EntityDocumentLookup $entityDocumentLookup ) { |
33
|
11 |
|
$this->entityDocumentLookup = $entityDocumentLookup; |
34
|
11 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @see EntityLookup:getEntity |
38
|
|
|
*/ |
39
|
|
|
public function getEntity( EntityId $entityId ) { |
40
|
|
|
return $this->entityDocumentLookup->getEntityDocumentForId( $entityId ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @see EntityLookup:hasEntity |
45
|
|
|
*/ |
46
|
|
|
public function hasEntity( EntityId $entityId ) { |
47
|
|
|
return $this->entityDocumentLookup->getEntityDocumentForId( $entityId ) !== null; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @see EntityDocumentLookup:getEntityDocumentForId |
52
|
|
|
*/ |
53
|
4 |
|
public function getEntityDocumentForId( EntityId $entityId ) { |
54
|
4 |
|
return $this->entityDocumentLookup->getEntityDocumentForId( $entityId ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @see EntityDocumentLookup:getEntityDocumentsForIds |
59
|
|
|
*/ |
60
|
3 |
|
public function getEntityDocumentsForIds( array $entityIds ) { |
61
|
3 |
|
return $this->entityDocumentLookup->getEntityDocumentsForIds( $entityIds ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @see ItemLookup::getItemForId |
66
|
|
|
*/ |
67
|
4 |
|
public function getItemForId( ItemId $itemId ) { |
68
|
|
|
try { |
69
|
4 |
|
return $this->entityDocumentLookup->getEntityDocumentForId( $itemId ); |
70
|
1 |
|
} catch(EntityLookupException $e) { |
71
|
1 |
|
throw new ItemLookupException( $e->getEntityId(), $e->getMessage(), $e ); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @see PropertyLookup::getPropertyForId |
77
|
|
|
*/ |
78
|
3 |
|
public function getPropertyForId( PropertyId $propertyId ) { |
79
|
|
|
try { |
80
|
3 |
|
return $this->entityDocumentLookup->getEntityDocumentForId( $propertyId ); |
81
|
1 |
|
} catch(EntityLookupException $e) { |
82
|
1 |
|
throw new PropertyLookupException( $e->getEntityId(), $e->getMessage(), $e ); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.