From b15ea36d54c33645b3c61d3dbfe38ed2146f04a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Hochd=C3=B6rfer?= Date: Thu, 15 Jun 2017 10:04:29 +0200 Subject: [PATCH] Remove BeanFactoryPostProcessor Injecting a container into a service is considered a bad practice, thus the BeanFactoryPostProcessor is removed. The general post processor logic is still in place, a custom BeanFactoryPostProcessor implementation can still be used. --- Upgrade.md | 7 ++++ docs/advanced/bean-post-processor.md | 8 ---- src/bitExpert/Disco/BeanFactoryAware.php | 28 ------------- src/bitExpert/Disco/BeanFactoryAwareTrait.php | 34 ---------------- .../Disco/BeanFactoryPostProcessor.php | 34 ---------------- .../MethodGenerator/Constructor.php | 2 - .../Disco/AnnotationBeanFactoryUnitTest.php | 14 ------- .../Disco/BeanFactoryAwareTraitUnitTest.php | 35 ---------------- .../BeanFactoryPostProcessorUnitTest.php | 40 ------------------- .../BeanConfigurationWithPostProcessor.php | 16 -------- .../Disco/Helper/BeanFactoryAwareService.php | 40 ------------------- 11 files changed, 7 insertions(+), 251 deletions(-) delete mode 100644 src/bitExpert/Disco/BeanFactoryAware.php delete mode 100644 src/bitExpert/Disco/BeanFactoryAwareTrait.php delete mode 100644 src/bitExpert/Disco/BeanFactoryPostProcessor.php delete mode 100644 tests/bitExpert/Disco/BeanFactoryAwareTraitUnitTest.php delete mode 100644 tests/bitExpert/Disco/BeanFactoryPostProcessorUnitTest.php delete mode 100644 tests/bitExpert/Disco/Helper/BeanFactoryAwareService.php diff --git a/Upgrade.md b/Upgrade.md index 8a55a1b..590ef92 100644 --- a/Upgrade.md +++ b/Upgrade.md @@ -38,6 +38,13 @@ the `@Parameter` collection. The new syntax looks like this: */ ``` +## BC BREAK: Removal of BeanFactoryPostProcessor + +Injecting a container into a bean (service) is considered a bad practice, +thus the BeanFactoryPostProcessor implementation is removed. The general +post processor logic is still in place, a custom BeanFactoryPostProcessor +implementation can still be used. + # Upgrade to Disco 0.5.0 ## BC BREAK: Rasing minimum PHP version to 7.0 diff --git a/docs/advanced/bean-post-processor.md b/docs/advanced/bean-post-processor.md index 45a35f1..f2f65ae 100644 --- a/docs/advanced/bean-post-processor.md +++ b/docs/advanced/bean-post-processor.md @@ -58,11 +58,3 @@ Disco will call every post processor for every new bean instance created. In case of a singleton bean the call for each post processor will happen once, in case of a lazy bean the call will happen when the "real" instance gets created. Disco will manage this all for you. - -# BeanFactoryPostProcessor - -Disco comes with one post processor implementation out-of-the-box: -`\bitExpert\Disco\BeanFactoryPostProcessor`. This post processor will only -run for classes implementing the `\bitExpert\Disco\BeanFactoryAware` -interface. As the name implies it will inject the current BeanFactory -instance into the created bean instance. diff --git a/src/bitExpert/Disco/BeanFactoryAware.php b/src/bitExpert/Disco/BeanFactoryAware.php deleted file mode 100644 index f5dc607..0000000 --- a/src/bitExpert/Disco/BeanFactoryAware.php +++ /dev/null @@ -1,28 +0,0 @@ -beanFactory = $beanFactory; - } -} diff --git a/src/bitExpert/Disco/BeanFactoryPostProcessor.php b/src/bitExpert/Disco/BeanFactoryPostProcessor.php deleted file mode 100644 index 3fabb87..0000000 --- a/src/bitExpert/Disco/BeanFactoryPostProcessor.php +++ /dev/null @@ -1,34 +0,0 @@ -setBeanFactory($beanFactory); - } - } - } -} diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/Constructor.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/Constructor.php index fa74d11..a530c44 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/Constructor.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/Constructor.php @@ -59,8 +59,6 @@ public function __construct( $body .= '$this->' . $sessionBeansProperty->getName() . ' = $' . $beanFactoryConfigurationParameter->getName() . '->getSessionBeanStore();' . PHP_EOL; $body .= '// register {@link \\bitExpert\\Disco\\BeanPostProcessor} instances' . PHP_EOL; - $body .= '$this->' . $beanPostProcessorsProperty->getName() . - '[] = new \bitExpert\Disco\BeanFactoryPostProcessor();' . PHP_EOL; foreach ($beanPostProcessorMethodNames as $methodName) { $body .= '$this->' . $beanPostProcessorsProperty->getName() . '[] = $this->' . $methodName . '(); '; $body .= PHP_EOL; diff --git a/tests/bitExpert/Disco/AnnotationBeanFactoryUnitTest.php b/tests/bitExpert/Disco/AnnotationBeanFactoryUnitTest.php index 44fb173..1a12a40 100644 --- a/tests/bitExpert/Disco/AnnotationBeanFactoryUnitTest.php +++ b/tests/bitExpert/Disco/AnnotationBeanFactoryUnitTest.php @@ -23,7 +23,6 @@ use bitExpert\Disco\Config\BeanConfigurationWithPrimitives; use bitExpert\Disco\Config\BeanConfigurationWithProtectedMethod; use bitExpert\Disco\Config\WrongReturnTypeConfiguration; -use bitExpert\Disco\Helper\BeanFactoryAwareService; use bitExpert\Disco\Helper\MasterService; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; @@ -251,19 +250,6 @@ public function postProcessorHookRunsAfterLazyBeanCreation() self::assertEquals('postProcessed', $bean->test); } - /** - * @test - */ - public function beanFactoryPostProcessorHookRuns() - { - $this->beanFactory = new AnnotationBeanFactory(BeanConfigurationWithPostProcessor::class); - BeanFactoryRegistry::register($this->beanFactory); - - /** @var BeanFactoryAwareService $bean */ - $bean = $this->beanFactory->get('beanFactoryAwareBean'); - self::assertInstanceOf(BeanFactory::class, $bean->getBeanFactory()); - } - /** * @test */ diff --git a/tests/bitExpert/Disco/BeanFactoryAwareTraitUnitTest.php b/tests/bitExpert/Disco/BeanFactoryAwareTraitUnitTest.php deleted file mode 100644 index f6e0e1e..0000000 --- a/tests/bitExpert/Disco/BeanFactoryAwareTraitUnitTest.php +++ /dev/null @@ -1,35 +0,0 @@ -createMock(BeanFactory::class); - $trait = $this->getMockForTrait(BeanFactoryAwareTrait::class); - - $trait->setBeanFactory($beanFactory); - - self::assertAttributeInstanceOf(BeanFactory::class, 'beanFactory', $trait); - self::assertAttributeSame($beanFactory, 'beanFactory', $trait); - } -} diff --git a/tests/bitExpert/Disco/BeanFactoryPostProcessorUnitTest.php b/tests/bitExpert/Disco/BeanFactoryPostProcessorUnitTest.php deleted file mode 100644 index 6a52c55..0000000 --- a/tests/bitExpert/Disco/BeanFactoryPostProcessorUnitTest.php +++ /dev/null @@ -1,40 +0,0 @@ -setAccessible(true); - $reflection->setValue(null); - - $processor->postProcess($service, 'BeanFactoryAwareService'); - self::assertNull($service->getBeanFactory()); - } -} diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php b/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php index 5bc604a..aa70803 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php @@ -33,14 +33,6 @@ public function sampleServiceBeanPostProcessor() : SampleServiceBeanPostProcesso return new SampleServiceBeanPostProcessor(); } - /** - * @BeanPostProcessor - */ - public function beanFactoryBeanPostProcessor() : BeanFactoryPostProcessor - { - return new BeanFactoryPostProcessor(); - } - /** * @Bean */ @@ -56,12 +48,4 @@ public function nonSingletonLazyRequestBean() : SampleService { return new SampleService(); } - - /** - * @Bean - */ - public function beanFactoryAwareBean() : BeanFactoryAwareService - { - return new BeanFactoryAwareService(); - } } diff --git a/tests/bitExpert/Disco/Helper/BeanFactoryAwareService.php b/tests/bitExpert/Disco/Helper/BeanFactoryAwareService.php deleted file mode 100644 index 358bd1f..0000000 --- a/tests/bitExpert/Disco/Helper/BeanFactoryAwareService.php +++ /dev/null @@ -1,40 +0,0 @@ -beanFactory; - } - - /** - * @param BeanFactory $beanFactory - */ - public function setBeanFactory(BeanFactory $beanFactory) - { - $this->beanFactory = $beanFactory; - } -}