Completed
Push — master ( 9a4875...187362 )
by David
05:27
created

FOSHttpCacheExtension::getDefaultProxyClient()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 6.1666

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
ccs 10
cts 12
cp 0.8333
rs 8.5125
cc 6
eloc 12
nc 6
nop 1
crap 6.1666
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle 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\HttpCacheBundle\DependencyInjection;
13
14
use FOS\HttpCache\ProxyClient\HttpDispatcher;
15
use FOS\HttpCacheBundle\DependencyInjection\Compiler\HashGeneratorPass;
16
use FOS\HttpCacheBundle\Http\ResponseMatcher\ExpressionResponseMatcher;
17
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
18
use Symfony\Component\Config\FileLocator;
19
use Symfony\Component\Console\Application;
20
use Symfony\Component\DependencyInjection\ChildDefinition;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\DependencyInjection\Definition;
23
use Symfony\Component\DependencyInjection\DefinitionDecorator;
24
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
25
use Symfony\Component\DependencyInjection\Reference;
26
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
27
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
28
29
/**
30
 * {@inheritdoc}
31
 */
32
class FOSHttpCacheExtension extends Extension
33
{
34
    /**
35
     * {@inheritdoc}
36
     */
37 27
    public function getConfiguration(array $config, ContainerBuilder $container)
38
    {
39 27
        return new Configuration($container->getParameter('kernel.debug'));
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 27
    public function load(array $configs, ContainerBuilder $container)
46
    {
47 27
        $configuration = $this->getConfiguration($configs, $container);
48 27
        $config = $this->processConfiguration($configuration, $configs);
0 ignored issues
show
Bug introduced by
It seems like $configuration defined by $this->getConfiguration($configs, $container) on line 47 can be null; however, Symfony\Component\Depend...:processConfiguration() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
49
50 27
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
51 27
        $loader->load('matcher.xml');
52
53 27
        if ($config['debug']['enabled'] || (!empty($config['cache_control']))) {
54 7
            $debugHeader = $config['debug']['enabled'] ? $config['debug']['header'] : false;
55 7
            $container->setParameter($this->getAlias().'.debug_header', $debugHeader);
56 7
            $loader->load('cache_control_listener.xml');
57
        }
58
59 27
        $this->loadCacheable($container, $config['cacheable']);
60
61 27
        if (!empty($config['cache_control'])) {
62 7
            $this->loadCacheControl($container, $config['cache_control']);
63
        }
64
65 26
        if (isset($config['proxy_client'])) {
66 18
            $this->loadProxyClient($container, $loader, $config['proxy_client']);
67
        }
68
69 25
        if (isset($config['test'])) {
70 2
            $this->loadTest($container, $loader, $config['test']);
71
        }
72
73 25
        if ($config['cache_manager']['enabled']) {
74 18
            if (array_key_exists('custom_proxy_client', $config['cache_manager'])) {
75
                // overwrite the previously set alias, if a proxy client was also configured
76 1
                $container->setAlias(
77 1
                    $this->getAlias().'.default_proxy_client',
78 1
                    $config['cache_manager']['custom_proxy_client']
79
                );
80
            }
81 18
            if ('auto' === $config['cache_manager']['generate_url_type']) {
82 18
                if (array_key_exists('custom_proxy_client', $config['cache_manager'])) {
83 1
                    $generateUrlType = UrlGeneratorInterface::ABSOLUTE_URL;
84
                } else {
85 17
                    $defaultClient = $this->getDefaultProxyClient($config['proxy_client']);
86 17
                    if ('noop' !== $defaultClient
87 17
                        && array_key_exists('base_url', $config['proxy_client'][$defaultClient])) {
88
                        $generateUrlType = UrlGeneratorInterface::ABSOLUTE_PATH;
89
                    } else {
90 18
                        $generateUrlType = UrlGeneratorInterface::ABSOLUTE_URL;
91
                    }
92
                }
93
            } else {
94
                $generateUrlType = $config['cache_manager']['generate_url_type'];
95
            }
96 18
            $container->setParameter($this->getAlias().'.cache_manager.generate_url_type', $generateUrlType);
97 18
            $loader->load('cache_manager.xml');
98 18
            if (class_exists(Application::class)) {
99 18
                $loader->load('cache_manager_commands.xml');
100
            }
101
        }
102
103 25
        if ($config['tags']['enabled']) {
104 18
            $this->loadCacheTagging(
105 18
                $container,
106 18
                $loader,
107 18
                $config['tags'],
108 18
                array_key_exists('proxy_client', $config)
109 17
                    ? $this->getDefaultProxyClient($config['proxy_client'])
110 18
                    : 'custom'
111
            );
112
        } else {
113 7
            $container->setParameter($this->getAlias().'.compiler_pass.tag_annotations', false);
114
        }
115
116 24
        if ($config['invalidation']['enabled']) {
117 17
            $loader->load('invalidation_listener.xml');
118
119 17
            if (!empty($config['invalidation']['expression_language'])) {
120
                $container->setAlias(
121
                    $this->getAlias().'.invalidation.expression_language',
122
                    $config['invalidation']['expression_language']
123
                );
124
            }
125
126 17
            if (!empty($config['invalidation']['rules'])) {
127 3
                $this->loadInvalidatorRules($container, $config['invalidation']['rules']);
128
            }
129
        }
130
131 24
        if ($config['user_context']['enabled']) {
132 5
            $this->loadUserContext($container, $loader, $config['user_context']);
133
        }
134
135 24
        if (!empty($config['flash_message']) && $config['flash_message']['enabled']) {
136 3
            unset($config['flash_message']['enabled']);
137 3
            $container->setParameter($this->getAlias().'.event_listener.flash_message.options', $config['flash_message']);
138
139 3
            $loader->load('flash_message.xml');
140
        }
141 24
    }
142
143 27
    private function loadCacheable(ContainerBuilder $container, array $config)
144
    {
145 27
        $definition = $container->getDefinition($this->getAlias().'.response_matcher.cacheable');
146
147
        // Change CacheableResponseMatcher to ExpressionResponseMatcher
148 27
        if ($config['response']['expression']) {
149
            $definition->setClass(ExpressionResponseMatcher::class)
150
                ->setArguments([$config['response']['expression']]);
151
        } else {
152 27
            $container->setParameter(
153 27
                $this->getAlias().'.cacheable.response.additional_status',
154 27
                $config['response']['additional_status']
155
            );
156
        }
157 27
    }
158
159
    /**
160
     * @param ContainerBuilder $container
161
     * @param array            $config
162
     *
163
     * @throws InvalidConfigurationException
164
     */
165 7
    private function loadCacheControl(ContainerBuilder $container, array $config)
166
    {
167 7
        $controlDefinition = $container->getDefinition($this->getAlias().'.event_listener.cache_control');
168
169 7
        foreach ($config['rules'] as $rule) {
170 7
            $ruleMatcher = $this->parseRuleMatcher($container, $rule['match']);
171
172 7
            if ('default' === $rule['headers']['overwrite']) {
173 7
                $rule['headers']['overwrite'] = $config['defaults']['overwrite'];
174
            }
175
176 7
            $controlDefinition->addMethodCall('addRule', [$ruleMatcher, $rule['headers']]);
177
        }
178 6
    }
179
180
    /**
181
     * Parse one cache control rule match configuration.
182
     *
183
     * @param ContainerBuilder $container
184
     * @param array            $match     Request and response match criteria
185
     *
186
     * @return Reference pointing to a rule matcher service
187
     */
188 7
    private function parseRuleMatcher(ContainerBuilder $container, array $match)
189
    {
190 7
        $requestMatcher = $this->parseRequestMatcher($container, $match);
191 7
        $responseMatcher = $this->parseResponseMatcher($container, $match);
192
193 7
        $signature = serialize([(string) $requestMatcher, (string) $responseMatcher]);
194 7
        $id = $this->getAlias().'.cache_control.rule_matcher.'.md5($signature);
195
196 7
        if ($container->hasDefinition($id)) {
197 1
            throw new InvalidConfigurationException('Duplicate match criteria. Would be hidden by a previous rule. match: '.json_encode($match));
198
        }
199
200
        $container
201 7
            ->setDefinition($id, $this->createChildDefinition($this->getAlias().'.rule_matcher'))
202 7
            ->replaceArgument(0, $requestMatcher)
203 7
            ->replaceArgument(1, $responseMatcher)
204
        ;
205
206 7
        return new Reference($id);
207
    }
208
209
    /**
210
     * Used for cache control, tag and invalidation rules.
211
     *
212
     * @param ContainerBuilder $container
213
     * @param array            $match
214
     *
215
     * @return Reference to the request matcher
216
     */
217 9
    private function parseRequestMatcher(ContainerBuilder $container, array $match)
218
    {
219 9
        $match['ips'] = (empty($match['ips'])) ? null : $match['ips'];
220
221
        $arguments = [
222 9
            $match['path'],
223 9
            $match['host'],
224 9
            $match['methods'],
225 9
            $match['ips'],
226 9
            $match['attributes'],
227
        ];
228 9
        $serialized = serialize($arguments);
229 9
        $id = $this->getAlias().'.request_matcher.'.md5($serialized).sha1($serialized);
230
231 9
        if (!$container->hasDefinition($id)) {
232
            $container
233 9
                ->setDefinition($id, $this->createChildDefinition($this->getAlias().'.request_matcher'))
234 9
                ->setArguments($arguments)
235
            ;
236
237 9
            if (!empty($match['query_string'])) {
238
                $container->getDefinition($id)->addMethodCall('setQueryString', [$match['query_string']]);
239
            }
240
        }
241
242 9
        return new Reference($id);
243
    }
244
245
    /**
246
     * Used only for cache control rules.
247
     *
248
     * @param ContainerBuilder $container
249
     * @param array            $config
250
     *
251
     * @return Reference to the correct response matcher service
252
     */
253 7
    private function parseResponseMatcher(ContainerBuilder $container, array $config)
254
    {
255 7
        if (!empty($config['additional_response_status'])) {
256 1
            $id = $this->getAlias().'cache_control.expression.'.md5(serialize($config['additional_response_status']));
257 1 View Code Duplication
            if (!$container->hasDefinition($id)) {
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...
258
                $container
259 1
                    ->setDefinition($id, $this->createChildDefinition($this->getAlias().'.response_matcher.cache_control.cacheable_response'))
260 1
                    ->setArguments([$config['additional_response_status']])
261
                ;
262
            }
263 6
        } elseif (!empty($config['match_response'])) {
264 2
            $id = $this->getAlias().'cache_control.match_response.'.md5($config['match_response']);
265 2 View Code Duplication
            if (!$container->hasDefinition($id)) {
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...
266
                $container
267 2
                    ->setDefinition($id, $this->createChildDefinition($this->getAlias().'.response_matcher.cache_control.expression'))
268 2
                    ->replaceArgument(0, $config['match_response'])
269
                ;
270
            }
271
        } else {
272 4
            $id = $this->getAlias().'.response_matcher.cacheable';
273
        }
274
275 7
        return new Reference($id);
276
    }
277
278 5
    private function loadUserContext(ContainerBuilder $container, XmlFileLoader $loader, array $config)
279
    {
280 5
        $loader->load('user_context.xml');
281
282 5
        $container->getDefinition($this->getAlias().'.user_context.request_matcher')
283 5
            ->replaceArgument(0, $config['match']['accept'])
284 5
            ->replaceArgument(1, $config['match']['method']);
285
286 5
        $container->setParameter($this->getAlias().'.event_listener.user_context.options', [
287 5
            'user_identifier_headers' => $config['user_identifier_headers'],
288 5
            'user_hash_header' => $config['user_hash_header'],
289 5
            'ttl' => $config['hash_cache_ttl'],
290 5
            'add_vary_on_hash' => $config['always_vary_on_context_hash'],
291
        ]);
292 5
        $container->getDefinition($this->getAlias().'.event_listener.user_context')
293 5
            ->replaceArgument(0, new Reference($config['match']['matcher_service']));
294
295 5
        $container->getDefinition($this->getAlias().'.user_context.anonymous_request_matcher')
296 5
            ->replaceArgument(0, $config['user_identifier_headers']);
297
298 5
        if ($config['logout_handler']['enabled']) {
299 5
            $container->getDefinition($this->getAlias().'.user_context_invalidator')
300 5
                ->replaceArgument(1, $config['user_identifier_headers'])
301 5
                ->replaceArgument(2, $config['match']['accept']);
302
303 5
            $container->setAlias('security.logout.handler.session', $this->getAlias().'.user_context.session_logout_handler');
304
        } else {
305
            $container->removeDefinition($this->getAlias().'.user_context.logout_handler');
306
            $container->removeDefinition($this->getAlias().'.user_context.session_logout_handler');
307
            $container->removeDefinition($this->getAlias().'.user_context_invalidator');
308
        }
309
310 5
        if ($config['role_provider']) {
311 3
            $container->getDefinition($this->getAlias().'.user_context.role_provider')
312 3
                ->addTag(HashGeneratorPass::TAG_NAME)
313 3
                ->setAbstract(false);
314
        }
315 5
    }
316
317 18
    private function loadProxyClient(ContainerBuilder $container, XmlFileLoader $loader, array $config)
318
    {
319 18
        if (isset($config['varnish'])) {
320 14
            $this->loadVarnish($container, $loader, $config['varnish']);
321
        }
322 17
        if (isset($config['nginx'])) {
323 2
            $this->loadNginx($container, $loader, $config['nginx']);
324
        }
325 17
        if (isset($config['symfony'])) {
326 1
            $this->loadSymfony($container, $loader, $config['symfony']);
327
        }
328 17
        if (isset($config['noop'])) {
329 1
            $loader->load('noop.xml');
330
        }
331
332 17
        $container->setAlias(
333 17
            $this->getAlias().'.default_proxy_client',
334 17
            $this->getAlias().'.proxy_client.'.$this->getDefaultProxyClient($config)
335
        );
336 17
    }
337
338
    /**
339
     * Define the http dispatcher service for the proxy client $name.
340
     *
341
     * @param ContainerBuilder $container
342
     * @param array            $config
343
     * @param string           $serviceName
344
     */
345 17
    private function createHttpDispatcherDefinition(ContainerBuilder $container, array $config, $serviceName)
346
    {
347 17
        foreach ($config['servers'] as $url) {
348 17
            $this->validateUrl($url, 'Not a valid Varnish server address: "%s"');
349
        }
350 17
        if (!empty($config['base_url'])) {
351 17
            $baseUrl = $this->prefixSchema($config['base_url']);
352 17
            $this->validateUrl($baseUrl, 'Not a valid base path: "%s"');
353
        } else {
354
            $baseUrl = null;
355
        }
356 16
        $httpClient = null;
357 16
        if ($config['http_client']) {
358 1
            $httpClient = new Reference($config['http_client']);
359
        }
360
361 16
        $definition = new Definition(HttpDispatcher::class, [
362 16
            $config['servers'],
363 16
            $baseUrl,
364 16
            $httpClient,
365
        ]);
366
367 16
        $container->setDefinition($serviceName, $definition);
368 16
    }
369
370 14
    private function loadVarnish(ContainerBuilder $container, XmlFileLoader $loader, array $config)
371
    {
372 14
        $this->createHttpDispatcherDefinition($container, $config['http'], $this->getAlias().'.proxy_client.varnish.http_dispatcher');
373
        $options = [
374 13
            'tags_header' => $config['tags_header'],
375
        ];
376 13
        if (!empty($config['header_length'])) {
377
            $options['header_length'] = $config['header_length'];
378
        }
379 13
        if (!empty($config['default_ban_headers'])) {
380
            $options['default_ban_headers'] = $config['default_ban_headers'];
381
        }
382 13
        $container->setParameter($this->getAlias().'.proxy_client.varnish.options', $options);
383
384 13
        $loader->load('varnish.xml');
385 13
    }
386
387 2
    private function loadNginx(ContainerBuilder $container, XmlFileLoader $loader, array $config)
388
    {
389 2
        $this->createHttpDispatcherDefinition($container, $config['http'], $this->getAlias().'.proxy_client.nginx.http_dispatcher');
390 2
        $container->setParameter($this->getAlias().'.proxy_client.nginx.options', [
391 2
            'purge_location' => $config['purge_location'],
392
        ]);
393 2
        $loader->load('nginx.xml');
394 2
    }
395
396 1
    private function loadSymfony(ContainerBuilder $container, XmlFileLoader $loader, array $config)
397
    {
398 1
        $this->createHttpDispatcherDefinition($container, $config['http'], $this->getAlias().'.proxy_client.symfony.http_dispatcher');
399
        $options = [
400 1
            'tags_header' => $config['tags_header'],
401 1
            'tags_method' => $config['tags_method'],
402 1
            'purge_method' => $config['purge_method'],
403
        ];
404 1
        if (!empty($config['header_length'])) {
405
            $options['header_length'] = $config['header_length'];
406
        }
407 1
        $container->setParameter($this->getAlias().'.proxy_client.symfony.options', $options);
408
409 1
        $loader->load('symfony.xml');
410 1
    }
411
412
    /**
413
     * @param ContainerBuilder $container
414
     * @param XmlFileLoader    $loader
415
     * @param array            $config    Configuration section for the tags node
416
     * @param string           $client    Name of the client used with the cache manager,
417
     *                                    "custom" when a custom client is used
418
     */
419 18
    private function loadCacheTagging(ContainerBuilder $container, XmlFileLoader $loader, array $config, $client)
420
    {
421 18
        if ('auto' === $config['enabled'] && !in_array($client, ['varnish', 'symfony'])) {
422 3
            $container->setParameter($this->getAlias().'.compiler_pass.tag_annotations', false);
423
424 3
            return;
425
        }
426 15
        if (!in_array($client, ['varnish', 'symfony', 'custom', 'noop'])) {
427 1
            throw new InvalidConfigurationException(sprintf('You can not enable cache tagging with the %s client', $client));
428
        }
429
430 14
        $container->setParameter($this->getAlias().'.compiler_pass.tag_annotations', true);
431 14
        $container->setParameter($this->getAlias().'.tag_handler.response_header', $config['response_header']);
432 14
        $container->setParameter($this->getAlias().'.tag_handler.strict', $config['strict']);
433 14
        $loader->load('cache_tagging.xml');
434 14
        if (class_exists(Application::class)) {
435 14
            $loader->load('cache_tagging_commands.xml');
436
        }
437
438 14
        if (!empty($config['expression_language'])) {
439
            $container->setAlias(
440
                $this->getAlias().'.tag_handler.expression_language',
441
                $config['expression_language']
442
            );
443
        }
444
445 14
        if (!empty($config['rules'])) {
446 3
            $this->loadTagRules($container, $config['rules']);
447
        }
448 14
    }
449
450 2
    private function loadTest(ContainerBuilder $container, XmlFileLoader $loader, array $config)
451
    {
452 2
        $container->setParameter($this->getAlias().'.test.cache_header', $config['cache_header']);
453
454 2
        if ($config['proxy_server']) {
455 2
            $this->loadProxyServer($container, $loader, $config['proxy_server']);
456
        }
457 2
    }
458
459 2
    private function loadProxyServer(ContainerBuilder $container, XmlFileLoader $loader, array $config)
460
    {
461 2
        if (isset($config['varnish'])) {
462 2
            $this->loadVarnishProxyServer($container, $loader, $config['varnish']);
463
        }
464
465 2
        if (isset($config['nginx'])) {
466
            $this->loadNginxProxyServer($container, $loader, $config['nginx']);
467
        }
468
469 2
        $container->setAlias(
470 2
            $this->getAlias().'.test.default_proxy_server',
471 2
            $this->getAlias().'.test.proxy_server.'.$this->getDefaultProxyClient($config)
472
        );
473 2
    }
474
475 2
    private function loadVarnishProxyServer(ContainerBuilder $container, XmlFileLoader $loader, $config)
476
    {
477 2
        $loader->load('varnish_proxy.xml');
478 2
        foreach ($config as $key => $value) {
479 2
            $container->setParameter(
480 2
                $this->getAlias().'.test.proxy_server.varnish.'.$key,
481 2
                $value
482
            );
483
        }
484 2
    }
485
486
    private function loadNginxProxyServer(ContainerBuilder $container, XmlFileLoader $loader, $config)
487
    {
488
        $loader->load('nginx_proxy.xml');
489
        foreach ($config as $key => $value) {
490
            $container->setParameter(
491
                $this->getAlias().'.test.proxy_server.nginx.'.$key,
492
                $value
493
            );
494
        }
495
    }
496
497 3
    private function loadTagRules(ContainerBuilder $container, array $config)
498
    {
499 3
        $tagDefinition = $container->getDefinition($this->getAlias().'.event_listener.tag');
500
501 3
        foreach ($config as $rule) {
502 3
            $ruleMatcher = $this->parseRequestMatcher($container, $rule['match']);
503
504
            $tags = [
505 3
                'tags' => $rule['tags'],
506 3
                'expressions' => $rule['tag_expressions'],
507
            ];
508
509 3
            $tagDefinition->addMethodCall('addRule', [$ruleMatcher, $tags]);
510
        }
511 3
    }
512
513 3
    private function loadInvalidatorRules(ContainerBuilder $container, array $config)
514
    {
515 3
        $tagDefinition = $container->getDefinition($this->getAlias().'.event_listener.invalidation');
516
517 3
        foreach ($config as $rule) {
518 3
            $ruleMatcher = $this->parseRequestMatcher($container, $rule['match']);
519 3
            $tagDefinition->addMethodCall('addRule', [$ruleMatcher, $rule['routes']]);
520
        }
521 3
    }
522
523 17
    private function validateUrl($url, $msg)
524
    {
525 17
        $prefixed = $this->prefixSchema($url);
526
527 17
        if (!$parts = parse_url($prefixed)) {
528 1
            throw new InvalidConfigurationException(sprintf($msg, $url));
529
        }
530 17
    }
531
532 17
    private function prefixSchema($url)
533
    {
534 17
        if (false === strpos($url, '://')) {
535 17
            $url = sprintf('%s://%s', 'http', $url);
536
        }
537
538 17
        return $url;
539
    }
540
541 17
    private function getDefaultProxyClient(array $config)
542
    {
543 17
        if (isset($config['default'])) {
544
            return $config['default'];
545
        }
546
547 17
        if (isset($config['varnish'])) {
548 13
            return 'varnish';
549
        }
550
551 4
        if (isset($config['nginx'])) {
552 2
            return 'nginx';
553
        }
554
555 2
        if (isset($config['symfony'])) {
556 1
            return 'symfony';
557
        }
558
559 1
        if (isset($config['noop'])) {
560 1
            return 'noop';
561
        }
562
563
        throw new InvalidConfigurationException('No proxy client configured');
564
    }
565
566
    /**
567
     * Build the child definition with fallback for Symfony versions < 3.3.
568
     *
569
     * @param string $id Id of the service to extend
570
     *
571
     * @return ChildDefinition|DefinitionDecorator
572
     */
573 9
    private function createChildDefinition($id)
574
    {
575 9
        if (class_exists(ChildDefinition::class)) {
576 9
            return new ChildDefinition($id);
577
        }
578
579
        return new DefinitionDecorator($id);
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Depend...ion\DefinitionDecorator has been deprecated with message: The DefinitionDecorator class is deprecated since version 3.3 and will be removed in 4.0. Use the Symfony\Component\DependencyInjection\ChildDefinition class instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
580
    }
581
}
582