Completed
Push — master ( 22e31b...1ddfef )
by Guilh
8s
created

FOSRestExtension::loadParamFetcherListener()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 4.25
Metric Value
dl 15
loc 15
ccs 9
cts 12
cp 0.75
rs 9.2
cc 4
eloc 8
nc 5
nop 3
crap 4.25
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 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...
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 5
        }
159 47
    }
160
161 47
    private function loadVersioning(array $config, XmlFileLoader $loader, ContainerBuilder $container)
162
    {
163 47
        if (!empty($config['versioning']['enabled'])) {
164 2
            $loader->load('versioning.xml');
165
166 2
            $versionListener = $container->getDefinition('fos_rest.versioning.listener');
167 2
            $versionListener->replaceArgument(2, $config['versioning']['default_version']);
168
169 2
            $resolvers = [];
170 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...
171 2
                $resolvers['query'] = $container->getDefinition('fos_rest.versioning.query_parameter_resolver');
172 2
                $resolvers['query']->replaceArgument(0, $config['versioning']['resolvers']['query']['parameter_name']);
173 2
            }
174 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...
175 2
                $resolvers['custom_header'] = $container->getDefinition('fos_rest.versioning.header_resolver');
176 2
                $resolvers['custom_header']->replaceArgument(0, $config['versioning']['resolvers']['custom_header']['header_name']);
177 2
            }
178 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...
179 2
                $resolvers['media_type'] = $container->getDefinition('fos_rest.versioning.media_type_resolver');
180 2
                $resolvers['media_type']->replaceArgument(0, $config['versioning']['resolvers']['media_type']['regex']);
181 2
            }
182
183 2
            $chainResolver = $container->getDefinition('fos_rest.versioning.chain_resolver');
184 2
            foreach ($config['versioning']['guessing_order'] as $resolver) {
185 2
                if (isset($resolvers[$resolver])) {
186 2
                    $chainResolver->addMethodCall('addResolver', [$resolvers[$resolver]]);
187 2
                }
188 2
            }
189 2
        }
190 47
    }
191
192 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...
193
    {
194 47
        if ($config['param_fetcher_listener']['enabled']) {
195 4
            $loader->load('param_fetcher_listener.xml');
196
197 4
            if (!empty($config['param_fetcher_listener']['service'])) {
198
                $service = $container->getDefinition('fos_rest.param_fetcher_listener');
199
                $service->clearTag('kernel.event_listener');
200
            }
201
202 4
            if ($config['param_fetcher_listener']['force']) {
203 1
                $container->getDefinition('fos_rest.param_fetcher_listener')->replaceArgument(1, true);
204 1
            }
205 4
        }
206 47
    }
207
208 47
    private function loadBodyConverter(array $config, $validator, XmlFileLoader $loader, ContainerBuilder $container)
209
    {
210 47
        if (empty($config['body_converter'])) {
211
            return;
212
        }
213
214 47
        if (!empty($config['body_converter']['enabled'])) {
215 2
            $loader->load('request_body_param_converter.xml');
216
217 2
            if (!empty($config['body_converter']['validation_errors_argument'])) {
218 2
                $container->getDefinition('fos_rest.converter.request_body')->replaceArgument(4, $config['body_converter']['validation_errors_argument']);
219 2
            }
220 2
        }
221
222 47
        if (!empty($config['body_converter']['validate'])) {
223 2
            $container->setAlias('fos_rest.validator', $validator);
224 2
        }
225 47
    }
226
227 47
    private function loadView(array $config, XmlFileLoader $loader, ContainerBuilder $container)
