Completed
Push — master ( 1ddfef...8de58a )
by Guilh
05:31
created

FOSRestExtension::loadView()   F

Complexity

Conditions 15
Paths 2916

Size

Total Lines 78
Code Lines 46

Duplication

Lines 36
Ratio 46.15 %

Code Coverage

Tests 52
CRAP Score 15.722

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 36
loc 78
ccs 52
cts 61
cp 0.8525
rs 2.1566
cc 15
eloc 46
nc 2916
nop 3
crap 15.722

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\HttpKernel\DependencyInjection\Extension;
20
use Symfony\Component\HttpFoundation\Response;
21
22
class FOSRestExtension extends Extension
23
{
24
    /**
25
     * Loads the services based on your application configuration.
26
     *
27
     * @param array            $configs
28
     * @param ContainerBuilder $container
29
     *
30
     * @throws \InvalidArgumentException
31
     * @throws \LogicException
32
     */
33 54
    public function load(array $configs, ContainerBuilder $container)
34
    {
35 54
        $configuration = new Configuration($container->getParameter('kernel.debug'));
36 54
        $config = $this->processConfiguration($configuration, $configs);
37
38 49
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
39 49
        $loader->load('view.xml');
40 49
        $loader->load('routing.xml');
41 49
        $loader->load('request.xml');
42 49
        $loader->load('serializer.xml');
43
44 49
        $container->getDefinition('fos_rest.routing.loader.controller')->replaceArgument(4, $config['routing_loader']['default_format']);
45 49
        $container->getDefinition('fos_rest.routing.loader.yaml_collection')->replaceArgument(4, $config['routing_loader']['default_format']);
46 49
        $container->getDefinition('fos_rest.routing.loader.xml_collection')->replaceArgument(4, $config['routing_loader']['default_format']);
47
48 49
        $container->getDefinition('fos_rest.routing.loader.yaml_collection')->replaceArgument(2, $config['routing_loader']['include_format']);
49 49
        $container->getDefinition('fos_rest.routing.loader.xml_collection')->replaceArgument(2, $config['routing_loader']['include_format']);
50 49
        $container->getDefinition('fos_rest.routing.loader.reader.action')->replaceArgument(3, $config['routing_loader']['include_format']);
51
52
        // The validator service alias is only set if validation is enabled for the request body converter
53 49
        $validator = $config['service']['validator'];
54 49
        unset($config['service']['validator']);
55
56 49
        foreach ($config['service'] as $key => $service) {
57 49
            if (null !== $service) {
58 49
                $container->setAlias('fos_rest.'.$key, $service);
59 49
            }
60 49
        }
61
62 49
        $this->loadForm($config, $loader, $container);
63 49
        $this->loadException($config, $loader, $container);
64 47
        $this->loadBodyConverter($config, $validator, $loader, $container);
65 47
        $this->loadView($config, $loader, $container);
66
67 47
        $this->loadBodyListener($config, $loader, $container);
68 47
        $this->loadFormatListener($config, $loader, $container);
69 47
        $this->loadVersioning($config, $loader, $container);
70 47
        $this->loadParamFetcherListener($config, $loader, $container);
71 47
        $this->loadAllowedMethodsListener($config, $loader, $container);
72 47
        $this->loadAccessDeniedListener($config, $loader, $container);
73 47
        $this->loadZoneMatcherListener($config, $loader, $container);
74
75
        // Needs RequestBodyParamConverter and View Handler loaded.
76 47
        $this->loadSerializer($config, $container);
77 47
    }
78
79 49
    private function loadForm(array $config, XmlFileLoader $loader, ContainerBuilder $container)
80
    {
81 49
        if (!empty($config['disable_csrf_role'])) {
82 1
            $loader->load('forms.xml');
83 1
            $container->getDefinition('fos_rest.form.extension.csrf_disable')->replaceArgument(1, $config['disable_csrf_role']);
84 1
        }
85 49
    }
86
87 47
    private function loadAccessDeniedListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
88
    {
89 47
        if ($config['access_denied_listener']['enabled'] && !empty($config['access_denied_listener']['formats'])) {
90
            $loader->load('access_denied_listener.xml');
91
92
            $service = $container->getDefinition('fos_rest.access_denied_listener');
93
94
            if (!empty($config['access_denied_listener']['service'])) {
95
                $service->clearTag('kernel.event_subscriber');
96
            }
97
98
            $service->replaceArgument(0, $config['access_denied_listener']['formats']);
99
            $service->replaceArgument(1, $config['unauthorized_challenge']);
100
        }
101 47
    }
102
103 47 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...
104
    {
105 47
        if ($config['allowed_methods_listener']['enabled']) {
106 1
            if (!empty($config['allowed_methods_listener']['service'])) {
107
                $service = $container->getDefinition('fos_rest.allowed_methods_listener');
108
                $service->clearTag('kernel.event_listener');
109
            }
110
111 1
            $loader->load('allowed_methods_listener.xml');
112
113 1
            $container->getDefinition('fos_rest.allowed_methods_loader')->replaceArgument(1, $config['cache_dir']);
114 1
        }
115 47
    }
116
117 47
    private function loadBodyListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
118
    {
119 47
        if ($config['body_listener']['enabled']) {
120 46
            $loader->load('body_listener.xml');
121
122 46
            $service = $container->getDefinition('fos_rest.body_listener');
123
124 46
            if (!empty($config['body_listener']['service'])) {
125
                $service->clearTag('kernel.event_listener');
126
            }
127
128 46
            $service->replaceArgument(1, $config['body_listener']['throw_exception_on_unsupported_content_type']);
129 46
            $service->addMethodCall('setDefaultFormat', array($config['body_listener']['default_format']));
130
131 46
            $container->getDefinition('fos_rest.decoder_provider')->replaceArgument(1, $config['body_listener']['decoders']);
132
133 46
            $arrayNormalizer = $config['body_listener']['array_normalizer'];
134
135 46
            if (null !== $arrayNormalizer['service']) {
136 3
                $bodyListener = $container->getDefinition('fos_rest.body_listener');
137 3
                $bodyListener->addArgument(new Reference($arrayNormalizer['service']));
138 3
                $bodyListener->addArgument($arrayNormalizer['forms']);
139 3
            }
140 46
        }
141 47
    }
142
143 47
    private function loadFormatListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
144
    {
145 47 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...
146 5
            $loader->load('format_listener.xml');
147
148 5
            if (!empty($config['format_listener']['service'])) {
149
                $service = $container->getDefinition('fos_rest.format_listener');
150
                $service->clearTag('kernel.event_listener');
151
            }
152
153 5
            $container->setParameter(
154 5
                'fos_rest.format_listener.rules',
155 5
                $config['format_listener']['rules']
156 5
            );
157 5
        }
158 47
    }
