| 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\InvalidArgumentException; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
final class TranslationProviderCollection |
| 20 |
{ |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
private array $providers; |
| 25 |
|
| 26 |
|
| 27 |
|
| 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 |
} |