diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 2c11feb0e082..ca437e2cf670 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -22,6 +22,7 @@ CHANGELOG * removed support for setting and accessing private services in `Container` * removed support for setting pre-defined services in `Container` * removed support for case insensitivity of parameter names + * removed `AutowireExceptionPass` and `AutowirePass::getAutowiringExceptions()`, use `Definition::addError()` and the `DefinitionErrorExceptionPass` instead 3.4.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php deleted file mode 100644 index f01617dd633c..000000000000 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowireExceptionPass.php +++ /dev/null @@ -1,74 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Compiler; - -@trigger_error('The '.__NAMESPACE__.'\AutowireExceptionPass class is deprecated since version 3.4 and will be removed in 4.0. Use the DefinitionErrorExceptionPass class instead.', E_USER_DEPRECATED); - -use Symfony\Component\DependencyInjection\ContainerBuilder; - -/** - * Throws autowire exceptions from AutowirePass for definitions that still exist. - * - * @deprecated since version 3.4, will be removed in 4.0. - * - * @author Ryan Weaver - */ -class AutowireExceptionPass implements CompilerPassInterface -{ - private $autowirePass; - private $inlineServicePass; - - public function __construct(AutowirePass $autowirePass, InlineServiceDefinitionsPass $inlineServicePass) - { - $this->autowirePass = $autowirePass; - $this->inlineServicePass = $inlineServicePass; - } - - public function process(ContainerBuilder $container) - { - // the pass should only be run once - if (null === $this->autowirePass || null === $this->inlineServicePass) { - return; - } - - $inlinedIds = $this->inlineServicePass->getInlinedServiceIds(); - $exceptions = $this->autowirePass->getAutowiringExceptions(); - - // free up references - $this->autowirePass = null; - $this->inlineServicePass = null; - - foreach ($exceptions as $exception) { - if ($this->doesServiceExistInTheContainer($exception->getServiceId(), $container, $inlinedIds)) { - throw $exception; - } - } - } - - private function doesServiceExistInTheContainer($serviceId, ContainerBuilder $container, array $inlinedIds) - { - if ($container->hasDefinition($serviceId)) { - return true; - } - - // was the service inlined? Of so, does its parent service exist? - if (isset($inlinedIds[$serviceId])) { - foreach ($inlinedIds[$serviceId] as $parentId) { - if ($this->doesServiceExistInTheContainer($parentId, $container, $inlinedIds)) { - return true; - } - } - } - - return false; - } -} diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index dba3fa82ce1a..1b099e0ac888 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -31,7 +31,6 @@ class AutowirePass extends AbstractRecursivePass private $autowired = array(); private $lastFailure; private $throwOnAutowiringException; - private $autowiringExceptions = array(); /** * @param bool $throwOnAutowireException Errors can be retrieved via Definition::getErrors() @@ -41,26 +40,11 @@ public function __construct($throwOnAutowireException = true) $this->throwOnAutowiringException = $throwOnAutowireException; } - /** - * @deprecated since version 3.4, to be removed in 4.0. - * - * @return AutowiringFailedException[] - */ - public function getAutowiringExceptions() - { - @trigger_error('Calling AutowirePass::getAutowiringExceptions() is deprecated since Symfony 3.4 and will be removed in 4.0. Use Definition::getErrors() instead.', E_USER_DEPRECATED); - - return $this->autowiringExceptions; - } - /** * {@inheritdoc} */ public function process(ContainerBuilder $container) { - // clear out any possibly stored exceptions from before - $this->autowiringExceptions = array(); - try { parent::process($container); } finally { @@ -82,7 +66,6 @@ protected function processValue($value, $isRoot = false) throw $e; } - $this->autowiringExceptions[] = $e; $this->container->getDefinition($this->currentId)->addError($e->getMessage()); return parent::processValue($value, $isRoot); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index 254ac3c00c6d..76f2e502170d 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -23,7 +23,6 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements RepeatablePassInterface { private $repeatedPass; - private $inlinedServiceIds = array(); /** * {@inheritdoc} @@ -33,22 +32,6 @@ public function setRepeatedPass(RepeatedPass $repeatedPass) $this->repeatedPass = $repeatedPass; } - /** - * Returns an array of all services inlined by this pass. - * - * The key is the inlined service id and its value is the list of services it was inlined into. - * - * @deprecated since version 3.4, to be removed in 4.0. - * - * @return array - */ - public function getInlinedServiceIds() - { - @trigger_error('Calling InlineServiceDefinitionsPass::getInlinedServiceIds() is deprecated since Symfony 3.4 and will be removed in 4.0.', E_USER_DEPRECATED); - - return $this->inlinedServiceIds; - } - /** * {@inheritdoc} */ @@ -63,7 +46,6 @@ protected function processValue($value, $isRoot = false) if ($this->isInlineableDefinition($id, $definition, $this->container->getCompiler()->getServiceReferenceGraph())) { $this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId)); - $this->inlinedServiceIds[$id][] = $this->currentId; if ($definition->isShared()) { return $definition; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php deleted file mode 100644 index a9c3445cefdd..000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowireExceptionPassTest.php +++ /dev/null @@ -1,145 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Tests\Compiler; - -use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\Compiler\AutowireExceptionPass; -use Symfony\Component\DependencyInjection\Compiler\AutowirePass; -use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException; - -/** - * @group legacy - */ -class AutowireExceptionPassTest extends TestCase -{ - public function testThrowsException() - { - $autowirePass = $this->getMockBuilder(AutowirePass::class) - ->getMock(); - - $autowireException = new AutowiringFailedException('foo_service_id', 'An autowiring exception message'); - $autowirePass->expects($this->any()) - ->method('getAutowiringExceptions') - ->will($this->returnValue(array($autowireException))); - - $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) - ->getMock(); - $inlinePass->expects($this->any()) - ->method('getInlinedServiceIds') - ->will($this->returnValue(array())); - - $container = new ContainerBuilder(); - $container->register('foo_service_id'); - - $pass = new AutowireExceptionPass($autowirePass, $inlinePass); - - try { - $pass->process($container); - $this->fail('->process() should throw the exception if the service id exists'); - } catch (\Exception $e) { - $this->assertSame($autowireException, $e); - } - } - - public function testThrowExceptionIfServiceInlined() - { - $autowirePass = $this->getMockBuilder(AutowirePass::class) - ->getMock(); - - $autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message'); - $autowirePass->expects($this->any()) - ->method('getAutowiringExceptions') - ->will($this->returnValue(array($autowireException))); - - $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) - ->getMock(); - $inlinePass->expects($this->any()) - ->method('getInlinedServiceIds') - ->will($this->returnValue(array( - // a_service inlined into b_service - 'a_service' => array('b_service'), - // b_service inlined into c_service - 'b_service' => array('c_service'), - ))); - - $container = new ContainerBuilder(); - // ONLY register c_service in the final container - $container->register('c_service', 'stdClass'); - - $pass = new AutowireExceptionPass($autowirePass, $inlinePass); - - try { - $pass->process($container); - $this->fail('->process() should throw the exception if the service id exists'); - } catch (\Exception $e) { - $this->assertSame($autowireException, $e); - } - } - - public function testDoNotThrowExceptionIfServiceInlinedButRemoved() - { - $autowirePass = $this->getMockBuilder(AutowirePass::class) - ->getMock(); - - $autowireException = new AutowiringFailedException('a_service', 'An autowiring exception message'); - $autowirePass->expects($this->any()) - ->method('getAutowiringExceptions') - ->will($this->returnValue(array($autowireException))); - - $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) - ->getMock(); - $inlinePass->expects($this->any()) - ->method('getInlinedServiceIds') - ->will($this->returnValue(array( - // a_service inlined into b_service - 'a_service' => array('b_service'), - // b_service inlined into c_service - 'b_service' => array('c_service'), - ))); - - // do NOT register c_service in the container - $container = new ContainerBuilder(); - - $pass = new AutowireExceptionPass($autowirePass, $inlinePass); - - $pass->process($container); - // mark the test as passed - $this->assertTrue(true); - } - - public function testNoExceptionIfServiceRemoved() - { - $autowirePass = $this->getMockBuilder(AutowirePass::class) - ->getMock(); - - $autowireException = new AutowiringFailedException('non_existent_service'); - $autowirePass->expects($this->any()) - ->method('getAutowiringExceptions') - ->will($this->returnValue(array($autowireException))); - - $inlinePass = $this->getMockBuilder(InlineServiceDefinitionsPass::class) - ->getMock(); - $inlinePass->expects($this->any()) - ->method('getInlinedServiceIds') - ->will($this->returnValue(array())); - - $container = new ContainerBuilder(); - - $pass = new AutowireExceptionPass($autowirePass, $inlinePass); - - $pass->process($container); - // mark the test as passed - $this->assertTrue(true); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index b8cd5216fe9d..c47d81322097 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -131,24 +131,6 @@ public function testCompleteExistingDefinitionWithNotDefinedArguments() $this->assertEquals(DInterface::class, (string) $container->getDefinition('h')->getArgument(1)); } - /** - * @group legacy - */ - public function testExceptionsAreStored() - { - $container = new ContainerBuilder(); - - $container->register('c1', __NAMESPACE__.'\CollisionA'); - $container->register('c2', __NAMESPACE__.'\CollisionB'); - $container->register('c3', __NAMESPACE__.'\CollisionB'); - $aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired'); - $aDefinition->setAutowired(true); - - $pass = new AutowirePass(false); - $pass->process($container); - $this->assertCount(1, $pass->getAutowiringExceptions()); - } - /** * @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException * @expectedExceptionMessage Invalid service "private_service": constructor of class "Symfony\Component\DependencyInjection\Tests\Compiler\PrivateConstructor" must be public. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php index 6154080c8bc0..3e1cf8a8c2b1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -252,33 +252,6 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining() $this->assertSame('inline', (string) $values[0]); } - /** - * @group legacy - */ - public function testGetInlinedServiceIdData() - { - $container = new ContainerBuilder(); - $container - ->register('inlinable.service') - ->setPublic(false) - ; - $container - ->register('non_inlinable.service') - ->setPublic(true) - ; - - $container - ->register('other_service') - ->setArguments(array(new Reference('inlinable.service'))) - ; - - $inlinePass = new InlineServiceDefinitionsPass(); - $repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), $inlinePass)); - $repeatedPass->process($container); - - $this->assertEquals(array('inlinable.service' => array('other_service')), $inlinePass->getInlinedServiceIds()); - } - protected function process(ContainerBuilder $container) { $repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));