independent-analytics
/
vendor
/
symfony
/
translation
/
Provider
/
TranslationProviderCollectionFactory.php
AbstractProviderFactory.php
1 month ago
Dsn.php
1 month ago
FilteringProvider.php
1 month ago
NullProvider.php
2 years ago
NullProviderFactory.php
2 years ago
ProviderFactoryInterface.php
2 years ago
ProviderInterface.php
2 years ago
TranslationProviderCollection.php
2 years ago
TranslationProviderCollectionFactory.php
1 month ago
TranslationProviderCollectionFactory.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace IAWPSCOPED\Symfony\Component\Translation\Provider; |
| 12 | |
| 13 | use IAWPSCOPED\Symfony\Component\Translation\Exception\UnsupportedSchemeException; |
| 14 | /** |
| 15 | * @author Mathieu Santostefano <msantostefano@protonmail.com> |
| 16 | * @internal |
| 17 | */ |
| 18 | class TranslationProviderCollectionFactory |
| 19 | { |
| 20 | private iterable $factories; |
| 21 | private array $enabledLocales; |
| 22 | /** |
| 23 | * @param iterable<mixed, ProviderFactoryInterface> $factories |
| 24 | */ |
| 25 | public function __construct(iterable $factories, array $enabledLocales) |
| 26 | { |
| 27 | $this->factories = $factories; |
| 28 | $this->enabledLocales = $enabledLocales; |
| 29 | } |
| 30 | public function fromConfig(array $config) : TranslationProviderCollection |
| 31 | { |
| 32 | $providers = []; |
| 33 | foreach ($config as $name => $currentConfig) { |
| 34 | $providers[$name] = $this->fromDsnObject(new Dsn($currentConfig['dsn']), !$currentConfig['locales'] ? $this->enabledLocales : $currentConfig['locales'], !$currentConfig['domains'] ? [] : $currentConfig['domains']); |
| 35 | } |
| 36 | return new TranslationProviderCollection($providers); |
| 37 | } |
| 38 | public function fromDsnObject(Dsn $dsn, array $locales, array $domains = []) : ProviderInterface |
| 39 | { |
| 40 | foreach ($this->factories as $factory) { |
| 41 | if ($factory->supports($dsn)) { |
| 42 | return new FilteringProvider($factory->create($dsn), $locales, $domains); |
| 43 | } |
| 44 | } |
| 45 | throw new UnsupportedSchemeException($dsn); |
| 46 | } |
| 47 | } |
| 48 |