|
| 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\Bundle\FrameworkBundle\Test; |
| 13 | + |
| 14 | +use Psr\Container\ContainerInterface as PsrContainerInterface; |
| 15 | +use Symfony\Component\DependencyInjection\Container; |
| 16 | +use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface; |
| 17 | +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
| 18 | + |
| 19 | +/** |
| 20 | + * @author Nicolas Grekas <p@tchwork.com> |
| 21 | + */ |
| 22 | +class TestContainer extends Container |
| 23 | +{ |
| 24 | + private $publicContainer; |
| 25 | + private $privateContainer; |
| 26 | + |
| 27 | + public function __construct(?ParameterBagInterface $parameterBag, SymfonyContainerInterface $publicContainer, PsrContainerInterface $privateContainer) |
| 28 | + { |
| 29 | + $this->parameterBag = $parameterBag ?? $publicContainer->getParameterBag(); |
| 30 | + $this->publicContainer = $publicContainer; |
| 31 | + $this->privateContainer = $privateContainer; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * {@inheritdoc} |
| 36 | + */ |
| 37 | + public function compile() |
| 38 | + { |
| 39 | + $this->publicContainer->compile(); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * {@inheritdoc} |
| 44 | + */ |
| 45 | + public function isCompiled() |
| 46 | + { |
| 47 | + return $this->publicContainer->isCompiled(); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * {@inheritdoc} |
| 52 | + */ |
| 53 | + public function set($id, $service) |
| 54 | + { |
| 55 | + $this->publicContainer->set($id, $service); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * {@inheritdoc} |
| 60 | + */ |
| 61 | + public function has($id) |
| 62 | + { |
| 63 | + return $this->publicContainer->has($id) || $this->privateContainer->has($id); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * {@inheritdoc} |
| 68 | + */ |
| 69 | + public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1) |
| 70 | + { |
| 71 | + return $this->privateContainer->has($id) ? $this->privateContainer->get($id) : $this->publicContainer->get($id, $invalidBehavior); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * {@inheritdoc} |
| 76 | + */ |
| 77 | + public function initialized($id) |
| 78 | + { |
| 79 | + return $this->publicContainer->initialized($id); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * {@inheritdoc} |
| 84 | + */ |
| 85 | + public function reset() |
| 86 | + { |
| 87 | + $this->publicContainer->reset(); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * {@inheritdoc} |
| 92 | + */ |
| 93 | + public function getServiceIds() |
| 94 | + { |
| 95 | + return $this->publicContainer->getServiceIds(); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * {@inheritdoc} |
| 100 | + */ |
| 101 | + public function getRemovedIds() |
| 102 | + { |
| 103 | + return $this->publicContainer->getRemovedIds(); |
| 104 | + } |
| 105 | +} |
0 commit comments