1
+ <?php
2
+ /*
3
+ * This file is part of the Sonata project.
4
+ *
5
+ * (c) Thomas Rabaix <[email protected] >
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+
11
+
12
+ namespace Bundle \MediaBundle \DependencyInjection ;
13
+
14
+ use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
15
+ use Symfony \Component \DependencyInjection \Resource \FileResource ;
16
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
17
+ use Symfony \Component \DependencyInjection \Reference ;
18
+ use Symfony \Component \DependencyInjection \Definition ;
19
+ use Symfony \Component \DependencyInjection \Extension \Extension ;
20
+
21
+ use Symfony \Component \Finder \Finder ;
22
+
23
+ /**
24
+ * MediaExtension
25
+ *
26
+ *
27
+ * @author Thomas Rabaix <[email protected] >
28
+ */
29
+ class MediaExtension extends Extension {
30
+
31
+ /**
32
+ * Loads the url shortener configuration.
33
+ *
34
+ * @param array $config An array of configuration settings
35
+ * @param ContainerBuilder $container A ContainerBuilder instance
36
+ */
37
+ public function configLoad ($ config , ContainerBuilder $ container ) {
38
+
39
+ $ definition = new Definition ($ config ['class ' ]);
40
+
41
+ foreach ($ config ['providers ' ] as $ name => $ provider ) {
42
+
43
+ $ provider_name = sprintf ('media.provider.%s ' , $ name );
44
+
45
+ $ config ['settings ' ]['quality ' ] = isset ($ config ['settings ' ]['quality ' ]) ? $ config ['settings ' ]['quality ' ] : 80 ;
46
+ $ config ['settings ' ]['format ' ] = isset ($ config ['settings ' ]['format ' ]) ? $ config ['settings ' ]['format ' ] : 'jpg ' ;
47
+ $ config ['settings ' ]['height ' ] = isset ($ config ['settings ' ]['height ' ]) ? $ config ['settings ' ]['height ' ] : 'false ' ;
48
+ $ config ['settings ' ]['constraint ' ] = isset ($ config ['settings ' ]['constraint ' ]) ? $ config ['settings ' ]['constraint ' ] : true ;
49
+
50
+ $ provider ['formats ' ] = is_array ($ provider ['formats ' ]) ? $ provider ['formats ' ] : array ();
51
+
52
+ $ provider_definition = new Definition ($ provider ['class ' ], array (
53
+ $ name ,
54
+ new Reference ($ config ['em ' ]),
55
+ $ config ['settings ' ],
56
+ ));
57
+
58
+ foreach ($ provider ['formats ' ] as $ format_name => $ format_definition ) {
59
+ $ provider_definition ->addMethodCall ('addFormat ' , array ($ format_name , $ format_definition ));
60
+ }
61
+
62
+ $ container ->setDefinition ($ provider_name , $ provider_definition );
63
+
64
+ $ definition ->addMethodCall ('addProvider ' , array ($ name , new Reference ($ provider_name )));
65
+ }
66
+
67
+ $ container ->setDefinition ('media.provider ' , $ definition );
68
+ }
69
+
70
+ /**
71
+ * Returns the base path for the XSD files.
72
+ *
73
+ * @return string The XSD base path
74
+ */
75
+ public function getXsdValidationBasePath () {
76
+
77
+ return __DIR__ .'/../Resources/config/schema ' ;
78
+ }
79
+
80
+ public function getNamespace () {
81
+
82
+ return 'http://www.sonata-project.org/schema/dic/media ' ;
83
+ }
84
+
85
+ public function getAlias () {
86
+
87
+ return "media " ;
88
+ }
89
+ }
0 commit comments