@@ -28,7 +28,7 @@ class LocaleConfig
28
28
/**
29
29
* The configured route action that holds a route's locale.
30
30
*
31
- * @var string
31
+ * @var string|null
32
32
*/
33
33
protected $ routeAction ;
34
34
@@ -37,7 +37,7 @@ class LocaleConfig
37
37
*
38
38
* @param array $config
39
39
*/
40
- public function __construct ($ config = [])
40
+ public function __construct (array $ config = [])
41
41
{
42
42
$ this ->supportedLocales = $ config ['supported_locales ' ] ?? [];
43
43
$ this ->omittedLocale = $ config ['omitted_locale ' ] ?? null ;
@@ -50,7 +50,7 @@ public function __construct($config = [])
50
50
*
51
51
* @return array
52
52
*/
53
- public function getSupportedLocales ()
53
+ public function getSupportedLocales (): array
54
54
{
55
55
return $ this ->supportedLocales ;
56
56
}
@@ -62,7 +62,7 @@ public function getSupportedLocales()
62
62
*
63
63
* @return void
64
64
*/
65
- public function setSupportedLocales ($ locales )
65
+ public function setSupportedLocales (array $ locales ): void
66
66
{
67
67
$ this ->supportedLocales = $ locales ;
68
68
}
@@ -72,7 +72,7 @@ public function setSupportedLocales($locales)
72
72
*
73
73
* @return string|null
74
74
*/
75
- public function getOmittedLocale ()
75
+ public function getOmittedLocale (): ? string
76
76
{
77
77
return $ this ->omittedLocale ;
78
78
}
@@ -84,7 +84,7 @@ public function getOmittedLocale()
84
84
*
85
85
* @return void
86
86
*/
87
- public function setOmittedLocale ($ locale )
87
+ public function setOmittedLocale (? string $ locale ): void
88
88
{
89
89
$ this ->omittedLocale = $ locale ;
90
90
}
@@ -94,7 +94,7 @@ public function setOmittedLocale($locale)
94
94
*
95
95
* @return string|null
96
96
*/
97
- public function getFallbackLocale ()
97
+ public function getFallbackLocale (): ? string
98
98
{
99
99
return $ this ->fallbackLocale ;
100
100
}
@@ -106,39 +106,39 @@ public function getFallbackLocale()
106
106
*
107
107
* @return void
108
108
*/
109
- public function setFallbackLocale ($ locale )
109
+ public function setFallbackLocale (? string $ locale ): void
110
110
{
111
111
$ this ->fallbackLocale = $ locale ;
112
112
}
113
113
114
114
/**
115
115
* Get the route action that holds a route's locale.
116
116
*
117
- * @return string
117
+ * @return string|null
118
118
*/
119
- public function getRouteAction ()
119
+ public function getRouteAction (): ? string
120
120
{
121
121
return $ this ->routeAction ;
122
122
}
123
123
124
124
/**
125
125
* Set the route action that holds a route's locale.
126
126
*
127
- * @param string $locale
127
+ * @param string $action
128
128
*
129
129
* @return string
130
130
*/
131
- public function setRouteAction ($ locale )
131
+ public function setRouteAction (string $ action ): string
132
132
{
133
- return $ this ->routeAction = $ locale ;
133
+ return $ this ->routeAction = $ action ;
134
134
}
135
135
136
136
/**
137
137
* Get the locales (not the slugs or domains).
138
138
*
139
139
* @return array
140
140
*/
141
- public function getLocales ()
141
+ public function getLocales (): array
142
142
{
143
143
$ locales = $ this ->getSupportedLocales ();
144
144
@@ -156,7 +156,7 @@ public function getLocales()
156
156
*
157
157
* @return string|null
158
158
*/
159
- public function findSlugByLocale ($ locale )
159
+ public function findSlugByLocale (string $ locale ): ? string
160
160
{
161
161
if ( ! $ this ->isSupportedLocale ($ locale ) || $ this ->hasCustomDomains ()) {
162
162
return null ;
@@ -172,7 +172,7 @@ public function findSlugByLocale($locale)
172
172
*
173
173
* @return string|null
174
174
*/
175
- public function findDomainByLocale ($ locale )
175
+ public function findDomainByLocale (string $ locale ): ? string
176
176
{
177
177
if ( ! $ this ->isSupportedLocale ($ locale ) || ! $ this ->hasCustomDomains ()) {
178
178
return null ;
@@ -188,7 +188,7 @@ public function findDomainByLocale($locale)
188
188
*
189
189
* @return string|null
190
190
*/
191
- public function findLocaleBySlug ($ slug )
191
+ public function findLocaleBySlug (string $ slug ): ? string
192
192
{
193
193
if ($ this ->hasCustomDomains ()) {
194
194
return null ;
@@ -208,7 +208,7 @@ public function findLocaleBySlug($slug)
208
208
*
209
209
* @return string|null
210
210
*/
211
- public function findLocaleByDomain ($ domain )
211
+ public function findLocaleByDomain (string $ domain ): ? string
212
212
{
213
213
if ( ! $ this ->hasCustomDomains ()) {
214
214
return null ;
@@ -222,7 +222,7 @@ public function findLocaleByDomain($domain)
222
222
*
223
223
* @return bool
224
224
*/
225
- public function hasLocales ()
225
+ public function hasLocales (): bool
226
226
{
227
227
return count ($ this ->getSupportedLocales ()) > 0 ;
228
228
}
@@ -233,7 +233,7 @@ public function hasLocales()
233
233
*
234
234
* @return bool
235
235
*/
236
- public function hasSimpleLocales ()
236
+ public function hasSimpleLocales (): bool
237
237
{
238
238
return is_numeric (key ($ this ->getSupportedLocales ()));
239
239
}
@@ -243,7 +243,7 @@ public function hasSimpleLocales()
243
243
*
244
244
* @return bool
245
245
*/
246
- public function hasCustomSlugs ()
246
+ public function hasCustomSlugs (): bool
247
247
{
248
248
return $ this ->hasLocales () && ! $ this ->hasSimpleLocales () && ! $ this ->hasCustomDomains ();
249
249
}
@@ -253,7 +253,7 @@ public function hasCustomSlugs()
253
253
*
254
254
* @return bool
255
255
*/
256
- public function hasCustomDomains ()
256
+ public function hasCustomDomains (): bool
257
257
{
258
258
$ firstValue = array_values ($ this ->getSupportedLocales ())[0 ] ?? '' ;
259
259
$ containsDot = strpos ($ firstValue , '. ' ) !== false ;
@@ -264,11 +264,11 @@ public function hasCustomDomains()
264
264
/**
265
265
* Check if the given locale is supported.
266
266
*
267
- * @param string $locale
267
+ * @param string|null $locale
268
268
*
269
269
* @return bool
270
270
*/
271
- public function isSupportedLocale ($ locale )
271
+ public function isSupportedLocale (? string $ locale ): bool
272
272
{
273
273
return in_array ($ locale , $ this ->getLocales ());
274
274
}
0 commit comments