These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Extension\PrependExtensionInterface; |
||
8 | use Symfony\Component\DependencyInjection\Loader; |
||
9 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
||
10 | use Symfony\Component\Yaml\Yaml; |
||
11 | |||
12 | /** |
||
13 | * This is the class that loads and manages your bundle configuration |
||
14 | * |
||
15 | * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
||
16 | */ |
||
17 | class KunstmaanMediaExtension extends Extension implements PrependExtensionInterface |
||
18 | { |
||
19 | /** |
||
20 | * Loads configuration |
||
21 | * |
||
22 | * @param array $configs Configuration |
||
23 | * @param ContainerBuilder $container Container |
||
24 | */ |
||
25 | 4 | public function load(array $configs, ContainerBuilder $container) |
|
26 | { |
||
27 | 4 | $configuration = new Configuration(); |
|
28 | 4 | $config = $this->processConfiguration($configuration, $configs); |
|
29 | |||
30 | 4 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
31 | |||
32 | 4 | $container->setParameter( |
|
33 | 4 | 'twig.form.resources', |
|
34 | 4 | array_merge( |
|
35 | 4 | $container->hasParameter('twig.form.resources') ? $container->getParameter('twig.form.resources') : [], |
|
36 | 4 | array('KunstmaanMediaBundle:Form:formWidgets.html.twig') |
|
37 | ) |
||
38 | ); |
||
39 | 4 | $container->setParameter('kunstmaan_media.soundcloud_api_key', $config['soundcloud_api_key']); |
|
40 | 4 | $container->setParameter('kunstmaan_media.remote_video', $config['remote_video']); |
|
41 | 4 | $container->setParameter('kunstmaan_media.enable_pdf_preview', $config['enable_pdf_preview']); |
|
42 | 4 | $container->setParameter('kunstmaan_media.blacklisted_extensions', $config['blacklisted_extensions']); |
|
43 | 4 | $container->setParameter('kunstmaan_media.web_root', $config['web_root']); |
|
44 | 4 | $container->setParameter('kunstmaan_media.full_media_path', $config['web_root'] . '%kunstmaan_media.media_path%'); |
|
45 | |||
46 | 4 | $loader->load('services.yml'); |
|
47 | 4 | $loader->load('handlers.yml'); |
|
48 | |||
49 | 4 | if ($config['enable_pdf_preview'] === true) { |
|
50 | 1 | $loader->load('pdf_preview.yml'); |
|
51 | } |
||
52 | |||
53 | 4 | $container->setParameter('liip_imagine.filter.loader.background.class', 'Kunstmaan\MediaBundle\Helper\Imagine\BackgroundFilterLoader'); |
|
54 | |||
55 | 4 | $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
56 | 4 | $loader->load('imagine.xml'); |
|
57 | |||
58 | 4 | $container->setAlias('liip_imagine.controller', 'Kunstmaan\MediaBundle\Helper\Imagine\ImagineController')->setPublic(true); |
|
59 | 4 | $container->setAlias('Liip\ImagineBundle\Controller\ImagineController', 'Kunstmaan\MediaBundle\Helper\Imagine\ImagineController')->setPublic(true); |
|
60 | 4 | $container->setAlias('liip_imagine.cache.resolver.prototype.web_path', 'Kunstmaan\MediaBundle\Helper\Imagine\WebPathResolver'); |
|
61 | 4 | $container->setAlias('liip_imagine.cache.manager', 'Kunstmaan\MediaBundle\Helper\Imagine\CacheManager')->setPublic(true); |
|
62 | 4 | $container->setAlias('liip_imagine.filter.loader.background', 'kunstmaan_media.imagine.filter.loader.background')->setPublic(true); |
|
63 | |||
64 | 4 | $this->addAvairyApiKeyParameter($container, $config); |
|
65 | 4 | } |
|
66 | |||
67 | 4 | public function prepend(ContainerBuilder $container) |
|
68 | { |
||
69 | 4 | if (!$container->hasParameter('kunstmaan_media.upload_dir')) { |
|
70 | 4 | $container->setParameter('kunstmaan_media.upload_dir', '/uploads/media/'); |
|
71 | } |
||
72 | |||
73 | 4 | $twigConfig = array(); |
|
74 | 4 | $twigConfig['globals']['upload_dir'] = $container->getParameter('kunstmaan_media.upload_dir'); |
|
75 | 4 | $twigConfig['globals']['mediabundleisactive'] = true; |
|
76 | 4 | $twigConfig['globals']['mediamanager'] = '@kunstmaan_media.media_manager'; |
|
77 | 4 | $container->prependExtensionConfig('twig', $twigConfig); |
|
78 | |||
79 | 4 | $liipConfig = Yaml::parse(file_get_contents(__DIR__ . '/../Resources/config/imagine_filters.yml')); |
|
80 | 4 | $container->prependExtensionConfig('liip_imagine', $liipConfig['liip_imagine']); |
|
81 | |||
82 | 4 | $defaultLocale = $container->hasParameter('kunstmaan_admin.default_locale') ? $container->getParameter('kunstmaan_admin.default_locale') : 'en'; |
|
83 | $stofDoctrineExtensionsConfig = [ |
||
84 | 4 | 'default_locale' => $defaultLocale, |
|
85 | 'translation_fallback' => true, |
||
86 | 'orm' => [ |
||
87 | 'default' => [ |
||
88 | 'translatable' => true, |
||
89 | ], |
||
90 | ], |
||
91 | ]; |
||
92 | |||
93 | 4 | $container->prependExtensionConfig('stof_doctrine_extensions', $stofDoctrineExtensionsConfig); |
|
94 | |||
95 | $doctrineGedmoEntityConfig = [ |
||
96 | 4 | 'orm' => [ |
|
97 | 'mappings' => [ |
||
98 | 'gedmo_translatable' => [ |
||
99 | 'type' => 'annotation', |
||
100 | 'prefix' => 'Gedmo\Translatable\Entity', |
||
101 | 'dir' => '%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity', |
||
102 | 'alias' => 'GedmoTranslatable', |
||
103 | 'is_bundle' => false, |
||
104 | ], |
||
105 | ], |
||
106 | ], |
||
107 | ]; |
||
108 | |||
109 | 4 | $container->prependExtensionConfig('doctrine', $doctrineGedmoEntityConfig); |
|
110 | |||
111 | 4 | $configs = $container->getExtensionConfig($this->getAlias()); |
|
112 | 4 | $this->processConfiguration(new Configuration(), $configs); |
|
113 | 4 | } |
|
114 | |||
115 | /** |
||
116 | * @return string |
||
117 | */ |
||
118 | 4 | public function getAlias() |
|
119 | { |
||
120 | 4 | return 'kunstmaan_media'; |
|
121 | } |
||
122 | |||
123 | 4 | View Code Duplication | private function addAvairyApiKeyParameter(ContainerBuilder $container, array $config) |
124 | { |
||
125 | 4 | $aviaryApiKey = $container->hasParameter('aviary_api_key') ? $container->getParameter('aviary_api_key') : null; |
|
126 | 4 | if (null === $config['aviary_api_key'] && null !== $aviaryApiKey) { |
|
127 | 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 KunstmaanDashboardBundle 5.2, this config value will replace the "aviary_api_key" parameter in KunstmaanDashboardBundle 6.0.', E_USER_DEPRECATED); |
|
0 ignored issues
–
show
|
|||
128 | } |
||
129 | |||
130 | 4 | if (null !== $config['aviary_api_key']) { |
|
131 | 1 | $aviaryApiKey = $config['aviary_api_key']; |
|
132 | } |
||
133 | |||
134 | 4 | $container->setParameter('kunstmaan_media.aviary_api_key', $aviaryApiKey); |
|
135 | 4 | } |
|
136 | } |
||
137 |
If you suppress an error, we recommend checking for the error condition explicitly: