1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\EntityStore\Api; |
4
|
|
|
|
5
|
|
|
use Mediawiki\Api\MediawikiApi; |
6
|
|
|
use Wikibase\DataModel\Entity\BasicEntityIdParser; |
7
|
|
|
use Wikibase\EntityStore\EntityStore; |
8
|
|
|
use Wikibase\EntityStore\EntityStoreOptions; |
9
|
|
|
use Wikibase\EntityStore\FeatureNotSupportedException; |
10
|
|
|
use Wikibase\EntityStore\Internal\DispatchingEntityIdForTermLookup; |
11
|
|
|
use Wikibase\EntityStore\Internal\DispatchingEntityLookup; |
12
|
|
|
use Wikibase\EntityStore\Internal\EntitySerializationFactory; |
13
|
|
|
use WikidataQueryApi\WikidataQueryApi; |
14
|
|
|
use WikidataQueryApi\WikidataQueryFactory; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @licence GPLv2+ |
18
|
|
|
* @author Thomas Pellissier Tanon |
19
|
|
|
*/ |
20
|
|
|
class ApiEntityStore extends EntityStore { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var DispatchingEntityLookup |
24
|
|
|
*/ |
25
|
|
|
private $entityLookup; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var DispatchingEntityIdForTermLookup |
29
|
|
|
*/ |
30
|
|
|
private $entityIdsForTermLookup; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var WikidataQueryApi|null |
34
|
|
|
*/ |
35
|
|
|
private $wikidataQueryApi; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param MediawikiApi $api |
39
|
|
|
* @param WikidataQueryApi|null $wikidataQueryApi |
40
|
|
|
* @param EntityStoreOptions|null $options |
41
|
|
|
*/ |
42
|
9 |
|
public function __construct( |
43
|
|
|
MediawikiApi $api, |
44
|
|
|
WikidataQueryApi $wikidataQueryApi = null, |
45
|
|
|
EntityStoreOptions $options = null |
46
|
|
|
) { |
47
|
9 |
|
parent::__construct( $options ); |
48
|
|
|
|
49
|
9 |
|
$this->entityLookup = $this->newEntityLookup( $api ); |
50
|
9 |
|
$this->entityIdsForTermLookup = $this->newEntityForTermLookup( $api ); |
51
|
9 |
|
$this->wikidataQueryApi = $wikidataQueryApi; |
52
|
9 |
|
} |
53
|
|
|
|
54
|
9 |
|
private function newEntityLookup( MediawikiApi $api ) { |
55
|
9 |
|
$serializationFactory = new EntitySerializationFactory(); |
56
|
9 |
|
return new DispatchingEntityLookup( |
57
|
9 |
|
new ApiEntityLookup( $api, $serializationFactory->newEntityDeserializer(), $this->getOptions() ) |
58
|
9 |
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
9 |
|
private function newEntityForTermLookup( MediawikiApi $api ) { |
62
|
9 |
|
return new DispatchingEntityIdForTermLookup( new ApiEntityIdForTermLookup( $api, new BasicEntityIdParser() ) ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @see EntityStore::getEntityLookup |
67
|
|
|
*/ |
68
|
1 |
|
public function getEntityLookup() { |
69
|
1 |
|
return $this->entityLookup; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @see EntityStore::getEntityDocumentLookup |
74
|
|
|
*/ |
75
|
2 |
|
public function getEntityDocumentLookup() { |
76
|
2 |
|
return $this->entityLookup; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @see EntityStore::getItemLookup |
81
|
|
|
*/ |
82
|
2 |
|
public function getItemLookup() { |
83
|
2 |
|
return $this->entityLookup; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @see EntityStore::getPropertyLookup |
88
|
|
|
*/ |
89
|
1 |
|
public function getPropertyLookup() { |
90
|
1 |
|
return $this->entityLookup; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @see EntityStore::getItemIdForTermLookup |
95
|
|
|
*/ |
96
|
2 |
|
public function getItemIdForTermLookup() { |
97
|
2 |
|
return $this->entityIdsForTermLookup; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @see EntityStore::getPropertyIdForTermLookup |
102
|
|
|
*/ |
103
|
2 |
|
public function getPropertyIdForTermLookup() { |
104
|
2 |
|
return $this->entityIdsForTermLookup; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @see EntityStore::getItemIdForQueryLookup |
109
|
|
|
*/ |
110
|
3 |
|
public function getItemIdForQueryLookup() { |
111
|
3 |
|
if( $this->wikidataQueryApi === null ) { |
112
|
1 |
|
throw new FeatureNotSupportedException( |
113
|
|
|
'ItemIdForQueryLookup not supported: you should configure it to support WikidataQuery' |
114
|
1 |
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
2 |
|
$factory = new WikidataQueryFactory( $this->wikidataQueryApi ); |
118
|
2 |
|
return new WikidataQueryItemIdForQueryLookup( $factory->newSimpleQueryService() ); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|