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\Compiler\QueryTypePass; |
12
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser; |
13
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor; |
14
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Collector\SuggestionCollector; |
15
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Collector\SuggestionCollectorAwareInterface; |
16
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Formatter\YamlSuggestionFormatter; |
17
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Security\PolicyProvider\PoliciesConfigBuilder; |
18
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Security\PolicyProvider\PolicyProviderInterface; |
19
|
|
|
use eZ\Bundle\EzPublishCoreBundle\SiteAccess\SiteAccessConfigurationFilter; |
20
|
|
|
use eZ\Publish\Core\QueryType\QueryType; |
21
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
22
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
23
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
24
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
25
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
26
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
27
|
|
|
use Symfony\Component\DependencyInjection\Loader\FileLoader; |
28
|
|
|
use Symfony\Component\Config\FileLocator; |
29
|
|
|
use InvalidArgumentException; |
30
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface; |
31
|
|
|
|
32
|
|
|
class EzPublishCoreExtension extends Extension implements PrependExtensionInterface |
33
|
|
|
{ |
34
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Collector\SuggestionCollector */ |
35
|
|
|
private $suggestionCollector; |
36
|
|
|
|
37
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface */ |
38
|
|
|
private $mainConfigParser; |
39
|
|
|
|
40
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface[] */ |
41
|
|
|
private $configParsers; |
42
|
|
|
|
43
|
|
|
/** @var PolicyProviderInterface[] */ |
44
|
|
|
private $policyProviders = []; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Holds a collection of YAML files, as an array with directory path as a |
48
|
|
|
* key to the array of contained file names. |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
private $defaultSettingsCollection = []; |
53
|
|
|
|
54
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\SiteAccess\SiteAccessConfigurationFilter[] */ |
55
|
|
|
private $siteaccessConfigurationFilters = []; |
56
|
|
|
|
57
|
|
|
public function __construct(array $configParsers = []) |
58
|
|
|
{ |
59
|
|
|
$this->configParsers = $configParsers; |
60
|
|
|
$this->suggestionCollector = new SuggestionCollector(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getAlias() |
64
|
|
|
{ |
65
|
|
|
return 'ezpublish'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Loads a specific configuration. |
70
|
|
|
* |
71
|
|
|
* @param mixed[] $configs An array of configuration values |
72
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance |
73
|
|
|
* |
74
|
|
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension |
75
|
|
|
* |
76
|
|
|
* @api |
77
|
|
|
*/ |
78
|
|
|
public function load(array $configs, ContainerBuilder $container) |
79
|
|
|
{ |
80
|
|
|
$loader = new Loader\YamlFileLoader( |
81
|
|
|
$container, |
82
|
|
|
new FileLocator(__DIR__ . '/../Resources/config') |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$configuration = $this->getConfiguration($configs, $container); |
86
|
|
|
|
87
|
|
|
// Note: this is where the transformation occurs |
88
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
89
|
|
|
|
90
|
|
|
// Base services and services overrides |
91
|
|
|
$loader->load('services.yml'); |
92
|
|
|
// Security services |
93
|
|
|
$loader->load('security.yml'); |
94
|
|
|
|
95
|
|
|
if (interface_exists('FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractorInterface')) { |
96
|
|
|
$loader->load('routing/js_routing.yml'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// Default settings |
100
|
|
|
$this->handleDefaultSettingsLoading($container, $loader); |
101
|
|
|
|
102
|
|
|
$this->registerRepositoriesConfiguration($config, $container); |
103
|
|
|
$this->registerSiteAccessConfiguration($config, $container); |
104
|
|
|
$this->registerImageMagickConfiguration($config, $container); |
105
|
|
|
$this->registerUrlAliasConfiguration($config, $container); |
106
|
|
|
$this->registerUrlWildcardsConfiguration($config, $container); |
107
|
|
|
|
108
|
|
|
// Routing |
109
|
|
|
$this->handleRouting($config, $container, $loader); |
110
|
|
|
// Public API loading |
111
|
|
|
$this->handleApiLoading($container, $loader); |
112
|
|
|
$this->handleTemplating($container, $loader); |
113
|
|
|
$this->handleSessionLoading($container, $loader); |
114
|
|
|
$this->handleCache($config, $container, $loader); |
115
|
|
|
$this->handleLocale($config, $container, $loader); |
116
|
|
|
$this->handleHelpers($config, $container, $loader); |
117
|
|
|
$this->handleImage($config, $container, $loader); |
118
|
|
|
$this->handleUrlChecker($config, $container, $loader); |
119
|
|
|
$this->handleUrlWildcards($config, $container, $loader); |
120
|
|
|
|
121
|
|
|
// Map settings |
122
|
|
|
$processor = new ConfigurationProcessor($container, 'ezsettings'); |
123
|
|
|
$processor->mapConfig($config, $this->getMainConfigParser()); |
124
|
|
|
|
125
|
|
|
if ($this->suggestionCollector->hasSuggestions()) { |
126
|
|
|
$message = ''; |
127
|
|
|
$suggestionFormatter = new YamlSuggestionFormatter(); |
128
|
|
|
foreach ($this->suggestionCollector->getSuggestions() as $suggestion) { |
129
|
|
|
$message .= $suggestionFormatter->format($suggestion) . "\n\n"; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
throw new InvalidArgumentException($message); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$this->buildPolicyMap($container); |
136
|
|
|
|
137
|
|
|
$container->registerForAutoconfiguration(QueryType::class) |
138
|
|
|
->addTag(QueryTypePass::QUERY_TYPE_SERVICE_TAG); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param array $config |
143
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
144
|
|
|
* |
145
|
|
|
* @return \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration |
146
|
|
|
*/ |
147
|
|
|
public function getConfiguration(array $config, ContainerBuilder $container) |
148
|
|
|
{ |
149
|
|
|
$configuration = new Configuration($this->getMainConfigParser(), $this->suggestionCollector); |
150
|
|
|
$configuration->setSiteAccessConfigurationFilters($this->siteaccessConfigurationFilters); |
151
|
|
|
|
152
|
|
|
return $configuration; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* {@inheritdoc} |
157
|
|
|
*/ |
158
|
|
|
public function prepend(ContainerBuilder $container) |
159
|
|
|
{ |
160
|
|
|
$this->prependTranslatorConfiguration($container); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface |
165
|
|
|
*/ |
166
|
|
|
private function getMainConfigParser() |
167
|
|
|
{ |
168
|
|
|
if ($this->mainConfigParser === null) { |
169
|
|
|
foreach ($this->configParsers as $parser) { |
170
|
|
|
if ($parser instanceof SuggestionCollectorAwareInterface) { |
171
|
|
|
$parser->setSuggestionCollector($this->suggestionCollector); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$this->mainConfigParser = new ConfigParser($this->configParsers); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
return $this->mainConfigParser; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Handle default settings. |
183
|
|
|
* |
184
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
185
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
186
|
|
|
* |
187
|
|
|
* @throws \Exception |
188
|
|
|
*/ |
189
|
|
|
private function handleDefaultSettingsLoading(ContainerBuilder $container, FileLoader $loader) |
190
|
|
|
{ |
191
|
|
|
$loader->load('default_settings.yml'); |
192
|
|
|
|
193
|
|
|
foreach ($this->defaultSettingsCollection as $fileLocation => $files) { |
194
|
|
|
$externalLoader = new Loader\YamlFileLoader($container, new FileLocator($fileLocation)); |
195
|
|
|
foreach ($files as $file) { |
196
|
|
|
$externalLoader->load($file); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
private function registerRepositoriesConfiguration(array $config, ContainerBuilder $container) |
202
|
|
|
{ |
203
|
|
|
if (!isset($config['repositories'])) { |
204
|
|
|
$config['repositories'] = []; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
foreach ($config['repositories'] as $name => &$repository) { |
208
|
|
|
if (empty($repository['fields_groups']['list'])) { |
209
|
|
|
$repository['fields_groups']['list'] = $container->getParameter('ezsettings.default.content.field_groups.list'); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
$container->setParameter('ezpublish.repositories', $config['repositories']); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
private function registerSiteAccessConfiguration(array $config, ContainerBuilder $container) |
217
|
|
|
{ |
218
|
|
|
if (!isset($config['siteaccess'])) { |
219
|
|
|
$config['siteaccess'] = []; |
220
|
|
|
$config['siteaccess']['list'] = ['setup']; |
221
|
|
|
$config['siteaccess']['default_siteaccess'] = 'setup'; |
222
|
|
|
$config['siteaccess']['groups'] = []; |
223
|
|
|
$config['siteaccess']['match'] = null; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
$container->setParameter('ezpublish.siteaccess.list', $config['siteaccess']['list']); |
227
|
|
|
ConfigurationProcessor::setAvailableSiteAccesses($config['siteaccess']['list']); |
228
|
|
|
$container->setParameter('ezpublish.siteaccess.default', $config['siteaccess']['default_siteaccess']); |
229
|
|
|
$container->setParameter('ezpublish.siteaccess.match_config', $config['siteaccess']['match']); |
230
|
|
|
|
231
|
|
|
// Register siteaccess groups + reverse |
232
|
|
|
$container->setParameter('ezpublish.siteaccess.groups', $config['siteaccess']['groups']); |
233
|
|
|
ConfigurationProcessor::setAvailableSiteAccessGroups($config['siteaccess']['groups']); |
234
|
|
|
$groupsBySiteaccess = []; |
235
|
|
View Code Duplication |
foreach ($config['siteaccess']['groups'] as $groupName => $groupMembers) { |
|
|
|
|
236
|
|
|
foreach ($groupMembers as $member) { |
237
|
|
|
if (!isset($groupsBySiteaccess[$member])) { |
238
|
|
|
$groupsBySiteaccess[$member] = []; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
$groupsBySiteaccess[$member][] = $groupName; |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
$container->setParameter('ezpublish.siteaccess.groups_by_siteaccess', $groupsBySiteaccess); |
245
|
|
|
ConfigurationProcessor::setGroupsBySiteAccess($groupsBySiteaccess); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
private function registerImageMagickConfiguration(array $config, ContainerBuilder $container) |
249
|
|
|
{ |
250
|
|
|
if (isset($config['imagemagick'])) { |
251
|
|
|
$container->setParameter('ezpublish.image.imagemagick.enabled', $config['imagemagick']['enabled']); |
252
|
|
|
if ($config['imagemagick']['enabled']) { |
253
|
|
|
$container->setParameter('ezpublish.image.imagemagick.executable_path', dirname($config['imagemagick']['path'])); |
254
|
|
|
$container->setParameter('ezpublish.image.imagemagick.executable', basename($config['imagemagick']['path'])); |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
$filters = isset($config['imagemagick']['filters']) ? $config['imagemagick']['filters'] : []; |
259
|
|
|
$filters = $filters + $container->getParameter('ezpublish.image.imagemagick.filters'); |
260
|
|
|
$container->setParameter('ezpublish.image.imagemagick.filters', $filters); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Handle routing parameters. |
265
|
|
|
* |
266
|
|
|
* @param array $config |
267
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
268
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
269
|
|
|
*/ |
270
|
|
|
private function handleRouting(array $config, ContainerBuilder $container, FileLoader $loader) |
271
|
|
|
{ |
272
|
|
|
$loader->load('routing.yml'); |
273
|
|
|
$container->setAlias('router', 'ezpublish.chain_router'); |
274
|
|
|
$container->getAlias('router')->setPublic(true); |
275
|
|
|
|
276
|
|
|
if (isset($config['router']['default_router']['non_siteaccess_aware_routes'])) { |
277
|
|
|
$container->setParameter( |
278
|
|
|
'ezpublish.default_router.non_siteaccess_aware_routes', |
279
|
|
|
array_merge( |
280
|
|
|
$container->getParameter('ezpublish.default_router.non_siteaccess_aware_routes'), |
281
|
|
|
$config['router']['default_router']['non_siteaccess_aware_routes'] |
282
|
|
|
) |
283
|
|
|
); |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Handle public API loading. |
289
|
|
|
* |
290
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
291
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
292
|
|
|
*/ |
293
|
|
|
private function handleApiLoading(ContainerBuilder $container, FileLoader $loader) |
294
|
|
|
{ |
295
|
|
|
// Loading configuration from Core/settings |
296
|
|
|
$coreLoader = new Loader\YamlFileLoader( |
297
|
|
|
$container, |
298
|
|
|
new FileLocator(__DIR__ . '/../../../Publish/Core/settings') |
299
|
|
|
); |
300
|
|
|
$coreLoader->load('repository.yml'); |
301
|
|
|
$coreLoader->load('repository/inner.yml'); |
302
|
|
|
$coreLoader->load('repository/event.yml'); |
303
|
|
|
$coreLoader->load('repository/siteaccessaware.yml'); |
304
|
|
|
$coreLoader->load('repository/autowire.yml'); |
305
|
|
|
$coreLoader->load('fieldtype_external_storages.yml'); |
306
|
|
|
$coreLoader->load('fieldtypes.yml'); |
307
|
|
|
$coreLoader->load('indexable_fieldtypes.yml'); |
308
|
|
|
$coreLoader->load('fieldtype_services.yml'); |
309
|
|
|
$coreLoader->load('roles.yml'); |
310
|
|
|
$coreLoader->load('storage_engines/common.yml'); |
311
|
|
|
$coreLoader->load('storage_engines/cache.yml'); |
312
|
|
|
$coreLoader->load('storage_engines/legacy.yml'); |
313
|
|
|
$coreLoader->load('storage_engines/shortcuts.yml'); |
314
|
|
|
$coreLoader->load('search_engines/common.yml'); |
315
|
|
|
$coreLoader->load('utils.yml'); |
316
|
|
|
$coreLoader->load('io.yml'); |
317
|
|
|
$coreLoader->load('policies.yml'); |
318
|
|
|
$coreLoader->load('notification.yml'); |
319
|
|
|
$coreLoader->load('user_preference.yml'); |
320
|
|
|
$coreLoader->load('events.yml'); |
321
|
|
|
$coreLoader->load('thumbnails.yml'); |
322
|
|
|
|
323
|
|
|
// Public API services |
324
|
|
|
$loader->load('papi.yml'); |
325
|
|
|
|
326
|
|
|
// Built-in field types |
327
|
|
|
$loader->load('fieldtype_services.yml'); |
328
|
|
|
|
329
|
|
|
// Storage engine |
330
|
|
|
$loader->load('storage_engines.yml'); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Handle templating parameters. |
335
|
|
|
* |
336
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
337
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
338
|
|
|
*/ |
339
|
|
|
private function handleTemplating(ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
340
|
|
|
{ |
341
|
|
|
$loader->load('templating.yml'); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Handle session parameters. |
346
|
|
|
* |
347
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
348
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
349
|
|
|
*/ |
350
|
|
|
private function handleSessionLoading(ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
351
|
|
|
{ |
352
|
|
|
$loader->load('session.yml'); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Handle cache parameters. |
357
|
|
|
* |
358
|
|
|
* @param array $config |
359
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
360
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
361
|
|
|
* |
362
|
|
|
* @throws \InvalidArgumentException |
363
|
|
|
*/ |
364
|
|
|
private function handleCache(array $config, ContainerBuilder $container, FileLoader $loader) |
365
|
|
|
{ |
366
|
|
|
$loader->load('cache.yml'); |
367
|
|
|
|
368
|
|
|
$purgeService = null; |
|
|
|
|
369
|
|
|
if (isset($config['http_cache']['purge_type'])) { |
370
|
|
|
$container->setParameter('ezpublish.http_cache.purge_type', $config['http_cache']['purge_type']); |
371
|
|
|
} |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Handle locale parameters. |
376
|
|
|
* |
377
|
|
|
* @param array $config |
378
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
379
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
380
|
|
|
*/ |
381
|
|
|
private function handleLocale(array $config, ContainerBuilder $container, FileLoader $loader) |
382
|
|
|
{ |
383
|
|
|
$loader->load('locale.yml'); |
384
|
|
|
$container->setParameter( |
385
|
|
|
'ezpublish.locale.conversion_map', |
386
|
|
|
$config['locale_conversion'] + $container->getParameter('ezpublish.locale.conversion_map') |
387
|
|
|
); |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Handle helpers. |
392
|
|
|
* |
393
|
|
|
* @param array $config |
394
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
395
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
396
|
|
|
*/ |
397
|
|
|
private function handleHelpers(array $config, ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
398
|
|
|
{ |
399
|
|
|
$loader->load('helpers.yml'); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* @param array $config |
404
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
405
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
406
|
|
|
*/ |
407
|
|
|
private function handleImage(array $config, ContainerBuilder $container, FileLoader $loader) |
408
|
|
|
{ |
409
|
|
|
$loader->load('image.yml'); |
410
|
|
|
|
411
|
|
|
$providers = []; |
412
|
|
|
if (isset($config['image_placeholder'])) { |
413
|
|
|
foreach ($config['image_placeholder'] as $name => $value) { |
414
|
|
|
if (isset($providers[$name])) { |
415
|
|
|
throw new InvalidConfigurationException("An image_placeholder called $name already exists"); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
$providers[$name] = $value; |
419
|
|
|
} |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
$container->setParameter('image_alias.placeholder_providers', $providers); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
private function handleUrlChecker($config, ContainerBuilder $container, FileLoader $loader) |
|
|
|
|
426
|
|
|
{ |
427
|
|
|
$loader->load('url_checker.yml'); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
private function buildPolicyMap(ContainerBuilder $container) |
431
|
|
|
{ |
432
|
|
|
$policiesBuilder = new PoliciesConfigBuilder($container); |
433
|
|
|
foreach ($this->policyProviders as $provider) { |
434
|
|
|
$provider->addPolicies($policiesBuilder); |
435
|
|
|
} |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* Adds a new policy provider to the internal collection. |
440
|
|
|
* One can call this method from a bundle `build()` method. |
441
|
|
|
* |
442
|
|
|
* ```php |
443
|
|
|
* public function build(ContainerBuilder $container) |
444
|
|
|
* { |
445
|
|
|
* $ezExtension = $container->getExtension('ezpublish'); |
446
|
|
|
* $ezExtension->addPolicyProvider($myPolicyProvider); |
447
|
|
|
* } |
448
|
|
|
* ``` |
449
|
|
|
* |
450
|
|
|
* @since 6.0 |
451
|
|
|
* |
452
|
|
|
* @param PolicyProviderInterface $policyProvider |
453
|
|
|
*/ |
454
|
|
|
public function addPolicyProvider(PolicyProviderInterface $policyProvider) |
455
|
|
|
{ |
456
|
|
|
$this->policyProviders[] = $policyProvider; |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* Adds a new config parser to the internal collection. |
461
|
|
|
* One can call this method from a bundle `build()` method. |
462
|
|
|
* |
463
|
|
|
* ```php |
464
|
|
|
* public function build(ContainerBuilder $container) |
465
|
|
|
* { |
466
|
|
|
* $ezExtension = $container->getExtension('ezpublish'); |
467
|
|
|
* $ezExtension->addConfigParser($myConfigParser); |
468
|
|
|
* } |
469
|
|
|
* ``` |
470
|
|
|
* |
471
|
|
|
* @since 6.0 |
472
|
|
|
* |
473
|
|
|
* @param \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface $configParser |
474
|
|
|
*/ |
475
|
|
|
public function addConfigParser(ParserInterface $configParser) |
476
|
|
|
{ |
477
|
|
|
$this->configParsers[] = $configParser; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* Adds new default settings to the internal collection. |
482
|
|
|
* One can call this method from a bundle `build()` method. |
483
|
|
|
* |
484
|
|
|
* ```php |
485
|
|
|
* public function build(ContainerBuilder $container) |
486
|
|
|
* { |
487
|
|
|
* $ezExtension = $container->getExtension('ezpublish'); |
488
|
|
|
* $ezExtension->addDefaultSettings( |
489
|
|
|
* __DIR__ . '/Resources/config', |
490
|
|
|
* ['default_settings.yml'] |
491
|
|
|
* ); |
492
|
|
|
* } |
493
|
|
|
* ``` |
494
|
|
|
* |
495
|
|
|
* @since 6.0 |
496
|
|
|
* |
497
|
|
|
* @param string $fileLocation |
498
|
|
|
* @param array $files |
499
|
|
|
*/ |
500
|
|
|
public function addDefaultSettings($fileLocation, array $files) |
501
|
|
|
{ |
502
|
|
|
$this->defaultSettingsCollection[$fileLocation] = $files; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
public function addSiteAccessConfigurationFilter(SiteAccessConfigurationFilter $filter) |
506
|
|
|
{ |
507
|
|
|
$this->siteaccessConfigurationFilters[] = $filter; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* @param array $config |
512
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
513
|
|
|
*/ |
514
|
|
|
private function registerUrlAliasConfiguration(array $config, ContainerBuilder $container) |
515
|
|
|
{ |
516
|
|
|
if (!isset($config['url_alias'])) { |
517
|
|
|
$config['url_alias'] = ['slug_converter' => []]; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
$container->setParameter('ezpublish.url_alias.slug_converter', $config['url_alias']['slug_converter']); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
525
|
|
|
*/ |
526
|
|
|
private function prependTranslatorConfiguration(ContainerBuilder $container) |
527
|
|
|
{ |
528
|
|
|
if (!$container->hasExtension('framework')) { |
529
|
|
|
return; |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
$fileSystem = new Filesystem(); |
533
|
|
|
$translationsPath = $container->getParameterBag()->get('kernel.root_dir') . '/../vendor/ezplatform-i18n'; |
534
|
|
|
|
535
|
|
|
if ($fileSystem->exists($translationsPath)) { |
536
|
|
|
$container->prependExtensionConfig('framework', ['translator' => ['paths' => [$translationsPath]]]); |
537
|
|
|
} |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
/** |
541
|
|
|
* @param array $config |
542
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
543
|
|
|
*/ |
544
|
|
|
private function registerUrlWildcardsConfiguration(array $config, ContainerBuilder $container): void |
545
|
|
|
{ |
546
|
|
|
$container->setParameter('ezpublish.url_wildcards.enabled', $config['url_wildcards']['enabled'] ?? false); |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* Loads configuration for UrlWildcardsRouter service if enabled. |
551
|
|
|
* |
552
|
|
|
* @param array $config |
553
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
554
|
|
|
* @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader |
555
|
|
|
*/ |
556
|
|
|
private function handleUrlWildcards(array $config, ContainerBuilder $container, Loader\YamlFileLoader $loader) |
|
|
|
|
557
|
|
|
{ |
558
|
|
|
if ($container->getParameter('ezpublish.url_wildcards.enabled')) { |
559
|
|
|
$loader->load('url_wildcard.yml'); |
560
|
|
|
} |
561
|
|
|
} |
562
|
|
|
} |
563
|
|
|
|
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.