| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\Provider; |
| 13 |
|
| 14 |
use Symfony\Component\Translation\Exception\UnsupportedSchemeException; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
class TranslationProviderCollectionFactory |
| 20 |
{ |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public function __construct( |
| 25 |
private iterable $factories, |
| 26 |
private array $enabledLocales, |
| 27 |
) { |
| 28 |
} |
| 29 |
|
| 30 |
public function fromConfig(array $config): TranslationProviderCollection |
| 31 |
{ |
| 32 |
$providers = []; |
| 33 |
foreach ($config as $name => $currentConfig) { |
| 34 |
$providers[$name] = $this->fromDsnObject( |
| 35 |
new Dsn($currentConfig['dsn']), |
| 36 |
!$currentConfig['locales'] ? $this->enabledLocales : $currentConfig['locales'], |
| 37 |
!$currentConfig['domains'] ? [] : $currentConfig['domains'] |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
return new TranslationProviderCollection($providers); |
| 42 |
} |
| 43 |
|
| 44 |
public function fromDsnObject(Dsn $dsn, array $locales, array $domains = []): ProviderInterface |
| 45 |
{ |
| 46 |
foreach ($this->factories as $factory) { |
| 47 |
if ($factory->supports($dsn)) { |
| 48 |
return new FilteringProvider($factory->create($dsn), $locales, $domains); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
throw new UnsupportedSchemeException($dsn); |
| 53 |
} |
| 54 |
} |