Skip to content

Commit 03870df

Browse files
committed
RequestMatcher deprecation
1 parent a6f8afb commit 03870df

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

DependencyInjection/Compiler/FormatListenerRulesPass.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Reference;
18+
use Symfony\Component\HttpFoundation\ChainRequestMatcher;
19+
use Symfony\Component\HttpFoundation\RequestMatcher;
20+
use Symfony\Component\HttpFoundation\RequestMatcher\AttributesRequestMatcher;
21+
use Symfony\Component\HttpFoundation\RequestMatcher\HostRequestMatcher;
22+
use Symfony\Component\HttpFoundation\RequestMatcher\MethodRequestMatcher;
23+
use Symfony\Component\HttpFoundation\RequestMatcher\PathRequestMatcher;
1824

1925
/**
2026
* @author Eduardo Gulias Davis <[email protected]>
@@ -83,9 +89,28 @@ private function createRequestMatcher(ContainerBuilder $container, ?string $path
8389

8490
if (!$container->hasDefinition($id)) {
8591
// only add arguments that are necessary
86-
$container
87-
->setDefinition($id, new ChildDefinition('fos_rest.format_request_matcher'))
88-
->setArguments($arguments);
92+
if (!class_exists(ChainRequestMatcher::class)) {
93+
$container
94+
->setDefinition($id, new ChildDefinition(RequestMatcher::class))
95+
->setArguments($arguments);
96+
} else {
97+
$matchers = [];
98+
if (!empty($path)) {
99+
$matchers[] = new PathRequestMatcher($path);
100+
}
101+
if (!empty($host)) {
102+
$matchers[] = new HostRequestMatcher($host);
103+
}
104+
if (!empty($methods)) {
105+
$matchers[] = new MethodRequestMatcher($methods);
106+
}
107+
if (!empty($attributes)) {
108+
$matchers[] = new AttributesRequestMatcher($attributes);
109+
}
110+
$container
111+
->setDefinition($id, new ChildDefinition(ChainRequestMatcher::class))
112+
->setArguments($matchers);
113+
}
89114
}
90115

91116
return new Reference($id);

Resources/config/format_listener.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<services>
8-
98
<service id="fos_rest.format_listener" class="FOS\RestBundle\EventListener\FormatListener">
109
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="34" />
1110
<argument type="service" id="fos_rest.format_negotiator" />
@@ -14,7 +13,5 @@
1413
<service id="fos_rest.format_negotiator" class="FOS\RestBundle\Negotiation\FormatNegotiator">
1514
<argument type="service" id="request_stack" />
1615
</service>
17-
18-
<service id="fos_rest.format_request_matcher" class="Symfony\Component\HttpFoundation\RequestMatcher" public="false" abstract="true" />
1916
</services>
2017
</container>

0 commit comments

Comments
 (0)