159
160 47
    private function loadVersioning(array $config, XmlFileLoader $loader, ContainerBuilder $container)
161
    {
162 47
        if (!empty($config['versioning']['enabled'])) {
163 2
            $loader->load('versioning.xml');
164
165 2
            $versionListener = $container->getDefinition('fos_rest.versioning.listener');
166 2
            $versionListener->replaceArgument(2, $config['versioning']['default_version']);
167
168 2
            $resolvers = [];
169 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...
170 2
                $resolvers['query'] = $container->getDefinition('fos_rest.versioning.query_parameter_resolver');
171 2
                $resolvers['query']->replaceArgument(0, $config['versioning']['resolvers']['query']['parameter_name']);
172 2
            }
173 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...
174 2
                $resolvers['custom_header'] = $container->getDefinition('fos_rest.versioning.header_resolver');
175 2
                $resolvers['custom_header']->replaceArgument(0, $config['versioning']['resolvers']['custom_header']['header_name']);
176 2
            }
177 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...
178 2
                $resolvers['media_type'] = $container->getDefinition('fos_rest.versioning.media_type_resolver');
179 2
                $resolvers['media_type']->replaceArgument(0, $config['versioning']['resolvers']['media_type']['regex']);
180 2
            }
181
182 2
            $chainResolver = $container->getDefinition('fos_rest.versioning.chain_resolver');
183 2
            foreach ($config['versioning']['guessing_order'] as $resolver) {
184 2
                if (isset($resolvers[$resolver])) {
185 2
                    $chainResolver->addMethodCall('addResolver', [$resolvers[$resolver]]);
186 2
                }
187 2
            }
188 2
        }
189 47
    }
190
191 47 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...
192
    {
193 47
        if ($config['param_fetcher_listener']['enabled']) {
194 4
            $loader->load('param_fetcher_listener.xml');
195
196 4
            if (!empty($config['param_fetcher_listener']['service'])) {
197
                $service = $container->getDefinition('fos_rest.param_fetcher_listener');
198
                $service->clearTag('kernel.event_listener');
199
            }
200
201 4
            if ($config['param_fetcher_listener']['force']) {
202 1
                $container->getDefinition('fos_rest.param_fetcher_listener')->replaceArgument(1, true);
203 1
            }
204 4
        }
205 47
    }
206
207 47
    private function loadBodyConverter(array $config, $validator, XmlFileLoader $loader, ContainerBuilder $container)
