Completed
Pull Request — 2.0 (#1059)
by Nick
02:41
created

AbstractWebPathResolverFactory::create()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 14
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\ChildDefinition;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
abstract class AbstractWebPathResolverFactory extends AbstractResolverFactory
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function create(ContainerBuilder $container, $resolverName, array $config)
26
    {
27
        $resolverDefinition = $this->getChildResolverDefinition();
28
        $pathResolverDefinition = new ChildDefinition('liip_imagine.util.resolver.prototype.path');
29
        $pathResolverDefinition->replaceArgument(0, $config['web_root']);
30
        $pathResolverDefinition->replaceArgument(1, $config['cache_prefix']);
31
32
        $pathResolverServiceId = 'liip_imagine.util.resolver.path';
33
        $container->setDefinition($pathResolverServiceId, $pathResolverDefinition);
34
35
        $resolverDefinition->replaceArgument(1, new Reference($pathResolverServiceId));
36
37
        $resolverDefinition->addTag(
38
            'liip_imagine.cache.resolver',
39
            [
40
                'resolver' => $resolverName,
41
            ]
42
        );
43
44
        $resolverId = 'liip_imagine.cache.resolver.';
45
        $container->setDefinition($resolverId.$resolverName, $resolverDefinition);
46
47
        return $resolverId;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function addConfiguration(ArrayNodeDefinition $builder)
54
    {
55
        $builder->children()
56
            ->scalarNode('web_root')
57
            ->defaultValue(
58
                SymfonyFramework::getContainerResolvableRootWebPath()
59
            )
60
            ->cannotBeEmpty()
61
            ->end()
62
            ->scalarNode('cache_prefix')
63
            ->defaultValue('media/cache')
64
            ->cannotBeEmpty()
65
            ->end()
66
            ->end();
67
    }
68
}
69