Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Provider/TranslationProviderCollectionFactory.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Translation\Provider;
13
14 use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
15
16 /**
17 * @author Mathieu Santostefano <[email protected]>
18 */
19 class TranslationProviderCollectionFactory
20 {
21 /**
22 * @param iterable<mixed, ProviderFactoryInterface> $factories
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 }