|
15 | 15 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
16 | 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
17 | 17 | 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; |
18 | 24 |
|
19 | 25 | /** |
20 | 26 | * @author Eduardo Gulias Davis <[email protected]> |
@@ -83,9 +89,28 @@ private function createRequestMatcher(ContainerBuilder $container, ?string $path |
83 | 89 |
|
84 | 90 | if (!$container->hasDefinition($id)) { |
85 | 91 | // 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 | + } |
89 | 114 | } |
90 | 115 |
|
91 | 116 | return new Reference($id); |
|
0 commit comments