1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Netgen\Bundle\InformationCollectionBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor; |
6
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface; |
7
|
|
|
use Netgen\InformationCollection\API\Action\ActionInterface; |
8
|
|
|
use Netgen\InformationCollection\API\ConfigurationConstants; |
9
|
|
|
use Symfony\Component\Config\FileLocator; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
12
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
13
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
14
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
15
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
16
|
|
|
use Symfony\Component\Config\Resource\FileResource; |
17
|
|
|
use Symfony\Component\Yaml\Yaml; |
18
|
|
|
use function array_merge; |
19
|
|
|
|
20
|
|
|
/** |
21
|
1 |
|
* This is the class that loads and manages your bundle configuration. |
22
|
|
|
* |
23
|
1 |
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
24
|
1 |
|
*/ |
25
|
|
|
class NetgenInformationCollectionExtension extends Extension implements PrependExtensionInterface |
26
|
1 |
|
{ |
27
|
1 |
|
/** |
28
|
1 |
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
31
|
|
|
{ |
32
|
1 |
|
$configuration = new Configuration(); |
33
|
1 |
|
$config = $this->processConfiguration($configuration, $configs); |
34
|
1 |
|
|
35
|
|
|
$bundleResourceLoader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
36
|
1 |
|
$bundleResourceLoader->load('services.yml'); |
37
|
|
|
// $loader->load('parameters.yml'); |
38
|
1 |
|
// $loader->load('default_settings.yml'); |
39
|
1 |
|
|
40
|
1 |
|
|
41
|
1 |
|
$libResourceLoader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../../lib/Resources/config')); |
42
|
1 |
|
$libResourceLoader->load('services.yml'); |
43
|
1 |
|
$libResourceLoader->load('parameters.yml'); |
44
|
1 |
|
$libResourceLoader->load('default_settings.yml'); |
45
|
1 |
|
|
46
|
1 |
|
|
47
|
|
|
$this->processSemanticConfig($container, $config); |
48
|
1 |
|
// $processor = new ConfigurationProcessor($container, ConfigurationConstants::SETTINGS_ROOT); |
49
|
1 |
|
// $configArrays = array( |
50
|
1 |
|
// ConfigurationConstants::ACTIONS, |
51
|
1 |
|
// ConfigurationConstants::ACTION_CONFIG, |
52
|
1 |
|
// ); |
53
|
|
|
// |
54
|
|
|
// $scopes = array_merge(array('default'), $container->getParameter('ezpublish.siteaccess.list')); |
55
|
|
|
// |
56
|
|
|
// foreach ($configArrays as $configArray) { |
57
|
|
|
// $processor->mapConfigArray($configArray, $config); |
58
|
|
|
// foreach ($scopes as $scope) { |
59
|
|
|
// $paramName = ConfigurationConstants::SETTINGS_ROOT . '.' . $scope . '.' . $configArray; |
60
|
|
|
// if (!$container->hasParameter($paramName)) { |
61
|
|
|
// continue; |
62
|
|
|
// } |
63
|
|
|
// |
64
|
|
|
// $scopeConfig = $container->getParameter($paramName); |
65
|
|
|
// foreach ((array) $scopeConfig as $key => $value) { |
66
|
|
|
// $container->setParameter($paramName . '.' . $key, $value); |
67
|
|
|
// } |
68
|
|
|
// } |
69
|
|
|
// } |
70
|
|
|
|
71
|
|
|
$this->setUpAutoConfiguration($container); |
72
|
|
|
$this->registerServiceDefinitions($container); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function prepend(ContainerBuilder $container) |
76
|
|
|
{ |
77
|
|
|
$this->addTwigConfig($container); |
78
|
|
|
$this->addDoctrineConfig($container); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Processes semantic config and translates it to container parameters. |
83
|
|
|
*/ |
84
|
|
|
private function processSemanticConfig(ContainerBuilder $container, array $config): void |
85
|
|
|
{ |
86
|
|
|
$processor = new ConfigurationProcessor($container, ConfigurationConstants::SETTINGS_ROOT); |
87
|
|
|
$processor->mapConfig( |
88
|
|
|
$config, |
89
|
|
|
static function ($config, $scope, ContextualizerInterface $c): void { |
90
|
|
|
$c->setContextualParameter('actions', $scope, $config['actions']); |
91
|
|
|
$c->setContextualParameter('action_config', $scope, $config['action_config']); |
92
|
|
|
$c->setContextualParameter('captcha', $scope, $config['captcha']); |
93
|
|
|
$c->setContextualParameter('export', $scope, $config['export']); |
94
|
|
|
} |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
protected function addDoctrineConfig(ContainerBuilder $container) |
99
|
|
|
{ |
100
|
|
|
$configDir = __DIR__ . '/../../lib/Doctrine/mappings'; |
101
|
|
|
|
102
|
|
|
$config = [ |
103
|
|
|
'orm' => [ |
104
|
|
|
'auto_mapping' => true, |
105
|
|
|
'mappings' => [ |
106
|
|
|
'NetgenInformationCollectionBundle' => [ |
107
|
|
|
'is_bundle' => false, |
108
|
|
|
'dir' => $configDir, |
109
|
|
|
'type' => 'xml', |
110
|
|
|
'prefix' => 'Netgen\InformationCollection\Doctrine\Entity' |
111
|
|
|
] |
112
|
|
|
] |
113
|
|
|
] |
114
|
|
|
]; |
115
|
|
|
|
116
|
|
|
$container->prependExtensionConfig('doctrine', $config); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
protected function addTwigConfig(ContainerBuilder $container): void |
120
|
|
|
{ |
121
|
|
|
$configs = array( |
122
|
|
|
'twig.yml' => 'twig', |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
$activatedBundles = array_keys($container->getParameter('kernel.bundles')); |
|
|
|
|
126
|
|
|
|
127
|
|
|
foreach ($configs as $fileName => $extensionName) { |
128
|
|
|
$configFile = __DIR__ . '/../../lib/Resources/config/' . $fileName; |
129
|
|
|
$config = Yaml::parse((string)file_get_contents($configFile)); |
130
|
|
|
$container->prependExtensionConfig($extensionName, $config); |
131
|
|
|
$container->addResource(new FileResource($configFile)); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
protected function setUpAutoConfiguration(ContainerBuilder $container): void |
136
|
|
|
{ |
137
|
|
|
$container->registerForAutoconfiguration(ActionInterface::class) |
138
|
|
|
->addTag('netgen_information_collection.action'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
protected function registerServiceDefinitions(ContainerBuilder $container): void |
142
|
|
|
{ |
143
|
|
|
$definitions = []; |
144
|
|
|
|
145
|
|
|
if (class_exists('\League\Csv\Writer')) { |
146
|
|
|
$csvExportFormatter = new Definition( |
147
|
|
|
\Netgen\InformationCollection\Core\Export\CsvExportResponseFormatter::class |
148
|
|
|
); |
149
|
|
|
$csvExportFormatter->addTag('netgen_information_collection.export.formatter'); |
150
|
|
|
$csvExportFormatter->addArgument(new Reference('ezpublish.translation_helper')); |
151
|
|
|
$csvExportFormatter->addArgument(new Reference('ezpublish.config.resolver')); |
152
|
|
|
$csvExportFormatter->setPublic(false); |
153
|
|
|
$csvExportFormatter->setAutowired(false); |
154
|
|
|
$csvExportFormatter->setAutoconfigured(false); |
155
|
|
|
|
156
|
|
|
$definitions[] = $csvExportFormatter; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
if (class_exists('\PhpOffice\PhpSpreadsheet\Spreadsheet')) { |
160
|
|
|
$xlsExportFormatter = new Definition( |
161
|
|
|
\Netgen\InformationCollection\Core\Export\XlsExportResponseFormatter::class |
162
|
|
|
); |
163
|
|
|
$xlsExportFormatter->addTag('netgen_information_collection.export.formatter'); |
164
|
|
|
$xlsExportFormatter->addArgument(new Reference('ezpublish.translation_helper')); |
165
|
|
|
$xlsExportFormatter->setPublic(false); |
166
|
|
|
$xlsExportFormatter->setAutowired(false); |
167
|
|
|
$xlsExportFormatter->setAutoconfigured(false); |
168
|
|
|
|
169
|
|
|
$xlsxExportFormatter = new Definition( |
170
|
|
|
\Netgen\InformationCollection\Core\Export\XlsxExportResponseFormatter::class |
171
|
|
|
); |
172
|
|
|
$xlsxExportFormatter->addTag('netgen_information_collection.export.formatter'); |
173
|
|
|
$xlsxExportFormatter->addArgument(new Reference('ezpublish.translation_helper')); |
174
|
|
|
$xlsxExportFormatter->setPublic(false); |
175
|
|
|
$xlsxExportFormatter->setAutowired(false); |
176
|
|
|
$xlsxExportFormatter->setAutoconfigured(false); |
177
|
|
|
|
178
|
|
|
$definitions[] = $xlsExportFormatter; |
179
|
|
|
$definitions[] = $xlsxExportFormatter; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
if (!empty($definitions)) { |
183
|
|
|
$container->addDefinitions($definitions); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.