Skip to content

Commit f0dff1d

Browse files
committed
Merge pull request #521 from wmde/entity-properties
Move id and fingerprint to Item and Property
2 parents 4fdb72b + fefd09f commit f0dff1d

3 files changed

Lines changed: 95 additions & 69 deletions

File tree

src/Entity/Entity.php

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Wikibase\DataModel\Term\AliasGroupList;
88
use Wikibase\DataModel\Term\Fingerprint;
99
use Wikibase\DataModel\Term\FingerprintProvider;
10-
use Wikibase\DataModel\Term\Term;
1110
use Wikibase\DataModel\Term\TermList;
1211

1312
/**
@@ -22,27 +21,6 @@
2221
*/
2322
abstract class Entity implements \Comparable, FingerprintProvider, EntityDocument {
2423

25-
/**
26-
* @var EntityId|null
27-
*/
28-
protected $id;
29-
30-
/**
31-
* @var Fingerprint
32-
*/
33-
protected $fingerprint;
34-
35-
/**
36-
* Returns the id of the entity or null if it does not have one.
37-
*
38-
* @since 0.1 return type changed in 0.3
39-
*
40-
* @return EntityId|null
41-
*/
42-
public function getId() {
43-
return $this->id;
44-
}
45-
4624
/**
4725
* Sets the value for the label in a certain value.
4826
*
@@ -52,7 +30,7 @@ public function getId() {
5230
* @param string $value
5331
*/
5432
public function setLabel( $languageCode, $value ) {
55-
$this->fingerprint->setLabel( $languageCode, $value );
33+
$this->getFingerprint()->setLabel( $languageCode, $value );
5634
}
5735

5836
/**
@@ -64,7 +42,7 @@ public function setLabel( $languageCode, $value ) {
6442
* @param string $value
6543
*/
6644
public function setDescription( $languageCode, $value ) {
67-
$this->fingerprint->setDescription( $languageCode, $value );
45+
$this->getFingerprint()->setDescription( $languageCode, $value );
6846
}
6947

7048
/**
@@ -75,7 +53,7 @@ public function setDescription( $languageCode, $value ) {
7553
* @param string $languageCode
7654
*/
7755
public function removeLabel( $languageCode ) {
78-
$this->fingerprint->removeLabel( $languageCode );
56+
$this->getFingerprint()->removeLabel( $languageCode );
7957
}
8058

8159
/**
@@ -86,7 +64,7 @@ public function removeLabel( $languageCode ) {
8664
* @param string $languageCode
8765
*/
8866
public function removeDescription( $languageCode ) {
89-
$this->fingerprint->removeDescription( $languageCode );
67+
$this->getFingerprint()->removeDescription( $languageCode );
9068
}
9169

9270
/**
@@ -99,7 +77,7 @@ public function removeDescription( $languageCode ) {
9977
* @return string[]
10078
*/
10179
public function getAliases( $languageCode ) {
102-
$aliases = $this->fingerprint->getAliasGroups();
80+
$aliases = $this->getFingerprint()->getAliasGroups();
10381

10482
if ( $aliases->hasGroupForLanguage( $languageCode ) ) {
10583
return $aliases->getByLanguage( $languageCode )->getAliases();
@@ -119,7 +97,7 @@ public function getAliases( $languageCode ) {
11997
* @return array[]
12098
*/
12199
public function getAllAliases( array $languageCodes = null ) {
122-
$aliases = $this->fingerprint->getAliasGroups();
100+
$aliases = $this->getFingerprint()->getAliasGroups();
123101

124102
$textLists = array();
125103

@@ -144,7 +122,7 @@ public function getAllAliases( array $languageCodes = null ) {
144122
* @param string[] $aliases
145123
*/
146124
public function setAliases( $languageCode, array $aliases ) {
147-
$this->fingerprint->setAliasGroup( $languageCode, $aliases );
125+
$this->getFingerprint()->setAliasGroup( $languageCode, $aliases );
148126
}
149127

150128
/**
@@ -222,11 +200,11 @@ public function getLabels( array $languageCodes = null ) {
222200
* @return string|bool
223201
*/
224202
public function getDescription( $languageCode ) {
225-
if ( !$this->fingerprint->hasDescription( $languageCode ) ) {
203+
if ( !$this->getFingerprint()->hasDescription( $languageCode ) ) {
226204
return false;
227205
}
228206

229-
return $this->fingerprint->getDescription( $languageCode )->getText();
207+
return $this->getFingerprint()->getDescription( $languageCode )->getText();
230208
}
231209

232210
/**
@@ -240,11 +218,11 @@ public function getDescription( $languageCode ) {
240218
* @return string|bool
241219
*/
242220
public function getLabel( $languageCode ) {
243-
if ( !$this->fingerprint->hasLabel( $languageCode ) ) {
221+
if ( !$this->getFingerprint()->hasLabel( $languageCode ) ) {
244222
return false;
245223
}
246224

247-
return $this->fingerprint->getLabel( $languageCode )->getText();
225+
return $this->getFingerprint()->getLabel( $languageCode )->getText();
248226
}
249227

250228
/**
@@ -257,9 +235,9 @@ public function getLabel( $languageCode ) {
257235
*/
258236
private function getMultilangTexts( $fieldKey, array $languageCodes = null ) {
259237
if ( $fieldKey === 'label' ) {
260-
$textList = $this->fingerprint->getLabels()->toTextArray();
238+
$textList = $this->getFingerprint()->getLabels()->toTextArray();
261239
} else {
262-
$textList = $this->fingerprint->getDescriptions()->toTextArray();
240+
$textList = $this->getFingerprint()->getDescriptions()->toTextArray();
263241
}
264242

265243
if ( $languageCodes !== null ) {
@@ -280,7 +258,7 @@ private function getMultilangTexts( $fieldKey, array $languageCodes = null ) {
280258
* @param string[] $labels
281259
*/
282260
public function setLabels( array $labels ) {
283-
$this->fingerprint->setLabels( new TermList() );
261+
$this->getFingerprint()->setLabels( new TermList() );
284262

285263
foreach ( $labels as $languageCode => $labelText ) {
286264
$this->setLabel( $languageCode, $labelText );
@@ -298,7 +276,7 @@ public function setLabels( array $labels ) {
298276
* @param string[] $descriptions
299277
*/
300278
public function setDescriptions( array $descriptions ) {
301-
$this->fingerprint->setDescriptions( new TermList() );
279+
$this->getFingerprint()->setDescriptions( new TermList() );
302280

303281
foreach ( $descriptions as $languageCode => $descriptionText ) {
304282
$this->setDescription( $languageCode, $descriptionText );
@@ -317,7 +295,7 @@ public function setDescriptions( array $descriptions ) {
317295
* @param array[] $aliasLists
318296
*/
319297
public function setAllAliases( array $aliasLists ) {
320-
$this->fingerprint->setAliasGroups( new AliasGroupList() );
298+
$this->getFingerprint()->setAliasGroups( new AliasGroupList() );
321299

322300
foreach( $aliasLists as $languageCode => $aliasList ) {
323301
$this->setAliases( $languageCode, $aliasList );
@@ -346,25 +324,13 @@ public function getClaims() {
346324
return array();
347325
}
348326

349-
/**
350-
* @since 0.7.3
351-
* @deprecated since 1.0
352-
*
353-
* @return Fingerprint
354-
*/
355-
public function getFingerprint() {
356-
return $this->fingerprint;
357-
}
358-
359327
/**
360328
* @since 0.7.3
361329
* @deprecated since 1.0
362330
*
363331
* @param Fingerprint $fingerprint
364332
*/
365-
public function setFingerprint( Fingerprint $fingerprint ) {
366-
$this->fingerprint = $fingerprint;
367-
}
333+
public abstract function setFingerprint( Fingerprint $fingerprint );
368334

369335
/**
370336
* Returns if the Entity has no content.

src/Entity/Item.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ class Item extends Entity implements StatementListHolder {
2525

2626
const ENTITY_TYPE = 'item';
2727

28+
/**
29+
* @var ItemId|null
30+
*/
31+
private $id;
32+
33+
/**
34+
* @var Fingerprint
35+
*/
36+
private $fingerprint;
37+
2838
/**
2939
* @var SiteLinkList
3040
*/
@@ -55,6 +65,17 @@ public function __construct(
5565
$this->statements = $statements ?: new StatementList();
5666
}
5767

68+
/**
69+
* Returns the id of the entity or null if it does not have one.
70+
*
71+
* @since 0.1 return type changed in 0.3
72+
*
73+
* @return ItemId|null
74+
*/
75+
public function getId() {
76+
return $this->id;
77+
}
78+
5879
/**
5980
* Can be integer since 0.1.
6081
* Can be ItemId since 0.5.
@@ -76,6 +97,24 @@ public function setId( $id ) {
7697
}
7798
}
7899

100+
/**
101+
* @since 0.7.3
102+
*
103+
* @return Fingerprint
104+
*/
105+
public function getFingerprint() {
106+
return $this->fingerprint;
107+
}
108+
109+
/**
110+
* @since 0.7.3
111+
*
112+
* @param Fingerprint $fingerprint
113+
*/
114+
public function setFingerprint( Fingerprint $fingerprint ) {
115+
$this->fingerprint = $fingerprint;
116+
}
117+
79118
/**
80119
* @param string $languageCode
81120
* @param string $value
@@ -106,15 +145,6 @@ public function setAliases( $languageCode, array $aliases ) {
106145
$this->fingerprint->setAliasGroup( $languageCode, $aliases );
107146
}
108147

109-
/**
110-
* @since 0.1 return type changed in 0.3
111-
*
112-
* @return ItemId|null
113-
*/
114-
public function getId() {
115-
return $this->id;
116-
}
117-
118148
/**
119149
* @since 0.8
120150
*

src/Entity/Property.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ class Property extends Entity implements StatementListHolder {
2222

2323
const ENTITY_TYPE = 'property';
2424

25+
/**
26+
* @var PropertyId|null
27+
*/
28+
private $id;
29+
30+
/**
31+
* @var Fingerprint
32+
*/
33+
private $fingerprint;
34+
2535
/**
2636
* @var string
2737
*/
@@ -52,6 +62,17 @@ public function __construct(
5262
$this->statements = $statements ?: new StatementList();
5363
}
5464

65+
/**
66+
* Returns the id of the entity or null if it does not have one.
67+
*
68+
* @since 0.1 return type changed in 0.3
69+
*
70+
* @return PropertyId|null
71+
*/
72+
public function getId() {
73+
return $this->id;
74+
}
75+
5576
/**
5677
* Can be integer since 0.1.
5778
* Can be PropertyId since 0.5.
@@ -73,6 +94,24 @@ public function setId( $id ) {
7394
}
7495
}
7596

97+
/**
98+
* @since 0.7.3
99+
*
100+
* @return Fingerprint
101+
*/
102+
public function getFingerprint() {
103+
return $this->fingerprint;
104+
}
105+
106+
/**
107+
* @since 0.7.3
108+
*
109+
* @param Fingerprint $fingerprint
110+
*/
111+
public function setFingerprint( Fingerprint $fingerprint ) {
112+
$this->fingerprint = $fingerprint;
113+
}
114+
76115
/**
77116
* @param string $languageCode
78117
* @param string $value
@@ -103,15 +142,6 @@ public function setAliases( $languageCode, array $aliases ) {
103142
$this->fingerprint->setAliasGroup( $languageCode, $aliases );
104143
}
105144

106-
/**
107-
* @since 0.1 return type changed in 0.3
108-
*
109-
* @return PropertyId|null
110-
*/
111-
public function getId() {
112-
return $this->id;
113-
}
114-
115145
/**
116146
* @since 0.4
117147
*

0 commit comments

Comments
 (0)