1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TranslationFormBundle package. |
7
|
|
|
* |
8
|
|
|
* (c) David ALLIX <http://a2lix.fr> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace A2lix\TranslationFormBundle\Locale; |
15
|
|
|
|
16
|
|
|
class SimpleProvider implements LocaleProviderInterface |
17
|
|
|
{ |
18
|
|
|
/** @var array */ |
19
|
|
|
protected $locales; |
20
|
|
|
/** @var string */ |
21
|
|
|
protected $defaultLocale; |
22
|
|
|
/** @var array */ |
23
|
|
|
protected $requiredLocales; |
24
|
|
|
|
25
|
13 |
|
public function __construct(array $locales, string $defaultLocale, array $requiredLocales = []) |
26
|
|
|
{ |
27
|
13 |
|
if (!in_array($defaultLocale, $locales, true)) { |
28
|
1 |
|
if (count($locales)) { |
29
|
1 |
|
throw new \InvalidArgumentException(sprintf('Default locale `%s` not found within the configured locales `[%s]`. Perhaps you need to add it to your `a2lix_translation_form.locales` bundle configuration?', $defaultLocale, implode(',', $locales))); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
throw new \InvalidArgumentException(sprintf('No locales were configured, but expected at least the default locale `%s`. Perhaps you need to add it to your `a2lix_translation_form.locales` bundle configuration?', $defaultLocale)); |
33
|
|
|
} |
34
|
|
|
|
35
|
13 |
|
if (array_diff($requiredLocales, $locales)) { |
36
|
1 |
|
throw new \InvalidArgumentException('Required locales should be contained in locales'); |
37
|
|
|
} |
38
|
|
|
|
39
|
13 |
|
$this->locales = $locales; |
40
|
13 |
|
$this->defaultLocale = $defaultLocale; |
41
|
13 |
|
$this->requiredLocales = $requiredLocales; |
42
|
13 |
|
} |
43
|
|
|
|
44
|
10 |
|
public function getLocales(): array |
45
|
|
|
{ |
46
|
10 |
|
return $this->locales; |
47
|
|
|
} |
48
|
|
|
|
49
|
10 |
|
public function getDefaultLocale(): string |
50
|
|
|
{ |
51
|
10 |
|
return $this->defaultLocale; |
52
|
|
|
} |
53
|
|
|
|
54
|
9 |
|
public function getRequiredLocales(): array |
55
|
|
|
{ |
56
|
9 |
|
return $this->requiredLocales; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|