1 | <?php |
||
14 | class OpeningHoursForDay implements ArrayAccess, Countable, IteratorAggregate |
||
15 | { |
||
16 | use DataTrait; |
||
17 | |||
18 | /** @var \Spatie\OpeningHours\TimeRange[] */ |
||
19 | protected $openingHours = []; |
||
20 | |||
21 | public static function fromStrings(array $strings) |
||
22 | { |
||
23 | if (isset($strings['hours'])) { |
||
24 | return static::fromStrings($strings['hours'])->setData($strings['data'] ?? null); |
||
25 | } |
||
26 | |||
27 | $openingHoursForDay = new static(); |
||
28 | |||
29 | if (isset($strings['data'])) { |
||
30 | $openingHoursForDay->setData($strings['data'] ?? null); |
||
31 | unset($strings['data']); |
||
32 | } |
||
33 | |||
34 | $timeRanges = Arr::map($strings, function ($string) { |
||
35 | return TimeRange::fromDefinition($string); |
||
36 | }); |
||
37 | |||
38 | $openingHoursForDay->guardAgainstTimeRangeOverlaps($timeRanges); |
||
39 | |||
40 | $openingHoursForDay->openingHours = $timeRanges; |
||
41 | |||
42 | return $openingHoursForDay; |
||
43 | } |
||
44 | |||
45 | public function isOpenAt(Time $time) |
||
55 | |||
56 | public function isOpenAtNight(Time $time) |
||
66 | |||
67 | /** |
||
68 | * @param callable[] $filters |
||
69 | * |
||
70 | * @return Time|bool |
||
71 | */ |
||
72 | public function openingHoursFilter(array $filters) |
||
86 | |||
87 | /** |
||
88 | * @param Time $time |
||
89 | * |
||
90 | * @return bool|Time |
||
91 | */ |
||
92 | public function nextOpen(Time $time) |
||
100 | |||
101 | /** |
||
102 | * @param Time $time |
||
103 | * |
||
104 | * @return bool|Time |
||
105 | */ |
||
106 | public function nextClose(Time $time) |
||
117 | |||
118 | protected function findNextOpenInFreeTime(Time $time, TimeRange $timeRange) |
||
124 | |||
125 | protected function findNextCloseInWorkingHours(Time $time, TimeRange $timeRange) |
||
131 | |||
132 | protected function findNextCloseInFreeTime(Time $time, TimeRange $timeRange) |
||
138 | |||
139 | public function offsetExists($offset): bool |
||
143 | |||
144 | public function offsetGet($offset) |
||
148 | |||
149 | public function offsetSet($offset, $value) |
||
153 | |||
154 | public function offsetUnset($offset) |
||
158 | |||
159 | public function count(): int |
||
163 | |||
164 | public function getIterator() |
||
168 | |||
169 | public function isEmpty(): bool |
||
173 | |||
174 | public function map(callable $callback): array |
||
178 | |||
179 | protected function guardAgainstTimeRangeOverlaps(array $openingHours) |
||
187 | |||
188 | public function __toString() |
||
197 | } |
||
198 |