208
    {
209 47
        if (empty($config['body_converter'])) {
210
            return;
211
        }
212
213 47
        if (!empty($config['body_converter']['enabled'])) {
214 2
            $loader->load('request_body_param_converter.xml');
215
216 2
            if (!empty($config['body_converter']['validation_errors_argument'])) {
217 2
                $container->getDefinition('fos_rest.converter.request_body')->replaceArgument(4, $config['body_converter']['validation_errors_argument']);
218 2
            }
219 2
        }
220
221 47
        if (!empty($config['body_converter']['validate'])) {
222 2
            $container->setAlias('fos_rest.validator', $validator);
223 2
        }
224 47
    }
225
226 47
    private function loadView(array $config, XmlFileLoader $loader, ContainerBuilder $container)
227
    {
228 47
        if (!empty($config['view']['jsonp_handler'])) {
229 1
            $handler = new DefinitionDecorator($config['service']['view_handler']);
230 1
            $handler->setPublic(true);
231
232 1
            $jsonpHandler = new Reference('fos_rest.view_handler.jsonp');
233 1
            $handler->addMethodCall('registerHandler', ['jsonp', [$jsonpHandler, 'createResponse']]);
234 1
            $container->setDefinition('fos_rest.view_handler', $handler);
235
236 1
            $container->getDefinition('fos_rest.view_handler.jsonp')->replaceArgument(0, $config['view']['jsonp_handler']['callback_param']);
237
238 1
            if (empty($config['view']['mime_types']['jsonp'])) {
239 1
                $config['view']['mime_types']['jsonp'] = $config['view']['jsonp_handler']['mime_type'];
240 1
            }
241 1
        }
242
243 47 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...
244 2
            $loader->load('mime_type_listener.xml');
245
246 2
            if (!empty($config['mime_type_listener']['service'])) {
247
                $service = $container->getDefinition('fos_rest.mime_type_listener');
248
                $service->clearTag('kernel.event_listener');
249
            }
250
251 2
            $container->getDefinition('fos_rest.mime_type_listener')->replaceArgument(0, $config['view']['mime_types']['formats']);
252 2
        }
253
254 47 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...
255 8
            $loader->load('view_response_listener.xml');
256 8
            $service = $container->getDefinition('fos_rest.view_response_listener');
257
258 8
            if (!empty($config['view_response_listener']['service'])) {
259
                $service->clearTag('kernel.event_listener');
260
            }
261
262 8
            $service->replaceArgument(1, $config['view']['view_response_listener']['force']);
263 8
        }
264
265 47
        $formats = [];
266 47 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...
267 47
            if ($enabled) {
268 47
                $formats[$format] = false;
269 47
            }
270 47
        }
271 47 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...
272 47
            if ($enabled) {
273 47
                $formats[$format] = true;
274 47
            }
275 47
        }
276
277 47
        $container->getDefinition('fos_rest.routing.loader.yaml_collection')->replaceArgument(3, $formats);
278 47
        $container->getDefinition('fos_rest.routing.loader.xml_collection')->replaceArgument(3, $formats);
279 47
        $container->getDefinition('fos_rest.routing.loader.reader.action')->replaceArgument(4, $formats);
280
281 47
        foreach ($config['view']['force_redirects'] as $format => $code) {
282 47
            if (true === $code) {
283 47
                $config['view']['force_redirects'][$format] = Response::HTTP_FOUND;
284 47
            }
285 47
        }
286
287 47 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...
288
            $config['view']['failed_validation'] = constant('\Symfony\Component\HttpFoundation\Response::'.$config['view']['failed_validation']);
289
        }
290
291 47
        $defaultViewHandler = $container->getDefinition('fos_rest.view_handler.default');
292 47
        $defaultViewHandler->replaceArgument(4, $formats);
293 47
        $defaultViewHandler->replaceArgument(5, $config['view']['failed_validation']);
294
295 47 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...
296
            $config['view']['empty_content'] = constant('\Symfony\Component\HttpFoundation\Response::'.$config['view']['empty_content']);
297
        }
298
299 47
        $defaultViewHandler->replaceArgument(6, $config['view']['empty_content']);
300 47
        $defaultViewHandler->replaceArgument(7, $config['view']['serialize_null']);
301 47
        $defaultViewHandler->replaceArgument(8, $config['view']['force_redirects']);
302 47
        $defaultViewHandler->replaceArgument(9, $config['view']['default_engine']);
303 47
    }
304
305 49
    private function loadException(array $config, XmlFileLoader $loader, ContainerBuilder $container)
306
    {
307 49
        if ($config['exception']['enabled']) {
308 15
            $loader->load('exception_listener.xml');
309
310 15
            if (!empty($config['exception']['service'])) {
311
                $service = $container->getDefinition('fos_rest.exception_listener');
312
                $service->clearTag('kernel.event_subscriber');
313
            }
314
315 15
            if ($config['exception']['exception_controller']) {
316
                $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, $config['exception']['exception_controller']);
317 15
            } elseif (isset($container->getParameter('kernel.bundles')['TwigBundle'])) {
318 3
                $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, 'fos_rest.exception.twig_controller:showAction');
319 3
            }
