Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle] add config option for resetting services #24554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -317,6 +318,10 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('web_link.xml');
}

if ($config['reset_services_on_terminate']) {
$container->register(ServiceResetListener::class)->addTag('kernel.event_subscriber')->setPublic(false);
}

$this->addAnnotatedClassesToCompile(array(
'**\\Controller\\',
'**\\Entity\\',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<xsd:attribute name="secret" type="xsd:string" />
<xsd:attribute name="default-locale" type="xsd:string" />
<xsd:attribute name="test" type="xsd:boolean" />
<xsd:attribute name="reset-services-on-terminate" type="xsd:boolean" />
</xsd:complexType>

<xsd:complexType name="form">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,5 @@
<service id="Symfony\Component\Config\Resource\SelfCheckingResourceChecker">
<tag name="config_cache.resource_checker" priority="-990" />
</service>

<service id="Symfony\Component\HttpKernel\EventListener\ServiceResetListener">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in #24634, we should keep that in xml, and remove it in the pass (sorry for the back and forth)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok no problem 😉 Done.

<argument /> <!-- ResettableServicePass will inject an iterator of initialized services here ($serviceId => $serviceInstance) -->
<argument type="collection" /> <!-- ResettableServicePass will inject an array of reset methods here ($serviceId => $method) -->
<tag name="kernel.event_subscriber" />
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
),
),
),
'reset_services_on_terminate' => false,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$container->loadFromExtension('framework', array(
'reset_services_on_terminate' => true,
));
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config reset-services-on-terminate="true" />
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
framework:
reset_services_on_terminate: true
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -998,6 +999,21 @@ public function testCachePoolServices()
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.def', 'cache.app', 11);
}

public function testDoesNotAddServiceResetListenerDefWhenOptionSetToFalse()
{
$container = $this->createContainerFromFile('default_config');
$this->assertFalse($container->hasDefinition(ServiceResetListener::class));
}

public function testAddsServiceResetListenerDefWhenOptionSetToTrue()
{
$container = $this->createContainerFromFile('reset_services');
$this->assertEquals(
(new Definition(ServiceResetListener::class))->addTag('kernel.event_subscriber')->setPublic(false),
$container->getDefinition(ServiceResetListener::class)
);
}

protected function createContainer(array $data = array())
{
return new ContainerBuilder(new ParameterBag(array_merge(array(
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.