Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Provider/TranslationProviderCollection.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\InvalidArgumentException;
15
16 /**
17 * @author Mathieu Santostefano <[email protected]>
18 */
19 final class TranslationProviderCollection
20 {
21 /**
22 * @var array<string, ProviderInterface>
23 */
24 private array $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 }