Skip to content

Instantly share code, notes, and snippets.

@koyablue
Created November 2, 2021 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koyablue/c00482616b954c51babb350dc151ad9d to your computer and use it in GitHub Desktop.
Save koyablue/c00482616b954c51babb350dc151ad9d to your computer and use it in GitHub Desktop.
<?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