|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Liip\ImagineBundle\DependencyInjection\Factory\Resolver; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
6
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
|
|
11
|
|
|
class AwsS3ResolverFactory implements ResolverFactoryInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* {@inheritdoc} |
|
15
|
|
|
*/ |
|
16
|
|
|
public function create(ContainerBuilder $container, $resolverName, array $config) |
|
17
|
|
|
{ |
|
18
|
|
|
$awsS3ClientId = 'liip_imagine.cache.resolver.'.$resolverName.'.client'; |
|
19
|
|
|
$awsS3ClientDefinition = new Definition('Aws\S3\S3Client'); |
|
20
|
|
|
if (method_exists($awsS3ClientDefinition, 'setFactory')) { |
|
21
|
|
|
$awsS3ClientDefinition->setFactory(array('Aws\S3\S3Client', 'factory')); |
|
22
|
|
|
} else { |
|
23
|
|
|
// to be removed when dependency on Symfony DependencyInjection is bumped to 2.6 |
|
24
|
|
|
$awsS3ClientDefinition->setFactoryClass('Aws\S3\S3Client'); |
|
|
|
|
|
|
25
|
|
|
$awsS3ClientDefinition->setFactoryMethod('factory'); |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
$awsS3ClientDefinition->addArgument($config['client_config']); |
|
28
|
|
|
$container->setDefinition($awsS3ClientId, $awsS3ClientDefinition); |
|
29
|
|
|
|
|
30
|
|
|
$resolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.aws_s3'); |
|
31
|
|
|
$resolverDefinition->replaceArgument(0, new Reference($awsS3ClientId)); |
|
32
|
|
|
$resolverDefinition->replaceArgument(1, $config['bucket']); |
|
33
|
|
|
$resolverDefinition->replaceArgument(2, $config['acl']); |
|
34
|
|
|
$resolverDefinition->replaceArgument(3, array_replace($config['url_options'], $config['get_options'])); |
|
35
|
|
|
$resolverDefinition->replaceArgument(4, $config['put_options']); |
|
36
|
|
|
$resolverId = 'liip_imagine.cache.resolver.'.$resolverName; |
|
37
|
|
|
$container->setDefinition($resolverId, $resolverDefinition); |
|
38
|
|
|
|
|
39
|
|
|
if (isset($config['cache_prefix'])) { |
|
40
|
|
|
$resolverDefinition->addMethodCall('setCachePrefix', array($config['cache_prefix'])); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
View Code Duplication |
if ($config['proxies']) { |
|
|
|
|
|
|
44
|
|
|
$proxiedResolverId = 'liip_imagine.cache.resolver.'.$resolverName.'.proxied'; |
|
45
|
|
|
|
|
46
|
|
|
$container->setDefinition($proxiedResolverId, $resolverDefinition); |
|
47
|
|
|
|
|
48
|
|
|
$proxyResolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.proxy'); |
|
49
|
|
|
$proxyResolverDefinition->replaceArgument(0, new Reference($proxiedResolverId)); |
|
50
|
|
|
$proxyResolverDefinition->replaceArgument(1, $config['proxies']); |
|
51
|
|
|
|
|
52
|
|
|
$container->setDefinition($resolverId, $proxyResolverDefinition); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
View Code Duplication |
if ($config['cache']) { |
|
|
|
|
|
|
56
|
|
|
$cachedResolverId = 'liip_imagine.cache.resolver.'.$resolverName.'.cached'; |
|
57
|
|
|
|
|
58
|
|
|
$container->setDefinition($cachedResolverId, $container->getDefinition($resolverId)); |
|
59
|
|
|
|
|
60
|
|
|
$cacheResolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.cache'); |
|
61
|
|
|
$cacheResolverDefinition->replaceArgument(0, new Reference($config['cache'])); |
|
62
|
|
|
$cacheResolverDefinition->replaceArgument(1, new Reference($cachedResolverId)); |
|
63
|
|
|
|
|
64
|
|
|
$container->setDefinition($resolverId, $cacheResolverDefinition); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$container->getDefinition($resolverId)->addTag('liip_imagine.cache.resolver', array( |
|
68
|
|
|
'resolver' => $resolverName, |
|
69
|
|
|
)); |
|
70
|
|
|
|
|
71
|
|
|
return $resolverId; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getName() |
|
78
|
|
|
{ |
|
79
|
|
|
return 'aws_s3'; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
*/ |
|
85
|
|
|
public function addConfiguration(ArrayNodeDefinition $builder) |
|
86
|
|
|
{ |
|
87
|
|
|
$builder |
|
88
|
|
|
->children() |
|
89
|
|
|
->scalarNode('bucket')->isRequired()->cannotBeEmpty()->end() |
|
90
|
|
|
->scalarNode('cache')->defaultValue(false)->end() |
|
91
|
|
|
->scalarNode('acl')->defaultValue('public-read')->cannotBeEmpty()->end() |
|
92
|
|
|
->scalarNode('cache_prefix')->defaultValue(null)->end() |
|
93
|
|
|
->arrayNode('client_config') |
|
94
|
|
|
->isRequired() |
|
95
|
|
|
->prototype('variable') |
|
96
|
|
|
->treatNullLike(array()) |
|
97
|
|
|
->end() |
|
98
|
|
|
->end() |
|
99
|
|
|
/* @deprecated Use `get_options` instead */ |
|
100
|
|
|
->arrayNode('url_options') |
|
101
|
|
|
->useAttributeAsKey('key') |
|
102
|
|
|
->prototype('scalar')->end() |
|
103
|
|
|
->end() |
|
104
|
|
|
->arrayNode('get_options') |
|
105
|
|
|
->useAttributeAsKey('key') |
|
106
|
|
|
->prototype('scalar')->end() |
|
107
|
|
|
->end() |
|
108
|
|
|
->arrayNode('put_options') |
|
109
|
|
|
->useAttributeAsKey('key') |
|
110
|
|
|
->prototype('scalar')->end() |
|
111
|
|
|
->end() |
|
112
|
|
|
->arrayNode('proxies') |
|
113
|
|
|
->defaultValue(array()) |
|
114
|
|
|
->useAttributeAsKey('name') |
|
115
|
|
|
->prototype('scalar')->end() |
|
116
|
|
|
->end() |
|
117
|
|
|
->end() |
|
118
|
|
|
; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.