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\InvalidArgumentException;
15
 
16
/**
17
 * @author Mathieu Santostefano <msantostefano@protonmail.com>
18
 */
19
final class TranslationProviderCollection
20
{
21
    /**
22
     * @var array<string, ProviderInterface>
23
     */
24
    private $providers;
25
 
26
    /**
27
     * @param array<string, ProviderInterface> $providers
28
     */
29
    public function __construct(iterable $providers)
30
    {
31
        $this->providers = \is_array($providers) ? $providers : iterator_to_array($providers);
32
    }
33
 
34
    public function __toString(): string
35
    {
36
        return '['.implode(',', array_keys($this->providers)).']';
37
    }
38
 
39
    public function has(string $name): bool
40
    {
41
        return isset($this->providers[$name]);
42
    }
43
 
44
    public function get(string $name): ProviderInterface
45
    {
46
        if (!$this->has($name)) {
47
            throw new InvalidArgumentException(sprintf('Provider "%s" not found. Available: "%s".', $name, (string) $this));
48
        }
49
 
50
        return $this->providers[$name];
51
    }
52
 
53
    public function keys(): array
54
    {
55
        return array_keys($this->providers);
56
    }
57
}