Completed
Pull Request — master (#1370)
by Mikhail
05:28
created

FOSRestExtension::loadAllowedMethodsListener()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Code Coverage

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