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