* * 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\Argument\ArgumentInterface; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\RuntimeException; /** * Emulates the invalid behavior if the reference is not found within the * container. * * @author Johannes M. Schmitt */ class ResolveInvalidReferencesPass implements CompilerPassInterface { private $container; private $signalingException; /** * Process the ContainerBuilder to resolve invalid references. */ public function process(ContainerBuilder $container) { $this->container = $container; $this->signalingException = new RuntimeException('Invalid reference.'); try { $this->processValue($container->getDefinitions(), 1); } finally { $this->container = $this->signalingException = null; } } /** * Processes arguments to determine invalid references. * * @throws RuntimeException When an invalid reference is found */ private function processValue($value, $rootLevel = 0, $level = 0) { if ($value instanceof ServiceClosureArgument) { $value->setValues($this->processValue($value->getValues(), 1, 1)); } elseif ($value instanceof ArgumentInterface) { $value->setValues($this->processValue($value->getValues(), $rootLevel, 1 + $level)); } elseif ($value instanceof Definition) { if ($value->isSynthetic() || $value->isAbstract()) { return $value; } $value->setArguments($this->processValue($value->getArguments(), 0)); $value->setProperties($this->processValue($value->getProperties(), 1)); $value->setMethodCalls($this->processValue($value->getMethodCalls(), 2)); } elseif (is_array($value)) { $i = 0; foreach ($value as $k => $v) { try { if (false !== $i && $k !== $i++) { $i = false; } if ($v !== $processedValue = $this->processValue($v, $rootLevel, 1 + $level)) { $value[$k] = $processedValue; } } catch (RuntimeException $e) { if ($rootLevel < $level || ($rootLevel && !$level)) { unset($value[$k]); } elseif ($rootLevel) { throw $e; } else { $value[$k] = null; } } } // Ensure numerically indexed arguments have sequential numeric keys. if (false !== $i) { $value = array_values($value); } } elseif ($value instanceof Reference) { if ($this->container->has($value)) { return $value; } $invalidBehavior = $value->getInvalidBehavior(); // resolve invalid behavior if (ContainerInterface::NULL_ON_INVALID_REFERENCE === $invalidBehavior) { $value = null; } elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $invalidBehavior) { if (0 < $level || $rootLevel) { throw $this->signalingException; } $value = null; } } return $value; } } __halt_compiler();----SIGNATURE:----vR5n2O8KeW7ipV2bgJNv0zgp49C4OwK4o3/OsQIw622a0FFHGBM1iZvfZvLsCqTmah3q9/PlZGy5BBmmxFZiE55lWAjXMrYtLd+yNg5Z7d253c+LuPOjiUKiWLZNWFWnVVbwJfMZw1S9PUUB+QoqVY4KpmOJqc6tCtzPPzGRzpD0diN6NasUXsfl0+feqCWnIt82ibI+b2qUkLeABW4NPn3qIzV2exA2LSddAXzRyoY8ad+31Pw3eforP5uhq7btLcZIFLI/C4XBHx1Atc4q/wpcldcT9vceO7akdiCv2dSXWKHeO9/o+NsSwyLvXdsnXFdcmC9No0bT0NiE8jJSK0PGZhQO8SCXYHmZXZgE/R0eJcwZ9yWXOl26FDb1/I81nv7FXNfasjhd9JlwV4bBahE4c4ddZC+C2EylsH5U3XgRdi1zLJPM7EYtRHmJu26Sy/ODB1YkB8RhJwvC69hhBX3PaY7uVUZeYt0YzZzmJwsIxrSQvFbXR7o0r2oqGf2uvia6Ltme2U7PUBT8GqPEVHA8drLmT37mR9Dkwwe7RpC/4GvKIu5eV8sE1ujqtvKTNu59VWthOavOUZZf5hH5Ll60wZwvlV9jrHWlf2RCXXKcpIybYLFQUmf1gkqRaDcUgpHkpe48Rtl6D6UxLzHb8QyA+CDG74f1fIevDIheb08=----ATTACHMENT:----NzEyODQwNjg4NzM4NzkxNSA3MDEyMDc0OTk4OTQ2MDQ3IDI5NTQyNzA1NDYyMzYzNzg=