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 | * Constructor of the class. |
||
32 | * |
||
33 | * @param string|int $value |
||
34 | * @param string $locale |
||
35 | * @return self |
||
|
|||
36 | */ |
||
37 | public function __construct($value, string $locale, bool $force = false) |
||
44 | |||
45 | /** |
||
46 | * Retrieve the current locale. |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getLocale() : string |
||
54 | |||
55 | /** |
||
56 | * Retrieve the supported locales. |
||
57 | * |
||
58 | * @return array |
||
59 | */ |
||
60 | public static function getLocales() : array |
||
67 | |||
68 | /** |
||
69 | * Retrieve the name of the weekday. |
||
70 | * |
||
71 | * @param string $locale |
||
72 | * @return string |
||
73 | */ |
||
74 | public function getName(string $locale = null) : string |
||
86 | |||
87 | /** |
||
88 | * Retrieve the name from a value. |
||
89 | * |
||
90 | * @param int $value |
||
91 | * @param string $locale |
||
92 | * @return string |
||
93 | */ |
||
94 | public static function getNameFromValue(int $value, string $locale) : string |
||
98 | |||
99 | /** |
||
100 | * Retrieve the names of every weekday for a locale. |
||
101 | * |
||
102 | * @param string $locale |
||
103 | * @return array |
||
104 | */ |
||
105 | public static function getNames(string $locale) : array |
||
115 | |||
116 | /** |
||
117 | * Retrieve the value of the weekday. |
||
118 | * |
||
119 | * @return int |
||
120 | */ |
||
121 | public function getValue() : int |
||
129 | |||
130 | /** |
||
131 | * Retrieve the value from a name. |
||
132 | * |
||
133 | * @param string $name |
||
134 | * @param string $locale |
||
135 | * @return string |
||
136 | */ |
||
137 | public static function getValueFromName(string $name, string $locale) : string |
||
141 | |||
142 | /** |
||
143 | * Check if the locale is supported. |
||
144 | * |
||
145 | * @param string $locales |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function isSupported(string $locale) : bool |
||
152 | |||
153 | /** |
||
154 | * Check if the locale is not supported. |
||
155 | * |
||
156 | * @param string $locales |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function isNotSupported(string $locale) : bool |
||
163 | |||
164 | /** |
||
165 | * Create a new instance from a value. |
||
166 | * |
||
167 | * @param string|int $value |
||
168 | * @param string $locale |
||
169 | * @return self |
||
170 | */ |
||
171 | public static function parse($value, string $locale) |
||
175 | |||
176 | /** |
||
177 | * Parse the name of the weekday based on the value. |
||
178 | * |
||
179 | * @param int $value |
||
180 | * @param string $locale |
||
181 | * @return string |
||
182 | */ |
||
183 | public function parseName(int $value, string $locale = null) : string |
||
193 | |||
194 | /** |
||
195 | * Parse the value from the weekday name. |
||
196 | * |
||
197 | * @param string $name |
||
198 | * @param string $locale |
||
199 | * @return int |
||
200 | */ |
||
201 | public function parseValue(string $name, string $locale = null) : int |
||
225 | |||
226 | /** |
||
227 | * Set the weekday based on the integer or string value. |
||
228 | * |
||
229 | * @param string|int $value |
||
230 | * @return self |
||
231 | */ |
||
232 | public function set($value) : self |
||
244 | |||
245 | /** |
||
246 | * Set the locale of the instance. |
||
247 | * |
||
248 | * @param string $locale |
||
249 | * @return self |
||
250 | */ |
||
251 | public function setLocale(string $locale) : self |
||
264 | |||
265 | /** |
||
266 | * Throw an exception to let the user know that the locale is not yet |
||
267 | * supported. |
||
268 | * |
||
269 | * @param string $locale |
||
270 | * @return void |
||
271 | */ |
||
272 | protected static function throwNotSupportedLocaleException(string $locale) : void |
||
278 | } |
||
279 |
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.