-
Notifications
You must be signed in to change notification settings - Fork 2
/
SkipDays.php
48 lines (44 loc) · 1.12 KB
/
SkipDays.php
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
<?php
namespace Lucinda\RSS;
/**
* Encapsulates a RSS skipDays entry according to specifications:
* https://www.rssboard.org/rss-profile#element-channel-skipdays
*/
class SkipDays implements Tag
{
/**
* @var string[]
*/
private array $days;
/**
* Sets days of the week during which the feed is not updated
*
* @param string[] $days Names of week days to skip (eg: ["Saturday", "Sunday"])
* @throws Exception
*/
public function __construct(array $days)
{
array_map(
function ($item) {
if (!in_array($item, ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday"])) {
throw new Exception("Invalid day: ".$item);
}
},
$days
);
$this->days = $days;
}
/**
* {@inheritDoc}
*
* @see Tag::__toString()
*/
public function __toString(): string
{
$output = "";
foreach ($this->days as $day) {
$output .= "<day>".$day."</day>";
}
return "<skipDays>".$output."</skipDays>";
}
}