1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\MediaBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Sonata\EasyExtendsBundle\Mapper\DoctrineCollector; |
15
|
|
|
use Symfony\Component\Config\Definition\Processor; |
16
|
|
|
use Symfony\Component\Config\FileLocator; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
19
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
20
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
21
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* MediaExtension. |
25
|
|
|
* |
26
|
|
|
* @author Thomas Rabaix <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class SonataMediaExtension extends Extension |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function load(array $configs, ContainerBuilder $container) |
34
|
|
|
{ |
35
|
|
|
$processor = new Processor(); |
36
|
|
|
$configuration = new Configuration(); |
37
|
|
|
$config = $processor->processConfiguration($configuration, $configs); |
38
|
|
|
|
39
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
40
|
|
|
$loader->load('provider.xml'); |
41
|
|
|
$loader->load('media.xml'); |
42
|
|
|
$loader->load('twig.xml'); |
43
|
|
|
$loader->load('security.xml'); |
44
|
|
|
$loader->load('extra.xml'); |
45
|
|
|
$loader->load('form.xml'); |
46
|
|
|
$loader->load('gaufrette.xml'); |
47
|
|
|
|
48
|
|
|
// NEXT_MAJOR: Remove Following lines |
49
|
|
|
$amazonS3Definition = $container->getDefinition('sonata.media.adapter.service.s3'); |
50
|
|
|
if (method_exists($amazonS3Definition, 'setFactory')) { |
51
|
|
|
$amazonS3Definition->setFactory(array('Aws\S3\S3Client', 'factory')); |
52
|
|
|
} else { |
53
|
|
|
$amazonS3Definition->setFactoryClass('Aws\S3\S3Client'); |
|
|
|
|
54
|
|
|
$amazonS3Definition->setFactoryMethod('factory'); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// NEXT_MAJOR: Remove Following lines |
58
|
|
|
$openCloudDefinition = $container->getDefinition('sonata.media.adapter.filesystem.opencloud.objectstore'); |
59
|
|
|
if (method_exists($openCloudDefinition, 'setFactory')) { |
60
|
|
|
$openCloudDefinition->setFactory(array(new Reference('sonata.media.adapter.filesystem.opencloud.connection'), 'ObjectStore')); |
61
|
|
|
} else { |
62
|
|
|
$openCloudDefinition->setFactoryService('sonata.media.adapter.filesystem.opencloud.connection'); |
|
|
|
|
63
|
|
|
$openCloudDefinition->setFactoryMethod('ObjectStore'); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$loader->load('validators.xml'); |
67
|
|
|
$loader->load('serializer.xml'); |
68
|
|
|
|
69
|
|
|
if (!in_array(strtolower($config['db_driver']), array('doctrine_orm', 'doctrine_mongodb', 'doctrine_phpcr'))) { |
70
|
|
|
throw new \InvalidArgumentException(sprintf('SonataMediaBundle - Invalid db driver "%s".', $config['db_driver'])); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
74
|
|
|
|
75
|
|
|
if (isset($bundles['FOSRestBundle']) && isset($bundles['NelmioApiDocBundle'])) { |
76
|
|
|
$loader->load(sprintf('api_form_%s.xml', $config['db_driver'])); |
77
|
|
|
|
78
|
|
|
if ('doctrine_orm' == $config['db_driver']) { |
79
|
|
|
$loader->load('api_controllers.xml'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (isset($bundles['SonataNotificationBundle'])) { |
84
|
|
|
$loader->load('consumer.xml'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if (isset($bundles['SonataFormatterBundle'])) { |
88
|
|
|
$loader->load('formatter.xml'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (isset($bundles['SonataBlockBundle'])) { |
92
|
|
|
$loader->load('block.xml'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
if (isset($bundles['SonataSeoBundle'])) { |
96
|
|
|
$loader->load('seo_block.xml'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if (!isset($bundles['LiipImagineBundle'])) { |
100
|
|
|
$container->removeDefinition('sonata.media.thumbnail.liip_imagine'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if ($this->isClassificationEnabled($config)) { |
104
|
|
|
$loader->load('category.xml'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
if (!array_key_exists($config['default_context'], $config['contexts'])) { |
108
|
|
|
throw new \InvalidArgumentException(sprintf('SonataMediaBundle - Invalid default context : %s, available : %s', $config['default_context'], json_encode(array_keys($config['contexts'])))); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$loader->load(sprintf('%s.xml', $config['db_driver'])); |
112
|
|
|
|
113
|
|
|
if (isset($bundles['SonataAdminBundle'])) { |
114
|
|
|
$loader->load(sprintf('%s_admin.xml', $config['db_driver'])); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$this->configureCategoryInMedia($container, $config); |
118
|
|
|
$this->configureFilesystemAdapter($container, $config); |
119
|
|
|
$this->configureCdnAdapter($container, $config); |
120
|
|
|
|
121
|
|
|
$pool = $container->getDefinition('sonata.media.pool'); |
122
|
|
|
$pool->replaceArgument(0, $config['default_context']); |
123
|
|
|
|
124
|
|
|
// this shameless hack is done in order to have one clean configuration |
125
|
|
|
// for adding formats .... |
126
|
|
|
$pool->addMethodCall('__hack__', $config); |
127
|
|
|
|
128
|
|
|
$strategies = array(); |
129
|
|
|
|
130
|
|
|
foreach ($config['contexts'] as $name => $settings) { |
131
|
|
|
$formats = array(); |
132
|
|
|
|
133
|
|
|
foreach ($settings['formats'] as $format => $value) { |
134
|
|
|
$formats[$name.'_'.$format] = $value; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$strategies[] = $settings['download']['strategy']; |
138
|
|
|
$pool->addMethodCall('addContext', array($name, $settings['providers'], $formats, $settings['download'])); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
$container->setParameter('sonata.media.admin_format', $config['admin_format']); |
142
|
|
|
|
143
|
|
|
$strategies = array_unique($strategies); |
144
|
|
|
|
145
|
|
|
foreach ($strategies as $strategyId) { |
146
|
|
|
$pool->addMethodCall('addDownloadSecurity', array($strategyId, new Reference($strategyId))); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
if ('doctrine_orm' == $config['db_driver']) { |
150
|
|
|
$this->registerDoctrineMapping($config); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
$container->setParameter('sonata.media.resizer.simple.adapter.mode', $config['resizer']['simple']['mode']); |
154
|
|
|
$container->setParameter('sonata.media.resizer.square.adapter.mode', $config['resizer']['square']['mode']); |
155
|
|
|
|
156
|
|
|
$this->configureParameterClass($container, $config); |
157
|
|
|
$this->configureExtra($container, $config); |
158
|
|
|
$this->configureBuzz($container, $config); |
159
|
|
|
$this->configureProviders($container, $config); |
160
|
|
|
$this->configureAdapters($container, $config); |
161
|
|
|
$this->configureResizers($container, $config); |
162
|
|
|
$this->configureClassesToCompile(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param ContainerBuilder $container |
167
|
|
|
* @param array $config |
168
|
|
|
*/ |
169
|
|
|
public function configureProviders(ContainerBuilder $container, array $config) |
170
|
|
|
{ |
171
|
|
|
$container->getDefinition('sonata.media.provider.image') |
172
|
|
|
->replaceArgument(5, array_map('strtolower', $config['providers']['image']['allowed_extensions'])) |
173
|
|
|
->replaceArgument(6, $config['providers']['image']['allowed_mime_types']) |
174
|
|
|
->replaceArgument(7, new Reference($config['providers']['image']['adapter'])) |
175
|
|
|
; |
176
|
|
|
|
177
|
|
|
$container->getDefinition('sonata.media.provider.file') |
178
|
|
|
->replaceArgument(5, $config['providers']['file']['allowed_extensions']) |
179
|
|
|
->replaceArgument(6, $config['providers']['file']['allowed_mime_types']) |
180
|
|
|
; |
181
|
|
|
|
182
|
|
|
$container->getDefinition('sonata.media.provider.youtube')->replaceArgument(7, $config['providers']['youtube']['html5']); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param ContainerBuilder $container |
187
|
|
|
* @param array $config |
188
|
|
|
*/ |
189
|
|
|
public function configureBuzz(ContainerBuilder $container, array $config) |
190
|
|
|
{ |
191
|
|
|
$container->getDefinition('sonata.media.buzz.browser') |
192
|
|
|
->replaceArgument(0, new Reference($config['buzz']['connector'])); |
193
|
|
|
|
194
|
|
|
foreach (array( |
195
|
|
|
'sonata.media.buzz.connector.curl', |
196
|
|
|
'sonata.media.buzz.connector.file_get_contents', |
197
|
|
|
) as $connector) { |
198
|
|
|
$container->getDefinition($connector) |
199
|
|
|
->addMethodCall('setIgnoreErrors', array($config['buzz']['client']['ignore_errors'])) |
200
|
|
|
->addMethodCall('setMaxRedirects', array($config['buzz']['client']['max_redirects'])) |
201
|
|
|
->addMethodCall('setTimeout', array($config['buzz']['client']['timeout'])) |
202
|
|
|
->addMethodCall('setVerifyPeer', array($config['buzz']['client']['verify_peer'])) |
203
|
|
|
->addMethodCall('setProxy', array($config['buzz']['client']['proxy'])); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param ContainerBuilder $container |
209
|
|
|
* @param array $config |
210
|
|
|
*/ |
211
|
|
|
public function configureParameterClass(ContainerBuilder $container, array $config) |
212
|
|
|
{ |
213
|
|
|
$container->setParameter('sonata.media.admin.media.entity', $config['class']['media']); |
214
|
|
|
$container->setParameter('sonata.media.admin.gallery.entity', $config['class']['gallery']); |
215
|
|
|
$container->setParameter('sonata.media.admin.gallery_item.entity', $config['class']['gallery_item']); |
216
|
|
|
|
217
|
|
|
$container->setParameter('sonata.media.media.class', $config['class']['media']); |
218
|
|
|
$container->setParameter('sonata.media.gallery.class', $config['class']['gallery']); |
219
|
|
|
|
220
|
|
|
$container->getDefinition('sonata.media.form.type.media')->replaceArgument(1, $config['class']['media']); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param array $config |
225
|
|
|
*/ |
226
|
|
|
public function registerDoctrineMapping(array $config) |
227
|
|
|
{ |
228
|
|
|
$collector = DoctrineCollector::getInstance(); |
229
|
|
|
|
230
|
|
|
$collector->addAssociation($config['class']['media'], 'mapOneToMany', array( |
231
|
|
|
'fieldName' => 'galleryItems', |
232
|
|
|
'targetEntity' => $config['class']['gallery_item'], |
233
|
|
|
'cascade' => array( |
234
|
|
|
'persist', |
235
|
|
|
), |
236
|
|
|
'mappedBy' => 'media', |
237
|
|
|
'orphanRemoval' => false, |
238
|
|
|
)); |
239
|
|
|
|
240
|
|
|
$collector->addAssociation($config['class']['gallery_item'], 'mapManyToOne', array( |
241
|
|
|
'fieldName' => 'gallery', |
242
|
|
|
'targetEntity' => $config['class']['gallery'], |
243
|
|
|
'cascade' => array( |
244
|
|
|
'persist', |
245
|
|
|
), |
246
|
|
|
'mappedBy' => null, |
247
|
|
|
'inversedBy' => 'galleryItems', |
248
|
|
|
'joinColumns' => array( |
249
|
|
|
array( |
250
|
|
|
'name' => 'gallery_id', |
251
|
|
|
'referencedColumnName' => 'id', |
252
|
|
|
), |
253
|
|
|
), |
254
|
|
|
'orphanRemoval' => false, |
255
|
|
|
)); |
256
|
|
|
|
257
|
|
|
$collector->addAssociation($config['class']['gallery_item'], 'mapManyToOne', array( |
258
|
|
|
'fieldName' => 'media', |
259
|
|
|
'targetEntity' => $config['class']['media'], |
260
|
|
|
'cascade' => array( |
261
|
|
|
'persist', |
262
|
|
|
), |
263
|
|
|
'mappedBy' => null, |
264
|
|
|
'inversedBy' => 'galleryItems', |
265
|
|
|
'joinColumns' => array( |
266
|
|
|
array( |
267
|
|
|
'name' => 'media_id', |
268
|
|
|
'referencedColumnName' => 'id', |
269
|
|
|
), |
270
|
|
|
), |
271
|
|
|
'orphanRemoval' => false, |
272
|
|
|
)); |
273
|
|
|
|
274
|
|
|
$collector->addAssociation($config['class']['gallery'], 'mapOneToMany', array( |
275
|
|
|
'fieldName' => 'galleryItems', |
276
|
|
|
'targetEntity' => $config['class']['gallery_item'], |
277
|
|
|
'cascade' => array( |
278
|
|
|
'persist', |
279
|
|
|
), |
280
|
|
|
'mappedBy' => 'gallery', |
281
|
|
|
'orphanRemoval' => true, |
282
|
|
|
'orderBy' => array( |
283
|
|
|
'position' => 'ASC', |
284
|
|
|
), |
285
|
|
|
)); |
286
|
|
|
|
287
|
|
|
if ($this->isClassificationEnabled($config)) { |
288
|
|
|
$collector->addAssociation($config['class']['media'], 'mapManyToOne', array( |
289
|
|
|
'fieldName' => 'category', |
290
|
|
|
'targetEntity' => $config['class']['category'], |
291
|
|
|
'cascade' => array( |
292
|
|
|
'persist', |
293
|
|
|
), |
294
|
|
|
'mappedBy' => null, |
295
|
|
|
'inversedBy' => null, |
296
|
|
|
'joinColumns' => array( |
297
|
|
|
array( |
298
|
|
|
'name' => 'category_id', |
299
|
|
|
'referencedColumnName' => 'id', |
300
|
|
|
'onDelete' => 'SET NULL', |
301
|
|
|
), |
302
|
|
|
), |
303
|
|
|
'orphanRemoval' => false, |
304
|
|
|
)); |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Inject CDN dependency to default provider. |
310
|
|
|
* |
311
|
|
|
* @param ContainerBuilder $container |
312
|
|
|
* @param array $config |
313
|
|
|
*/ |
314
|
|
|
public function configureCdnAdapter(ContainerBuilder $container, array $config) |
315
|
|
|
{ |
316
|
|
|
// add the default configuration for the server cdn |
317
|
|
|
if ($container->hasDefinition('sonata.media.cdn.server') && isset($config['cdn']['server'])) { |
318
|
|
|
$container->getDefinition('sonata.media.cdn.server') |
319
|
|
|
->replaceArgument(0, $config['cdn']['server']['path']) |
320
|
|
|
; |
321
|
|
|
} else { |
322
|
|
|
$container->removeDefinition('sonata.media.cdn.server'); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
if ($container->hasDefinition('sonata.media.cdn.panther') && isset($config['cdn']['panther'])) { |
326
|
|
|
$container->getDefinition('sonata.media.cdn.panther') |
327
|
|
|
->replaceArgument(0, $config['cdn']['panther']['path']) |
328
|
|
|
->replaceArgument(1, $config['cdn']['panther']['username']) |
329
|
|
|
->replaceArgument(2, $config['cdn']['panther']['password']) |
330
|
|
|
->replaceArgument(3, $config['cdn']['panther']['site_id']) |
331
|
|
|
; |
332
|
|
|
} else { |
333
|
|
|
$container->removeDefinition('sonata.media.cdn.panther'); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
if ($container->hasDefinition('sonata.media.cdn.cloudfront') && isset($config['cdn']['cloudfront'])) { |
337
|
|
|
$container->getDefinition('sonata.media.cdn.cloudfront') |
338
|
|
|
->replaceArgument(0, $config['cdn']['cloudfront']['path']) |
339
|
|
|
->replaceArgument(1, $config['cdn']['cloudfront']['key']) |
340
|
|
|
->replaceArgument(2, $config['cdn']['cloudfront']['secret']) |
341
|
|
|
->replaceArgument(3, $config['cdn']['cloudfront']['distribution_id']) |
342
|
|
|
; |
343
|
|
|
} else { |
344
|
|
|
$container->removeDefinition('sonata.media.cdn.cloudfront'); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
if ($container->hasDefinition('sonata.media.cdn.fallback') && isset($config['cdn']['fallback'])) { |
348
|
|
|
$container->getDefinition('sonata.media.cdn.fallback') |
349
|
|
|
->replaceArgument(0, new Reference($config['cdn']['fallback']['master'])) |
350
|
|
|
->replaceArgument(1, new Reference($config['cdn']['fallback']['fallback'])) |
351
|
|
|
; |
352
|
|
|
} else { |
353
|
|
|
$container->removeDefinition('sonata.media.cdn.fallback'); |
354
|
|
|
} |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Inject filesystem dependency to default provider. |
359
|
|
|
* |
360
|
|
|
* @param ContainerBuilder $container |
361
|
|
|
* @param array $config |
362
|
|
|
*/ |
363
|
|
|
public function configureFilesystemAdapter(ContainerBuilder $container, array $config) |
364
|
|
|
{ |
365
|
|
|
// add the default configuration for the local filesystem |
366
|
|
|
if ($container->hasDefinition('sonata.media.adapter.filesystem.local') && isset($config['filesystem']['local'])) { |
367
|
|
|
$container->getDefinition('sonata.media.adapter.filesystem.local') |
368
|
|
|
->addArgument($config['filesystem']['local']['directory']) |
369
|
|
|
->addArgument($config['filesystem']['local']['create']) |
370
|
|
|
; |
371
|
|
|
} else { |
372
|
|
|
$container->removeDefinition('sonata.media.adapter.filesystem.local'); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
// add the default configuration for the FTP filesystem |
376
|
|
|
if ($container->hasDefinition('sonata.media.adapter.filesystem.ftp') && isset($config['filesystem']['ftp'])) { |
377
|
|
|
$container->getDefinition('sonata.media.adapter.filesystem.ftp') |
378
|
|
|
->addArgument($config['filesystem']['ftp']['directory']) |
379
|
|
|
->addArgument($config['filesystem']['ftp']['host']) |
380
|
|
|
->addArgument(array( |
381
|
|
|
'port' => $config['filesystem']['ftp']['port'], |
382
|
|
|
'username' => $config['filesystem']['ftp']['username'], |
383
|
|
|
'password' => $config['filesystem']['ftp']['password'], |
384
|
|
|
'passive' => $config['filesystem']['ftp']['passive'], |
385
|
|
|
'create' => $config['filesystem']['ftp']['create'], |
386
|
|
|
'mode' => $config['filesystem']['ftp']['mode'], |
387
|
|
|
)) |
388
|
|
|
; |
389
|
|
|
} else { |
390
|
|
|
$container->removeDefinition('sonata.media.adapter.filesystem.ftp'); |
391
|
|
|
$container->removeDefinition('sonata.media.filesystem.ftp'); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
// add the default configuration for the S3 filesystem |
395
|
|
|
if ($container->hasDefinition('sonata.media.adapter.filesystem.s3') && isset($config['filesystem']['s3'])) { |
396
|
|
|
$container->getDefinition('sonata.media.adapter.filesystem.s3') |
397
|
|
|
->replaceArgument(0, new Reference('sonata.media.adapter.service.s3')) |
398
|
|
|
->replaceArgument(1, $config['filesystem']['s3']['bucket']) |
399
|
|
|
->replaceArgument(2, array('create' => $config['filesystem']['s3']['create'], 'region' => $config['filesystem']['s3']['region'], 'directory' => $config['filesystem']['s3']['directory'], 'ACL' => $config['filesystem']['s3']['acl'])) |
400
|
|
|
; |
401
|
|
|
|
402
|
|
|
$container->getDefinition('sonata.media.metadata.amazon') |
403
|
|
|
->addArgument(array( |
404
|
|
|
'acl' => $config['filesystem']['s3']['acl'], |
405
|
|
|
'storage' => $config['filesystem']['s3']['storage'], |
406
|
|
|
'encryption' => $config['filesystem']['s3']['encryption'], |
407
|
|
|
'meta' => $config['filesystem']['s3']['meta'], |
408
|
|
|
'cache_control' => $config['filesystem']['s3']['cache_control'], |
409
|
|
|
)) |
410
|
|
|
; |
411
|
|
|
|
412
|
|
|
if (3 === $config['filesystem']['s3']['sdk_version']) { |
413
|
|
|
$container->getDefinition('sonata.media.adapter.service.s3') |
414
|
|
|
->replaceArgument(0, array( |
415
|
|
|
'credentials' => array( |
416
|
|
|
'secret' => $config['filesystem']['s3']['secretKey'], |
417
|
|
|
'key' => $config['filesystem']['s3']['accessKey'], |
418
|
|
|
), |
419
|
|
|
'region' => $config['filesystem']['s3']['region'], |
420
|
|
|
'version' => $config['filesystem']['s3']['version'], |
421
|
|
|
)) |
422
|
|
|
; |
423
|
|
|
} else { |
424
|
|
|
$container->getDefinition('sonata.media.adapter.service.s3') |
425
|
|
|
->replaceArgument(0, array( |
426
|
|
|
'secret' => $config['filesystem']['s3']['secretKey'], |
427
|
|
|
'key' => $config['filesystem']['s3']['accessKey'], |
428
|
|
|
)) |
429
|
|
|
; |
430
|
|
|
} |
431
|
|
|
} else { |
432
|
|
|
$container->removeDefinition('sonata.media.adapter.filesystem.s3'); |
433
|
|
|
$container->removeDefinition('sonata.media.filesystem.s3'); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
if ($container->hasDefinition('sonata.media.adapter.filesystem.replicate') && isset($config['filesystem']['replicate'])) { |
437
|
|
|
$container->getDefinition('sonata.media.adapter.filesystem.replicate') |
438
|
|
|
->replaceArgument(0, new Reference($config['filesystem']['replicate']['master'])) |
439
|
|
|
->replaceArgument(1, new Reference($config['filesystem']['replicate']['slave'])) |
440
|
|
|
; |
441
|
|
|
} else { |
442
|
|
|
$container->removeDefinition('sonata.media.adapter.filesystem.replicate'); |
443
|
|
|
$container->removeDefinition('sonata.media.filesystem.replicate'); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
if ($container->hasDefinition('sonata.media.adapter.filesystem.mogilefs') && isset($config['filesystem']['mogilefs'])) { |
447
|
|
|
$container->getDefinition('sonata.media.adapter.filesystem.mogilefs') |
448
|
|
|
->replaceArgument(0, $config['filesystem']['mogilefs']['domain']) |
449
|
|
|
->replaceArgument(1, $config['filesystem']['mogilefs']['hosts']) |
450
|
|
|
; |
451
|
|
|
} else { |
452
|
|
|
$container->removeDefinition('sonata.media.adapter.filesystem.mogilefs'); |
453
|
|
|
$container->removeDefinition('sonata.media.filesystem.mogilefs'); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
if ($container->hasDefinition('sonata.media.adapter.filesystem.opencloud') && |
457
|
|
|
(isset($config['filesystem']['openstack']) || isset($config['filesystem']['rackspace']))) { |
458
|
|
|
if (isset($config['filesystem']['openstack'])) { |
459
|
|
|
$container->setParameter('sonata.media.adapter.filesystem.opencloud.class', 'OpenCloud\OpenStack'); |
460
|
|
|
$settings = 'openstack'; |
461
|
|
|
} else { |
462
|
|
|
$container->setParameter('sonata.media.adapter.filesystem.opencloud.class', 'OpenCloud\Rackspace'); |
463
|
|
|
$settings = 'rackspace'; |
464
|
|
|
} |
465
|
|
|
$container->getDefinition('sonata.media.adapter.filesystem.opencloud.connection') |
466
|
|
|
->replaceArgument(0, $config['filesystem'][$settings]['url']) |
467
|
|
|
->replaceArgument(1, $config['filesystem'][$settings]['secret']) |
468
|
|
|
; |
469
|
|
|
$container->getDefinition('sonata.media.adapter.filesystem.opencloud') |
470
|
|
|
->replaceArgument(1, $config['filesystem'][$settings]['containerName']) |
471
|
|
|
->replaceArgument(2, $config['filesystem'][$settings]['create_container']); |
472
|
|
|
$container->getDefinition('sonata.media.adapter.filesystem.opencloud.objectstore') |
473
|
|
|
->replaceArgument(1, $config['filesystem'][$settings]['region']); |
474
|
|
|
} else { |
475
|
|
|
$container->removeDefinition('sonata.media.adapter.filesystem.opencloud'); |
476
|
|
|
$container->removeDefinition('sonata.media.adapter.filesystem.opencloud.connection'); |
477
|
|
|
$container->removeDefinition('sonata.media.adapter.filesystem.opencloud.objectstore'); |
478
|
|
|
$container->removeDefinition('sonata.media.filesystem.opencloud'); |
479
|
|
|
} |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* @param ContainerBuilder $container |
484
|
|
|
* @param array $config |
485
|
|
|
*/ |
486
|
|
|
public function configureExtra(ContainerBuilder $container, array $config) |
487
|
|
|
{ |
488
|
|
|
if ($config['pixlr']['enabled']) { |
489
|
|
|
$container->getDefinition('sonata.media.extra.pixlr') |
490
|
|
|
->replaceArgument(0, $config['pixlr']['referrer']) |
491
|
|
|
->replaceArgument(1, $config['pixlr']['secret']) |
492
|
|
|
; |
493
|
|
|
} else { |
494
|
|
|
$container->removeDefinition('sonata.media.extra.pixlr'); |
495
|
|
|
} |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* Add class to compile. |
500
|
|
|
*/ |
501
|
|
|
public function configureClassesToCompile() |
502
|
|
|
{ |
503
|
|
|
$this->addClassesToCompile(array( |
504
|
|
|
'Sonata\\MediaBundle\\CDN\\CDNInterface', |
505
|
|
|
'Sonata\\MediaBundle\\CDN\\CloudFront', |
506
|
|
|
'Sonata\\MediaBundle\\CDN\\Fallback', |
507
|
|
|
'Sonata\\MediaBundle\\CDN\\PantherPortal', |
508
|
|
|
'Sonata\\MediaBundle\\CDN\\Server', |
509
|
|
|
'Sonata\\MediaBundle\\Extra\\Pixlr', |
510
|
|
|
'Sonata\\MediaBundle\\Filesystem\\Local', |
511
|
|
|
'Sonata\\MediaBundle\\Filesystem\\Replicate', |
512
|
|
|
'Sonata\\MediaBundle\\Generator\\DefaultGenerator', |
513
|
|
|
'Sonata\\MediaBundle\\Generator\\GeneratorInterface', |
514
|
|
|
'Sonata\\MediaBundle\\Generator\\ODMGenerator', |
515
|
|
|
'Sonata\\MediaBundle\\Generator\\PHPCRGenerator', |
516
|
|
|
'Sonata\\MediaBundle\\Metadata\\AmazonMetadataBuilder', |
517
|
|
|
'Sonata\\MediaBundle\\Metadata\\MetadataBuilderInterface', |
518
|
|
|
'Sonata\\MediaBundle\\Metadata\\NoopMetadataBuilder', |
519
|
|
|
'Sonata\\MediaBundle\\Metadata\\ProxyMetadataBuilder', |
520
|
|
|
'Sonata\\MediaBundle\\Model\\Gallery', |
521
|
|
|
'Sonata\\MediaBundle\\Model\\GalleryItem', |
522
|
|
|
'Sonata\\MediaBundle\\Model\\GalleryItemInterface', |
523
|
|
|
'Sonata\\MediaBundle\\Model\\GalleryInterface', |
524
|
|
|
'Sonata\\MediaBundle\\Model\\GalleryManager', |
525
|
|
|
'Sonata\\MediaBundle\\Model\\GalleryManagerInterface', |
526
|
|
|
'Sonata\\MediaBundle\\Model\\Media', |
527
|
|
|
'Sonata\\MediaBundle\\Model\\MediaInterface', |
528
|
|
|
'Sonata\\MediaBundle\\Model\\MediaManagerInterface', |
529
|
|
|
'Sonata\\MediaBundle\\Provider\\BaseProvider', |
530
|
|
|
'Sonata\\MediaBundle\\Provider\\BaseVideoProvider', |
531
|
|
|
'Sonata\\MediaBundle\\Provider\\DailyMotionProvider', |
532
|
|
|
'Sonata\\MediaBundle\\Provider\\FileProvider', |
533
|
|
|
'Sonata\\MediaBundle\\Provider\\ImageProvider', |
534
|
|
|
'Sonata\\MediaBundle\\Provider\\MediaProviderInterface', |
535
|
|
|
'Sonata\\MediaBundle\\Provider\\Pool', |
536
|
|
|
'Sonata\\MediaBundle\\Provider\\VimeoProvider', |
537
|
|
|
'Sonata\\MediaBundle\\Provider\\YouTubeProvider', |
538
|
|
|
'Sonata\\MediaBundle\\Resizer\\ResizerInterface', |
539
|
|
|
'Sonata\\MediaBundle\\Resizer\\SimpleResizer', |
540
|
|
|
'Sonata\\MediaBundle\\Resizer\\SquareResizer', |
541
|
|
|
'Sonata\\MediaBundle\\Security\\DownloadStrategyInterface', |
542
|
|
|
'Sonata\\MediaBundle\\Security\\ForbiddenDownloadStrategy', |
543
|
|
|
'Sonata\\MediaBundle\\Security\\PublicDownloadStrategy', |
544
|
|
|
'Sonata\\MediaBundle\\Security\\RolesDownloadStrategy', |
545
|
|
|
'Sonata\\MediaBundle\\Security\\SessionDownloadStrategy', |
546
|
|
|
'Sonata\\MediaBundle\\Templating\\Helper\\MediaHelper', |
547
|
|
|
'Sonata\\MediaBundle\\Thumbnail\\ConsumerThumbnail', |
548
|
|
|
'Sonata\\MediaBundle\\Thumbnail\\FormatThumbnail', |
549
|
|
|
'Sonata\\MediaBundle\\Thumbnail\\ThumbnailInterface', |
550
|
|
|
'Sonata\\MediaBundle\\Twig\\Extension\\MediaExtension', |
551
|
|
|
'Sonata\\MediaBundle\\Twig\\Node\\MediaNode', |
552
|
|
|
'Sonata\\MediaBundle\\Twig\\Node\\PathNode', |
553
|
|
|
'Sonata\\MediaBundle\\Twig\\Node\\ThumbnailNode', |
554
|
|
|
)); |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
/** |
558
|
|
|
* Sets category and category manager in media bundle. |
559
|
|
|
* |
560
|
|
|
* @param ContainerBuilder $container |
561
|
|
|
* @param array $config |
562
|
|
|
*/ |
563
|
|
|
private function configureCategoryInMedia(ContainerBuilder $container, array $config) |
564
|
|
|
{ |
565
|
|
|
if (!$this->isClassificationEnabled($config)) { |
566
|
|
|
return; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
$container->setAlias('sonata.media.manager.category', $config['category_manager'] ?: 'sonata.media.manager.category.default'); |
570
|
|
|
|
571
|
|
|
if (null === $config['class']['category']) { |
572
|
|
|
$config['class']['category'] = 'Application\\Sonata\\ClassificationBundle\\Entity\\Category'; |
573
|
|
|
} |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
/** |
577
|
|
|
* Checks if the classification of media is enabled. |
578
|
|
|
* |
579
|
|
|
* @param array $config |
580
|
|
|
* |
581
|
|
|
* @return bool |
582
|
|
|
*/ |
583
|
|
|
private function isClassificationEnabled(array $config) |
584
|
|
|
{ |
585
|
|
|
return !$config['force_disable_category'] && |
586
|
|
|
(null !== $config['category_manager'] || interface_exists('Sonata\ClassificationBundle\Model\CategoryInterface')); |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
/* |
590
|
|
|
* @param ContainerBuilder $container |
591
|
|
|
* @param array $config |
592
|
|
|
*/ |
593
|
|
|
private function configureAdapters(ContainerBuilder $container, array $config) |
594
|
|
|
{ |
595
|
|
|
foreach (array('gd', 'imagick', 'gmagick') as $adapter) { |
596
|
|
|
if ($container->hasParameter('sonata.media.adapter.image.'.$adapter.'.class')) { |
597
|
|
|
$container->register('sonata.media.adapter.image.'.$adapter, $container->getParameter('sonata.media.adapter.image.'.$adapter.'.class')); |
598
|
|
|
} |
599
|
|
|
} |
600
|
|
|
$container->setAlias('sonata.media.adapter.image.default', $config['adapters']['default']); |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* @param ContainerBuilder $container |
605
|
|
|
* @param array $config |
606
|
|
|
*/ |
607
|
|
|
private function configureResizers(ContainerBuilder $container, array $config) |
608
|
|
|
{ |
609
|
|
|
if ($container->hasParameter('sonata.media.resizer.simple.class')) { |
610
|
|
|
$class = $container->getParameter('sonata.media.resizer.simple.class'); |
611
|
|
|
$definition = new Definition($class, array( |
612
|
|
|
new Reference('sonata.media.adapter.image.default'), |
613
|
|
|
'%sonata.media.resizer.simple.adapter.mode%', |
614
|
|
|
new Reference('sonata.media.metadata.proxy'), |
615
|
|
|
)); |
616
|
|
|
$container->setDefinition('sonata.media.resizer.simple', $definition); |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
if ($container->hasParameter('sonata.media.resizer.square.class')) { |
620
|
|
|
$class = $container->getParameter('sonata.media.resizer.square.class'); |
621
|
|
|
$definition = new Definition($class, array( |
622
|
|
|
new Reference('sonata.media.adapter.image.default'), |
623
|
|
|
'%sonata.media.resizer.square.adapter.mode%', |
624
|
|
|
new Reference('sonata.media.metadata.proxy'), |
625
|
|
|
)); |
626
|
|
|
$container->setDefinition('sonata.media.resizer.square', $definition); |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
$container->setAlias('sonata.media.resizer.default', $config['resizers']['default']); |
630
|
|
|
} |
631
|
|
|
} |
632
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.