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');