228
    {
229 47
        if (!empty($config['view']['jsonp_handler'])) {
230 1
            $handler = new DefinitionDecorator($config['service']['view_handler']);
231 1
            $handler->setPublic(true);
232
233 1
            $jsonpHandler = new Reference('fos_rest.view_handler.jsonp');
234 1
            $handler->addMethodCall('registerHandler', ['jsonp', [$jsonpHandler, 'createResponse']]);
235 1
            $container->setDefinition('fos_rest.view_handler', $handler);
236
237 1
            $container->getDefinition('fos_rest.view_handler.jsonp')->replaceArgument(0, $config['view']['jsonp_handler']['callback_param']);
238
239 1
            if (empty($config['view']['mime_types']['jsonp'])) {
240 1
                $config['view']['mime_types']['jsonp'] = $config['view']['jsonp_handler']['mime_type'];
241 1
            }
242 1
        }
243
244 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...
245 2
            $loader->load('mime_type_listener.xml');
246
247 2
            if (!empty($config['mime_type_listener']['service'])) {
248
                $service = $container->getDefinition('fos_rest.mime_type_listener');
249
                $service->clearTag('kernel.event_listener');
250
            }
251
252 2
            $container->getDefinition('fos_rest.mime_type_listener')->replaceArgument(0, $config['view']['mime_types']['formats']);
253 2
        }
254
255 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...
256 8
            $loader->load('view_response_listener.xml');
257 8
            $service = $container->getDefinition('fos_rest.view_response_listener');
258
259 8
            if (!empty($config['view_response_listener']['service'])) {
260
                $service->clearTag('kernel.event_listener');
261
            }
262
263 8
            $service->replaceArgument(1, $config['view']['view_response_listener']['force']);
264 8
        }
265
266 47
        $formats = [];
267 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...
268 47
            if ($enabled) {
269 47
                $formats[$format] = false;
270 47
            }
271 47
        }
272 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...
273 47
            if ($enabled) {
274 47
                $formats[$format] = true;
275 47
            }
276 47
        }
277
278 47
        $container->getDefinition('fos_rest.routing.loader.yaml_collection')->replaceArgument(3, $formats);
279 47
        $container->getDefinition('fos_rest.routing.loader.xml_collection')->replaceArgument(3, $formats);
280 47
        $container->getDefinition('fos_rest.routing.loader.reader.action')->replaceArgument(4, $formats);
281
282 47
        foreach ($config['view']['force_redirects'] as $format => $code) {
283 47
            if (true === $code) {
284 47
                $config['view']['force_redirects'][$format] = Response::HTTP_FOUND;
285 47
            }
286 47
        }
287
288 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...
289
            $config['view']['failed_validation'] = constant('\Symfony\Component\HttpFoundation\Response::'.$config['view']['failed_validation']);
290
        }
291
292 47
        $defaultViewHandler = $container->getDefinition('fos_rest.view_handler.default');
293 47
        $defaultViewHandler->replaceArgument(4, $formats);
294 47
        $defaultViewHandler->replaceArgument(5, $config['view']['failed_validation']);
295
296 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...
297
            $config['view']['empty_content'] = constant('\Symfony\Component\HttpFoundation\Response::'.$config['view']['empty_content']);
298
        }
299
300 47
        $defaultViewHandler->replaceArgument(6, $config['view']['empty_content']);
301 47
        $defaultViewHandler->replaceArgument(7, $config['view']['serialize_null']);
302 47
        $defaultViewHandler->replaceArgument(8, $config['view']['force_redirects']);
303 47
        $defaultViewHandler->replaceArgument(9, $config['view']['default_engine']);
304 47
    }
305
306 49
    private function loadException(array $config, XmlFileLoader $loader, ContainerBuilder $container)
307
    {
308 49
        if ($config['exception']['enabled']) {
309 15
            $loader->load('exception_listener.xml');
310
311 15
            if (!empty($config['exception']['service'])) {
312
                $service = $container->getDefinition('fos_rest.exception_listener');
313
                $service->clearTag('kernel.event_subscriber');
314
            }
315
316 15
            if ($config['exception']['exception_controller']) {
317
                $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, $config['exception']['exception_controller']);
318 15
            } elseif (isset($container->getParameter('kernel.bundles')['TwigBundle'])) {
319 3
                $container->getDefinition('fos_rest.exception_listener')->replaceArgument(0, 'fos_rest.exception.twig_controller:showAction');
320 3
            }
321
322 15
            $container->getDefinition('fos_rest.exception.codes_map')
323 15
                ->replaceArgument(0, $config['exception']['codes']);
324 15
            $container->getDefinition('fos_rest.exception.messages_map')
325 15
                ->replaceArgument(0, $config['exception']['messages']);
326
327 15
            $container->getDefinition('fos_rest.exception.controller')
328 15
                ->replaceArgument(2, $config['exception']['debug']);
329 15
            $container->getDefinition('fos_rest.serializer.exception_normalizer.jms')
330 15
                ->replaceArgument(1, $config['exception']['debug']);
331 15
            $container->getDefinition('fos_rest.serializer.exception_normalizer.symfony')
332 15
                ->replaceArgument(1, $config['exception']['debug']);
333 15
        }
