Completed
Push — 2.x ( 7a9740...56924e )
by Lukas Kahwe
17s queued 11s
created

FlysystemLoaderFactory::getChildLoaderName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
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\Factory\Loader;
13
14
use League\Flysystem\FilesystemOperator;
15
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
class FlysystemLoaderFactory extends AbstractLoaderFactory
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function create(ContainerBuilder $container, $loaderName, array $config)
25
    {
26
        $definition = $this->getChildLoaderDefinition($this->getChildLoaderName());
27
28
        if ($container->hasDefinition('liip_imagine.mime_types')) {
29
            $mimeTypes = $container->getDefinition('liip_imagine.mime_types');
30
            $definition->replaceArgument(0, $mimeTypes);
31
        }
32
33
        $definition->replaceArgument(1, new Reference($config['filesystem_service']));
34
35
        return $this->setTaggedLoaderDefinition($loaderName, $definition, $container);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getName()
42
    {
43
        return 'flysystem';
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function addConfiguration(ArrayNodeDefinition $builder)
50
    {
51
        $builder
52
            ->children()
53
                ->scalarNode('filesystem_service')
54
                    ->isRequired()
55
                    ->cannotBeEmpty()
56
                ->end()
57
            ->end();
58
    }
59
60
    /**
61
     * @return string|null
62
     */
63
    private function getChildLoaderName()
64
    {
65
        if (interface_exists(FilesystemOperator::class)) {
66
            return 'flysystem2';
67
        }
68
69
        return null;
70
    }
71
}
72