1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Services\Diff; |
4
|
|
|
|
5
|
|
|
use Diff\DiffOp\Diff\Diff; |
6
|
|
|
use Diff\Patcher\PatcherException; |
7
|
|
|
use Wikibase\DataModel\Services\Diff\Internal\AliasGroupListPatcher; |
8
|
|
|
use Wikibase\DataModel\Term\Fingerprint; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @since 1.0 |
12
|
|
|
* |
13
|
|
|
* @license GPL-2.0-or-later |
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
15
|
|
|
* @author Thiemo Kreuz |
16
|
|
|
*/ |
17
|
|
|
class FingerprintPatcher { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var TermListPatcher |
21
|
|
|
*/ |
22
|
|
|
private $termListPatcher; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var AliasGroupListPatcher |
26
|
|
|
*/ |
27
|
|
|
private $aliasGroupListPatcher; |
28
|
|
|
|
29
|
|
|
public function __construct() { |
30
|
|
|
$this->termListPatcher = new TermListPatcher(); |
31
|
|
|
$this->aliasGroupListPatcher = new AliasGroupListPatcher(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @since 1.0 |
36
|
|
|
* |
37
|
|
|
* @param Fingerprint $fingerprint |
38
|
|
|
* @param Diff $patch typically an {@link EntityDiff} |
39
|
|
|
* |
40
|
|
|
* @throws PatcherException |
41
|
|
|
*/ |
42
|
|
|
public function patchFingerprint( Fingerprint $fingerprint, Diff $patch ) { |
43
|
|
|
if ( !$patch->isAssociative() ) { |
|
|
|
|
44
|
|
|
throw new PatcherException( '$patch must be associative' ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if ( isset( $patch['label'] ) ) { |
48
|
|
|
$this->termListPatcher->patchTermList( |
49
|
|
|
$fingerprint->getLabels(), |
50
|
|
|
$patch['label'] |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ( isset( $patch['description'] ) ) { |
55
|
|
|
$this->termListPatcher->patchTermList( |
56
|
|
|
$fingerprint->getDescriptions(), |
57
|
|
|
$patch['description'] |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ( isset( $patch['aliases'] ) ) { |
62
|
|
|
$this->aliasGroupListPatcher->patchAliasGroupList( |
63
|
|
|
$fingerprint->getAliasGroups(), |
64
|
|
|
$patch['aliases'] |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.