|
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 3.13 |
|
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
|
|
|
* @param Fingerprint $fingerprint |
|
36
|
|
|
* @param Diff $patch typically an {@link EntityDiff} |
|
37
|
|
|
* |
|
38
|
|
|
* @throws PatcherException |
|
39
|
|
|
*/ |
|
40
|
|
|
public function patchFingerprint( Fingerprint $fingerprint, Diff $patch ) { |
|
41
|
|
|
if ( !$patch->isAssociative() ) { |
|
|
|
|
|
|
42
|
|
|
throw new PatcherException( '$patch must be associative' ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if ( isset( $patch['label'] ) ) { |
|
46
|
|
|
$this->termListPatcher->patchTermList( |
|
47
|
|
|
$fingerprint->getLabels(), |
|
48
|
|
|
$patch['label'] |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if ( isset( $patch['description'] ) ) { |
|
53
|
|
|
$this->termListPatcher->patchTermList( |
|
54
|
|
|
$fingerprint->getDescriptions(), |
|
55
|
|
|
$patch['description'] |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if ( isset( $patch['aliases'] ) ) { |
|
60
|
|
|
$this->aliasGroupListPatcher->patchAliasGroupList( |
|
61
|
|
|
$fingerprint->getAliasGroups(), |
|
62
|
|
|
$patch['aliases'] |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
If an expression can have both
false, andnullas possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.