1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the EzPublishCoreExtension class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection; |
10
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser; |
12
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor; |
13
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Collector\SuggestionCollector; |
14
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Collector\SuggestionCollectorAwareInterface; |
15
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Formatter\YamlSuggestionFormatter; |
16
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Security\PolicyProvider\PoliciesConfigBuilder; |
17
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Security\PolicyProvider\PolicyProviderInterface; |
18
|
|
|
use eZ\Bundle\EzPublishCoreBundle\SiteAccess\SiteAccessConfigurationFilter; |
19
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
20
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
21
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
22
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
23
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
24
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
25
|
|
|
use Symfony\Component\DependencyInjection\Loader\FileLoader; |
26
|
|
|
use Symfony\Component\Config\FileLocator; |
27
|
|
|
use InvalidArgumentException; |
28
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface; |
29
|
|
|
|
30
|
|
|
class EzPublishCoreExtension extends Extension implements PrependExtensionInterface |
31
|
|
|
{ |
32
|
|
|
const RICHTEXT_CUSTOM_STYLES_PARAMETER = 'ezplatform.ezrichtext.custom_styles'; |
33
|
|
|
const RICHTEXT_CUSTOM_TAGS_PARAMETER = 'ezplatform.ezrichtext.custom_tags'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Collector\SuggestionCollector |
37
|
|
|
*/ |
38
|
|
|
private $suggestionCollector; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface |
42
|
|
|
*/ |
43
|
|
|
private $mainConfigParser; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface[] |
47
|
|
|
*/ |
48
|
|
|
private $configParsers; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var PolicyProviderInterface[] |
52
|
|
|
*/ |
53
|
|
|
private $policyProviders = []; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Holds a collection of YAML files, as an array with directory path as a |
57
|
|
|
* key to the array of contained file names. |
58
|
|
|
* |
59
|
|
|
* @var array |
60
|
|
|
*/ |
61
|
|
|
private $defaultSettingsCollection = []; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var \eZ\Bundle\EzPublishCoreBundle\SiteAccess\SiteAccessConfigurationFilter[] |
65
|
|
|
*/ |
66
|
|
|
private $siteaccessConfigurationFilters = []; |
67
|
|
|
|
68
|
|
|
public function __construct(array $configParsers = array()) |
69
|
|
|
{ |
70
|
|
|
$this->configParsers = $configParsers; |
71
|
|
|
$this->suggestionCollector = new SuggestionCollector(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getAlias() |
75
|
|
|
{ |
76
|
|
|
return 'ezpublish'; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Loads a specific configuration. |
81
|
|
|
* |
82
|
|
|
* @param mixed[] $configs An array of configuration values |
83
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance |
84
|
|
|
* |
85
|
|
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension |
86
|
|
|
* |
87
|
|
|
* @api |
88
|
|
|
*/ |
89
|
|
|
public function load(array $configs, ContainerBuilder $container) |
90
|
|
|
{ |
91
|
|
|
$loader = new Loader\YamlFileLoader( |
92
|
|
|
$container, |
93
|
|
|
new FileLocator(__DIR__ . '/../Resources/config') |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$configuration = $this->getConfiguration($configs, $container); |
97
|
|
|
|
98
|
|
|
// Note: this is where the transformation occurs |
99
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
100
|
|
|
|
101
|
|
|
// Base services and services overrides |
102
|
|
|
$loader->load('services.yml'); |
103
|
|
|
// Security services |
104
|
|
|
$loader->load('security.yml'); |
105
|
|
|
|
106
|
|
|
if (interface_exists('FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractorInterface')) { |
107
|
|
|
$loader->load('routing/js_routing.yml'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
// Default settings |
111
|
|
|
$this->handleDefaultSettingsLoading($container, $loader); |
112
|
|
|
|
113
|
|
|
$this->registerRepositoriesConfiguration($config, $container); |
114
|
|
|
$this->registerSiteAccessConfiguration($config, $container); |
115
|
|
|
$this->registerImageMagickConfiguration($config, $container); |
116
|
|
|
$this->registerPageConfiguration($config, $container); |
117
|
|
|
$this->registerRichTextConfiguration($config, $container); |
118
|
|
|
$this->registerUrlAliasConfiguration($config, $container); |
119
|
|
|
|
120
|
|
|
// Routing |
121
|
|
|
$this->handleRouting($config, $container, $loader); |
122
|
|
|
// Public API loading |
123
|
|
|
$this->handleApiLoading($container, $loader); |
124
|
|
|
$this->handleTemplating($container, $loader); |
125
|
|
|
$this->handleSessionLoading($container, $loader); |
126
|
|
|
$this->handleCache($config, $container, $loader); |
127
|
|
|
$this->handleLocale($config, $container, $loader); |
128
|
|
|
$this->handleHelpers($config, $container, $loader); |
129
|
|
|
$this->handleImage($config, $container, $loader); |
130
|
|
|
$this->handleUrlChecker($config, $container, $loader); |
131
|
|
|
|
132
|
|
|
// Map settings |
133
|
|
|
$processor = new ConfigurationProcessor($container, 'ezsettings'); |
134
|
|
|
$processor->mapConfig($config, $this->getMainConfigParser()); |
135
|
|
|
|
136
|
|
|
if ($this->suggestionCollector->hasSuggestions()) { |
137
|
|
|
$message = ''; |
138
|
|
|
$suggestionFormatter = new YamlSuggestionFormatter(); |
139
|
|
|
foreach ($this->suggestionCollector->getSuggestions() as $suggestion) { |
140
|
|
|
$message .= $suggestionFormatter->format($suggestion) . "\n\n"; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
throw new InvalidArgumentException($message); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$this->handleSiteAccessesRelation($container); |
147
|
|
|
$this->buildPolicyMap($container); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param array $config |
152
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
153
|
|
|
* |
154
|
|
|
* @return \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration |
155
|
|
|
*/ |
156
|
|
|
public function getConfiguration(array $config, ContainerBuilder $container) |
157
|
|
|
{ |
158
|
|
|
$configuration = new Configuration($this->getMainConfigParser(), $this->suggestionCollector); |
159
|
|
|
$configuration->setSiteAccessConfigurationFilters($this->siteaccessConfigurationFilters); |
160
|
|
|
|
161
|
|
|
return $configuration; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* {@inheritdoc} |
166
|
|
|
*/ |
167
|
|
|
public function prepend(ContainerBuilder $container) |
168
|
|
|
{ |
169
|
|
|
$this->prependTranslatorConfiguration($container); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface |
174
|
|
|
*/ |
175
|
|
|
private function getMainConfigParser() |
176
|
|
|
{ |
177
|
|
|
if ($this->mainConfigParser === null) { |
178
|
|
|
foreach ($this->configParsers as $parser) { |
179
|
|
|
if ($parser instanceof SuggestionCollectorAwareInterface) { |
180
|
|
|
$parser->setSuggestionCollector($this->suggestionCollector); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
$this->mainConfigParser = new ConfigParser($this->configParsers); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
return $this->mainConfigParser; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Handle default settings. |
192
|
|
|
* |
193
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
194
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
195
|
|
|
* |
196
|
|
|
* @throws \Exception |
197
|
|
|
*/ |
198
|
|
|
private function handleDefaultSettingsLoading(ContainerBuilder $container, FileLoader $loader) |
199
|
|
|
{ |
200
|
|
|
$loader->load('default_settings.yml'); |
201
|
|
|
|
202
|
|
|
if (!$this->isRichTextBundleEnabled($container)) { |
203
|
|
|
$loader->load('ezrichtext_default_settings.yml'); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
foreach ($this->defaultSettingsCollection as $fileLocation => $files) { |
207
|
|
|
$externalLoader = new Loader\YamlFileLoader($container, new FileLocator($fileLocation)); |
208
|
|
|
foreach ($files as $file) { |
209
|
|
|
$externalLoader->load($file); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
private function registerRepositoriesConfiguration(array $config, ContainerBuilder $container) |
215
|
|
|
{ |
216
|
|
|
if (!isset($config['repositories'])) { |
217
|
|
|
$config['repositories'] = array(); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
foreach ($config['repositories'] as $name => &$repository) { |
221
|
|
|
if (empty($repository['fields_groups']['list'])) { |
222
|
|
|
$repository['fields_groups']['list'] = $container->getParameter('ezsettings.default.content.field_groups.list'); |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
$container->setParameter('ezpublish.repositories', $config['repositories']); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
private function registerSiteAccessConfiguration(array $config, ContainerBuilder $container) |
230
|
|
|
{ |
231
|
|
|
if (!isset($config['siteaccess'])) { |
232
|
|
|
$config['siteaccess'] = array(); |
233
|
|
|
$config['siteaccess']['list'] = array('setup'); |
234
|
|
|
$config['siteaccess']['default_siteaccess'] = 'setup'; |
235
|
|
|
$config['siteaccess']['groups'] = array(); |
236
|
|
|
$config['siteaccess']['match'] = null; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
$container->setParameter('ezpublish.siteaccess.list', $config['siteaccess']['list']); |
240
|
|
|
ConfigurationProcessor::setAvailableSiteAccesses($config['siteaccess']['list']); |
241
|
|
|
$container->setParameter('ezpublish.siteaccess.default', $config['siteaccess']['default_siteaccess']); |
242
|
|
|
$container->setParameter('ezpublish.siteaccess.match_config', $config['siteaccess']['match']); |
243
|
|
|
|
244
|
|
|
// Register siteaccess groups + reverse |
245
|
|
|
$container->setParameter('ezpublish.siteaccess.groups', $config['siteaccess']['groups']); |
246
|
|
|
$groupsBySiteaccess = array(); |
247
|
|
View Code Duplication |
foreach ($config['siteaccess']['groups'] as $groupName => $groupMembers) { |
|
|
|
|
248
|
|
|
foreach ($groupMembers as $member) { |
249
|
|
|
if (!isset($groupsBySiteaccess[$member])) { |
250
|
|
|
$groupsBySiteaccess[$member] = array(); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
$groupsBySiteaccess[$member][] = $groupName; |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
$container->setParameter('ezpublish.siteaccess.groups_by_siteaccess', $groupsBySiteaccess); |
257
|
|
|
ConfigurationProcessor::setGroupsBySiteAccess($groupsBySiteaccess); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
private function registerImageMagickConfiguration(array $config, ContainerBuilder $container) |
261
|
|
|
{ |
262
|
|
|
if (isset($config['imagemagick'])) { |
263
|
|
|
$container->setParameter('ezpublish.image.imagemagick.enabled', $config['imagemagick']['enabled']); |
264
|
|
|
if ($config['imagemagick']['enabled']) { |
265
|
|
|
$container->setParameter('ezpublish.image.imagemagick.executable_path', dirname($config['imagemagick']['path'])); |
266
|
|
|
$container->setParameter('ezpublish.image.imagemagick.executable', basename($config['imagemagick']['path'])); |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
$filters = isset($config['imagemagick']['filters']) ? $config['imagemagick']['filters'] : array(); |
271
|
|
|
$filters = $filters + $container->getParameter('ezpublish.image.imagemagick.filters'); |
272
|
|
|
$container->setParameter('ezpublish.image.imagemagick.filters', $filters); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
private function registerPageConfiguration(array $config, ContainerBuilder $container) |
276
|
|
|
{ |
277
|
|
|
if (isset($config['ezpage']['layouts'])) { |
278
|
|
|
$container->setParameter( |
279
|
|
|
'ezpublish.ezpage.layouts', |
280
|
|
|
$config['ezpage']['layouts'] + $container->getParameter('ezpublish.ezpage.layouts') |
281
|
|
|
); |
282
|
|
|
} |
283
|
|
|
if (isset($config['ezpage']['blocks'])) { |
284
|
|
|
$container->setParameter( |
285
|
|
|
'ezpublish.ezpage.blocks', |
286
|
|
|
$config['ezpage']['blocks'] + $container->getParameter('ezpublish.ezpage.blocks') |
287
|
|
|
); |
288
|
|
|
} |
289
|
|
|
if (isset($config['ezpage']['enabledLayouts'])) { |
290
|
|
|
$container->setParameter( |
291
|
|
|
'ezpublish.ezpage.enabledLayouts', |
292
|
|
|
$config['ezpage']['enabledLayouts'] + $container->getParameter('ezpublish.ezpage.enabledLayouts') |
293
|
|
|
); |
294
|
|
|
} |
295
|
|
|
if (isset($config['ezpage']['enabledBlocks'])) { |
296
|
|
|
$container->setParameter( |
297
|
|
|
'ezpublish.ezpage.enabledBlocks', |
298
|
|
|
$config['ezpage']['enabledBlocks'] + $container->getParameter('ezpublish.ezpage.enabledBlocks') |
299
|
|
|
); |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* Register parameters of global RichText configuration. |
305
|
|
|
* |
306
|
|
|
* @param array $config |
307
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
308
|
|
|
*/ |
309
|
|
|
private function registerRichTextConfiguration(array $config, ContainerBuilder $container) |
310
|
|
|
{ |
311
|
|
View Code Duplication |
if (isset($config['ezrichtext']['custom_tags'])) { |
|
|
|
|
312
|
|
|
$container->setParameter( |
313
|
|
|
static::RICHTEXT_CUSTOM_TAGS_PARAMETER, |
314
|
|
|
$config['ezrichtext']['custom_tags'] |
315
|
|
|
); |
316
|
|
|
} |
317
|
|
View Code Duplication |
if (isset($config['ezrichtext']['custom_styles'])) { |
|
|
|
|
318
|
|
|
$container->setParameter( |
319
|
|
|
static::RICHTEXT_CUSTOM_STYLES_PARAMETER, |
320
|
|
|
$config['ezrichtext']['custom_styles'] |
321
|
|
|
); |
322
|
|
|
} |
323
|
|
|
// keep BC |
324
|
|
|
if (!empty($config['ezrichtext']) && $this->isRichTextBundleEnabled($container)) { |
325
|
|
|
$container->prependExtensionConfig('ezrichtext', $config['ezrichtext']); |
326
|
|
|
if (!empty($config['ezrichtext']['custom_tags']) || !empty($config['ezrichtext']['custom_styles'])) { |
327
|
|
|
@trigger_error( |
|
|
|
|
328
|
|
|
'ezpublish.ezrichtext configuration is deprecated since v7.4, move entire configuration node to ezrichtext extension', |
329
|
|
|
E_USER_DEPRECATED |
330
|
|
|
); |
331
|
|
|
} |
332
|
|
|
} |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Handle routing parameters. |
337
|
|
|
* |
338
|
|
|
* @param array $config |
339
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
340
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
341
|
|
|
*/ |
342
|
|
|
private function handleRouting(array $config, ContainerBuilder $container, FileLoader $loader) |
343
|
|
|
{ |
344
|
|
|
$loader->load('routing.yml'); |
345
|
|
|
$container->setAlias('router', 'ezpublish.chain_router'); |
346
|
|
|
|
347
|
|
|
if (isset($config['router']['default_router']['non_siteaccess_aware_routes'])) { |
348
|
|
|
$container->setParameter( |
349
|
|
|
'ezpublish.default_router.non_siteaccess_aware_routes', |
350
|
|
|
array_merge( |
351
|
|
|
$container->getParameter('ezpublish.default_router.non_siteaccess_aware_routes'), |
352
|
|
|
$config['router']['default_router']['non_siteaccess_aware_routes'] |
353
|
|
|
) |
354
|
|
|
); |
355
|
|
|
} |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Handle public API loading. |
360
|
|
|
* |
361
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
362
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
363
|
|
|
*/ |
364
|
|
|
private function handleApiLoading(ContainerBuilder $container, FileLoader $loader) |
365
|
|
|
{ |
366
|
|
|
// Loading configuration from Core/settings |
367
|
|
|
$coreLoader = new Loader\YamlFileLoader( |
368
|
|
|
$container, |
369
|
|
|
new FileLocator(__DIR__ . '/../../../Publish/Core/settings') |
370
|
|
|
); |
371
|
|
|
$coreLoader->load('repository.yml'); |
372
|
|
|
$coreLoader->load('repository/inner.yml'); |
373
|
|
|
$coreLoader->load('repository/signalslot.yml'); |
374
|
|
|
$coreLoader->load('repository/siteaccessaware.yml'); |
375
|
|
|
$coreLoader->load('fieldtype_external_storages.yml'); |
376
|
|
|
$coreLoader->load('fieldtypes.yml'); |
377
|
|
|
$coreLoader->load('indexable_fieldtypes.yml'); |
378
|
|
|
$coreLoader->load('roles.yml'); |
379
|
|
|
$coreLoader->load('storage_engines/common.yml'); |
380
|
|
|
$coreLoader->load('storage_engines/cache.yml'); |
381
|
|
|
$coreLoader->load('storage_engines/legacy.yml'); |
382
|
|
|
$coreLoader->load('storage_engines/shortcuts.yml'); |
383
|
|
|
$coreLoader->load('search_engines/common.yml'); |
384
|
|
|
$coreLoader->load('utils.yml'); |
385
|
|
|
$coreLoader->load('io.yml'); |
386
|
|
|
$coreLoader->load('policies.yml'); |
387
|
|
|
$coreLoader->load('notification.yml'); |
388
|
|
|
$coreLoader->load('user_preference.yml'); |
389
|
|
|
|
390
|
|
|
// Load Core RichText settings |
391
|
|
|
if (!$this->isRichTextBundleEnabled($container)) { |
392
|
|
|
$coreLoader->load('richtext.yml'); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
// Public API services |
396
|
|
|
$loader->load('papi.yml'); |
397
|
|
|
|
398
|
|
|
// Built-in field types |
399
|
|
|
$loader->load('fieldtype_services.yml'); |
400
|
|
|
|
401
|
|
|
// Storage engine |
402
|
|
|
$loader->load('storage_engines.yml'); |
403
|
|
|
|
404
|
|
|
// Load CoreBundle RichText settings |
405
|
|
|
if (!$this->isRichTextBundleEnabled($container)) { |
406
|
|
|
$loader->load('richtext.yml'); |
407
|
|
|
} |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Handle templating parameters. |
412
|
|
|
* |
413
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
414
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
415
|
|
|
*/ |
416
|
|
|
private function handleTemplating(ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
417
|
|
|
{ |
418
|
|
|
$loader->load('templating.yml'); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Handle session parameters. |
423
|
|
|
* |
424
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
425
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
426
|
|
|
*/ |
427
|
|
|
private function handleSessionLoading(ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
428
|
|
|
{ |
429
|
|
|
$loader->load('session.yml'); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Handle cache parameters. |
434
|
|
|
* |
435
|
|
|
* @param array $config |
436
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
437
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
438
|
|
|
* |
439
|
|
|
* @throws \InvalidArgumentException |
440
|
|
|
*/ |
441
|
|
|
private function handleCache(array $config, ContainerBuilder $container, FileLoader $loader) |
442
|
|
|
{ |
443
|
|
|
$loader->load('cache.yml'); |
444
|
|
|
|
445
|
|
|
$purgeService = null; |
|
|
|
|
446
|
|
|
if (isset($config['http_cache']['purge_type'])) { |
447
|
|
|
$container->setParameter('ezpublish.http_cache.purge_type', $config['http_cache']['purge_type']); |
448
|
|
|
} |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* Handle locale parameters. |
453
|
|
|
* |
454
|
|
|
* @param array $config |
455
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
456
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
457
|
|
|
*/ |
458
|
|
|
private function handleLocale(array $config, ContainerBuilder $container, FileLoader $loader) |
459
|
|
|
{ |
460
|
|
|
$loader->load('locale.yml'); |
461
|
|
|
$container->setParameter( |
462
|
|
|
'ezpublish.locale.conversion_map', |
463
|
|
|
$config['locale_conversion'] + $container->getParameter('ezpublish.locale.conversion_map') |
464
|
|
|
); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* Handle helpers. |
469
|
|
|
* |
470
|
|
|
* @param array $config |
471
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
472
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
473
|
|
|
*/ |
474
|
|
|
private function handleHelpers(array $config, ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
475
|
|
|
{ |
476
|
|
|
$loader->load('helpers.yml'); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* Handles relation between SiteAccesses. |
481
|
|
|
* Related SiteAccesses share the same repository and root location id. |
482
|
|
|
* |
483
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
484
|
|
|
*/ |
485
|
|
|
private function handleSiteAccessesRelation(ContainerBuilder $container) |
486
|
|
|
{ |
487
|
|
|
$configResolver = $container->get('ezpublish.config.resolver.core'); |
488
|
|
|
$configResolver->setContainer($container); |
489
|
|
|
|
490
|
|
|
$saRelationMap = array(); |
491
|
|
|
$saList = $container->getParameter('ezpublish.siteaccess.list'); |
492
|
|
|
// First build the SiteAccess relation map, indexed by repository and rootLocationId. |
493
|
|
|
foreach ($saList as $sa) { |
494
|
|
|
$repository = $configResolver->getParameter('repository', 'ezsettings', $sa); |
495
|
|
|
if (!isset($saRelationMap[$repository])) { |
496
|
|
|
$saRelationMap[$repository] = array(); |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
$rootLocationId = $configResolver->getParameter('content.tree_root.location_id', 'ezsettings', $sa); |
500
|
|
|
if (!isset($saRelationMap[$repository][$rootLocationId])) { |
501
|
|
|
$saRelationMap[$repository][$rootLocationId] = array(); |
502
|
|
|
} |
503
|
|
|
$saRelationMap[$repository][$rootLocationId][] = $sa; |
504
|
|
|
} |
505
|
|
|
$container->setParameter('ezpublish.siteaccess.relation_map', $saRelationMap); |
506
|
|
|
|
507
|
|
|
// Now build the related SiteAccesses list, based on the relation map. |
508
|
|
|
foreach ($saList as $sa) { |
509
|
|
|
$repository = $configResolver->getParameter('repository', 'ezsettings', $sa); |
510
|
|
|
$rootLocationId = $configResolver->getParameter('content.tree_root.location_id', 'ezsettings', $sa); |
511
|
|
|
$container->setParameter( |
512
|
|
|
"ezsettings.$sa.related_siteaccesses", |
513
|
|
|
$saRelationMap[$repository][$rootLocationId] |
514
|
|
|
); |
515
|
|
|
} |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* @param array $config |
520
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
521
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
522
|
|
|
*/ |
523
|
|
|
private function handleImage(array $config, ContainerBuilder $container, FileLoader $loader) |
524
|
|
|
{ |
525
|
|
|
$loader->load('image.yml'); |
526
|
|
|
|
527
|
|
|
$providers = []; |
528
|
|
|
if (isset($config['image_placeholder'])) { |
529
|
|
|
foreach ($config['image_placeholder'] as $name => $value) { |
530
|
|
|
if (isset($providers[$name])) { |
531
|
|
|
throw new InvalidConfigurationException("A image_placeholder named $name already exists"); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
$providers[$name] = $value; |
535
|
|
|
} |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
$container->setParameter('image_alias.placeholder_providers', $providers); |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
private function handleUrlChecker($config, ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
542
|
|
|
{ |
543
|
|
|
$loader->load('url_checker.yml'); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
private function buildPolicyMap(ContainerBuilder $container) |
547
|
|
|
{ |
548
|
|
|
$policiesBuilder = new PoliciesConfigBuilder($container); |
549
|
|
|
foreach ($this->policyProviders as $provider) { |
550
|
|
|
$provider->addPolicies($policiesBuilder); |
551
|
|
|
} |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* Adds a new policy provider to the internal collection. |
556
|
|
|
* One can call this method from a bundle `build()` method. |
557
|
|
|
* |
558
|
|
|
* ```php |
559
|
|
|
* public function build(ContainerBuilder $container) |
560
|
|
|
* { |
561
|
|
|
* $ezExtension = $container->getExtension('ezpublish'); |
562
|
|
|
* $ezExtension->addPolicyProvider($myPolicyProvider); |
563
|
|
|
* } |
564
|
|
|
* ``` |
565
|
|
|
* |
566
|
|
|
* @since 6.0 |
567
|
|
|
* |
568
|
|
|
* @param PolicyProviderInterface $policyProvider |
569
|
|
|
*/ |
570
|
|
|
public function addPolicyProvider(PolicyProviderInterface $policyProvider) |
571
|
|
|
{ |
572
|
|
|
$this->policyProviders[] = $policyProvider; |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
/** |
576
|
|
|
* Adds a new config parser to the internal collection. |
577
|
|
|
* One can call this method from a bundle `build()` method. |
578
|
|
|
* |
579
|
|
|
* ```php |
580
|
|
|
* public function build(ContainerBuilder $container) |
581
|
|
|
* { |
582
|
|
|
* $ezExtension = $container->getExtension('ezpublish'); |
583
|
|
|
* $ezExtension->addConfigParser($myConfigParser); |
584
|
|
|
* } |
585
|
|
|
* ``` |
586
|
|
|
* |
587
|
|
|
* @since 6.0 |
588
|
|
|
* |
589
|
|
|
* @param \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface $configParser |
590
|
|
|
*/ |
591
|
|
|
public function addConfigParser(ParserInterface $configParser) |
592
|
|
|
{ |
593
|
|
|
$this->configParsers[] = $configParser; |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
/** |
597
|
|
|
* Adds new default settings to the internal collection. |
598
|
|
|
* One can call this method from a bundle `build()` method. |
599
|
|
|
* |
600
|
|
|
* ```php |
601
|
|
|
* public function build(ContainerBuilder $container) |
602
|
|
|
* { |
603
|
|
|
* $ezExtension = $container->getExtension('ezpublish'); |
604
|
|
|
* $ezExtension->addDefaultSettings( |
605
|
|
|
* __DIR__ . '/Resources/config', |
606
|
|
|
* ['default_settings.yml'] |
607
|
|
|
* ); |
608
|
|
|
* } |
609
|
|
|
* ``` |
610
|
|
|
* |
611
|
|
|
* @since 6.0 |
612
|
|
|
* |
613
|
|
|
* @param string $fileLocation |
614
|
|
|
* @param array $files |
615
|
|
|
*/ |
616
|
|
|
public function addDefaultSettings($fileLocation, array $files) |
617
|
|
|
{ |
618
|
|
|
$this->defaultSettingsCollection[$fileLocation] = $files; |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
public function addSiteAccessConfigurationFilter(SiteAccessConfigurationFilter $filter) |
622
|
|
|
{ |
623
|
|
|
$this->siteaccessConfigurationFilters[] = $filter; |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* @param array $config |
628
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
629
|
|
|
*/ |
630
|
|
|
private function registerUrlAliasConfiguration(array $config, ContainerBuilder $container) |
631
|
|
|
{ |
632
|
|
|
if (!isset($config['url_alias'])) { |
633
|
|
|
$config['url_alias'] = ['slug_converter' => []]; |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
$container->setParameter('ezpublish.url_alias.slug_converter', $config['url_alias']['slug_converter']); |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
private function isRichTextBundleEnabled(ContainerBuilder $container) |
640
|
|
|
{ |
641
|
|
|
return $container->hasParameter('kernel.bundles') |
642
|
|
|
&& array_key_exists( |
643
|
|
|
'EzPlatformRichTextBundle', |
644
|
|
|
$container->getParameter('kernel.bundles') |
645
|
|
|
); |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
650
|
|
|
*/ |
651
|
|
|
private function prependTranslatorConfiguration(ContainerBuilder $container) |
652
|
|
|
{ |
653
|
|
|
if (!$container->hasExtension('framework')) { |
654
|
|
|
return; |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
$fileSystem = new Filesystem(); |
658
|
|
|
$translationsPath = $container->getParameterBag()->get('kernel.root_dir') . '/../vendor/ezplatform-i18n'; |
659
|
|
|
|
660
|
|
|
if ($fileSystem->exists($translationsPath)) { |
661
|
|
|
$container->prependExtensionConfig('framework', ['translator' => ['paths' => [$translationsPath]]]); |
662
|
|
|
} |
663
|
|
|
} |
664
|
|
|
} |
665
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.