Completed
Push — ezp28009-richtext_compatibilit... ( 0daef8...8ac8e2 )
by
unknown
23:10
created

EzPublishCoreExtension   F

Complexity

Total Complexity 71

Size/Duplication

Total Lines 610
Duplicated Lines 3.44 %

Coupling/Cohesion

Components 1
Dependencies 13

Importance

Changes 0
Metric Value
dl 21
loc 610
rs 2.71
c 0
b 0
f 0
wmc 71
lcom 1
cbo 13

28 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAlias() 0 4 1
B load() 0 60 4
A getConfiguration() 0 7 1
A getMainConfigParser() 0 14 4
A handleDefaultSettingsLoading() 0 15 4
A registerRepositoriesConfiguration() 0 14 4
A registerSiteAccessConfiguration() 9 30 5
A registerImageMagickConfiguration() 0 14 4
A registerPageConfiguration() 0 27 5
B registerRichTextConfiguration() 12 25 7
A handleRouting() 0 15 2
A handleApiLoading() 0 45 3
A handleTemplating() 0 4 1
A handleSessionLoading() 0 4 1
A handleCache() 0 9 2
A handleLocale() 0 8 1
A handleHelpers() 0 4 1
A handleSiteAccessesRelation() 0 32 5
A handleImage() 0 17 4
A handleUrlChecker() 0 4 1
A buildPolicyMap() 0 7 2
A addPolicyProvider() 0 4 1
A addConfigParser() 0 4 1
A addDefaultSettings() 0 4 1
A addSiteAccessConfigurationFilter() 0 4 1
A registerUrlAliasConfiguration() 0 8 2
A isRichTextBundleEnabled() 0 8 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like EzPublishCoreExtension often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EzPublishCoreExtension, and based on these observations, apply Extract Interface, too.

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\HttpKernel\DependencyInjection\Extension;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\DependencyInjection\Loader;
23
use Symfony\Component\DependencyInjection\Loader\FileLoader;
24
use Symfony\Component\Config\FileLocator;
25
use InvalidArgumentException;
26
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface;
27
28
class EzPublishCoreExtension extends Extension
29
{
30
    const RICHTEXT_CUSTOM_STYLES_PARAMETER = 'ezplatform.ezrichtext.custom_styles';
31
    const RICHTEXT_CUSTOM_TAGS_PARAMETER = 'ezplatform.ezrichtext.custom_tags';
32
33
    /**
34
     * @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\Collector\SuggestionCollector
35
     */
36
    private $suggestionCollector;
37
38
    /**
39
     * @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface
40
     */
41
    private $mainConfigParser;
42
43
    /**
44
     * @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface[]
45
     */
46
    private $configParsers;
47
48
    /**
49
     * @var PolicyProviderInterface[]
50
     */
51
    private $policyProviders = [];
52
53
    /**
54
     * Holds a collection of YAML files, as an array with directory path as a
55
     * key to the array of contained file names.
56
     *
57
     * @var array
58
     */
59
    private $defaultSettingsCollection = [];
60
61
    /**
62
     * @var \eZ\Bundle\EzPublishCoreBundle\SiteAccess\SiteAccessConfigurationFilter[]
63
     */
64
    private $siteaccessConfigurationFilters = [];
65
66
    public function __construct(array $configParsers = array())
67
    {
68
        $this->configParsers = $configParsers;
69
        $this->suggestionCollector = new SuggestionCollector();
70
    }
71
72
    public function getAlias()
73
    {
74
        return 'ezpublish';
75
    }
76
77
    /**
78
     * Loads a specific configuration.
79
     *
80
     * @param mixed[] $configs An array of configuration values
81
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
82
     *
83
     * @throws \InvalidArgumentException When provided tag is not defined in this extension
84
     *
85
     * @api
86
     */
87
    public function load(array $configs, ContainerBuilder $container)
88
    {
89
        $loader = new Loader\YamlFileLoader(
90
            $container,
91
            new FileLocator(__DIR__ . '/../Resources/config')
92
        );
93
94
        $configuration = $this->getConfiguration($configs, $container);
95
96
        // Note: this is where the transformation occurs
97
        $config = $this->processConfiguration($configuration, $configs);
98
99
        // Base services and services overrides
100
        $loader->load('services.yml');
101
        // Security services
102
        $loader->load('security.yml');
103
104
        if (interface_exists('FOS\JsRoutingBundle\Extractor\ExposedRoutesExtractorInterface')) {
105
            $loader->load('routing/js_routing.yml');
106
        }
107
108
        // Default settings
109
        $this->handleDefaultSettingsLoading($container, $loader);
110
111
        $this->registerRepositoriesConfiguration($config, $container);
112
        $this->registerSiteAccessConfiguration($config, $container);
113
        $this->registerImageMagickConfiguration($config, $container);
114
        $this->registerPageConfiguration($config, $container);
115
        $this->registerRichTextConfiguration($config, $container);
116
        $this->registerUrlAliasConfiguration($config, $container);
117
118
        // Routing
119
        $this->handleRouting($config, $container, $loader);
120
        // Public API loading
121
        $this->handleApiLoading($container, $loader);
122
        $this->handleTemplating($container, $loader);
123
        $this->handleSessionLoading($container, $loader);
124
        $this->handleCache($config, $container, $loader);
125
        $this->handleLocale($config, $container, $loader);
126
        $this->handleHelpers($config, $container, $loader);
127
        $this->handleImage($config, $container, $loader);
128
        $this->handleUrlChecker($config, $container, $loader);
129
130
        // Map settings
131
        $processor = new ConfigurationProcessor($container, 'ezsettings');
132
        $processor->mapConfig($config, $this->getMainConfigParser());
133
134
        if ($this->suggestionCollector->hasSuggestions()) {
135
            $message = '';
136
            $suggestionFormatter = new YamlSuggestionFormatter();
137
            foreach ($this->suggestionCollector->getSuggestions() as $suggestion) {
138
                $message .= $suggestionFormatter->format($suggestion) . "\n\n";
139
            }
140
141
            throw new InvalidArgumentException($message);
142
        }
143
144
        $this->handleSiteAccessesRelation($container);
145
        $this->buildPolicyMap($container);
146
    }
147
148
    /**
149
     * @param array $config
150
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
151
     *
152
     * @return \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration
153
     */
154
    public function getConfiguration(array $config, ContainerBuilder $container)
155
    {
156
        $configuration = new Configuration($this->getMainConfigParser(), $this->suggestionCollector);
157
        $configuration->setSiteAccessConfigurationFilters($this->siteaccessConfigurationFilters);
158
159
        return $configuration;
160
    }
161
162
    /**
163
     * @return \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface
164
     */
165
    private function getMainConfigParser()
166
    {
167
        if ($this->mainConfigParser === null) {
168
            foreach ($this->configParsers as $parser) {
169
                if ($parser instanceof SuggestionCollectorAwareInterface) {
170
                    $parser->setSuggestionCollector($this->suggestionCollector);
171
                }
172
            }
173
174
            $this->mainConfigParser = new ConfigParser($this->configParsers);
175
        }
176
177
        return $this->mainConfigParser;
178
    }
179
180
    /**
181
     * Handle default settings.
182
     *
183
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
184
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
185
     *
186
     * @throws \Exception
187
     */
188
    private function handleDefaultSettingsLoading(ContainerBuilder $container, FileLoader $loader)
189
    {
190
        $loader->load('default_settings.yml');
191
192
        if (!$this->isRichTextBundleEnabled($container)) {
193
            $loader->load('ezrichtext_default_settings.yml');
194
        }
195
196
        foreach ($this->defaultSettingsCollection as $fileLocation => $files) {
197
            $externalLoader = new Loader\YamlFileLoader($container, new FileLocator($fileLocation));
198
            foreach ($files as $file) {
199
                $externalLoader->load($file);
200
            }
201
        }
202
    }
203
204
    private function registerRepositoriesConfiguration(array $config, ContainerBuilder $container)
205
    {
206
        if (!isset($config['repositories'])) {
207
            $config['repositories'] = array();
208
        }
209
210
        foreach ($config['repositories'] as $name => &$repository) {
211
            if (empty($repository['fields_groups']['list'])) {
212
                $repository['fields_groups']['list'] = $container->getParameter('ezsettings.default.content.field_groups.list');
213
            }
214
        }
215
216
        $container->setParameter('ezpublish.repositories', $config['repositories']);
217
    }
218
219
    private function registerSiteAccessConfiguration(array $config, ContainerBuilder $container)
220
    {
221
        if (!isset($config['siteaccess'])) {
222
            $config['siteaccess'] = array();
223
            $config['siteaccess']['list'] = array('setup');
224
            $config['siteaccess']['default_siteaccess'] = 'setup';
225
            $config['siteaccess']['groups'] = array();
226
            $config['siteaccess']['match'] = null;
227
        }
228
229
        $container->setParameter('ezpublish.siteaccess.list', $config['siteaccess']['list']);
230
        ConfigurationProcessor::setAvailableSiteAccesses($config['siteaccess']['list']);
231
        $container->setParameter('ezpublish.siteaccess.default', $config['siteaccess']['default_siteaccess']);
232
        $container->setParameter('ezpublish.siteaccess.match_config', $config['siteaccess']['match']);
233
234
        // Register siteaccess groups + reverse
235
        $container->setParameter('ezpublish.siteaccess.groups', $config['siteaccess']['groups']);
236
        $groupsBySiteaccess = array();
237 View Code Duplication
        foreach ($config['siteaccess']['groups'] as $groupName => $groupMembers) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
238
            foreach ($groupMembers as $member) {
239
                if (!isset($groupsBySiteaccess[$member])) {
240
                    $groupsBySiteaccess[$member] = array();
241
                }
242
243
                $groupsBySiteaccess[$member][] = $groupName;
244
            }
245
        }
246
        $container->setParameter('ezpublish.siteaccess.groups_by_siteaccess', $groupsBySiteaccess);
247
        ConfigurationProcessor::setGroupsBySiteAccess($groupsBySiteaccess);
248
    }
