8000 [FrameworkBundle] add config option for resetting services by dmaicher · Pull Request #24554 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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 1 commit
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
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')->defaultFalse()->end()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

any better idea for the name?

Copy link
Member

Choose a reason for hiding this comment

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

reset_services_on_terminate?
no more comment :)

->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']) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of registering and removing the service, I'd rather invert that condition and only register the service if the feature has been enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense 👍

$container->removeDefinition(ServiceResetListener::class);
}

$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" type="xsd:boolean" />
</xsd:complexType>

<xsd:complexType name="form">
Expand Down
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' => false,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$container->loadFromExtension('framework', array(
'reset_services' => 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="true" />
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
framework:
reset_services: 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,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(
Expand Down
0