1 | <?php |
||
15 | class Calendar implements CalendarInterface, JsonLdSerializableInterface, SerializableInterface |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var CalendarType |
||
20 | */ |
||
21 | protected $type = null; |
||
22 | |||
23 | /** |
||
24 | * @var DateTimeInterface |
||
25 | */ |
||
26 | protected $startDate = null; |
||
27 | |||
28 | /** |
||
29 | * @var DateTimeInterface |
||
30 | */ |
||
31 | protected $endDate = null; |
||
32 | |||
33 | /** |
||
34 | * @var Timestamp[] |
||
35 | */ |
||
36 | protected $timestamps = array(); |
||
37 | |||
38 | /** |
||
39 | * @var OpeningHour[] |
||
40 | */ |
||
41 | protected $openingHours = array(); |
||
42 | |||
43 | /** |
||
44 | * @param CalendarType $type |
||
45 | * @param DateTimeInterface|null $startDate |
||
46 | * @param DateTimeInterface|null $endDate |
||
47 | * @param Timestamp[] $timestamps |
||
48 | * @param OpeningHour[] $openingHours |
||
49 | */ |
||
50 | public function __construct( |
||
51 | CalendarType $type, |
||
52 | DateTimeInterface $startDate = null, |
||
53 | DateTimeInterface $endDate = null, |
||
54 | array $timestamps = array(), |
||
55 | array $openingHours = array() |
||
56 | ) { |
||
57 | if (($type->is(CalendarType::MULTIPLE()) || $type->is(CalendarType::SINGLE())) && empty($startDate)) { |
||
58 | throw new \UnexpectedValueException('Start date can not be empty for calendar type: ' . $type . '.'); |
||
59 | } |
||
60 | |||
61 | if ($type->is(CalendarType::PERIODIC()) && (empty($startDate) || empty($endDate))) { |
||
62 | throw new \UnexpectedValueException('A period should have a start- and end-date.'); |
||
63 | } |
||
64 | |||
65 | $this->type = $type->toNative(); |
||
66 | $this->startDate = $startDate; |
||
67 | $this->endDate = $endDate; |
||
68 | $this->timestamps = $timestamps; |
||
69 | $this->openingHours = $openingHours; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @inheritdoc |
||
74 | */ |
||
75 | public function getType() |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | public function serialize() |
||
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | public static function deserialize(array $data) |
||
134 | |||
135 | /** |
||
136 | * This deserialization function takes into account old data that might be missing a timezone. |
||
137 | * It will fall back to creating a DateTime object and assume Brussels. |
||
138 | * If this still fails an error will be thrown. |
||
139 | * |
||
140 | * @param $dateTimeData |
||
141 | * @return DateTime |
||
142 | * |
||
143 | * @throws InvalidArgumentException |
||
144 | */ |
||
145 | private static function deserializeDateTime($dateTimeData) |
||
159 | |||
160 | /** |
||
161 | * @inheritdoc |
||
162 | */ |
||
163 | public function getStartDate() |
||
167 | |||
168 | /** |
||
169 | * @inheritdoc |
||
170 | */ |
||
171 | public function getEndDate() |
||
175 | |||
176 | /** |
||
177 | * @inheritdoc |
||
178 | */ |
||
179 | public function getOpeningHours() |
||
183 | |||
184 | /** |
||
185 | * @inheritdoc |
||
186 | */ |
||
187 | public function getTimestamps() |
||
191 | |||
192 | /** |
||
193 | * Return the jsonLD version of a calendar. |
||
194 | */ |
||
195 | public function toJsonLd() |
||
234 | } |
||
235 |