Completed
Push — master ( 4e7f59...3511da )
by David
13s
created

FOSHttpCacheExtension::validateUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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