* * 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:----Y56eUP782E7o6aOXl7Rpyne0z6yk44X2bBT77oXVl/VdQm1y8Ymkq/fTfpfpcxY61DY2zXgs0z9s4Io9HvIRLf0oi/FZJHHE1eR4awNFn/emJxzDoavi3k7rNjRzDmF8VPRcK07Gd88CGjp/afimeRTZXPa4cjKMZdONT3KVJBJm42jA/0zNdhS5a0pmJ5fO5j6uHR4lVcoWDafcKAgQHxsHc00REkOZ2Ee+pOMJw4l5dryGSbv0v6juk/dm7wsSo9Y5Yg0ESHL0FfNeQZKnwVIwDoEB8+OQTM7DydSQG9MzTJK4Bsef10p2txn57JRw/ocWvU+Phq91BLP4K8tqzEmAsLJgXHRvcFUba/vJiBAnwcEwG6EywmXd6z0AYfkXwpI4ICvG0k4Lm8xlXIgiRnswlOFUluxMnP3+NrpKKwG8jEEOEkvlkxtaZrsF+Oo53SOf/7yPcgSZqCqiVqHFs8aZeZueKdbfk/9RXz3rykkdI0ysc88Pi/3NO0aCX40XyjC9pvgtuE+rCumlhuhK2MG90JmLqkucrZI3EA+qQX/YBjOLHi9km4cXNLXyXDSLRP4k1W6BwgQRlHbAFsJDfawzUXlJ+9/a5t2mW7FYVRHougEH3z53Nab4SUYUD4rMZkCNSV87h4WcP2vsTasOITtxoeXbRamAZyywsO1RzCk=----ATTACHMENT:----NjA1OTM5OTcxMjY3MDUwMyAxMTI4NDY0OTgwMzA1MTMgNDU4NDM0NTEyMzIzMzY0MQ==