Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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
 
12
namespace Symfony\Component\Translation\Provider;
13
 
14
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
15
 
16
/**
17
 * @author Mathieu Santostefano <msantostefano@protonmail.com>
18
 */
19
class TranslationProviderCollectionFactory
20
{
21
    private iterable $factories;
22
    private array $enabledLocales;
23
 
24
    /**
25
     * @param iterable<mixed, ProviderFactoryInterface> $factories
26
     */
27
    public function __construct(iterable $factories, array $enabledLocales)
28
    {
29
        $this->factories = $factories;
30
        $this->enabledLocales = $enabledLocales;
31
    }
32
 
33
    public function fromConfig(array $config): TranslationProviderCollection
34
    {
35
        $providers = [];
36
        foreach ($config as $name => $currentConfig) {
37
            $providers[$name] = $this->fromDsnObject(
38
                new Dsn($currentConfig['dsn']),
39
                !$currentConfig['locales'] ? $this->enabledLocales : $currentConfig['locales'],
40
                !$currentConfig['domains'] ? [] : $currentConfig['domains']
41
            );
42
        }
43
 
44
        return new TranslationProviderCollection($providers);
45
    }
46
 
47
    public function fromDsnObject(Dsn $dsn, array $locales, array $domains = []): ProviderInterface
48
    {
49
        foreach ($this->factories as $factory) {
50
            if ($factory->supports($dsn)) {
51
                return new FilteringProvider($factory->create($dsn), $locales, $domains);
52
            }
53
        }
54
 
55
        throw new UnsupportedSchemeException($dsn);
56
    }
57
}