Completed
Push — master ( 6edf1e...6ec708 )
by Guilh
16:16 queued 06:22
created

FOSRestExtension::loadBodyConverter()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.0113

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
ccs 12
cts 13
cp 0.9231
rs 8.8571
cc 5
eloc 9
nc 7
nop 4
crap 5.0113
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\DefinitionDecorator;
17
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
18
use Symfony\Component\DependencyInjection\Reference;
19
use Symfony\Component\Form\AbstractType;
20
use Symfony\Component\Form\Extension\Core\Type\FormType;
21
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
22
use Symfony\Component\HttpFoundation\Response;
23
24
class FOSRestExtension extends Extension
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public function getConfiguration(array $config, ContainerBuilder $container)
30
    {
31 1
        return new Configuration($container->getParameter('kernel.debug'));
32
    }
33
34
    /**
35
     * Loads the services based on your application configuration.
36
     *
37
     * @param array            $configs
38
     * @param ContainerBuilder $container
39
     *
40
     * @throws \InvalidArgumentException
41
     * @throws \LogicException
42
     */
43 55
    public function load(array $configs, ContainerBuilder $container)
44
    {
45 55
        $configuration = new Configuration($container->getParameter('kernel.debug'));
46 55
        $config = $this->processConfiguration($configuration, $configs);
47
48 50
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
49 50
        $loader->load('view.xml');
50 50
        $loader->load('routing.xml');
51 50
        $loader->load('request.xml');
52 50
        $loader->load('serializer.xml');
53
54 50
        $container->getDefinition('fos_rest.routing.loader.controller')->replaceArgument(4, $config['routing_loader']['default_format']);
55 50
        $container->getDefinition('fos_rest.routing.loader.yaml_collection')->replaceArgument(4, $config['routing_loader']['default_format']);
56 50
        $container->getDefinition('fos_rest.routing.loader.xml_collection')->replaceArgument(4, $config['routing_loader']['default_format']);
57
58 50
        $container->getDefinition('fos_rest.routing.loader.yaml_collection')->replaceArgument(2, $config['routing_loader']['include_format']);
59 50
        $container->getDefinition('fos_rest.routing.loader.xml_collection')->replaceArgument(2, $config['routing_loader']['include_format']);
60 50
        $container->getDefinition('fos_rest.routing.loader.reader.action')->replaceArgument(3, $config['routing_loader']['include_format']);
61
62
        // The validator service alias is only set if validation is enabled for the request body converter
63 50
        $validator = $config['service']['validator'];
64 50
        unset($config['service']['validator']);
65
66 50
        foreach ($config['service'] as $key => $service) {
67 50
            if (null !== $service) {
68 50
                $container->setAlias('fos_rest.'.$key, $service);
69 50
            }
70 50
        }
71
72 50
        $this->loadForm($config, $loader, $container);
73 50
        $this->loadException($config, $loader, $container);
74 50
        $this->loadBodyConverter($config, $validator, $loader, $container);
75 50
        $this->loadView($config, $loader, $container);
76
77 50
        $this->loadBodyListener($config, $loader, $container);
78 50
        $this->loadFormatListener($config, $loader, $container);
79 50
        $this->loadVersioning($config, $loader, $container);
80 50
        $this->loadParamFetcherListener($config, $loader, $container);
81 50
        $this->loadAllowedMethodsListener($config, $loader, $container);
82 50
        $this->loadAccessDeniedListener($config, $loader, $container);
83 50
        $this->loadZoneMatcherListener($config, $loader, $container);
84
85
        // Needs RequestBodyParamConverter and View Handler loaded.
86 50
        $this->loadSerializer($config, $container);
87 50
    }
88
89 50
    private function loadForm(array $config, XmlFileLoader $loader, ContainerBuilder $container)
