Skip to content
This repository was archived by the owner on Feb 18, 2020. It is now read-only.

Commit 0efc11c

Browse files
authored
Merge pull request #10 from wmde/abstract
Change scope of package to just the interface
2 parents ab9f9c2 + 6f2bcf6 commit 0efc11c

20 files changed

+328
-1065
lines changed

README.md

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,17 @@
44
[![Latest Stable Version](https://poser.pugx.org/wikibase/term-store/version.png)](https://packagist.org/packages/wikibase/term-store)
55
[![Download count](https://poser.pugx.org/wikibase/term-store/d/total.png)](https://packagist.org/packages/wikibase/term-store)
66

7-
Small library for looking up terms by item or property id or finding ids by term.
7+
Tiny library that defines the interface for term persistence of Wikibase entities.
88

99
## Usage
1010

11-
The public entry point of the package is `DoctrineTermStore`, which is used to construct all services.
11+
Real implementations of the interface can be found in
12+
[dependent packages](https://packagist.org/packages/wikibase/term-store/dependents).
1213

13-
```php
14-
$termStore = new DoctrineTermStore( /* config */ );
15-
```
16-
17-
Getting terms:
18-
19-
```php
20-
$fingerprint = $termStore->newPropertyTermStore()->getTerms( $propertyId );
21-
```
22-
23-
Schema creation:
14+
This library does provide some trivial implementations, mainly to facilitate testing.
2415

25-
```php
26-
$termStore->install();
27-
```
16+
* `InMemoryPropertyTermStore` - simple in memory Fake
17+
* `ThrowingPropertyTermStore` - throws an exception when one of its methods is invoked
2818

2919
## Installation
3020

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
"license": "BSD-3-Clause",
44
"description": "Small library for looking up terms by item or property id or findings ids by term",
55
"require": {
6-
"php": "^5.6.99|^7.0",
7-
"wikibase/data-model": "~9.1",
8-
"doctrine/dbal": "~2.5",
9-
"onoi/message-reporter": "~1.3"
6+
"php": "^7.0",
7+
"wikibase/data-model": "~9.1"
108
},
119
"require-dev": {
1210
"doctrine/dbal": "~2.5.13",

phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingPropertyTypeHint" />
154154
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint" />
155155
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint" />
156+
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing" />
156157
</rule>
157158

158159
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">

src/DoctrineTermStore.php

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Wikibase\TermStore\Implementations;
4+
5+
use Wikibase\DataModel\Entity\ItemId;
6+
use Wikibase\DataModel\Term\Fingerprint;
7+
use Wikibase\TermStore\ItemTermStore;
8+
use Wikibase\TermStore\TermStoreException;
9+
10+
class InMemoryItemTermStore implements ItemTermStore {
11+
12+
private $fingerprints = [];
13+
14+
/**
15+
* @throws TermStoreException
16+
*/
17+
public function storeTerms( ItemId $itemId, Fingerprint $terms ) {
18+
$this->fingerprints[$itemId->getNumericId()] = $terms;
19+
}
20+
21+
/**
22+
* @throws TermStoreException
23+
*/
24+
public function deleteTerms( ItemId $itemId ) {
25+
unset( $this->fingerprints[$itemId->getNumericId()] );
26+
}
27+
28+
/**
29+
* @throws TermStoreException
30+
*/
31+
public function getTerms( ItemId $itemId ): Fingerprint {
32+
if ( array_key_exists( $itemId->getNumericId(), $this->fingerprints ) ) {
33+
return $this->fingerprints[$itemId->getNumericId()];
34+
}
35+
36+
return new Fingerprint();
37+
}
38+
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Wikibase\TermStore\Implementations;
4+
5+
use Wikibase\DataModel\Entity\PropertyId;
6+
use Wikibase\DataModel\Term\Fingerprint;
7+
use Wikibase\TermStore\PropertyTermStore;
8+
use Wikibase\TermStore\TermStoreException;
9+
10+
class InMemoryPropertyTermStore implements PropertyTermStore {
11+
12+
private $fingerprints = [];
13+
14+
/**
15+
* @throws TermStoreException
16+
*/
17+
public function storeTerms( PropertyId $propertyId, Fingerprint $terms ) {
18+
$this->fingerprints[$propertyId->getNumericId()] = $terms;
19+
}
20+
21+
/**
22+
* @throws TermStoreException
23+
*/
24+
public function deleteTerms( PropertyId $propertyId ) {
25+
unset( $this->fingerprints[$propertyId->getNumericId()] );
26+
}
27+
28+
/**
29+
* @throws TermStoreException
30+
*/
31+
public function getTerms( PropertyId $propertyId ): Fingerprint {
32+
if ( array_key_exists( $propertyId->getNumericId(), $this->fingerprints ) ) {
33+
return $this->fingerprints[$propertyId->getNumericId()];
34+
}
35+
36+
return new Fingerprint();
37+
}
38+
39+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Wikibase\TermStore\Implementations;
4+
5+
use Wikibase\DataModel\Entity\ItemId;
6+
use Wikibase\DataModel\Term\Fingerprint;
7+
use Wikibase\TermStore\ItemTermStore;
8+
use Wikibase\TermStore\TermStoreException;
9+
10+
class ThrowingItemTermStore implements ItemTermStore {
11+
12+
/**
13+
* @throws TermStoreException
14+
*/
15+
public function storeTerms( ItemId $itemId, Fingerprint $terms ) {
16+
throw new TermStoreException();
17+
}
18+
19+
/**
20+
* @throws TermStoreException
21+
*/
22+
public function deleteTerms( ItemId $itemId ) {
23+
throw new TermStoreException();
24+
}
25+
26+
/**
27+
* @throws TermStoreException
28+
*/
29+
public function getTerms( ItemId $itemId ): Fingerprint {
30+
throw new TermStoreException();
31+
}
32+
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Wikibase\TermStore\Implementations;
4+
5+
use Wikibase\DataModel\Entity\PropertyId;
6+
use Wikibase\DataModel\Term\Fingerprint;
7+
use Wikibase\TermStore\PropertyTermStore;
8+
use Wikibase\TermStore\TermStoreException;
9+
10+
class ThrowingPropertyTermStore implements PropertyTermStore {
11+
12+
/**
13+
* @throws TermStoreException
14+
*/
15+
public function storeTerms( PropertyId $propertyId, Fingerprint $terms ) {
16+
throw new TermStoreException();
17+
}
18+
19+
/**
20+
* @throws TermStoreException
21+
*/
22+
public function deleteTerms( PropertyId $propertyId ) {
23+
throw new TermStoreException();
24+
}
25+
26+
/**
27+
* @throws TermStoreException
28+
*/
29+
public function getTerms( PropertyId $propertyId ): Fingerprint {
30+
throw new TermStoreException();
31+
}
32+
33+
}

src/ItemTermStore.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Wikibase\TermStore;
4+
5+
use Wikibase\DataModel\Entity\ItemId;
6+
use Wikibase\DataModel\Term\Fingerprint;
7+
8+
interface ItemTermStore {
9+
10+
/**
11+
* Updates the stored terms for the specified item.
12+
* @throws TermStoreException
13+
*/
14+
public function storeTerms( ItemId $itemId, Fingerprint $terms );
15+
16+
/**
17+
* @throws TermStoreException
18+
*/
19+
public function deleteTerms( ItemId $itemId );
20+
21+
/**
22+
* Returns an empty Fingerprint when no terms are found.
23+
* @throws TermStoreException
24+
*/
25+
public function getTerms( ItemId $itemId ): Fingerprint;
26+
27+
}

0 commit comments

Comments
 (0)