334
335 49
        foreach ($config['exception']['codes'] as $exception => $code) {
336 2
            if (!is_numeric($code)) {
337
                $config['exception']['codes'][$exception] = constant("\Symfony\Component\HttpFoundation\Response::$code");
338
            }
339
340 2
            $this->testExceptionExists($exception);
341 48
        }
342
343 48
        foreach ($config['exception']['messages'] as $exception => $message) {
344 5
            $this->testExceptionExists($exception);
345 47
        }
346 47
    }
347
348 47
    private function loadSerializer(array $config, ContainerBuilder $container)
349
    {
350 47
        $bodyConverter = $container->hasDefinition('fos_rest.converter.request_body') ? $container->getDefinition('fos_rest.converter.request_body') : null;
351 47
        $viewHandler = $container->getDefinition('fos_rest.view_handler.default');
352
353 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...
354 1
            if ($bodyConverter) {
355
                $bodyConverter->replaceArgument(2, $config['serializer']['version']);
356
            }
357 1
            $viewHandler->addMethodCall('setExclusionStrategyVersion', array($config['serializer']['version']));
358 1
        }
359
360 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...
361 1
            if ($bodyConverter) {
362
                $bodyConverter->replaceArgument(1, $config['serializer']['groups']);
363
            }
364 1
            $viewHandler->addMethodCall('setExclusionStrategyGroups', array($config['serializer']['groups']));
365 1
        }
366
367 47
        $viewHandler->addMethodCall('setSerializeNullStrategy', array($config['serializer']['serialize_null']));
368 47
    }
369
370 47
    private function loadZoneMatcherListener(array $config, XmlFileLoader $loader, ContainerBuilder $container)
371
    {
372 47
        if (!empty($config['zone'])) {
373 1
            $loader->load('zone_matcher_listener.xml');
374 1
            $zoneMatcherListener = $container->getDefinition('fos_rest.zone_matcher_listener');
375
376 1
            foreach ($config['zone'] as $zone) {
377 1
                $matcher = $this->createZoneRequestMatcher($container,
378 1
                    $zone['path'],
379 1
                    $zone['host'],
380 1
                    $zone['methods'],
381 1
                    $zone['ips']
382 1
                );
383
384 1
                $zoneMatcherListener->addMethodCall('addRequestMatcher', array($matcher));
385 1
            }
386 1
        }
387 47
    }
388
389 1
    private function createZoneRequestMatcher(ContainerBuilder $container, $path = null, $host = null, $methods = array(), $ip = null)
390
    {
391 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...
392
            $methods = array_map('strtoupper', (array) $methods);
393
        }
394
395 1
        $serialized = serialize(array($path, $host, $methods, $ip));
396 1
        $id = 'fos_rest.zone_request_matcher.'.md5($serialized).sha1($serialized);
397
398
        // only add arguments that are necessary
399 1
        $arguments = array($path, $host, $methods, $ip);
400 1
        while (count($arguments) > 0 && !end($arguments)) {
401 1
            array_pop($arguments);
402 1
        }
403
404
        $container
405 1
            ->setDefinition($id, new DefinitionDecorator('fos_rest.zone_request_matcher'))
406 1
            ->setArguments($arguments)
407
        ;
408
409 1
        return new Reference($id);
410
    }
411
412
    /**
413
     * Checks if an exception is loadable.
414
     *
415
     * @param string $exception Class to test
416
     *
417
     * @throws \InvalidArgumentException if the class was not found.
418
     */
419 7
    private function testExceptionExists($exception)
420
    {
421 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...
422 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.");
423
        }
424 5
    }
425
}
426