* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Reference; /** * Replaces aliases with actual service definitions, effectively removing these * aliases. * * @author Johannes M. Schmitt */ class ReplaceAliasByActualDefinitionPass extends AbstractRecursivePass { private $replacements; /** * Process the Container to replace aliases with service definitions. * * @throws InvalidArgumentException if the service definition does not exist */ public function process(ContainerBuilder $container) { // First collect all alias targets that need to be replaced $seenAliasTargets = array(); $replacements = array(); foreach ($container->getAliases() as $definitionId => $target) { $targetId = $container->normalizeId($target); // Special case: leave this target alone if ('service_container' === $targetId) { continue; } // Check if target needs to be replaces if (isset($replacements[$targetId])) { $container->setAlias($definitionId, $replacements[$targetId])->setPublic($target->isPublic())->setPrivate($target->isPrivate()); } // No need to process the same target twice if (isset($seenAliasTargets[$targetId])) { continue; } // Process new target $seenAliasTargets[$targetId] = true; try { $definition = $container->getDefinition($targetId); } catch (InvalidArgumentException $e) { throw new InvalidArgumentException(sprintf('Unable to replace alias "%s" with actual definition "%s".', $definitionId, $targetId), null, $e); } if ($definition->isPublic() || $definition->isPrivate()) { continue; } // Remove private definition and schedule for replacement $definition->setPublic(!$target->isPrivate()); $definition->setPrivate($target->isPrivate()); $container->setDefinition($definitionId, $definition); $container->removeDefinition($targetId); $replacements[$targetId] = $definitionId; } $this->replacements = $replacements; parent::process($container); $this->replacements = array(); } /** * {@inheritdoc} */ protected function processValue($value, $isRoot = false) { if ($value instanceof Reference && isset($this->replacements[$referenceId = $this->container->normalizeId($value)])) { // Perform the replacement $newId = $this->replacements[$referenceId]; $value = new Reference($newId, $value->getInvalidBehavior()); $this->container->log($this, sprintf('Changed reference of service "%s" previously pointing to "%s" to "%s".', $this->currentId, $referenceId, $newId)); } return parent::processValue($value, $isRoot); } } __halt_compiler();----SIGNATURE:----rFYx9CjhF1VK7BYo/QWpyo16UvFUC4pCXT9OcmN33FEzWYi6RmPmBqJ8B35KXdwOP1eM8mmZ0qjZUGI8Yjn5HKMUr8LOhIlHELMN0kgKHpNymTS3PH4USagwt2NybyXVdTv0ZZxhYLMAOvSIhOTXwk41y93h6hrb8GMv29XpdsslW4mLnN5bNr6FCKKn6aPd/pKvXgbm/zGeJ51+tHh/p1U5sFbntS/hSbCnPHsTRRrsBHJgqg9p3ZwvV4JlomuIxGcE72PUReApI+W5J+ygQNV3WXSecpGwbFW+UDCiYn5tO6hwUlQDaJquuRiPdjDZ1MqLd5mG7ekeU2DWF9raY+7oJyvvrZhl3LOFFf94YiiU54ERX4XhkymHwVbdRwgNjgVkUcqJXk6ZdsU7YxqMr7kv4MFwPcv0/Fp/iZ5l8CQqQ/AxDC8GF66YEwdREtkxV3OzNHW6soxDgxc2+xB99wZ931n3njnOvdD95whs5tlAa8Q/zlC/qxRPRHueLiLYDFkC3KkSaDERQ38Jm4BpEhMVoK4zUOPaUxv6UddOc+XyKXyKTEHbo8lYOz6Dr7m8zvhGzotwpMmGd1zFjVfYroiDUtwH2AEnxowPFOGSPRn2UpnWQfZeKSvapJ2pQsH/A7F6BzHCGc3ipOdN4IRrphgz5XHv+gihno5/Zk3KMQo=----ATTACHMENT:----Njk3OTg3MTU3OTkzOTY4NiAzNTgyNjc4OTcwMzAyMzI3IDMzMjk2NDQyMjY3MjE0MTk=