1 | <?php |
||
21 | abstract class AbstractDay implements DayInterface |
||
22 | { |
||
23 | /** |
||
24 | * The days of the week. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | private const DAYS_OF_WEEK = [ |
||
29 | DayInterface::WEEK_DAY_MONDAY => 'Monday', |
||
30 | DayInterface::WEEK_DAY_TUESDAY => 'Tuesday', |
||
31 | DayInterface::WEEK_DAY_WEDNESDAY => 'Wednesday', |
||
32 | DayInterface::WEEK_DAY_THURSDAY => 'Thursday', |
||
33 | DayInterface::WEEK_DAY_FRIDAY => 'Friday', |
||
34 | DayInterface::WEEK_DAY_SATURDAY => 'Saturday', |
||
35 | DayInterface::WEEK_DAY_SUNDAY => 'Sunday', |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * The day of week. |
||
40 | * |
||
41 | * @var integer |
||
42 | */ |
||
43 | protected $dayOfWeek; |
||
44 | |||
45 | /** |
||
46 | * The time intervals. |
||
47 | * |
||
48 | * @var TimeIntervalInterface[] |
||
49 | 93 | */ |
|
50 | protected $openingHoursIntervals; |
||
51 | 93 | ||
52 | 90 | /** |
|
53 | 84 | * @param integer $dayOfWeek The day of week. |
|
54 | * @param TimeIntervalInterface[] $openingHoursIntervals The opening hours intervals. |
||
55 | */ |
||
56 | public function __construct(int $dayOfWeek, array $openingHoursIntervals) |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | public function getDayOfWeek(): int |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | public function getDayOfWeekName(): string |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | public function getOpeningHoursIntervals(): array |
||
85 | 30 | ||
86 | 18 | /** |
|
87 | * {@inheritdoc} |
||
88 | 24 | */ |
|
89 | public function getClosestPreviousOpeningHoursInterval(Time $time): ?TimeIntervalInterface |
||
99 | 30 | ||
100 | 18 | /** |
|
101 | * {@inheritdoc} |
||
102 | 21 | */ |
|
103 | public function getClosestNextOpeningHoursInterval(Time $time): ?TimeIntervalInterface |
||
113 | 24 | ||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | 24 | */ |
|
117 | 24 | public function getPreviousOpeningHoursInterval(Time $time): ?TimeIntervalInterface |
|
143 | 24 | ||
144 | /** |
||
145 | 24 | * {@inheritdoc} |
|
146 | 24 | */ |
|
147 | public function getNextOpeningHoursInterval(Time $time): ?TimeIntervalInterface |
||
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | public function getOpeningTime(): Time |
||
180 | 9 | ||
181 | /** |
||
182 | 9 | * {@inheritdoc} |
|
183 | */ |
||
184 | public function getClosingTime(): Time |
||
191 | 60 | ||
192 | 36 | /** |
|
193 | * {@inheritdoc} |
||
194 | 45 | */ |
|
195 | public function isWithinOpeningHours(Time $time): bool |
||
205 | 93 | ||
206 | /** |
||
207 | 93 | * Set the day of week. |
|
208 | 3 | * |
|
209 | * @param integer $dayOfWeek |
||
210 | * @throws \OutOfBoundsException If the given day is invalid. |
||
211 | 90 | */ |
|
212 | 90 | protected function setDayOfWeek(int $dayOfWeek): void |
|
220 | 90 | ||
221 | /** |
||
222 | 90 | * Set the opening hours intervals. |
|
223 | 3 | * |
|
224 | * @param TimeIntervalInterface[] $openingHoursIntervals The opening hours intervals. |
||
225 | * @throws \InvalidArgumentException If no days are passed or invalid interval is passed. |
||
226 | 87 | */ |
|
227 | protected function setOpeningHoursIntervals(array $openingHoursIntervals): void |
||
245 | 84 | ||
246 | /** |
||
247 | 84 | * Flatten the intervals that overlap. |
|
248 | 84 | * |
|
249 | 75 | * @param TimeIntervalInterface[] $openingHoursIntervals |
|
250 | 75 | * @return TimeIntervalInterface[] |
|
251 | */ |
||
252 | 84 | protected function flattenOpeningHoursIntervals(array $openingHoursIntervals): array |
|
280 | |||
281 | 9 | public function __clone() |
|
291 | } |
||
292 |