mailpoet
/
vendor-prefixed
/
symfony
/
translation
/
Provider
/
TranslationProviderCollectionFactory.php
AbstractProviderFactory.php
1 year ago
Dsn.php
1 year ago
FilteringProvider.php
1 year ago
NullProvider.php
1 year ago
NullProviderFactory.php
1 year ago
ProviderFactoryInterface.php
1 year ago
ProviderInterface.php
1 year ago
TranslationProviderCollection.php
1 year ago
TranslationProviderCollectionFactory.php
1 year ago
index.php
1 year ago
TranslationProviderCollectionFactory.php
32 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Translation\Provider; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Translation\Exception\UnsupportedSchemeException; |
| 5 | class TranslationProviderCollectionFactory |
| 6 | { |
| 7 | private $factories; |
| 8 | private $enabledLocales; |
| 9 | public function __construct(iterable $factories, array $enabledLocales) |
| 10 | { |
| 11 | $this->factories = $factories; |
| 12 | $this->enabledLocales = $enabledLocales; |
| 13 | } |
| 14 | public function fromConfig(array $config) : TranslationProviderCollection |
| 15 | { |
| 16 | $providers = []; |
| 17 | foreach ($config as $name => $currentConfig) { |
| 18 | $providers[$name] = $this->fromDsnObject(new Dsn($currentConfig['dsn']), !$currentConfig['locales'] ? $this->enabledLocales : $currentConfig['locales'], !$currentConfig['domains'] ? [] : $currentConfig['domains']); |
| 19 | } |
| 20 | return new TranslationProviderCollection($providers); |
| 21 | } |
| 22 | public function fromDsnObject(Dsn $dsn, array $locales, array $domains = []) : ProviderInterface |
| 23 | { |
| 24 | foreach ($this->factories as $factory) { |
| 25 | if ($factory->supports($dsn)) { |
| 26 | return new FilteringProvider($factory->create($dsn), $locales, $domains); |
| 27 | } |
| 28 | } |
| 29 | throw new UnsupportedSchemeException($dsn); |
| 30 | } |
| 31 | } |
| 32 |