Created
November 2, 2021 05:59
-
-
Save koyablue/c00482616b954c51babb350dc151ad9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Packages\FrontPage\Shared\Domain\Models; | |
use InvalidArgumentException; | |
class Locale | |
{ | |
private const LOCALE = [ | |
'en', | |
'ja', | |
'pt', | |
'vi', | |
'zh', | |
]; | |
private string $locale; | |
public function __construct(string $locale) | |
{ | |
if (!$this->isValidLocale($locale)) { | |
throw new InvalidArgumentException(); | |
} | |
$this->locale = $locale; | |
} | |
public function getLocale(): string | |
{ | |
return $this->locale; | |
} | |
/** | |
* 設定できるlocaleの値の配列を返す | |
* | |
* @return array | |
*/ | |
public static function availableLocales(): array | |
{ | |
return self::LOCALE; | |
} | |
private function isValidLocale(string $locale): bool | |
{ | |
return in_array($locale, self::LOCALE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment