blob: aa2a670e17a195845a57c7277a4b41200d88e463 (
plain)
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
71
72
73
74
75
76
77
78
79
80
81
|
<?php
declare(strict_types=1);
class I18nValue {
private const STATE_DIRTY = 'dirty';
public const STATE_IGNORE = 'ignore';
private const STATE_TODO = 'todo';
private const STATES = [
self::STATE_DIRTY,
self::STATE_IGNORE,
self::STATE_TODO,
];
private string $value;
private ?string $state = null;
/** @param I18nValue|string $data */
public function __construct($data) {
if ($data instanceof I18nValue) {
$data = $data->__toString();
}
$data = explode(' -> ', $data);
$this->value = (string)(array_shift($data) ?? '');
if (count($data) === 0) {
return;
}
$state = array_shift($data);
if (in_array($state, self::STATES, true)) {
$this->state = $state;
}
}
public function __clone(): void {
$this->markAsTodo();
}
public function equal(I18nValue $value): bool {
return $this->value === $value->getValue();
}
public function isIgnore(): bool {
return $this->state === self::STATE_IGNORE;
}
public function isTodo(): bool {
return $this->state === self::STATE_TODO;
}
public function markAsDirty(): void {
$this->state = self::STATE_DIRTY;
}
public function markAsIgnore(): void {
$this->state = self::STATE_IGNORE;
}
public function markAsTodo(): void {
$this->state = self::STATE_TODO;
}
public function unmarkAsIgnore(): void {
if ($this->state === self::STATE_IGNORE) {
$this->state = null;
}
}
#[\Override]
public function __toString(): string {
if ($this->state === null) {
return $this->value;
}
return "{$this->value} -> {$this->state}";
}
public function getValue(): string {
return $this->value;
}
}
|