WebPathResolverFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.7998
cc 1
nc 1
nop 3
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\Resolver;
13
14
use Liip\ImagineBundle\Utility\Framework\SymfonyFramework;
15
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18
class WebPathResolverFactory extends AbstractResolverFactory
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function create(ContainerBuilder $container, $resolverName, array $config)
24
    {
25
        $resolverDefinition = $this->getChildResolverDefinition();
26
        $resolverDefinition->replaceArgument(2, $config['web_root']);
27
        $resolverDefinition->replaceArgument(3, $config['cache_prefix']);
28
        $resolverDefinition->addTag('liip_imagine.cache.resolver', [
29
            'resolver' => $resolverName,
30
        ]);
31
32
        $resolverId = 'liip_imagine.cache.resolver.';
33
        $container->setDefinition($resolverId.$resolverName, $resolverDefinition);
34
35
        return $resolverId;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getName()
42
    {
43
        return 'web_path';
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function addConfiguration(ArrayNodeDefinition $builder)
50
    {
51
        $builder
52
            ->children()
53
                ->scalarNode('web_root')
54
                    ->defaultValue(SymfonyFramework::getContainerResolvableRootWebPath())
55
                    ->cannotBeEmpty()
56
                ->end()
57
                ->scalarNode('cache_prefix')
58
                    ->defaultValue('media/cache')
59
                    ->cannotBeEmpty()
60
                ->end()
61
            ->end();
62
    }
63
}
64