249
250
    private function registerImageMagickConfiguration(array $config, ContainerBuilder $container)
251
    {
252
        if (isset($config['imagemagick'])) {
253
            $container->setParameter('ezpublish.image.imagemagick.enabled', $config['imagemagick']['enabled']);
254
            if ($config['imagemagick']['enabled']) {
255
                $container->setParameter('ezpublish.image.imagemagick.executable_path', dirname($config['imagemagick']['path']));
256
                $container->setParameter('ezpublish.image.imagemagick.executable', basename($config['imagemagick']['path']));
257
            }
258
        }
259
260
        $filters = isset($config['imagemagick']['filters']) ? $config['imagemagick']['filters'] : array();
261
        $filters = $filters + $container->getParameter('ezpublish.image.imagemagick.filters');
262
        $container->setParameter('ezpublish.image.imagemagick.filters', $filters);
263
    }
264
265
    private function registerPageConfiguration(array $config, ContainerBuilder $container)
266
    {
267
        if (isset($config['ezpage']['layouts'])) {
268
            $container->setParameter(
269
                'ezpublish.ezpage.layouts',
270
                $config['ezpage']['layouts'] + $container->getParameter('ezpublish.ezpage.layouts')
271
            );
272
        }
273
        if (isset($config['ezpage']['blocks'])) {
274
            $container->setParameter(
275
                'ezpublish.ezpage.blocks',
276
                $config['ezpage']['blocks'] + $container->getParameter('ezpublish.ezpage.blocks')
277
            );
278
        }
279
        if (isset($config['ezpage']['enabledLayouts'])) {
280
            $container->setParameter(
281
                'ezpublish.ezpage.enabledLayouts',
282
                $config['ezpage']['enabledLayouts'] + $container->getParameter('ezpublish.ezpage.enabledLayouts')
283
            );
284
        }
285
        if (isset($config['ezpage']['enabledBlocks'])) {
286
            $container->setParameter(
287
                'ezpublish.ezpage.enabledBlocks',
288
                $config['ezpage']['enabledBlocks'] + $container->getParameter('ezpublish.ezpage.enabledBlocks')
289
            );
290
        }
291
    }
