1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Netgen\Bundle\InformationCollectionBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor; |
6
|
|
|
use Netgen\InformationCollection\API\Action\ActionInterface; |
7
|
|
|
use Netgen\InformationCollection\API\ConfigurationConstants; |
8
|
|
|
use Netgen\InformationCollection\Core\Export\CsvExportResponseFormatter; |
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 |
|
$processor = new ConfigurationProcessor($container, ConfigurationConstants::SETTINGS_ROOT); |
47
|
|
|
$configArrays = array( |
48
|
1 |
|
ConfigurationConstants::ACTIONS, |
49
|
1 |
|
ConfigurationConstants::ACTION_CONFIG, |
50
|
1 |
|
); |
51
|
1 |
|
|
52
|
1 |
|
$scopes = array_merge(array('default'), $container->getParameter('ezpublish.siteaccess.list')); |
53
|
|
|
|
54
|
|
|
foreach ($configArrays as $configArray) { |
55
|
|
|
$processor->mapConfigArray($configArray, $config); |
56
|
|
|
foreach ($scopes as $scope) { |
57
|
|
|
$paramName = ConfigurationConstants::SETTINGS_ROOT . '.' . $scope . '.' . $configArray; |
58
|
|
|
if (!$container->hasParameter($paramName)) { |
59
|
|
|
continue; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$scopeConfig = $container->getParameter($paramName); |
63
|
|
|
foreach ((array) $scopeConfig as $key => $value) { |
64
|
|
|
$container->setParameter($paramName . '.' . $key, $value); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$this->setUpAutoConfiguration($container); |
70
|
|
|
$this->registerServiceDefinitions($container); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function prepend(ContainerBuilder $container) |
74
|
|
|
{ |
75
|
|
|
$this->addTwigConfig($container); |
76
|
|
|
$this->addDoctrineConfig($container); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function addDoctrineConfig(ContainerBuilder $container) |
80
|
|
|
{ |
81
|
|
|
$configDir = __DIR__ . '/../../lib/Doctrine/mappings'; |
82
|
|
|
|
83
|
|
|
$config = [ |
84
|
|
|
'orm' => [ |
85
|
|
|
'auto_mapping' => true, |
86
|
|
|
'mappings' => [ |
87
|
|
|
'NetgenInformationCollectionBundle' => [ |
88
|
|
|
'is_bundle' => false, |
89
|
|
|
'dir' => $configDir, |
90
|
|
|
'type' => 'xml', |
91
|
|
|
'prefix' => 'Netgen\InformationCollection\Doctrine\Entity' |
92
|
|
|
] |
93
|
|
|
] |
94
|
|
|
] |
95
|
|
|
]; |
96
|
|
|
|
97
|
|
|
$container->prependExtensionConfig('doctrine', $config); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
protected function addTwigConfig(ContainerBuilder $container): void |
101
|
|
|
{ |
102
|
|
|
$configs = array( |
103
|
|
|
'twig.yml' => 'twig', |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$activatedBundles = array_keys($container->getParameter('kernel.bundles')); |
|
|
|
|
107
|
|
|
|
108
|
|
|
foreach ($configs as $fileName => $extensionName) { |
109
|
|
|
$configFile = __DIR__ . '/../../lib/Resources/config/' . $fileName; |
110
|
|
|
$config = Yaml::parse((string)file_get_contents($configFile)); |
111
|
|
|
$container->prependExtensionConfig($extensionName, $config); |
112
|
|
|
$container->addResource(new FileResource($configFile)); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
protected function setUpAutoConfiguration(ContainerBuilder $container): void |
117
|
|
|
{ |
118
|
|
|
$container->registerForAutoconfiguration(ActionInterface::class) |
119
|
|
|
->addTag('netgen_information_collection.action'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
protected function registerServiceDefinitions(ContainerBuilder $container): void |
123
|
|
|
{ |
124
|
|
|
$definitions = []; |
125
|
|
|
|
126
|
|
View Code Duplication |
if (class_exists('\League\Csv\Writer')) { |
|
|
|
|
127
|
|
|
$csvExportFormatter = new Definition( |
128
|
|
|
\Netgen\InformationCollection\Core\Export\CsvExportResponseFormatter::class |
129
|
|
|
); |
130
|
|
|
$csvExportFormatter->addTag('netgen_information_collection.export.formatter'); |
131
|
|
|
$csvExportFormatter->addArgument(new Reference('ezpublish.translation_helper')); |
132
|
|
|
$csvExportFormatter->addArgument(new Reference('ezpublish.config.resolver')); |
133
|
|
|
$csvExportFormatter->setPublic(false); |
134
|
|
|
$csvExportFormatter->setAutowired(false); |
135
|
|
|
$csvExportFormatter->setAutoconfigured(false); |
136
|
|
|
|
137
|
|
|
$definitions[] = $csvExportFormatter; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
View Code Duplication |
if (class_exists('\PHPExcel')) { |
|
|
|
|
141
|
|
|
$xlsExportFormatter = new Definition( |
142
|
|
|
\Netgen\InformationCollection\Core\Export\XlsExportResponseFormatter::class |
143
|
|
|
); |
144
|
|
|
$xlsExportFormatter->addTag('netgen_information_collection.export.formatter'); |
145
|
|
|
$xlsExportFormatter->addArgument(new Reference('ezpublish.translation_helper')); |
146
|
|
|
$xlsExportFormatter->setPublic(false); |
147
|
|
|
$xlsExportFormatter->setAutowired(false); |
148
|
|
|
$xlsExportFormatter->setAutoconfigured(false); |
149
|
|
|
|
150
|
|
|
$definitions[] = $xlsExportFormatter; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
if (!empty($definitions)) { |
154
|
|
|
$container->addDefinitions($definitions); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
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.