-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPropertyPatcher.php
More file actions
70 lines (57 loc) · 1.59 KB
/
PropertyPatcher.php
File metadata and controls
70 lines (57 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Wikibase\DataModel\Services\Diff;
use InvalidArgumentException;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\Property;
use Wikibase\DataModel\Services\Diff\Internal\FingerprintPatcher;
/**
* @since 1.0
*
* @license GPL-2.0+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class PropertyPatcher implements EntityPatcherStrategy {
/**
* @var FingerprintPatcher
*/
private $fingerprintPatcher;
/**
* @var StatementListPatcher
*/
private $statementListPatcher;
public function __construct() {
$this->fingerprintPatcher = new FingerprintPatcher();
$this->statementListPatcher = new StatementListPatcher();
}
/**
* @param string $entityType
*
* @return boolean
*/
public function canPatchEntityType( $entityType ) {
return $entityType === 'property';
}
/**
* @param EntityDocument $entity
* @param EntityDiff $patch
*
* @return Property
* @throws InvalidArgumentException
*/
public function patchEntity( EntityDocument $entity, EntityDiff $patch ) {
$this->assertIsProperty( $entity );
$this->patchProperty( $entity, $patch );
}
private function assertIsProperty( EntityDocument $property ) {
if ( !( $property instanceof Property ) ) {
throw new InvalidArgumentException( '$property must be an instance of Property' );
}
}
private function patchProperty( Property $property, EntityDiff $patch ) {
$this->fingerprintPatcher->patchFingerprint( $property->getFingerprint(), $patch );
$this->statementListPatcher->patchStatementList(
$property->getStatements(),
$patch->getClaimsDiff()
);
}
}