1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\MediaBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
8
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
9
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
10
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
11
|
|
|
use Symfony\Component\Mime\MimeTypes; |
12
|
|
|
use Symfony\Component\Yaml\Yaml; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* This is the class that loads and manages your bundle configuration |
16
|
|
|
* |
17
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
18
|
|
|
*/ |
19
|
|
|
class KunstmaanMediaExtension extends Extension implements PrependExtensionInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Loads configuration |
23
|
|
|
* |
24
|
|
|
* @param array $configs Configuration |
25
|
|
|
* @param ContainerBuilder $container Container |
26
|
|
|
*/ |
27
|
4 |
|
public function load(array $configs, ContainerBuilder $container) |
28
|
|
|
{ |
29
|
4 |
|
$configuration = new Configuration(); |
30
|
4 |
|
$config = $this->processConfiguration($configuration, $configs); |
31
|
|
|
|
32
|
4 |
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
33
|
|
|
|
34
|
4 |
|
$container->setParameter( |
35
|
4 |
|
'twig.form.resources', |
36
|
4 |
|
array_merge( |
37
|
4 |
|
$container->hasParameter('twig.form.resources') ? $container->getParameter('twig.form.resources') : [], |
38
|
4 |
|
['@KunstmaanMedia/Form/formWidgets.html.twig'] |
39
|
|
|
) |
40
|
|
|
); |
41
|
4 |
|
$container->setParameter('kunstmaan_media.soundcloud_api_key', $config['soundcloud_api_key']); |
42
|
4 |
|
$container->setParameter('kunstmaan_media.remote_video', $config['remote_video']); |
43
|
4 |
|
$container->setParameter('kunstmaan_media.enable_pdf_preview', $config['enable_pdf_preview']); |
44
|
4 |
|
$container->setParameter('kunstmaan_media.blacklisted_extensions', $config['blacklisted_extensions']); |
45
|
4 |
|
$container->setParameter('kunstmaan_media.web_root', $config['web_root']); |
46
|
4 |
|
$container->setParameter('kunstmaan_media.full_media_path', $config['web_root'] . '%kunstmaan_media.media_path%'); |
47
|
|
|
|
48
|
4 |
|
$loader->load('services.yml'); |
49
|
4 |
|
$loader->load('handlers.yml'); |
50
|
|
|
|
51
|
4 |
|
if ($config['enable_pdf_preview'] === true) { |
52
|
1 |
|
$loader->load('pdf_preview.yml'); |
53
|
|
|
} |
54
|
|
|
|
55
|
4 |
|
$container->setParameter('liip_imagine.filter.loader.background.class', 'Kunstmaan\MediaBundle\Helper\Imagine\BackgroundFilterLoader'); |
56
|
|
|
|
57
|
4 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
58
|
4 |
|
$loader->load('imagine.xml'); |
59
|
|
|
|
60
|
4 |
|
$container->setAlias('liip_imagine.controller', 'Kunstmaan\MediaBundle\Helper\Imagine\ImagineController')->setPublic(true); |
61
|
4 |
|
$container->setAlias('Liip\ImagineBundle\Controller\ImagineController', 'Kunstmaan\MediaBundle\Helper\Imagine\ImagineController')->setPublic(true); |
62
|
4 |
|
$container->setAlias('liip_imagine.cache.resolver.prototype.web_path', 'Kunstmaan\MediaBundle\Helper\Imagine\WebPathResolver'); |
63
|
4 |
|
$container->setAlias('liip_imagine.cache.manager', 'Kunstmaan\MediaBundle\Helper\Imagine\CacheManager')->setPublic(true); |
64
|
4 |
|
$container->setAlias('liip_imagine.filter.loader.background', 'kunstmaan_media.imagine.filter.loader.background')->setPublic(true); |
65
|
|
|
|
66
|
4 |
|
$this->addAvairyApiKeyParameter($container, $config); |
67
|
|
|
|
68
|
4 |
|
if (!$container->hasDefinition('mime_types')) { |
69
|
4 |
|
$mimeTypes = new Definition(MimeTypes::class); |
70
|
4 |
|
$mimeTypes->setPublic(true); |
71
|
4 |
|
$container->setDefinition('mime_types', $mimeTypes); |
72
|
|
|
} |
73
|
4 |
|
} |
74
|
|
|
|
75
|
4 |
|
public function prepend(ContainerBuilder $container) |
76
|
|
|
{ |
77
|
4 |
|
if (!$container->hasParameter('kunstmaan_media.upload_dir')) { |
78
|
4 |
|
$container->setParameter('kunstmaan_media.upload_dir', '/uploads/media/'); |
79
|
|
|
} |
80
|
|
|
|
81
|
4 |
|
$twigConfig = []; |
82
|
4 |
|
$twigConfig['globals']['upload_dir'] = $container->getParameter('kunstmaan_media.upload_dir'); |
83
|
4 |
|
$twigConfig['globals']['mediabundleisactive'] = true; |
84
|
4 |
|
$twigConfig['globals']['mediamanager'] = '@kunstmaan_media.media_manager'; |
85
|
4 |
|
$container->prependExtensionConfig('twig', $twigConfig); |
86
|
|
|
|
87
|
4 |
|
$liipConfig = Yaml::parse(file_get_contents(__DIR__ . '/../Resources/config/imagine_filters.yml')); |
88
|
4 |
|
$container->prependExtensionConfig('liip_imagine', $liipConfig['liip_imagine']); |
89
|
|
|
|
90
|
4 |
|
$defaultLocale = $container->hasParameter('kunstmaan_admin.default_locale') ? $container->getParameter('kunstmaan_admin.default_locale') : 'en'; |
91
|
|
|
$stofDoctrineExtensionsConfig = [ |
92
|
4 |
|
'default_locale' => $defaultLocale, |
93
|
|
|
'translation_fallback' => true, |
94
|
|
|
'orm' => [ |
95
|
|
|
'default' => [ |
96
|
|
|
'translatable' => true, |
97
|
|
|
], |
98
|
|
|
], |
99
|
|
|
]; |
100
|
|
|
|
101
|
4 |
|
$container->prependExtensionConfig('stof_doctrine_extensions', $stofDoctrineExtensionsConfig); |
102
|
|
|
|
103
|
|
|
$doctrineGedmoEntityConfig = [ |
104
|
|
|
'orm' => [ |
105
|
|
|
'mappings' => [ |
106
|
|
|
'gedmo_translatable' => [ |
107
|
4 |
|
'type' => 'annotation', |
108
|
|
|
'prefix' => 'Gedmo\Translatable\Entity', |
109
|
|
|
'dir' => '%kernel.project_dir%/vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity', |
110
|
|
|
'alias' => 'GedmoTranslatable', |
111
|
|
|
'is_bundle' => false, |
112
|
|
|
], |
113
|
|
|
], |
114
|
|
|
], |
115
|
|
|
]; |
116
|
|
|
|
117
|
4 |
|
$container->prependExtensionConfig('doctrine', $doctrineGedmoEntityConfig); |
118
|
|
|
|
119
|
|
|
$frameworkExtensionConfig = [ |
120
|
|
|
'assets' => [ |
121
|
|
|
'packages' => [ |
122
|
4 |
|
'media' => null, |
123
|
|
|
], |
124
|
|
|
], |
125
|
|
|
]; |
126
|
4 |
|
$container->prependExtensionConfig('framework', $frameworkExtensionConfig); |
127
|
|
|
|
128
|
4 |
|
$configs = $container->getExtensionConfig($this->getAlias()); |
129
|
4 |
|
$this->processConfiguration(new Configuration(), $configs); |
130
|
4 |
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
4 |
|
public function getAlias() |
136
|
|
|
{ |
137
|
4 |
|
return 'kunstmaan_media'; |
138
|
|
|
} |
139
|
|
|
|
140
|
4 |
View Code Duplication |
private function addAvairyApiKeyParameter(ContainerBuilder $container, array $config) |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
// NEXT_MAJOR: Remove parameter, config option and all aviary related files (twig, js, etc) |
143
|
4 |
|
$aviaryApiKey = $container->hasParameter('aviary_api_key') ? $container->getParameter('aviary_api_key') : null; |
144
|
4 |
|
if (null === $config['aviary_api_key'] && null !== $aviaryApiKey) { |
145
|
1 |
|
@trigger_error('Not providing a value for the "kunstmaan_media.aviary_api_key" config while setting the "aviary_api_key" parameter is deprecated since KunstmaanMediaBundle 5.2, this config value will replace the "aviary_api_key" parameter in KunstmaanMediaBundle 6.0.', E_USER_DEPRECATED); |
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
4 |
|
if (null !== $config['aviary_api_key']) { |
149
|
1 |
|
$aviaryApiKey = $config['aviary_api_key']; |
150
|
|
|
} |
151
|
|
|
|
152
|
4 |
|
$container->setParameter('kunstmaan_media.aviary_api_key', $aviaryApiKey); |
153
|
4 |
|
} |
154
|
|
|
} |
155
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.