1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JeroenDesloovere\SitemapBundle\Item; |
4
|
|
|
|
5
|
|
|
use JeroenDesloovere\SitemapBundle\Exception\SitemapException; |
6
|
|
|
|
7
|
|
|
final class ChangeFrequency |
8
|
|
|
{ |
9
|
|
|
protected const ALWAYS = 'always'; |
10
|
|
|
protected const HOURLY = 'hourly'; |
11
|
|
|
protected const DAILY = 'daily'; |
12
|
|
|
protected const WEEKLY = 'weekly'; |
13
|
|
|
protected const MONTHLY = 'monthly'; |
14
|
|
|
protected const YEARLY = 'yearly'; |
15
|
|
|
protected const NEVER = 'never'; |
16
|
|
|
|
17
|
|
|
public const POSSIBLE_VALUES = [ |
18
|
|
|
self::ALWAYS, |
19
|
|
|
self::HOURLY, |
20
|
|
|
self::DAILY, |
21
|
|
|
self::WEEKLY, |
22
|
|
|
self::MONTHLY, |
23
|
|
|
self::YEARLY, |
24
|
|
|
self::NEVER, |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
/** @var string */ |
28
|
|
|
private $value; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $changeFrequency |
32
|
|
|
* @throws \Exception |
33
|
|
|
*/ |
34
|
|
|
private function __construct(string $changeFrequency) |
35
|
|
|
{ |
36
|
|
|
if (!in_array($changeFrequency, self::POSSIBLE_VALUES)) { |
37
|
|
|
throw SitemapException::forNotExistingChangeFrequency($changeFrequency); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$this->value = $changeFrequency; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function __toString(): string |
44
|
|
|
{ |
45
|
|
|
return $this->value; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function equals(ChangeFrequency $changeFrequency): bool |
49
|
|
|
{ |
50
|
|
|
if (!($changeFrequency instanceof $this)) { |
51
|
|
|
return false; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $changeFrequency === $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public static function always(): self |
58
|
|
|
{ |
59
|
|
|
return new self(self::ALWAYS); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function isAlways(): bool |
63
|
|
|
{ |
64
|
|
|
return $this->equals(self::always()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public static function hourly(): self |
68
|
|
|
{ |
69
|
|
|
return new self(self::HOURLY); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function isHourly(): bool |
73
|
|
|
{ |
74
|
|
|
return $this->equals(self::hourly()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public static function daily(): self |
78
|
|
|
{ |
79
|
|
|
return new self(self::DAILY); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function isDaily(): bool |
83
|
|
|
{ |
84
|
|
|
return $this->equals(self::daily()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public static function weekly(): self |
88
|
|
|
{ |
89
|
|
|
return new self(self::WEEKLY); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function isWeekly(): bool |
93
|
|
|
{ |
94
|
|
|
return $this->equals(self::weekly()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public static function monthly(): self |
98
|
|
|
{ |
99
|
|
|
return new self(self::MONTHLY); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function isMonthly(): bool |
103
|
|
|
{ |
104
|
|
|
return $this->equals(self::monthly()); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public static function yearly(): self |
108
|
|
|
{ |
109
|
|
|
return new self(self::YEARLY); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function isYearly(): bool |
113
|
|
|
{ |
114
|
|
|
return $this->equals(self::yearly()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public static function never(): self |
118
|
|
|
{ |
119
|
|
|
return new self(self::NEVER); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function isNever(): bool |
123
|
|
|
{ |
124
|
|
|
return $this->equals(self::never()); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|