1 | <?php |
||
8 | class Weekday |
||
9 | { |
||
10 | use HasVerboseLocalization; |
||
11 | |||
12 | /** |
||
13 | * The locale of the application. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $locale; |
||
18 | |||
19 | /** |
||
20 | * The name of the weekday. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $name; |
||
25 | |||
26 | /** |
||
27 | * The value of the weekday. |
||
28 | * |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $value; |
||
32 | |||
33 | /** |
||
34 | * Constructor of the class. |
||
35 | * |
||
36 | * @param string|int $value |
||
37 | * @param string $locale |
||
38 | */ |
||
39 | public function __construct($value, string $locale) |
||
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 translation in a specific locale. |
||
118 | * |
||
119 | * @param string $locale |
||
120 | * @return string |
||
121 | */ |
||
122 | public function getTranslationIn(string $locale) : string |
||
126 | |||
127 | /** |
||
128 | * Retrieve the value of the weekday. |
||
129 | * |
||
130 | * @return int |
||
131 | */ |
||
132 | public function getValue() : int |
||
140 | |||
141 | /** |
||
142 | * Retrieve the value from a name. |
||
143 | * |
||
144 | * @param string $name |
||
145 | * @param string $locale |
||
146 | * @return string |
||
147 | */ |
||
148 | public static function getValueFromName(string $name, string $locale) : string |
||
152 | |||
153 | /** |
||
154 | * Check if the locale is supported. |
||
155 | * |
||
156 | * @param string $locale |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function isSupported(string $locale) : bool |
||
163 | |||
164 | /** |
||
165 | * Check if the locale is not supported. |
||
166 | * |
||
167 | * @param string $locale |
||
168 | * @return bool |
||
169 | */ |
||
170 | public function isNotSupported(string $locale) : bool |
||
174 | |||
175 | /** |
||
176 | * Create a new instance from a value. |
||
177 | * |
||
178 | * @param string|int $value |
||
179 | * @param string $locale |
||
180 | * @return self |
||
181 | */ |
||
182 | public static function parse($value, string $locale) |
||
186 | |||
187 | /** |
||
188 | * Parse the name of the weekday based on the value. |
||
189 | * |
||
190 | * @param int $value |
||
191 | * @param string $locale |
||
192 | * @return string |
||
193 | */ |
||
194 | public function parseName(int $value, string $locale = null) : string |
||
204 | |||
205 | /** |
||
206 | * Parse the value from the weekday name. |
||
207 | * |
||
208 | * @param string $name |
||
209 | * @param string $locale |
||
210 | * @return int |
||
211 | */ |
||
212 | public function parseValue(string $name, string $locale = null) : int |
||
236 | |||
237 | /** |
||
238 | * Set the weekday based on the integer or string value. |
||
239 | * |
||
240 | * @param string|int $value |
||
241 | * @return self |
||
242 | */ |
||
243 | public function set($value) : self |
||
255 | |||
256 | /** |
||
257 | * Set the locale of the instance. |
||
258 | * |
||
259 | * @param string $locale |
||
260 | * @return self |
||
261 | */ |
||
262 | public function setLocale(string $locale) : self |
||
275 | |||
276 | /** |
||
277 | * Throw an exception to let the user know that the locale is not yet |
||
278 | * supported. |
||
279 | * |
||
280 | * @param string $locale |
||
281 | * @return void |
||
282 | */ |
||
283 | protected static function throwNotSupportedLocaleException(string $locale) : void |
||
289 | } |
||
290 |