Completed
Pull Request — 2.x (#1379)
by Michael
01:50
created

MaybeSetMimeServicesAsAliasesCompilerPass   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 14 2
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Definition;
16
17
/**
18
 * Changes the `liip_imagine.mime_type_guesser` and `liip_imagine.extension_guesser` services to be aliases of the
19
 * `mime_types` service provided by the FrameworkBundle when available.
20
 *
21
 * This compiler pass can be removed when dropping support for Symfony 4.2 and earlier.
22
 *
23
 * @internal
24
 */
25
final class MaybeSetMimeServicesAsAliasesCompilerPass extends AbstractCompilerPass
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function process(ContainerBuilder $container): void
31
    {
32
        if ($container->hasDefinition('mime_types')) {
33
            $container->removeDefinition('liip_imagine.mime_type_guesser');
34
            $container->removeDefinition('liip_imagine.extension_guesser');
35
36
            $container->setAlias('liip_imagine.mime_type_guesser', 'mime_types');
37
            $container->setAlias('liip_imagine.extension_guesser', 'mime_types');
38
39
            $message = 'Replaced the "%s" and "%s" service definitions with aliases to "%s"';
40
41
            $this->log($container, $message, 'liip_imagine.mime_type_guesser', 'liip_imagine.extension_guesser', 'mime_types');
42
        }
43
    }
44
}
45