90
    {
91 50
        if (!empty($config['disable_csrf_role'])) {
92 1
            $loader->load('forms.xml');
93
94 1
            $definition = $container->getDefinition('fos_rest.form.extension.csrf_disable');
95 1
            $definition->replaceArgument(1, $config['disable_csrf_role']);
96
97
            // BC for Symfony < 2.8: the extended_type attribute is used on higher versions
98 1
            if (!method_exists(AbstractType::class, 'getBlockPrefix')) {
99
                $definition->addTag('form.type_extension', ['alias' => 'form']);
100
            } else {
101 1
                $definition->addTag('form.type_extension', ['extended_type' => FormType::class]);
102
            }
103 1
        }
104 50
    }
105
106 50
    private function loadAccessDeniedListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
107
    {
108 50
        if ($config['access_denied_listener']['enabled'] && !empty($config['access_denied_listener']['formats'])) {
109
            $loader->load('access_denied_listener.xml');
110
111
            $service = $container->getDefinition('fos_rest.access_denied_listener');
112
113
            if (!empty($config['access_denied_listener']['service'])) {
114
                $service->clearTag('kernel.event_subscriber');
115
            }
116
117
            $service->replaceArgument(0, $config['access_denied_listener']['formats']);
118
            $service->replaceArgument(1, $config['unauthorized_challenge']);
119
        }
120 50
    }
121
122 50 View Code Duplication
    private function loadAllowedMethodsListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
    {
124 50
        if ($config['allowed_methods_listener']['enabled']) {
125 2
            if (!empty($config['allowed_methods_listener']['service'])) {
126
                $service = $container->getDefinition('fos_rest.allowed_methods_listener');
127
                $service->clearTag('kernel.event_listener');
128
            }
129
130 2
            $loader->load('allowed_methods_listener.xml');
131
132 2
            $container->getDefinition('fos_rest.allowed_methods_loader')->replaceArgument(1, $config['cache_dir']);
133 2
        }
134 50
    }
135
136 50
    private function loadBodyListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
137
    {
138 50
        if ($config['body_listener']['enabled']) {
139 49
            $loader->load('body_listener.xml');
140
141 49
            $service = $container->getDefinition('fos_rest.body_listener');
142
143 49
            if (!empty($config['body_listener']['service'])) {
144
                $service->clearTag('kernel.event_listener');
145
            }
146
147 49
            $service->replaceArgument(1, $config['body_listener']['throw_exception_on_unsupported_content_type']);
148 49
            $service->addMethodCall('setDefaultFormat', array($config['body_listener']['default_format']));
149
150 49
            $container->getDefinition('fos_rest.decoder_provider')->replaceArgument(1, $config['body_listener']['decoders']);
151
152 49
            $arrayNormalizer = $config['body_listener']['array_normalizer'];
153
154 49
            if (null !== $arrayNormalizer['service']) {
155 3
                $bodyListener = $container->getDefinition('fos_rest.body_listener');
156 3
                $bodyListener->addArgument(new Reference($arrayNormalizer['service']));
157 3
                $bodyListener->addArgument($arrayNormalizer['forms']);
158 3
            }
159 49
        }
160 50
    }
161
162 50
    private function loadFormatListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
