Skip to content

Commit 35d4b80

Browse files
committed
avoid deprecation with symfony 3.3+
1 parent abe2fcd commit 35d4b80

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/DependencyInjection/FOSHttpCacheExtension.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use FOS\HttpCacheBundle\Http\ResponseMatcher\ExpressionResponseMatcher;
1717
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1818
use Symfony\Component\Config\FileLocator;
19+
use Symfony\Component\DependencyInjection\ChildDefinition;
1920
use Symfony\Component\DependencyInjection\ContainerBuilder;
2021
use Symfony\Component\DependencyInjection\Definition;
2122
use Symfony\Component\DependencyInjection\DefinitionDecorator;
@@ -227,10 +228,17 @@ private function createRequestMatcher(ContainerBuilder $container, $path = null,
227228
$id = $this->getAlias().'.request_matcher.'.md5($serialized).sha1($serialized);
228229

229230
if (!$container->hasDefinition($id)) {
230-
$container
231-
->setDefinition($id, new DefinitionDecorator($this->getAlias().'.request_matcher'))
232-
->setArguments($arguments)
233-
;
231+
if (class_exists(ChildDefinition::class)) {
232+
$container
233+
->setDefinition($id, new ChildDefinition($this->getAlias().'.request_matcher'))
234+
->setArguments($arguments)
235+
;
236+
} else {
237+
$container
238+
->setDefinition($id, new DefinitionDecorator($this->getAlias().'.request_matcher'))
239+
->setArguments($arguments)
240+
;
241+
}
234242
}
235243

236244
return new Reference($id);

tests/Unit/DependencyInjection/Compiler/HashGeneratorPassTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ public function testConfigNoContext()
4444
$config = $this->getBaseConfig();
4545
$this->extension->load([$config], $container);
4646
$this->userContextListenerPass->process($container);
47-
$this->assertCount(21, $container->getDefinitions());
47+
if ($container->hasDefinition('service_container')) {
48+
// symfony 3.3+
49+
$this->assertCount(22, $container->getDefinitions());
50+
} else {
51+
$this->assertCount(21, $container->getDefinitions());
52+
}
4853
}
4954

5055
/**

0 commit comments

Comments
 (0)