1 | <?php |
||
7 | class PhpWeekday |
||
8 | { |
||
9 | /** |
||
10 | * The locale of the application. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $locale; |
||
15 | |||
16 | /** |
||
17 | * The name of the weekday. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $name; |
||
22 | |||
23 | /** |
||
24 | * The value of the weekday. |
||
25 | * |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $value; |
||
29 | |||
30 | /** |
||
31 | * The list of supported locales. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected static $locales = []; |
||
36 | |||
37 | /** |
||
38 | * Constructor of the class. |
||
39 | * |
||
40 | * @param string|int $value |
||
41 | * @param string $locale |
||
42 | * @param bool $force |
||
43 | * @return self |
||
|
|||
44 | */ |
||
45 | public function __construct($value, string $locale, bool $force = false) |
||
56 | |||
57 | /** |
||
58 | * Retrieve the current locale. |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | public function getLocale() : string |
||
66 | |||
67 | /** |
||
68 | * Retrieve the supported locales. |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | public static function getLocales() : array |
||
76 | |||
77 | /** |
||
78 | * Retrieve the name of the weekday. |
||
79 | * |
||
80 | * @param string $locale |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getName(string $locale = null) : string |
||
95 | |||
96 | /** |
||
97 | * Retrieve the name from a value. |
||
98 | * |
||
99 | * @param int $value |
||
100 | * @param string $locale |
||
101 | * @return string |
||
102 | */ |
||
103 | public static function getNameFromValue(int $value, string $locale) : string |
||
107 | |||
108 | /** |
||
109 | * Retrieve the names of every weekday for a locale. |
||
110 | * |
||
111 | * @param string $locale |
||
112 | * @return array |
||
113 | */ |
||
114 | public static function getNames(string $locale) : array |
||
124 | |||
125 | /** |
||
126 | * Retrieve the value of the weekday. |
||
127 | * |
||
128 | * @return int |
||
129 | */ |
||
130 | public function getValue() : int |
||
138 | |||
139 | /** |
||
140 | * Retrieve the value from a name. |
||
141 | * |
||
142 | * @param string $name |
||
143 | * @param string $locale |
||
144 | * @return string |
||
145 | */ |
||
146 | public static function getValueFromName(string $name, string $locale) : string |
||
150 | |||
151 | /** |
||
152 | * Check if the locales has been loaded. |
||
153 | * |
||
154 | * @return bool |
||
155 | */ |
||
156 | public function hasLoadedLocales() : bool |
||
160 | |||
161 | /** |
||
162 | * Check if the locales has not been loaded yet. |
||
163 | * |
||
164 | * @return bool |
||
165 | */ |
||
166 | public function hasNotLoadedLocales() : bool |
||
170 | |||
171 | /** |
||
172 | * Check if the locale is supported. |
||
173 | * |
||
174 | * @param string $locales |
||
175 | * @return bool |
||
176 | */ |
||
177 | public function isSupported(string $locale) : bool |
||
181 | |||
182 | /** |
||
183 | * Check if the locale is not supported. |
||
184 | * |
||
185 | * @param string $locales |
||
186 | * @return bool |
||
187 | */ |
||
188 | public function isNotSupported(string $locale) : bool |
||
192 | |||
193 | /** |
||
194 | * Create a new instance from a value. |
||
195 | * |
||
196 | * @param string|int $value |
||
197 | * @param string $locale |
||
198 | * @param bool $force |
||
199 | * @return self |
||
200 | */ |
||
201 | public static function parse($value, string $locale, bool $force = false) |
||
205 | |||
206 | /** |
||
207 | * Parse the name of the weekday based on the value. |
||
208 | * |
||
209 | * @param int $value |
||
210 | * @param string $locale |
||
211 | * @return string |
||
212 | */ |
||
213 | public function parseName(int $value, string $locale = null) : string |
||
223 | |||
224 | /** |
||
225 | * Parse the value from the weekday name. |
||
226 | * |
||
227 | * @param string $name |
||
228 | * @param string $locale |
||
229 | * @return int |
||
230 | */ |
||
231 | public function parseValue(string $name, string $locale = null) : int |
||
255 | |||
256 | /** |
||
257 | * Refresh the list of supported locales. |
||
258 | * |
||
259 | * @return array |
||
260 | */ |
||
261 | protected static function refreshLocales() : array |
||
270 | |||
271 | /** |
||
272 | * Set the weekday based on the integer or string value. |
||
273 | * |
||
274 | * @param string|int $value |
||
275 | * @return self |
||
276 | */ |
||
277 | public function set($value) : self |
||
289 | |||
290 | /** |
||
291 | * Set the locale of the instance. |
||
292 | * |
||
293 | * @param string $locale |
||
294 | * @return self |
||
295 | */ |
||
296 | public function setLocale(string $locale) : self |
||
309 | |||
310 | /** |
||
311 | * Throw an exception to let the user know that the locale is not yet |
||
312 | * supported. |
||
313 | * |
||
314 | * @param string $locale |
||
315 | * @return void |
||
316 | */ |
||
317 | protected static function throwNotSupportedLocaleException(string $locale) : void |
||
323 | } |
||
324 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.