Argument
2 years ago
Attribute
2 years ago
Exception
2 years ago
ParameterBag
3 years ago
Alias.php
4 years ago
ChildDefinition.php
4 years ago
Container.php
2 years ago
ContainerAwareInterface.php
2 years ago
ContainerAwareTrait.php
2 years ago
ContainerBuilder.php
2 years ago
ContainerInterface.php
4 years ago
Definition.php
2 years ago
EnvVarLoaderInterface.php
4 years ago
EnvVarProcessor.php
2 years ago
EnvVarProcessorInterface.php
4 years ago
ExpressionLanguage.php
2 years ago
ExpressionLanguageProvider.php
2 years ago
Parameter.php
4 years ago
Reference.php
4 years ago
ReverseContainer.php
2 years ago
ServiceLocator.php
2 years ago
TaggedContainerInterface.php
4 years ago
TypedReference.php
2 years ago
Variable.php
4 years ago
index.php
3 years ago
ReverseContainer.php
45 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\DependencyInjection; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Psr\Container\ContainerInterface; |
| 5 | use MailPoetVendor\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
| 6 | final class ReverseContainer |
| 7 | { |
| 8 | private $serviceContainer; |
| 9 | private $reversibleLocator; |
| 10 | private $tagName; |
| 11 | private $getServiceId; |
| 12 | public function __construct(Container $serviceContainer, ContainerInterface $reversibleLocator, string $tagName = 'container.reversible') |
| 13 | { |
| 14 | $this->serviceContainer = $serviceContainer; |
| 15 | $this->reversibleLocator = $reversibleLocator; |
| 16 | $this->tagName = $tagName; |
| 17 | $this->getServiceId = \Closure::bind(function (object $service) : ?string { |
| 18 | return (\array_search($service, $this->services, \true) ?: \array_search($service, $this->privates, \true)) ?: null; |
| 19 | }, $serviceContainer, Container::class); |
| 20 | } |
| 21 | public function getId(object $service) : ?string |
| 22 | { |
| 23 | if ($this->serviceContainer === $service) { |
| 24 | return 'service_container'; |
| 25 | } |
| 26 | if (null === ($id = ($this->getServiceId)($service))) { |
| 27 | return null; |
| 28 | } |
| 29 | if ($this->serviceContainer->has($id) || $this->reversibleLocator->has($id)) { |
| 30 | return $id; |
| 31 | } |
| 32 | return null; |
| 33 | } |
| 34 | public function getService(string $id) : object |
| 35 | { |
| 36 | if ($this->reversibleLocator->has($id)) { |
| 37 | return $this->reversibleLocator->get($id); |
| 38 | } |
| 39 | if (isset($this->serviceContainer->getRemovedIds()[$id])) { |
| 40 | throw new ServiceNotFoundException($id, null, null, [], \sprintf('The "%s" service is private and cannot be accessed by reference. You should either make it public, or tag it as "%s".', $id, $this->tagName)); |
| 41 | } |
| 42 | return $this->serviceContainer->get($id); |
| 43 | } |
| 44 | } |
| 45 |