[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
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\Component\DependencyInjection\Compiler; 13 14 use Symfony\Component\DependencyInjection\Alias; 15 use Symfony\Component\DependencyInjection\Definition; 16 use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; 17 use Symfony\Component\DependencyInjection\Reference; 18 use Symfony\Component\DependencyInjection\ContainerBuilder; 19 20 /** 21 * Replaces all references to aliases with references to the actual service. 22 * 23 * @author Johannes M. Schmitt <schmittjoh@gmail.com> 24 */ 25 class ResolveReferencesToAliasesPass implements CompilerPassInterface 26 { 27 private $container; 28 29 /** 30 * Processes the ContainerBuilder to replace references to aliases with actual service references. 31 * 32 * @param ContainerBuilder $container 33 */ 34 public function process(ContainerBuilder $container) 35 { 36 $this->container = $container; 37 38 foreach ($container->getDefinitions() as $definition) { 39 if ($definition->isSynthetic() || $definition->isAbstract()) { 40 continue; 41 } 42 43 $definition->setArguments($this->processArguments($definition->getArguments())); 44 $definition->setMethodCalls($this->processArguments($definition->getMethodCalls())); 45 $definition->setProperties($this->processArguments($definition->getProperties())); 46 $definition->setFactoryService($this->processFactoryService($definition->getFactoryService())); 47 } 48 49 foreach ($container->getAliases() as $id => $alias) { 50 $aliasId = (string) $alias; 51 if ($aliasId !== $defId = $this->getDefinitionId($aliasId)) { 52 $container->setAlias($id, new Alias($defId, $alias->isPublic())); 53 } 54 } 55 } 56 57 /** 58 * Processes the arguments to replace aliases. 59 * 60 * @param array $arguments An array of References 61 * 62 * @return array An array of References 63 */ 64 private function processArguments(array $arguments) 65 { 66 foreach ($arguments as $k => $argument) { 67 if (is_array($argument)) { 68 $arguments[$k] = $this->processArguments($argument); 69 } elseif ($argument instanceof Reference) { 70 $defId = $this->getDefinitionId($id = (string) $argument); 71 72 if ($defId !== $id) { 73 $arguments[$k] = new Reference($defId, $argument->getInvalidBehavior(), $argument->isStrict()); 74 } 75 } 76 } 77 78 return $arguments; 79 } 80 81 private function processFactoryService($factoryService) 82 { 83 if (null === $factoryService) { 84 return; 85 } 86 87 return $this->getDefinitionId($factoryService); 88 } 89 90 /** 91 * Resolves an alias into a definition id. 92 * 93 * @param string $id The definition or alias id to resolve 94 * 95 * @return string The definition id with aliases resolved 96 */ 97 private function getDefinitionId($id) 98 { 99 $seen = array(); 100 while ($this->container->hasAlias($id)) { 101 if (isset($seen[$id])) { 102 throw new ServiceCircularReferenceException($id, array_keys($seen)); 103 } 104 $seen[$id] = true; 105 $id = (string) $this->container->getAlias($id); 106 } 107 108 return $id; 109 } 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |