[ Index ] |
PHP Cross Reference of phpBB-3.2.11-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\ContainerBuilder; 15 use Symfony\Component\DependencyInjection\ContainerInterface; 16 use Symfony\Component\DependencyInjection\Exception\RuntimeException; 17 use Symfony\Component\DependencyInjection\Reference; 18 19 /** 20 * Emulates the invalid behavior if the reference is not found within the 21 * container. 22 * 23 * @author Johannes M. Schmitt <schmittjoh@gmail.com> 24 */ 25 class ResolveInvalidReferencesPass implements CompilerPassInterface 26 { 27 private $container; 28 29 /** 30 * Process the ContainerBuilder to resolve invalid references. 31 */ 32 public function process(ContainerBuilder $container) 33 { 34 $this->container = $container; 35 foreach ($container->getDefinitions() as $definition) { 36 if ($definition->isSynthetic() || $definition->isAbstract()) { 37 continue; 38 } 39 40 $definition->setArguments( 41 $this->processArguments($definition->getArguments()) 42 ); 43 44 $calls = array(); 45 foreach ($definition->getMethodCalls() as $call) { 46 try { 47 $calls[] = array($call[0], $this->processArguments($call[1], true)); 48 } catch (RuntimeException $e) { 49 // this call is simply removed 50 } 51 } 52 $definition->setMethodCalls($calls); 53 54 $properties = array(); 55 foreach ($definition->getProperties() as $name => $value) { 56 try { 57 $value = $this->processArguments(array($value), true); 58 $properties[$name] = reset($value); 59 } catch (RuntimeException $e) { 60 // ignore property 61 } 62 } 63 $definition->setProperties($properties); 64 } 65 } 66 67 /** 68 * Processes arguments to determine invalid references. 69 * 70 * @param array $arguments An array of Reference objects 71 * @param bool $inMethodCall 72 * 73 * @return array 74 * 75 * @throws RuntimeException When the config is invalid 76 */ 77 private function processArguments(array $arguments, $inMethodCall = false) 78 { 79 foreach ($arguments as $k => $argument) { 80 if (\is_array($argument)) { 81 $arguments[$k] = $this->processArguments($argument, $inMethodCall); 82 } elseif ($argument instanceof Reference) { 83 $id = (string) $argument; 84 85 $invalidBehavior = $argument->getInvalidBehavior(); 86 $exists = $this->container->has($id); 87 88 // resolve invalid behavior 89 if (!$exists && ContainerInterface::NULL_ON_INVALID_REFERENCE === $invalidBehavior) { 90 $arguments[$k] = null; 91 } elseif (!$exists && ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $invalidBehavior) { 92 if ($inMethodCall) { 93 throw new RuntimeException('Method shouldn\'t be called.'); 94 } 95 96 $arguments[$k] = null; 97 } 98 } 99 } 100 101 return $arguments; 102 } 103 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |