independent-analytics
/
vendor
/
symfony
/
translation
/
Provider
/
TranslationProviderCollection.php
AbstractProviderFactory.php
1 month ago
Dsn.php
1 month ago
FilteringProvider.php
1 month ago
NullProvider.php
2 years ago
NullProviderFactory.php
2 years ago
ProviderFactoryInterface.php
2 years ago
ProviderInterface.php
2 years ago
TranslationProviderCollection.php
2 years ago
TranslationProviderCollectionFactory.php
1 month ago
TranslationProviderCollection.php
51 lines
| 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 | namespace IAWPSCOPED\Symfony\Component\Translation\Provider; |
| 12 | |
| 13 | use IAWPSCOPED\Symfony\Component\Translation\Exception\InvalidArgumentException; |
| 14 | /** |
| 15 | * @author Mathieu Santostefano <msantostefano@protonmail.com> |
| 16 | * @internal |
| 17 | */ |
| 18 | final class TranslationProviderCollection |
| 19 | { |
| 20 | /** |
| 21 | * @var array<string, ProviderInterface> |
| 22 | */ |
| 23 | private $providers; |
| 24 | /** |
| 25 | * @param array<string, ProviderInterface> $providers |
| 26 | */ |
| 27 | public function __construct(iterable $providers) |
| 28 | { |
| 29 | $this->providers = \is_array($providers) ? $providers : \iterator_to_array($providers); |
| 30 | } |
| 31 | public function __toString() : string |
| 32 | { |
| 33 | return '[' . \implode(',', \array_keys($this->providers)) . ']'; |
| 34 | } |
| 35 | public function has(string $name) : bool |
| 36 | { |
| 37 | return isset($this->providers[$name]); |
| 38 | } |
| 39 | public function get(string $name) : ProviderInterface |
| 40 | { |
| 41 | if (!$this->has($name)) { |
| 42 | throw new InvalidArgumentException(\sprintf('Provider "%s" not found. Available: "%s".', $name, (string) $this)); |
| 43 | } |
| 44 | return $this->providers[$name]; |
| 45 | } |
| 46 | public function keys() : array |
| 47 | { |
| 48 | return \array_keys($this->providers); |
| 49 | } |
| 50 | } |
| 51 |