292
293
    /**
294
     * Register parameters of global RichText configuration.
295
     *
296
     * @param array $config
297
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
298
     */
299
    private function registerRichTextConfiguration(array $config, ContainerBuilder $container)
300
    {
301 View Code Duplication
        if (isset($config['ezrichtext']['custom_tags'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
302
            $container->setParameter(
303
                static::RICHTEXT_CUSTOM_TAGS_PARAMETER,
304
                $config['ezrichtext']['custom_tags']
305
            );
306
        }
307 View Code Duplication
        if (isset($config['ezrichtext']['custom_styles'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
308
            $container->setParameter(
309
                static::RICHTEXT_CUSTOM_STYLES_PARAMETER,
310
                $config['ezrichtext']['custom_styles']
311
            );
312
        }
313
        // keep BC
314
        if (!empty($config['ezrichtext']) && $this->isRichTextBundleEnabled($container)) {
315
            $container->prependExtensionConfig('ezrichtext', $config['ezrichtext']);
316
            if (!empty($config['ezrichtext']['custom_tags']) || !empty($config['ezrichtext']['custom_styles'])) {
317
                @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
318
                    'ezpublish.ezrichtext configuration is deprecated since v7.4, move entire configuration node to ezrichtext extension',
319
                    E_USER_DEPRECATED
320
                );
321
            }
322
        }
323
    }
324
325
    /**
326
     * Handle routing parameters.
327
     *
328
     * @param array $config
329
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
330
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
331
     */
332
    private function handleRouting(array $config, ContainerBuilder $container, FileLoader $loader)
333
    {
334
        $loader->load('routing.yml');
335
        $container->setAlias('router', 'ezpublish.chain_router');
336
337
        if (isset($config['router']['default_router']['non_siteaccess_aware_routes'])) {
338
            $container->setParameter(
339
                'ezpublish.default_router.non_siteaccess_aware_routes',
340
                array_merge(
341
                    $container->getParameter('ezpublish.default_router.non_siteaccess_aware_routes'),
342
                    $config['router']['default_router']['non_siteaccess_aware_routes']
343
                )
344
            );
345
        }
346
    }
347
348
    /**
349
     * Handle public API loading.
350
     *
351
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
352
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
353
     */
354
    private function handleApiLoading(ContainerBuilder $container, FileLoader $loader)
355
    {
356
        // Loading configuration from Core/settings
357
        $coreLoader = new Loader\YamlFileLoader(
358
            $container,
359
            new FileLocator(__DIR__ . '/../../../Publish/Core/settings')
360
        );
361
        $coreLoader->load('repository.yml');
362
        $coreLoader->load('repository/inner.yml');
363
        $coreLoader->load('repository/signalslot.yml');
364
        $coreLoader->load('repository/siteaccessaware.yml');
365
        $coreLoader->load('fieldtype_external_storages.yml');
366
        $coreLoader->load('fieldtypes.yml');
367
        $coreLoader->load('indexable_fieldtypes.yml');
368
        $coreLoader->load('roles.yml');
369
        $coreLoader->load('storage_engines/common.yml');
370
        $coreLoader->load('storage_engines/cache.yml');
371
        $coreLoader->load('storage_engines/legacy.yml');
372
        $coreLoader->load('storage_engines/shortcuts.yml');
373
        $coreLoader->load('search_engines/common.yml');
374
        $coreLoader->load('utils.yml');
375
        $coreLoader->load('io.yml');
376
        $coreLoader->load('policies.yml');
377
        $coreLoader->load('notification.yml');
378
        $coreLoader->load('user_preference.yml');
379
380
        // Load Core RichText settings
381
        if (!$this->isRichTextBundleEnabled($container)) {
382
            $coreLoader->load('richtext.yml');
383
        }
384
385
        // Public API services
386
        $loader->load('papi.yml');
387
388
        // Built-in field types
389
        $loader->load('fieldtype_services.yml');
390
391
        // Storage engine
392
        $loader->load('storage_engines.yml');
393
394
        // Load CoreBundle RichText settings
395
        if (!$this->isRichTextBundleEnabled($container)) {
396
            $loader->load('richtext.yml');
397
        }
398
    }
399
400
    /**
401
     * Handle templating parameters.
402
     *
403
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
404
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
405
     */
406
    private function handleTemplating(ContainerBuilder $container, FileLoader $loader)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
407
    {
408
        $loader->load('templating.yml');
409
    }
410
411
    /**
412
     * Handle session parameters.
413
     *
414
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
415
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
416
     */
417
    private function handleSessionLoading(ContainerBuilder $container, FileLoader $loader)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
418
    {
419
        $loader->load('session.yml');
420
    }
421
422
    /**
423
     * Handle cache parameters.
424
     *
425
     * @param array $config
426
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
427
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
428
     *
429
     * @throws \InvalidArgumentException
430
     */
431
    private function handleCache(array $config, ContainerBuilder $container, FileLoader $loader)
432
    {
433
        $loader->load('cache.yml');
434
435
        $purgeService = null;
0 ignored issues
show
Unused Code introduced by
$purgeService is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
436
        if (isset($config['http_cache']['purge_type'])) {
437
            $container->setParameter('ezpublish.http_cache.purge_type', $config['http_cache']['purge_type']);
438
        }
439
    }
440
441
    /**
442
     * Handle locale parameters.
443
     *
444
     * @param array $config
445
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
446
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
447
     */
448
    private function handleLocale(array $config, ContainerBuilder $container, FileLoader $loader)
449
    {
450
        $loader->load('locale.yml');
451
        $container->setParameter(
452
            'ezpublish.locale.conversion_map',
453
            $config['locale_conversion'] + $container->getParameter('ezpublish.locale.conversion_map')
454
        );
455
    }
456
457
    /**
458
     * Handle helpers.
459
     *
460
     * @param array $config
461
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
462
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
463
     */
464
    private function handleHelpers(array $config, ContainerBuilder $container, FileLoader $loader)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
465
    {
466
        $loader->load('helpers.yml');
467
    }
468
469
    /**
470
     * Handles relation between SiteAccesses.
471
     * Related SiteAccesses share the same repository and root location id.
472
     *
473
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
474
     */
475
    private function handleSiteAccessesRelation(ContainerBuilder $container)
476
    {
477
        $configResolver = $container->get('ezpublish.config.resolver.core');
478
        $configResolver->setContainer($container);
479
480
        $saRelationMap = array();
481
        $saList = $container->getParameter('ezpublish.siteaccess.list');
482
        // First build the SiteAccess relation map, indexed by repository and rootLocationId.
483
        foreach ($saList as $sa) {
484
            $repository = $configResolver->getParameter('repository', 'ezsettings', $sa);
485
            if (!isset($saRelationMap[$repository])) {
486
                $saRelationMap[$repository] = array();
487
            }
488
489
            $rootLocationId = $configResolver->getParameter('content.tree_root.location_id', 'ezsettings', $sa);
490
            if (!isset($saRelationMap[$repository][$rootLocationId])) {
491
                $saRelationMap[$repository][$rootLocationId] = array();
492
            }
493
            $saRelationMap[$repository][$rootLocationId][] = $sa;
494
        }
495
        $container->setParameter('ezpublish.siteaccess.relation_map', $saRelationMap);
496
497
        // Now build the related SiteAccesses list, based on the relation map.
498
        foreach ($saList as $sa) {
499
            $repository = $configResolver->getParameter('repository', 'ezsettings', $sa);
500
            $rootLocationId = $configResolver->getParameter('content.tree_root.location_id', 'ezsettings', $sa);
501
            $container->setParameter(
502
                "ezsettings.$sa.related_siteaccesses",
503
                $saRelationMap[$repository][$rootLocationId]
504
            );
505
        }
506
    }
507
508
    /**
509
     * @param array $config
510
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
511
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
512
     */
513
    private function handleImage(array $config, ContainerBuilder $container, FileLoader $loader)
514
    {
515
        $loader->load('image.yml');
516
517
        $providers = [];
518
        if (isset($config['image_placeholder'])) {
519
            foreach ($config['image_placeholder'] as $name => $value) {
520
                if (isset($providers[$name])) {
521
                    throw new InvalidConfigurationException("A image_placeholder named $name already exists");
522
                }
523
524
                $providers[$name] = $value;
525
            }
526
        }
527
528
        $container->setParameter('image_alias.placeholder_providers', $providers);
529
    }
530
531
    private function handleUrlChecker($config, ContainerBuilder $container, FileLoader $loader)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
532
    {
533
        $loader->load('url_checker.yml');
534
    }
535
536
    private function buildPolicyMap(ContainerBuilder $container)
537
    {
538
        $policiesBuilder = new PoliciesConfigBuilder($container);
539
        foreach ($this->policyProviders as $provider) {
540
            $provider->addPolicies($policiesBuilder);
541
        }
542
    }
543
544
    /**
545
     * Adds a new policy provider to the internal collection.
546
     * One can call this method from a bundle `build()` method.
547
     *
548
     * ```php
549
     * public function build(ContainerBuilder $container)
550
     * {
551
     *     $ezExtension = $container->getExtension('ezpublish');
552
     *     $ezExtension->addPolicyProvider($myPolicyProvider);
553
     * }
554
     * ```
555
     *
556
     * @since 6.0
557
     *
558
     * @param PolicyProviderInterface $policyProvider
559
     */
560
    public function addPolicyProvider(PolicyProviderInterface $policyProvider)
561
    {
562
        $this->policyProviders[] = $policyProvider;
563
    }
564
565
    /**
566
     * Adds a new config parser to the internal collection.
567
     * One can call this method from a bundle `build()` method.
568
     *
569
     * ```php
570
     * public function build(ContainerBuilder $container)
571
     * {
572
     *     $ezExtension = $container->getExtension('ezpublish');
573
     *     $ezExtension->addConfigParser($myConfigParser);
574
     * }
575
     * ```
576
     *
577
     * @since 6.0
578
     *
579
     * @param \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface $configParser
580
     */
581
    public function addConfigParser(ParserInterface $configParser)
582
    {
583
        $this->configParsers[] = $configParser;
584
    }
585
586
    /**
587
     * Adds new default settings to the internal collection.
588
     * One can call this method from a bundle `build()` method.
589
     *
590
     * ```php
591
     * public function build(ContainerBuilder $container)
592
     * {
593
     *     $ezExtension = $container->getExtension('ezpublish');
594
     *     $ezExtension->addDefaultSettings(
595
     *         __DIR__ . '/Resources/config',
596
     *         ['default_settings.yml']
597
     *     );
598
     * }
599
     * ```
600
     *
601
     * @since 6.0
602
     *
603
     * @param string $fileLocation
604
     * @param array $files
605
     */
606
    public function addDefaultSettings($fileLocation, array $files)
607
    {
608
        $this->defaultSettingsCollection[$fileLocation] = $files;
609
    }
610
611
    public function addSiteAccessConfigurationFilter(SiteAccessConfigurationFilter $filter)
612
    {
613
        $this->siteaccessConfigurationFilters[] = $filter;
614
    }
615
616
    /**
617
     * @param array $config
618
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
619
     */
620
    private function registerUrlAliasConfiguration(array $config, ContainerBuilder $container)
621
    {
622
        if (!isset($config['url_alias'])) {
623
            $config['url_alias'] = ['slug_converter' => []];
624
        }
625
626
        $container->setParameter('ezpublish.url_alias.slug_converter', $config['url_alias']['slug_converter']);
627
    }
628
629
    private function isRichTextBundleEnabled(ContainerBuilder $container)
630
    {
631
        return $container->hasParameter('kernel.bundles')
632
            && array_key_exists(
633
                'EzPlatformRichTextBundle',
634
                $container->getParameter('kernel.bundles')
635
            );
636
    }
637
}
638