1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\DataModel\Term; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Immutable value object. |
9
|
|
|
* |
10
|
|
|
* @since 2.4.0 |
11
|
|
|
* |
12
|
|
|
* @license GPL-2.0-or-later |
13
|
|
|
* @author Jan Zerebecki < [email protected] > |
14
|
|
|
*/ |
15
|
|
|
class TermFallback extends Term { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string Actual language of the text. |
19
|
|
|
*/ |
20
|
|
|
private $actualLanguageCode; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string|null Source language if the text is a transliteration. |
24
|
|
|
*/ |
25
|
|
|
private $sourceLanguageCode; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $requestedLanguageCode Requested language, not necessarily the language of the |
29
|
|
|
* text. |
30
|
|
|
* @param string $text |
31
|
|
|
* @param string $actualLanguageCode Actual language of the text. |
32
|
|
|
* @param string|null $sourceLanguageCode Source language if the text is a transliteration. |
33
|
|
|
* |
34
|
|
|
* @throws InvalidArgumentException |
35
|
|
|
*/ |
36
|
|
|
public function __construct( $requestedLanguageCode, $text, $actualLanguageCode, $sourceLanguageCode ) { |
37
|
|
|
parent::__construct( $requestedLanguageCode, $text ); |
38
|
|
|
|
39
|
|
|
if ( !is_string( $actualLanguageCode ) || $actualLanguageCode === '' ) { |
40
|
|
|
throw new InvalidArgumentException( '$actualLanguageCode must be a non-empty string' ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if ( !( $sourceLanguageCode === null |
44
|
|
|
|| ( is_string( $sourceLanguageCode ) && $sourceLanguageCode !== '' ) |
45
|
|
|
) ) { |
46
|
|
|
throw new InvalidArgumentException( '$sourceLanguageCode must be a non-empty string or null' ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->actualLanguageCode = $actualLanguageCode; |
50
|
|
|
$this->sourceLanguageCode = $sourceLanguageCode; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getActualLanguageCode() { |
57
|
|
|
return $this->actualLanguageCode; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string|null |
62
|
|
|
*/ |
63
|
|
|
public function getSourceLanguageCode() { |
64
|
|
|
return $this->sourceLanguageCode; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* |
69
|
|
|
* @param mixed $target |
70
|
|
|
* |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
|
public function equals( $target ) { |
74
|
|
|
if ( $this === $target ) { |
75
|
|
|
return true; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $target instanceof self |
79
|
|
|
&& parent::equals( $target ) |
80
|
|
|
&& $this->actualLanguageCode === $target->actualLanguageCode |
81
|
|
|
&& $this->sourceLanguageCode === $target->sourceLanguageCode; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|