320
321 15
            $container->getDefinition('fos_rest.exception.codes_map')
322 15
                ->replaceArgument(0, $config['exception']['codes']);
323 15
            $container->getDefinition('fos_rest.exception.messages_map')
324 15
                ->replaceArgument(0, $config['exception']['messages']);
325
326 15
            $container->getDefinition('fos_rest.exception.controller')
327 15
                ->replaceArgument(2, $config['exception']['debug']);
328 15
            $container->getDefinition('fos_rest.serializer.exception_normalizer.jms')
329 15
                ->replaceArgument(1, $config['exception']['debug']);
330 15
            $container->getDefinition('fos_rest.serializer.exception_normalizer.symfony')
331 15
                ->replaceArgument(1, $config['exception']['debug']);
332 15
        }
333
334 49
        foreach ($config['exception']['codes'] as $exception => $code) {
335 2
            if (!is_numeric($code)) {
336
                $config['exception']['codes'][$exception] = constant("\Symfony\Component\HttpFoundation\Response::$code");
337
            }
338
339 2
            $this->testExceptionExists($exception);
340 48
        }
341
342 48
        foreach ($config['exception']['messages'] as $exception => $message) {
343 5
            $this->testExceptionExists($exception);
344 47
        }
345 47
    }
346
347 47
    private function loadSerializer(array $config, ContainerBuilder $container)
348
    {
349 47
        $bodyConverter = $container->hasDefinition('fos_rest.converter.request_body') ? $container->getDefinition('fos_rest.converter.request_body') : null;
350 47
        $viewHandler = $container->getDefinition('fos_rest.view_handler.default');
351
352 47 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...
353 1
            if ($bodyConverter) {
354
                $bodyConverter->replaceArgument(2, $config['serializer']['version']);
355
            }
356 1
            $viewHandler->addMethodCall('setExclusionStrategyVersion', array($config['serializer']['version']));
357 1
        }
358
359 47 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...
360 1
            if ($bodyConverter) {
361
                $bodyConverter->replaceArgument(1, $config['serializer']['groups']);
362
            }
363 1
            $viewHandler->addMethodCall('setExclusionStrategyGroups', array($config['serializer']['groups']));
364 1
        }
365
366 47
        $viewHandler->addMethodCall('setSerializeNullStrategy', array($config['serializer']['serialize_null']));
367 47
    }
368
369 47
    private function loadZoneMatcherListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
370
    {
371 47
        if (!empty($config['zone'])) {
372 1
            $loader->load('zone_matcher_listener.xml');
373 1
            $zoneMatcherListener = $container->getDefinition('fos_rest.zone_matcher_listener');
374
375 1
            foreach ($config['zone'] as $zone) {
376 1
                $matcher = $this->createZoneRequestMatcher($container,
377 1
                    $zone['path'],
378 1
                    $zone['host'],
379 1
                    $zone['methods'],
380 1
                    $zone['ips']
381 1
                );
382
383 1
                $zoneMatcherListener->addMethodCall('addRequestMatcher', array($matcher));
384 1
            }
385 1
        }
386 47
    }
387
388 1
    private function createZoneRequestMatcher(ContainerBuilder $container, $path = null, $host = null, $methods = array(), $ip = null)
389
    {
390 1
        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...
391
            $methods = array_map('strtoupper', (array) $methods);
392
        }
393
394 1
        $serialized = serialize(array($path, $host, $methods, $ip));
395 1
        $id = 'fos_rest.zone_request_matcher.'.md5($serialized).sha1($serialized);
396
397
        // only add arguments that are necessary
398 1
        $arguments = array($path, $host, $methods, $ip);
399 1
        while (count($arguments) > 0 && !end($arguments)) {
400 1
            array_pop($arguments);
401 1
        }
402
403
        $container
404 1
            ->setDefinition($id, new DefinitionDecorator('fos_rest.zone_request_matcher'))
405 1
            ->setArguments($arguments)
406
        ;
407
408 1
        return new Reference($id);
409
    }
410
411
    /**
412
     * Checks if an exception is loadable.
413
     *
414
     * @param string $exception Class to test
415
     *
416
     * @throws \InvalidArgumentException if the class was not found.
417
     */
418 7
    private function testExceptionExists($exception)
419
    {
420 7
        if (!is_subclass_of($exception, \Exception::class) && !is_a($exception, \Exception::class, true)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Exception::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
421 2
            throw new \InvalidArgumentException("FOSRestBundle exception mapper: Could not load class '$exception' or the class does not extend from '\Exception'. Most probably this is a configuration problem.");
422
        }
423 5
    }
424
}
425