|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sludio\HelperBundle\Sitemap\Entity; |
|
4
|
|
|
|
|
5
|
|
|
class Url |
|
6
|
|
|
{ |
|
7
|
|
|
const CHANGEFREQ_ALWAYS = 'always'; |
|
8
|
|
|
const CHANGEFREQ_HOURLY = 'hourly'; |
|
9
|
|
|
const CHANGEFREQ_DAILY = 'daily'; |
|
10
|
|
|
const CHANGEFREQ_WEEKLY = 'weekly'; |
|
11
|
|
|
const CHANGEFREQ_MONTHLY = 'monthly'; |
|
12
|
|
|
const CHANGEFREQ_YEARLY = 'yearly'; |
|
13
|
|
|
const CHANGEFREQ_NEVER = 'never'; |
|
14
|
|
|
|
|
15
|
|
|
protected $loc = null; |
|
16
|
|
|
protected $lastmod = null; |
|
17
|
|
|
protected $changefreq = null; |
|
18
|
|
|
protected $priority = null; |
|
19
|
|
|
protected $videos = []; |
|
20
|
|
|
protected $images = []; |
|
21
|
|
|
|
|
22
|
|
View Code Duplication |
public function setLoc($loc) |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
if (strlen($loc) > 2048) { |
|
25
|
|
|
throw new \DomainException('The loc value must be less than 2,048 characters'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$this->loc = $loc; |
|
29
|
|
|
|
|
30
|
|
|
return $this; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function getLoc() |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->loc; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
View Code Duplication |
public function setLastmod($lastmod) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
if ($lastmod !== null && !$lastmod instanceof \DateTime) { |
|
41
|
|
|
$lastmod = new \DateTime($lastmod); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$this->lastmod = $lastmod; |
|
45
|
|
|
|
|
46
|
|
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getLastmod() |
|
50
|
|
|
{ |
|
51
|
|
|
if ($this->lastmod === null) { |
|
52
|
|
|
return null; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
if ($this->getChangefreq() === null || in_array($this->getChangefreq(), [ |
|
56
|
|
|
self::CHANGEFREQ_ALWAYS, |
|
57
|
|
|
self::CHANGEFREQ_HOURLY, |
|
58
|
|
|
])) { |
|
59
|
|
|
return $this->lastmod->format(\DateTime::W3C); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $this->lastmod->format('Y-m-d'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function setChangefreq($changefreq) |
|
66
|
|
|
{ |
|
67
|
|
|
$validFreqs = [ |
|
68
|
|
|
self::CHANGEFREQ_ALWAYS, |
|
69
|
|
|
self::CHANGEFREQ_HOURLY, |
|
70
|
|
|
self::CHANGEFREQ_DAILY, |
|
71
|
|
|
self::CHANGEFREQ_WEEKLY, |
|
72
|
|
|
self::CHANGEFREQ_MONTHLY, |
|
73
|
|
|
self::CHANGEFREQ_YEARLY, |
|
74
|
|
|
self::CHANGEFREQ_NEVER, |
|
75
|
|
|
null, |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
if (!in_array($changefreq, $validFreqs)) { |
|
79
|
|
|
throw new \DomainException(sprintf('Invalid changefreq given. Valid values are: %s', implode(', ', $validFreqs))); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$this->changefreq = $changefreq; |
|
83
|
|
|
|
|
84
|
|
|
return $this; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getChangefreq() |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->changefreq; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function setPriority($priority) |
|
93
|
|
|
{ |
|
94
|
|
|
$priority = (float)$priority; |
|
95
|
|
|
|
|
96
|
|
|
if ($priority < 0 || $priority > 1) { |
|
97
|
|
|
throw new \DomainException('The priority must be between 0 and 1'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$this->priority = $priority; |
|
101
|
|
|
|
|
102
|
|
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getPriority() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->priority; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function addVideo(Video $video) |
|
111
|
|
|
{ |
|
112
|
|
|
$this->videos[] = $video; |
|
113
|
|
|
|
|
114
|
|
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function setVideos($videos) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->videos = $videos; |
|
120
|
|
|
|
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getVideos() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->videos; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function addImage(Image $image) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->images[] = $image; |
|
132
|
|
|
|
|
133
|
|
|
return $this; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function setImages($images) |
|
137
|
|
|
{ |
|
138
|
|
|
$this->images = $images; |
|
139
|
|
|
|
|
140
|
|
|
return $this; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function getImages() |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->images; |
|
146
|
|
|
} |
|
147
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.