* * 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:----ZG6Ms3SHx3IFeHvb1NaWHjcOeKrIMLWCG93xo2JJ/8tyEmNqu+ZpDz7rcXYnCFnP8BfSbNW1MiRbyLmaiiltLlsUWGPnrXKse378TOmnoNCBaQjxOGkLXEly1sX54lqpd4c5r50CAL4yB666QhVqDlCDulkaJqkBIYu8K32X2IS15ZdpwPmgyhiShpmOp6drBtjw5jJnN9G5iM2VzNUfQ3KqKGjXllX2H48PYTenG9etvtmWn9EsiKV5j24KFR8JLTdEgt5oOdfGB/hkzVQG2TlpAd2UHp7Bgsmxi153BSNtTCQyOCqH2TpcKxqR7Ufb8L/DL0AVQkxPgSSOt2NPTQGMgKQeYrdPTfZJyeuAWE2HVD8JsljICek5syaqB/MJaHtkbw5YV3jwU4ezRowAMus+2Awtd19irsXL6Dset7AzVDIzdQBHwnghHVmLyAcwlqP+OSn2XRdhuc0fkI1bAZhTPyM8DdxfZ0woiJk2P0K/7elDDywJZuR+78jXiMxbyNHNv6qnucLPXv+8veHY9gPVDqiur9sU1TJWynWYIKGavK8vskCTZLpHPUyz8pSb3dqSEjd2Ck7BRu2PcofTqeFz04/v9nw+mM+ruGwk/g58wGeZaTSh46ywZi1Dkw/3jmPOpR6EdWNFGAV5XBifx4BO3hVetF7VbTXROtKDQvg=----ATTACHMENT:----NjM4OTg5NTk4NDk3MzYyMyA5MjE1MDIzMjk0NDgwNDA0IDI0OTQ0NDc2NjQ1OTM0Mzk=