|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the XabbuhPandaBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Christian Flothmann <[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 Xabbuh\PandaBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
19
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* XabbuhPandaExtension. |
|
23
|
|
|
* |
|
24
|
|
|
* @author Christian Flothmann <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class XabbuhPandaExtension extends Extension |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritDoc} |
|
30
|
|
|
*/ |
|
31
|
4 |
|
public function load(array $configs, ContainerBuilder $container) |
|
32
|
|
|
{ |
|
33
|
4 |
|
$configuration = new Configuration(); |
|
34
|
4 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
35
|
|
|
|
|
36
|
4 |
|
$container->setParameter( |
|
37
|
4 |
|
'xabbuh_panda.video_uploader.multiple_files', |
|
38
|
4 |
|
$config['video_uploader']['multiple_files'] |
|
39
|
|
|
); |
|
40
|
4 |
|
$container->setParameter( |
|
41
|
4 |
|
'xabbuh_panda.video_uploader.cancel_button', |
|
42
|
4 |
|
$config['video_uploader']['cancel_button'] |
|
43
|
|
|
); |
|
44
|
4 |
|
$container->setParameter( |
|
45
|
4 |
|
'xabbuh_panda.video_uploader.progress_bar', |
|
46
|
4 |
|
$config['video_uploader']['progress_bar'] |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
4 |
|
$container->setParameter('xabbuh_panda.account.default', $config['default_account']); |
|
50
|
4 |
|
$container->setParameter('xabbuh_panda.cloud.default', $config['default_cloud']); |
|
51
|
|
|
|
|
52
|
|
|
// and load the service definitions |
|
53
|
4 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
54
|
4 |
|
$loader->load('account_manager.xml'); |
|
55
|
4 |
|
$loader->load('cloud_manager.xml'); |
|
56
|
4 |
|
$loader->load('cloud_factory.xml'); |
|
57
|
4 |
|
$loader->load('controller.xml'); |
|
58
|
4 |
|
$loader->load('transformers.xml'); |
|
59
|
4 |
|
$loader->load('video_uploader_extension.xml'); |
|
60
|
|
|
|
|
61
|
|
|
// Add the tag for the form type extension without using deprecated APIs |
|
62
|
4 |
|
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) { |
|
63
|
4 |
|
$container->getDefinition('xabbuh_panda.video_uploader_extension') |
|
64
|
4 |
|
->addTag('form.type_extension', array('extended_type' => 'Symfony\Component\Form\Extension\Core\Type\FileType')); |
|
65
|
|
|
} else { |
|
66
|
|
|
$container->getDefinition('xabbuh_panda.video_uploader_extension') |
|
67
|
|
|
->addTag('form.type_extension', array('alias' => 'file')); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
4 |
|
$this->loadAccounts($config['accounts'], $container); |
|
71
|
4 |
|
$this->loadClouds($config['clouds'], $container); |
|
72
|
4 |
|
$this->registerSerializerFactory($container); |
|
73
|
4 |
|
} |
|
74
|
|
|
|
|
75
|
4 |
|
private function loadAccounts(array $accounts, ContainerBuilder $container) |
|
76
|
|
|
{ |
|
77
|
4 |
|
$accountManagerDefinition = $container->getDefinition('xabbuh_panda.account_manager'); |
|
78
|
|
|
|
|
79
|
4 |
|
foreach ($accounts as $name => $accountConfig) { |
|
80
|
|
|
// register each account as a service |
|
81
|
|
|
$accountDefinition = new Definition( |
|
82
|
|
|
'Xabbuh\PandaClient\Api\Account', |
|
83
|
|
|
array( |
|
84
|
|
|
$accountConfig['access_key'], |
|
85
|
|
|
$accountConfig['secret_key'], |
|
86
|
|
|
$accountConfig['api_host'] |
|
87
|
|
|
) |
|
88
|
|
|
); |
|
89
|
|
|
$id = 'xabbuh_panda.'.strtr($name, ' -', '_').'_account'; |
|
90
|
|
|
$container->setDefinition($id, $accountDefinition); |
|
91
|
|
|
|
|
92
|
|
|
// and pass it to the manager's registerAccount() method |
|
93
|
|
|
$accountManagerDefinition->addMethodCall( |
|
94
|
|
|
'registerAccount', |
|
95
|
|
|
array($name, new Reference($id)) |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
4 |
|
} |
|
99
|
|
|
|
|
100
|
4 |
|
private function loadClouds(array $clouds, ContainerBuilder $container) |
|
101
|
|
|
{ |
|
102
|
4 |
|
$cloudManagerDefinition = $container->getDefinition('xabbuh_panda.cloud_manager'); |
|
103
|
|
|
|
|
104
|
4 |
|
foreach ($clouds as $name => $cloudConfig) { |
|
105
|
|
|
// register each cloud as a service |
|
106
|
2 |
|
$cloudDefinition = new Definition( |
|
107
|
2 |
|
'Xabbuh\PandaClient\Api\Cloud', |
|
108
|
|
|
array( |
|
109
|
2 |
|
$cloudConfig['id'], |
|
110
|
2 |
|
isset($cloudConfig['account']) ? $cloudConfig['account'] : null, |
|
111
|
|
|
) |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
2 |
|
if (method_exists($cloudDefinition, 'setFactory')) { |
|
115
|
2 |
|
$cloudDefinition->setFactory(array(new Reference('xabbuh_panda.cloud_factory'), 'get')); |
|
116
|
|
|
} else { |
|
117
|
|
|
$cloudDefinition->setFactoryService('xabbuh_panda.cloud_factory'); |
|
|
|
|
|
|
118
|
|
|
$cloudDefinition->setFactoryMethod('get'); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
2 |
|
$id = 'xabbuh_panda.'.strtr($name, ' -', '_').'_cloud'; |
|
122
|
2 |
|
$container->setDefinition($id, $cloudDefinition); |
|
123
|
|
|
|
|
124
|
|
|
// and pass it to the manager's registerAccount() method |
|
125
|
2 |
|
$cloudManagerDefinition->addMethodCall( |
|
126
|
2 |
|
'registerCloud', |
|
127
|
2 |
|
array($name, new Reference($id)) |
|
128
|
|
|
); |
|
129
|
|
|
} |
|
130
|
4 |
|
} |
|
131
|
|
|
|
|
132
|
4 |
|
private function registerSerializerFactory(ContainerBuilder $container) |
|
133
|
|
|
{ |
|
134
|
|
|
$serializers = array( |
|
135
|
4 |
|
'xabbuh_panda.serializer.cloud' => 'getCloudSerializer', |
|
136
|
|
|
'xabbuh_panda.serializer.encoding' => 'getEncodingSerializer', |
|
137
|
|
|
'xabbuh_panda.serializer.profile' => 'getProfileSerializer', |
|
138
|
|
|
'xabbuh_panda.serializer.video' => 'getVideoSerializer', |
|
139
|
|
|
); |
|
140
|
|
|
|
|
141
|
4 |
|
foreach ($serializers as $serviceId => $factoryMethod) { |
|
142
|
4 |
|
$definition = $container->getDefinition($serviceId); |
|
143
|
|
|
|
|
144
|
4 |
|
if (method_exists($definition, 'setFactory')) { |
|
145
|
4 |
|
$definition->setFactory(array('%xabbuh_panda.serializer.factory.class%', $factoryMethod)); |
|
146
|
|
|
} else { |
|
147
|
|
|
$definition->setFactoryClass('%xabbuh_panda.serializer.factory.class%'); |
|
|
|
|
|
|
148
|
4 |
|
$definition->setFactoryMethod($factoryMethod); |
|
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
4 |
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* {@inheritDoc} |
|
155
|
|
|
*/ |
|
156
|
4 |
|
public function getNamespace() |
|
157
|
|
|
{ |
|
158
|
4 |
|
return 'http://xabbuh.de/schema/dic/xabbuh/panda'; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* {@inheritDoc} |
|
163
|
|
|
*/ |
|
164
|
|
|
public function getXsdValidationBasePath() |
|
165
|
|
|
{ |
|
166
|
|
|
return __DIR__.'/../Resources/config/schema'; |
|
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.