| Total Complexity | 7 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 10 | class LocaleProvider implements LocaleProviderInterface |
||
| 11 | { |
||
| 12 | /** @var array */ |
||
| 13 | protected $locales; |
||
| 14 | |||
| 15 | /** @var string */ |
||
| 16 | protected $defaultLocale; |
||
| 17 | |||
| 18 | /** @var array */ |
||
| 19 | protected $requiredLocales; |
||
| 20 | |||
| 21 | public function __construct(array $locales, string $defaultLocale, array $requiredLocales = []) |
||
| 22 | { |
||
| 23 | if (empty($locales)) { |
||
| 24 | throw new \InvalidArgumentException('No locales were configured, but expected at least one locale. Check `i18n_form.locales` bundle configuration!'); |
||
| 25 | } |
||
| 26 | |||
| 27 | if (!\in_array($defaultLocale, $locales, true)) { |
||
| 28 | throw new \InvalidArgumentException(sprintf('Default locale `%s` not found within the configured locales `[%s]`. Perhaps you need to add it to your `i18n_form.locales` bundle configuration?', $defaultLocale, implode(',', $locales))); |
||
| 29 | } |
||
| 30 | |||
| 31 | if (array_diff($requiredLocales, $locales)) { |
||
| 32 | throw new \InvalidArgumentException('Required locales should be contained in locales'); |
||
| 33 | } |
||
| 34 | |||
| 35 | $this->locales = $locales; |
||
| 36 | $this->defaultLocale = $defaultLocale; |
||
| 37 | $this->requiredLocales = $requiredLocales; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * {@inheritdoc} |
||
| 42 | */ |
||
| 43 | public function getLocales(): array |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | public function getDefaultLocale(): string |
||
| 52 | { |
||
| 53 | return $this->defaultLocale; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | public function getRequiredLocales(): array |
||
| 62 | } |
||
| 63 | } |
||
| 64 |