Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\DependencyInjection\Compiler; Chris@14: Chris@14: @trigger_error('The '.__NAMESPACE__.'\AutowireExceptionPass class is deprecated since Symfony 3.4 and will be removed in 4.0. Use the DefinitionErrorExceptionPass class instead.', E_USER_DEPRECATED); Chris@14: Chris@14: use Symfony\Component\DependencyInjection\ContainerBuilder; Chris@14: Chris@14: /** Chris@14: * Throws autowire exceptions from AutowirePass for definitions that still exist. Chris@14: * Chris@14: * @deprecated since version 3.4, will be removed in 4.0. Chris@14: * Chris@14: * @author Ryan Weaver Chris@14: */ Chris@14: class AutowireExceptionPass implements CompilerPassInterface Chris@14: { Chris@14: private $autowirePass; Chris@14: private $inlineServicePass; Chris@14: Chris@14: public function __construct(AutowirePass $autowirePass, InlineServiceDefinitionsPass $inlineServicePass) Chris@14: { Chris@14: $this->autowirePass = $autowirePass; Chris@14: $this->inlineServicePass = $inlineServicePass; Chris@14: } Chris@14: Chris@14: public function process(ContainerBuilder $container) Chris@14: { Chris@14: // the pass should only be run once Chris@14: if (null === $this->autowirePass || null === $this->inlineServicePass) { Chris@14: return; Chris@14: } Chris@14: Chris@14: $inlinedIds = $this->inlineServicePass->getInlinedServiceIds(); Chris@14: $exceptions = $this->autowirePass->getAutowiringExceptions(); Chris@14: Chris@14: // free up references Chris@14: $this->autowirePass = null; Chris@14: $this->inlineServicePass = null; Chris@14: Chris@14: foreach ($exceptions as $exception) { Chris@14: if ($this->doesServiceExistInTheContainer($exception->getServiceId(), $container, $inlinedIds)) { Chris@14: throw $exception; Chris@14: } Chris@14: } Chris@14: } Chris@14: Chris@14: private function doesServiceExistInTheContainer($serviceId, ContainerBuilder $container, array $inlinedIds) Chris@14: { Chris@14: if ($container->hasDefinition($serviceId)) { Chris@14: return true; Chris@14: } Chris@14: Chris@14: // was the service inlined? Of so, does its parent service exist? Chris@14: if (isset($inlinedIds[$serviceId])) { Chris@14: foreach ($inlinedIds[$serviceId] as $parentId) { Chris@14: if ($this->doesServiceExistInTheContainer($parentId, $container, $inlinedIds)) { Chris@14: return true; Chris@14: } Chris@14: } Chris@14: } Chris@14: Chris@14: return false; Chris@14: } Chris@14: }