Skip to content

Commit 02706d2

Browse files
Merge branch '5.4' into 6.0
* 5.4: Fix tests on PHP 8.1 [Cache] Fix memory leak [Config] Add missing use statement in generated config builder classes [DependencyInjection] fix inlining when non-shared services are involved [FrameworkBundle] fix deprecation message [DoctrineBridge] add support for the JSON type [PHPUnitBridge] Fix Uncaught ValueError [HttpClient] Implement ResetInterface for all http clients [HttpKernel] allow ignoring kernel.reset methods that don't exist [FrameworkBundle] fix registering late resettable services [Validator] Missing translations for Greek (el) translate for japanese 101,102,103 Use symfony-*-bridge instead of symfony-bridge for component bridges Fix Loco Provider [HttpClient] Curl http client has to reinit curl multi handle on reset [SecurityBundle] Fix compat with symfony/security-core:^6 (ter) [Validator] Add Swedish translation for issue #43737
2 parents f23b9c8 + ad260a4 commit 02706d2

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CHANGELOG
1717
* Deprecate `AbstractTestSessionListener::getSession` inject a session in the request instead
1818
* Deprecate the `fileLinkFormat` parameter of `DebugHandlersListener`
1919
* Add support for configuring log level, and status code by exception class
20+
* Allow ignoring "kernel.reset" methods that don't exist with "on_invalid" attribute
2021

2122
5.3
2223
---

DependencyInjection/ResettableServicePass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public function process(ContainerBuilder $container)
4646
$methods[$id] = [];
4747
}
4848

49+
if ('ignore' === ($attributes['on_invalid'] ?? null)) {
50+
$attributes['method'] = '?'.$attributes['method'];
51+
}
52+
4953
$methods[$id][] = $attributes['method'];
5054
}
5155
}

DependencyInjection/ServicesResetter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function reset()
4040
{
4141
foreach ($this->resettableServices as $id => $service) {
4242
foreach ((array) $this->resetMethods[$id] as $resetMethod) {
43+
if ('?' === $resetMethod[0] && !method_exists($service, $resetMethod = substr($resetMethod, 1))) {
44+
continue;
45+
}
46+
4347
$service->$resetMethod();
4448
}
4549
}

Tests/DependencyInjection/ResettableServicePassTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ public function testMissingMethod()
7070
$container->compile();
7171
}
7272

73+
public function testIgnoreInvalidMethod()
74+
{
75+
$container = new ContainerBuilder();
76+
$container->register(ResettableService::class)
77+
->setPublic(true)
78+
->addTag('kernel.reset', ['method' => 'missingMethod', 'on_invalid' => 'ignore']);
79+
$container->register('services_resetter', ServicesResetter::class)
80+
->setPublic(true)
81+
->setArguments([null, []]);
82+
$container->addCompilerPass(new ResettableServicePass());
83+
84+
$container->compile();
85+
86+
$this->assertSame([ResettableService::class => ['?missingMethod']], $container->getDefinition('services_resetter')->getArgument(1));
87+
88+
$resettable = $container->get(ResettableService::class);
89+
$resetter = $container->get('services_resetter');
90+
$resetter->reset();
91+
}
92+
7393
public function testCompilerPassWithoutResetters()
7494
{
7595
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)