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
|
|
|
class WebPathResolverFactory extends AbstractResolverFactory |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
public function create(ContainerBuilder $container, $resolverName, array $config) |
26
|
|
|
{ |
27
|
|
|
if ($config["rel_url"]) { |
28
|
|
|
$resolverDefinition = $this->getChildResolverDefinition(sprintf("rel_%s", $this->getName())); |
29
|
|
|
} else { |
30
|
|
|
$resolverDefinition = $this->getChildResolverDefinition(); |
31
|
|
|
} |
32
|
|
|
$pathResolverDefinition = new ChildDefinition('liip_imagine.util.resolver.prototype.path'); |
33
|
|
|
$pathResolverDefinition->replaceArgument(0, $config['web_root']); |
34
|
|
|
$pathResolverDefinition->replaceArgument(1, $config['cache_prefix']); |
35
|
|
|
|
36
|
|
|
$pathResolverServiceId = 'liip_imagine.util.resolver.path'; |
37
|
|
|
$container->setDefinition($pathResolverServiceId, $pathResolverDefinition); |
38
|
|
|
|
39
|
|
|
$resolverDefinition->replaceArgument(1, new Reference($pathResolverServiceId)); |
40
|
|
|
|
41
|
|
|
$resolverDefinition->addTag('liip_imagine.cache.resolver', [ |
42
|
|
|
'resolver' => $resolverName, |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
$resolverId = 'liip_imagine.cache.resolver.'; |
46
|
|
|
$container->setDefinition($resolverId.$resolverName, $resolverDefinition); |
47
|
|
|
|
48
|
|
|
return $resolverId; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function getName() |
55
|
|
|
{ |
56
|
|
|
return 'web_path'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function addConfiguration(ArrayNodeDefinition $builder) |
63
|
|
|
{ |
64
|
|
|
$builder |
65
|
|
|
->children() |
66
|
|
|
->scalarNode('web_root') |
67
|
|
|
->defaultValue(SymfonyFramework::getContainerResolvableRootWebPath()) |
68
|
|
|
->cannotBeEmpty() |
69
|
|
|
->end() |
70
|
|
|
->scalarNode('cache_prefix') |
71
|
|
|
->defaultValue('media/cache') |
72
|
|
|
->cannotBeEmpty() |
73
|
|
|
->end() |
74
|
|
|
->booleanNode('rel_url') |
75
|
|
|
->defaultFalse() |
76
|
|
|
->end() |
77
|
|
|
->end(); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|