diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 49fd03165a5b7..064c913180d99 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -60,6 +60,7 @@ CHANGELOG * Added `asset.request_context.base_path` and `asset.request_context.secure` parameters to provide a default request context in case the stack is empty (similar to `router.request_context.*` parameters) * Display environment variables managed by `Dotenv` in `AboutCommand` + * Added new `framework.reset_services_on_terminate` configuration option to enable resetting services tagged with `kernel.reset` on kernel termination 3.3.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 4d5af046cbec2..ce92ec17b7c3d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -107,6 +107,7 @@ public function getConfigTreeBuilder() ->beforeNormalization()->ifString()->then(function ($v) { return array($v); })->end() ->prototype('scalar')->end() ->end() + ->booleanNode('reset_services_on_terminate')->defaultFalse()->end() ->end() ; diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 568bb0913ebc7..aa3c0d306d4b9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -56,6 +56,7 @@ use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\HttpKernel\EventListener\ServiceResetListener; use Symfony\Component\Lock\Factory; use Symfony\Component\Lock\Lock; use Symfony\Component\Lock\LockInterface; @@ -317,6 +318,10 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('web_link.xml'); } + if (!$config['reset_services_on_terminate']) { + $container->removeDefinition(ServiceResetListener::class); + } + $this->addAnnotatedClassesToCompile(array( '**\\Controller\\', '**\\Entity\\', diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 181dd9334a80b..14fc42e63f95d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -38,6 +38,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index e6e83d40b538d..502ceee8bf4f8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -352,6 +352,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor ), ), ), + 'reset_services_on_terminate' => false, ); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/reset_services.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/reset_services.php new file mode 100644 index 0000000000000..e19272e392dbc --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/reset_services.php @@ -0,0 +1,5 @@ +loadFromExtension('framework', array( + 'reset_services_on_terminate' => true, +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/reset_services.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/reset_services.xml new file mode 100644 index 0000000000000..18fab3254afbb --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/reset_services.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/reset_services.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/reset_services.yml new file mode 100644 index 0000000000000..4ddd9832e6135 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/reset_services.yml @@ -0,0 +1,2 @@ +framework: + reset_services_on_terminate: true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 89f8f48182157..d63f052c84a41 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -32,6 +32,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpKernel\EventListener\ServiceResetListener; use Symfony\Component\PropertyAccess\PropertyAccessor; use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer; @@ -998,6 +999,18 @@ public function testCachePoolServices() $this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.def', 'cache.app', 11); } + public function testRemovesServiceResetListenerDefWhenOptionSetToFalse() + { + $container = $this->createContainerFromFile('default_config'); + $this->assertFalse($container->hasDefinition(ServiceResetListener::class)); + } + + public function testDoesNotRemoveServiceResetListenerDefWhenOptionSetToTrue() + { + $container = $this->createContainerFromFile('reset_services'); + $this->assertTrue($container->hasDefinition(ServiceResetListener::class)); + } + protected function createContainer(array $data = array()) { return new ContainerBuilder(new ParameterBag(array_merge(array(