163
    {
164 50 View Code Duplication
        if ($config['format_listener']['enabled'] && !empty($config['format_listener']['rules'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
165 6
            $loader->load('format_listener.xml');
166
167 6
            if (!empty($config['format_listener']['service'])) {
168
                $service = $container->getDefinition('fos_rest.format_listener');
169
                $service->clearTag('kernel.event_listener');
170
            }
171
172 6
            $container->setParameter(
173 6
                'fos_rest.format_listener.rules',
174 6
                $config['format_listener']['rules']
175 6
            );
176 6
        }
177 50
    }
178
179 50
    private function loadVersioning(array $config, XmlFileLoader $loader, ContainerBuilder $container)
180
    {
181 50
        if (!empty($config['versioning']['enabled'])) {
182 2
            $loader->load('versioning.xml');
183
184 2
            $versionListener = $container->getDefinition('fos_rest.versioning.listener');
185 2
            $versionListener->replaceArgument(2, $config['versioning']['default_version']);
186
187 2
            $resolvers = [];
188 2 View Code Duplication
            if ($config['versioning']['resolvers']['query']['enabled']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
189 2
                $resolvers['query'] = $container->getDefinition('fos_rest.versioning.query_parameter_resolver');
190 2
                $resolvers['query']->replaceArgument(0, $config['versioning']['resolvers']['query']['parameter_name']);
191 2
            }
192 2 View Code Duplication
            if ($config['versioning']['resolvers']['custom_header']['enabled']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
193 2
                $resolvers['custom_header'] = $container->getDefinition('fos_rest.versioning.header_resolver');
194 2
                $resolvers['custom_header']->replaceArgument(0, $config['versioning']['resolvers']['custom_header']['header_name']);
195 2
            }
196 2 View Code Duplication
            if ($config['versioning']['resolvers']['media_type']['enabled']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
197 2
                $resolvers['media_type'] = $container->getDefinition('fos_rest.versioning.media_type_resolver');
198 2
                $resolvers['media_type']->replaceArgument(0, $config['versioning']['resolvers']['media_type']['regex']);
199 2
            }
200
201 2
            $chainResolver = $container->getDefinition('fos_rest.versioning.chain_resolver');
202 2
            foreach ($config['versioning']['guessing_order'] as $resolver) {
203 2
                if (isset($resolvers[$resolver])) {
204 2
                    $chainResolver->addMethodCall('addResolver', [$resolvers[$resolver]]);
205 2
                }
206 2
            }
207 2
        }
208 50
    }
209
210 50 View Code Duplication
    private function loadParamFetcherListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
211
    {
212 50
        if ($config['param_fetcher_listener']['enabled']) {
213 4
            $loader->load('param_fetcher_listener.xml');
214
215 4
            if (!empty($config['param_fetcher_listener']['service'])) {
216
                $service = $container->getDefinition('fos_rest.param_fetcher_listener');
217
                $service->clearTag('kernel.event_listener');
218
            }
219
220 4
            if ($config['param_fetcher_listener']['force']) {
221 1
                $container->getDefinition('fos_rest.param_fetcher_listener')->replaceArgument(1, true);
222 1
            }
223 4
        }
224 50
    }
225
226 50
    private function loadBodyConverter(array $config, $validator, XmlFileLoader $loader, ContainerBuilder $container)
227
    {
228 50
        if (empty($config['body_converter'])) {
229
            return;
230
        }
231
232 50
        if (!empty($config['body_converter']['enabled'])) {
233 2
            $loader->load('request_body_param_converter.xml');
234
235 2
            if (!empty($config['body_converter']['validation_errors_argument'])) {
236 2
                $container->getDefinition('fos_rest.converter.request_body')->replaceArgument(4, $config['body_converter']['validation_errors_argument']);
237 2
            }
238 2
        }
239
240 50
        if (!empty($config['body_converter']['validate'])) {
241 2
            $container->setAlias('fos_rest.validator', $validator);
242 2
        }
243 50
    }
244
245 50
    private function loadView(array $config, XmlFileLoader $loader, ContainerBuilder $container)
246
    {
247 50
        if (!empty($config['view']['jsonp_handler'])) {
248 1
            $handler = new DefinitionDecorator($config['service']['view_handler']);
249 1
            $handler->setPublic(true);
250
251 1
            $jsonpHandler = new Reference('fos_rest.view_handler.jsonp');
252 1
            $handler->addMethodCall('registerHandler', ['jsonp', [$jsonpHandler, 'createResponse']]);
253 1
            $container->setDefinition('fos_rest.view_handler', $handler);
254
255 1
            $container->getDefinition('fos_rest.view_handler.jsonp')->replaceArgument(0, $config['view']['jsonp_handler']['callback_param']);
256
257 1
            if (empty($config['view']['mime_types']['jsonp'])) {
258 1
                $config['view']['mime_types']['jsonp'] = $config['view']['jsonp_handler']['mime_type'];
259 1
            }
260 1
        }
261
262 50 View Code Duplication
        if ($config['view']['mime_types']['enabled']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
263 2
            $loader->load('mime_type_listener.xml');
264
265 2
            if (!empty($config['mime_type_listener']['service'])) {
266
                $service = $container->getDefinition('fos_rest.mime_type_listener');
267
                $service->clearTag('kernel.event_listener');
268
            }
269
270 2
            $container->getDefinition('fos_rest.mime_type_listener')->replaceArgument(0, $config['view']['mime_types']['formats']);
271 2
        }
272
273 50 View Code Duplication
        if ($config['view']['view_response_listener']['enabled']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
274 8
            $loader->load('view_response_listener.xml');
275 8
            $service = $container->getDefinition('fos_rest.view_response_listener');
276
277 8
            if (!empty($config['view_response_listener']['service'])) {
278
                $service->clearTag('kernel.event_listener');
279
            }
280
281 8
            $service->replaceArgument(1, $config['view']['view_response_listener']['force']);
282 8
        }
283
284 50
        $formats = [];
285 50 View Code Duplication
        foreach ($config['view']['formats'] as $format => $enabled) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
286 50
            if ($enabled) {
287 50
                $formats[$format] = false;
288 50
            }
289 50
        }
290 50 View Code Duplication
        foreach ($config['view']['templating_formats'] as $format => $enabled) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
291 50
            if ($enabled) {
292 50
                $formats[$format] = true;
293 50
            }
294 50
        }
295
296 50
        $container->getDefinition('fos_rest.routing.loader.yaml_collection')->replaceArgument(3, $formats);
297 50
        $container->getDefinition('fos_rest.routing.loader.xml_collection')->replaceArgument(3, $formats);
298 50
        $container->getDefinition('fos_rest.routing.loader.reader.action')->replaceArgument(4, $formats);
299
300 50
        foreach ($config['view']['force_redirects'] as $format => $code) {
301 50
            if (true === $code) {
302 50
                $config['view']['force_redirects'][$format] = Response::HTTP_FOUND;
303 50
            }
304 50
        }
305
306 50 View Code Duplication
        if (!is_numeric($config['view']['failed_validation'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
307
            $config['view']['failed_validation'] = constant('\Symfony\Component\HttpFoundation\Response::'.$config['view']['failed_validation']);
308
        }
309
310 50
        $defaultViewHandler = $container->getDefinition('fos_rest.view_handler.default');
311 50
        $defaultViewHandler->replaceArgument(4, $formats);
312 50
        $defaultViewHandler->replaceArgument(5, $config['view']['failed_validation']);
313
314 50 View Code Duplication
        if (!is_numeric($config['view']['empty_content'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
315
            $config['view']['empty_content'] = constant('\Symfony\Component\HttpFoundation\Response::'.$config['view']['empty_content']);
316
        }
317
318 50
        $defaultViewHandler->replaceArgument(6, $config['view']['empty_content']);
319 50
        $defaultViewHandler->replaceArgument(7, $config['view']['serialize_null']);
320 50
        $defaultViewHandler->replaceArgument(8, $config['view']['force_redirects']);
321 50
        $defaultViewHandler->replaceArgument(9, $config['view']['default_engine']);
322 50
    }
323
324 50
    private function loadException(array $config, XmlFileLoader $loader, ContainerBuilder $container)
325
    {
326 50
        if ($config['exception']['enabled']) {
327 14
            $loader->load('exception_listener.xml');
328
329 14
            if (!empty($config['exception']['service'])) {
330
                $service = $container->getDefinition('fos_rest.exception_listener');
331
                $service->clearTag('kernel.event_subscriber');
332
            }
333
334 14
            if ($config['exception']['exception_controller']) {
335
                $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, $config['exception']['exception_controller']);
336 14
            } elseif (isset($container->getParameter('kernel.bundles')['TwigBundle'])) {
337 4
                $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, 'fos_rest.exception.twig_controller:showAction');
338 4
            }
339
340 14
            $container->getDefinition('fos_rest.exception.codes_map')
341 14
                ->replaceArgument(0, $config['exception']['codes']);
342 14
            $container->getDefinition('fos_rest.exception.messages_map')
343 14
                ->replaceArgument(0, $config['exception']['messages']);
344
345 14
            $container->getDefinition('fos_rest.exception.controller')
346 14
                ->replaceArgument(2, $config['exception']['debug']);
347 14
            $container->getDefinition('fos_rest.serializer.exception_normalizer.jms')
348 14
                ->replaceArgument(1, $config['exception']['debug']);
349 14
            $container->getDefinition('fos_rest.serializer.exception_normalizer.symfony')
350 14
                ->replaceArgument(1, $config['exception']['debug']);
351 14
        }
352 50
    }
353
354 50
    private function loadSerializer(array $config, ContainerBuilder $container)
355
    {
356 50
        $bodyConverter = $container->hasDefinition('fos_rest.converter.request_body') ? $container->getDefinition('fos_rest.converter.request_body') : null;
357 50
        $viewHandler = $container->getDefinition('fos_rest.view_handler.default');
358
359 50 View Code Duplication
        if (!empty($config['serializer']['version'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
360 1
            if ($bodyConverter) {
361
                $bodyConverter->replaceArgument(2, $config['serializer']['version']);
362
            }
363 1
            $viewHandler->addMethodCall('setExclusionStrategyVersion', array($config['serializer']['version']));
364 1
        }
365
366 50 View Code Duplication
        if (!empty($config['serializer']['groups'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
367 1
            if ($bodyConverter) {
368
                $bodyConverter->replaceArgument(1, $config['serializer']['groups']);
369
            }
370 1
            $viewHandler->addMethodCall('setExclusionStrategyGroups', array($config['serializer']['groups']));
371 1
        }
372
373 50
        $viewHandler->addMethodCall('setSerializeNullStrategy', array($config['serializer']['serialize_null']));
374 50
    }
375
376 50
    private function loadZoneMatcherListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
377
    {
378 50
        if (!empty($config['zone'])) {
379 2
            $loader->load('zone_matcher_listener.xml');
380 2
            $zoneMatcherListener = $container->getDefinition('fos_rest.zone_matcher_listener');
381
382 2
            foreach ($config['zone'] as $zone) {
383 2
                $matcher = $this->createZoneRequestMatcher($container,
384 2
                    $zone['path'],
385 2
                    $zone['host'],
386 2
                    $zone['methods'],
387 2
                    $zone['ips']
388 2
                );
389
390 2
                $zoneMatcherListener->addMethodCall('addRequestMatcher', array($matcher));
391 2
            }
392 2
        }
393 50
    }
394
395 2
    private function createZoneRequestMatcher(ContainerBuilder $container, $path = null, $host = null, $methods = array(), $ip = null)
396
    {
397 2
        if ($methods) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $methods of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
398
            $methods = array_map('strtoupper', (array) $methods);
399
        }
400
401 2
        $serialized = serialize(array($path, $host, $methods, $ip));
402 2
        $id = 'fos_rest.zone_request_matcher.'.md5($serialized).sha1($serialized);
403
404
        // only add arguments that are necessary
405 2
        $arguments = array($path, $host, $methods, $ip);
406 2
        while (count($arguments) > 0 && !end($arguments)) {
407 2
            array_pop($arguments);
408 2
        }
409
410
        $container
411 2
            ->setDefinition($id, new DefinitionDecorator('fos_rest.zone_request_matcher'))
412 2
            ->setArguments($arguments)
413
        ;
414
415 2
        return new Reference($id);
416
    }
417
}
418