@@ -143,6 +143,7 @@ public function addResource($format, $resource, $locale, $domain = null)
143
143
}
144
144
145
145
$ this ->assertValidLocale ($ locale );
146
+ $ locale ?: $ locale = class_exists (\Locale::class) ? \Locale::getDefault () : 'en ' ;
146
147
147
148
$ this ->resources [$ locale ][] = [$ format , $ resource , $ domain ];
148
149
@@ -163,15 +164,15 @@ public function setLocale($locale)
163
164
}
164
165
165
166
$ this ->assertValidLocale ($ locale );
166
- $ this ->locale = $ locale ?? ( class_exists (\Locale::class) ? \Locale:: getDefault () : ' en ' ) ;
167
+ $ this ->locale = $ locale ;
167
168
}
168
169
169
170
/**
170
171
* {@inheritdoc}
171
172
*/
172
173
public function getLocale ()
173
174
{
174
- return $ this ->locale ;
175
+ return $ this ->locale ?: ( class_exists (\Locale::class) ? \Locale:: getDefault () : ' en ' ) ;
175
176
}
176
177
177
178
/**
@@ -281,7 +282,7 @@ public function transChoice($id, $number, array $parameters = [], $domain = null
281
282
*/
282
283
public function getCatalogue ($ locale = null )
283
284
{
284
- if (null === $ locale ) {
285
+ if (! $ locale ) {
285
286
$ locale = $ this ->getLocale ();
286
287
} else {
287
288
$ this ->assertValidLocale ($ locale );
@@ -505,7 +506,7 @@ protected function computeFallbackLocales($locale)
505
506
*/
506
507
protected function assertValidLocale ($ locale )
507
508
{
508
- if (null !== $ locale && 1 !== preg_match ('/^[a-z0-9@_ \\. \\-]*$/i ' , $ locale )) {
509
+ if (! preg_match ('/^[a-z0-9@_ \\. \\-]*$/i ' , ( string ) $ locale )) {
509
510
throw new InvalidArgumentException (sprintf ('Invalid "%s" locale. ' , $ locale ));
510
511
}
511
512
}
0 commit comments