Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\DependencyInjection\Compiler; Chris@0: Chris@0: use Symfony\Component\DependencyInjection\Definition; Chris@0: use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; Chris@0: use Symfony\Component\DependencyInjection\ContainerInterface; Chris@0: use Symfony\Component\DependencyInjection\Reference; Chris@0: use Symfony\Component\DependencyInjection\ContainerBuilder; Chris@0: Chris@0: /** Chris@0: * Checks that all references are pointing to a valid service. Chris@0: * Chris@0: * @author Johannes M. Schmitt Chris@0: */ Chris@0: class CheckExceptionOnInvalidReferenceBehaviorPass implements CompilerPassInterface Chris@0: { Chris@0: private $container; Chris@0: private $sourceId; Chris@0: Chris@0: public function process(ContainerBuilder $container) Chris@0: { Chris@0: $this->container = $container; Chris@0: Chris@0: foreach ($container->getDefinitions() as $id => $definition) { Chris@0: $this->sourceId = $id; Chris@0: $this->processDefinition($definition); Chris@0: } Chris@0: } Chris@0: Chris@0: private function processDefinition(Definition $definition) Chris@0: { Chris@0: $this->processReferences($definition->getArguments()); Chris@0: $this->processReferences($definition->getMethodCalls()); Chris@0: $this->processReferences($definition->getProperties()); Chris@0: } Chris@0: Chris@0: private function processReferences(array $arguments) Chris@0: { Chris@0: foreach ($arguments as $argument) { Chris@0: if (is_array($argument)) { Chris@0: $this->processReferences($argument); Chris@0: } elseif ($argument instanceof Definition) { Chris@0: $this->processDefinition($argument); Chris@0: } elseif ($argument instanceof Reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $argument->getInvalidBehavior()) { Chris@0: $destId = (string) $argument; Chris@0: Chris@0: if (!$this->container->has($destId)) { Chris@0: throw new ServiceNotFoundException($destId, $this->sourceId); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: }