1 | <?php |
||
26 | abstract class AbstractProvider |
||
27 | { |
||
28 | /** |
||
29 | * Timezone. |
||
30 | * |
||
31 | * @var DateTimeZone |
||
32 | */ |
||
33 | protected $timezone; |
||
34 | |||
35 | /** |
||
36 | * List of holidays by year. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | private $holidays = array(); |
||
41 | |||
42 | /** |
||
43 | * @param null|DateTimeZone $timezone (optional) Timezone |
||
44 | */ |
||
45 | 46 | public function __construct(DateTimeZone $timezone = null) |
|
49 | |||
50 | /** |
||
51 | * Prepare the holidays in given year. |
||
52 | * |
||
53 | * @param int $year The year to prepare the holidays for |
||
54 | * |
||
55 | * @return array An array of holidays |
||
56 | */ |
||
57 | abstract protected function prepareHolidays($year); |
||
58 | |||
59 | /** |
||
60 | * Returns timezone. |
||
61 | * |
||
62 | * @return DateTimeZone |
||
63 | */ |
||
64 | 30 | public function getTimeZone() |
|
68 | |||
69 | /** |
||
70 | * Creates a holiday object based on current timezone. |
||
71 | * |
||
72 | * @param string $name Name |
||
73 | * @param mixed $time Time |
||
74 | * @param string $type Type |
||
75 | * |
||
76 | * @return Holiday |
||
77 | */ |
||
78 | 28 | public function createHoliday($name, $time, $type = Holiday::TYPE_HOLIDAY) |
|
82 | |||
83 | /** |
||
84 | * Provides a DateTime object that represents easter sunday for this year.<br/> |
||
85 | * The time is always set to 00:00:00. |
||
86 | * |
||
87 | * @param int $year The year for which to calculcate the easter sunday date |
||
88 | * |
||
89 | * @throws InvalidArgumentException |
||
90 | * |
||
91 | * @return DateTime |
||
92 | */ |
||
93 | 26 | protected function getEaster($year) |
|
102 | |||
103 | /** |
||
104 | * Prepare the holidays in given year based on {@see prepareHolidays()}. |
||
105 | * |
||
106 | * @param int $year |
||
107 | * |
||
108 | * @throws UnexpectedValueException |
||
109 | */ |
||
110 | 34 | private function prepareHolidaysByYear($year) |
|
127 | |||
128 | /** |
||
129 | * Returns the holidays in given year. |
||
130 | * |
||
131 | * @param int $year The year to get the holidays for |
||
132 | * @param null|string $type (optional) Holiday type |
||
133 | * |
||
134 | * @throws InvalidArgumentException |
||
135 | * |
||
136 | * @return array An array of Holidays |
||
137 | */ |
||
138 | 34 | public function getHolidaysByYear($year, $type = null) |
|
154 | |||
155 | /** |
||
156 | * Returns all holidays in the given time period. |
||
157 | * |
||
158 | * @param DateTime $startDate The start date |
||
159 | * @param mixed $endDateOrType (optional) The end date or holiday type |
||
160 | * @param string $type (optional) Holiday type |
||
161 | * |
||
162 | * @return array |
||
163 | */ |
||
164 | 31 | public function getHolidays( |
|
202 | |||
203 | /** |
||
204 | * Returns true if any holiday exists in the given time period. |
||
205 | * |
||
206 | * @param DateTime $startDate The start date |
||
207 | * @param null|DateTime $endDate (optional) The end date |
||
208 | * @param null|string $type (optional) Holiday type |
||
209 | * |
||
210 | * @return bool |
||
211 | */ |
||
212 | 1 | public function hasHolidays( |
|
219 | |||
220 | /** |
||
221 | * Returns true if $date is a holiday. |
||
222 | * |
||
223 | * @param DateTime $date The date |
||
224 | * @param null|string $type (optional) Holiday type |
||
225 | * |
||
226 | * @return bool |
||
227 | */ |
||
228 | 1 | public function isHoliday(DateTime $date, $type = null) |
|
232 | } |
||
233 |