Completed
Push — 7.5 ( f79096...9972f5 )
by
unknown
27:34
created

EzPublishCoreExtension::isRichTextBundleEnabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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
        $this->registerUrlWildcardsConfiguration($config, $container);
120
121
        // Routing
122
        $this->handleRouting($config, $container, $loader);
123
        // Public API loading
124
        $this->handleApiLoading($container, $loader);
125
        $this->handleTemplating($container, $loader);
126
        $this->handleSessionLoading($container, $loader);
127
        $this->handleCache($config, $container, $loader);
128
        $this->handleLocale($config, $container, $loader);
129
        $this->handleHelpers($config, $container, $loader);
130
        $this->handleImage($config, $container, $loader);
131
        $this->handleUrlChecker($config, $container, $loader);
132
        $this->handleUrlWildcards($config, $container, $loader);
133
134
        // Map settings
135
        $processor = new ConfigurationProcessor($container, 'ezsettings');
136
        $processor->mapConfig($config, $this->getMainConfigParser());
137
138
        if ($this->suggestionCollector->hasSuggestions()) {
139
            $message = '';
140
            $suggestionFormatter = new YamlSuggestionFormatter();
141
            foreach ($this->suggestionCollector->getSuggestions() as $suggestion) {
142
                $message .= $suggestionFormatter->format($suggestion) . "\n\n";
143
            }
144
145
            throw new InvalidArgumentException($message);
146
        }
147
148
        $this->handleSiteAccessesRelation($container);
149
        $this->buildPolicyMap($container);
150
    }
151
152
    /**
153
     * @param array $config
154
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
155
     *
156
     * @return \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration
157
     */
158
    public function getConfiguration(array $config, ContainerBuilder $container)
159
    {
160
        $configuration = new Configuration($this->getMainConfigParser(), $this->suggestionCollector);
161
        $configuration->setSiteAccessConfigurationFilters($this->siteaccessConfigurationFilters);
162
163
        return $configuration;
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169
    public function prepend(ContainerBuilder $container)
170
    {
171
        $this->prependTranslatorConfiguration($container);
172
    }
173
174
    /**
175
     * @return \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface
176
     */
177
    private function getMainConfigParser()
178
    {
179
        if ($this->mainConfigParser === null) {
180
            foreach ($this->configParsers as $parser) {
181
                if ($parser instanceof SuggestionCollectorAwareInterface) {
182
                    $parser->setSuggestionCollector($this->suggestionCollector);
183
                }
184
            }
185
186
            $this->mainConfigParser = new ConfigParser($this->configParsers);
187
        }
188
189
        return $this->mainConfigParser;
190
    }
191
192
    /**
193
     * Handle default settings.
194
     *
195
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
196
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
197
     *
198
     * @throws \Exception
199
     */
200
    private function handleDefaultSettingsLoading(ContainerBuilder $container, FileLoader $loader)
201
    {
202
        $loader->load('default_settings.yml');
203
204
        if (!$this->isRichTextBundleEnabled($container)) {
205
            $loader->load('ezrichtext_default_settings.yml');
206
        }
207
208
        foreach ($this->defaultSettingsCollection as $fileLocation => $files) {
209
            $externalLoader = new Loader\YamlFileLoader($container, new FileLocator($fileLocation));
210
            foreach ($files as $file) {
211
                $externalLoader->load($file);
212
            }
213
        }
214
    }
215
216
    private function registerRepositoriesConfiguration(array $config, ContainerBuilder $container)
217
    {
218
        if (!isset($config['repositories'])) {
219
            $config['repositories'] = array();
220
        }
221
222
        foreach ($config['repositories'] as $name => &$repository) {
223
            if (empty($repository['fields_groups']['list'])) {
224
                $repository['fields_groups']['list'] = $container->getParameter('ezsettings.default.content.field_groups.list');
225
            }
226
        }
227
228
        $container->setParameter('ezpublish.repositories', $config['repositories']);
229
    }
230
231
    private function registerSiteAccessConfiguration(array $config, ContainerBuilder $container)
232
    {
233
        if (!isset($config['siteaccess'])) {
234
            $config['siteaccess'] = array();
235
            $config['siteaccess']['list'] = array('setup');
236
            $config['siteaccess']['default_siteaccess'] = 'setup';
237
            $config['siteaccess']['groups'] = array();
238
            $config['siteaccess']['match'] = null;
239
        }
240
241
        $container->setParameter('ezpublish.siteaccess.list', $config['siteaccess']['list']);
242
        ConfigurationProcessor::setAvailableSiteAccesses($config['siteaccess']['list']);
243
        $container->setParameter('ezpublish.siteaccess.default', $config['siteaccess']['default_siteaccess']);
244
        $container->setParameter('ezpublish.siteaccess.match_config', $config['siteaccess']['match']);
245
246
        // Register siteaccess groups + reverse
247
        $container->setParameter('ezpublish.siteaccess.groups', $config['siteaccess']['groups']);
248
        $groupsBySiteaccess = array();
249 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...
250
            foreach ($groupMembers as $member) {
251
                if (!isset($groupsBySiteaccess[$member])) {
252
                    $groupsBySiteaccess[$member] = array();
253
                }
254
255
                $groupsBySiteaccess[$member][] = $groupName;
256
            }
257
        }
258
        $container->setParameter('ezpublish.siteaccess.groups_by_siteaccess', $groupsBySiteaccess);
259
        ConfigurationProcessor::setGroupsBySiteAccess($groupsBySiteaccess);
260
    }
261
262
    private function registerImageMagickConfiguration(array $config, ContainerBuilder $container)
263
    {
264
        if (isset($config['imagemagick'])) {
265
            $container->setParameter('ezpublish.image.imagemagick.enabled', $config['imagemagick']['enabled']);
266
            if ($config['imagemagick']['enabled']) {
267
                $container->setParameter('ezpublish.image.imagemagick.executable_path', dirname($config['imagemagick']['path']));
268
                $container->setParameter('ezpublish.image.imagemagick.executable', basename($config['imagemagick']['path']));
269
            }
270
        }
271
272
        $filters = isset($config['imagemagick']['filters']) ? $config['imagemagick']['filters'] : array();
273
        $filters = $filters + $container->getParameter('ezpublish.image.imagemagick.filters');
274
        $container->setParameter('ezpublish.image.imagemagick.filters', $filters);
275
    }
276
277
    private function registerPageConfiguration(array $config, ContainerBuilder $container)
278
    {
279
        if (isset($config['ezpage']['layouts'])) {
280
            $container->setParameter(
281
                'ezpublish.ezpage.layouts',
282
                $config['ezpage']['layouts'] + $container->getParameter('ezpublish.ezpage.layouts')
283
            );
284
        }
285
        if (isset($config['ezpage']['blocks'])) {
286
            $container->setParameter(
287
                'ezpublish.ezpage.blocks',
288
                $config['ezpage']['blocks'] + $container->getParameter('ezpublish.ezpage.blocks')
289
            );
290
        }
291
        if (isset($config['ezpage']['enabledLayouts'])) {
292
            $container->setParameter(
293
                'ezpublish.ezpage.enabledLayouts',
294
                $config['ezpage']['enabledLayouts'] + $container->getParameter('ezpublish.ezpage.enabledLayouts')
295
            );
296
        }
297
        if (isset($config['ezpage']['enabledBlocks'])) {
298
            $container->setParameter(
299
                'ezpublish.ezpage.enabledBlocks',
300
                $config['ezpage']['enabledBlocks'] + $container->getParameter('ezpublish.ezpage.enabledBlocks')
301
            );
302
        }
303
    }
304
305
    /**
306
     * Register parameters of global RichText configuration.
307
     *
308
     * @param array $config
309
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
310
     */
311
    private function registerRichTextConfiguration(array $config, ContainerBuilder $container)
312
    {
313 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...
314
            $container->setParameter(
315
                static::RICHTEXT_CUSTOM_TAGS_PARAMETER,
316
                $config['ezrichtext']['custom_tags']
317
            );
318
        }
319 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...
320
            $container->setParameter(
321
                static::RICHTEXT_CUSTOM_STYLES_PARAMETER,
322
                $config['ezrichtext']['custom_styles']
323
            );
324
        }
325
        // keep BC
326
        if (!empty($config['ezrichtext']) && $this->isRichTextBundleEnabled($container)) {
327
            $container->prependExtensionConfig('ezrichtext', $config['ezrichtext']);
328
            if (!empty($config['ezrichtext']['custom_tags']) || !empty($config['ezrichtext']['custom_styles'])) {
329
                @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...
330
                    'ezpublish.ezrichtext configuration is deprecated since v7.4, move entire configuration node to ezrichtext extension',
331
                    E_USER_DEPRECATED
332
                );
333
            }
334
        }
335
    }
336
337
    /**
338
     * Handle routing parameters.
339
     *
340
     * @param array $config
341
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
342
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
343
     */
344
    private function handleRouting(array $config, ContainerBuilder $container, FileLoader $loader)
345
    {
346
        $loader->load('routing.yml');
347
        $container->setAlias('router', 'ezpublish.chain_router');
348
349
        if (isset($config['router']['default_router']['non_siteaccess_aware_routes'])) {
350
            $container->setParameter(
351
                'ezpublish.default_router.non_siteaccess_aware_routes',
352
                array_merge(
353
                    $container->getParameter('ezpublish.default_router.non_siteaccess_aware_routes'),
354
                    $config['router']['default_router']['non_siteaccess_aware_routes']
355
                )
356
            );
357
        }
358
    }
359
360
    /**
361
     * Handle public API loading.
362
     *
363
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
364
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
365
     */
366
    private function handleApiLoading(ContainerBuilder $container, FileLoader $loader)
367
    {
368
        // Loading configuration from Core/settings
369
        $coreLoader = new Loader\YamlFileLoader(
370
            $container,
371
            new FileLocator(__DIR__ . '/../../../Publish/Core/settings')
372
        );
373
        $coreLoader->load('repository.yml');
374
        $coreLoader->load('repository/inner.yml');
375
        $coreLoader->load('repository/signalslot.yml');
376
        $coreLoader->load('repository/siteaccessaware.yml');
377
        $coreLoader->load('fieldtype_external_storages.yml');
378
        $coreLoader->load('fieldtypes.yml');
379
        $coreLoader->load('indexable_fieldtypes.yml');
380
        $coreLoader->load('roles.yml');
381
        $coreLoader->load('storage_engines/common.yml');
382
        $coreLoader->load('storage_engines/cache.yml');
383
        $coreLoader->load('storage_engines/legacy.yml');
384
        $coreLoader->load('storage_engines/shortcuts.yml');
385
        $coreLoader->load('search_engines/common.yml');
386
        $coreLoader->load('utils.yml');
387
        $coreLoader->load('io.yml');
388
        $coreLoader->load('policies.yml');
389
        $coreLoader->load('notification.yml');
390
        $coreLoader->load('user_preference.yml');
391
392
        // Load Core RichText settings
393
        if (!$this->isRichTextBundleEnabled($container)) {
394
            $coreLoader->load('richtext.yml');
395
        }
396
397
        // Public API services
398
        $loader->load('papi.yml');
399
400
        // Built-in field types
401
        $loader->load('fieldtype_services.yml');
402
403
        // Storage engine
404
        $loader->load('storage_engines.yml');
405
406
        // Load CoreBundle RichText settings
407
        if (!$this->isRichTextBundleEnabled($container)) {
408
            $loader->load('richtext.yml');
409
        }
410
    }
411
412
    /**
413
     * Handle templating parameters.
414
     *
415
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
416
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
417
     */
418
    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...
419
    {
420
        $loader->load('templating.yml');
421
    }
422
423
    /**
424
     * Handle session parameters.
425
     *
426
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
427
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
428
     */
429
    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...
430
    {
431
        $loader->load('session.yml');
432
    }
433
434
    /**
435
     * Handle cache parameters.
436
     *
437
     * @param array $config
438
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
439
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
440
     *
441
     * @throws \InvalidArgumentException
442
     */
443
    private function handleCache(array $config, ContainerBuilder $container, FileLoader $loader)
444
    {
445
        $loader->load('cache.yml');
446
447
        $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...
448
        if (isset($config['http_cache']['purge_type'])) {
449
            $container->setParameter('ezpublish.http_cache.purge_type', $config['http_cache']['purge_type']);
450
        }
451
    }
452
453
    /**
454
     * Handle locale parameters.
455
     *
456
     * @param array $config
457
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
458
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
459
     */
460
    private function handleLocale(array $config, ContainerBuilder $container, FileLoader $loader)
461
    {
462
        $loader->load('locale.yml');
463
        $container->setParameter(
464
            'ezpublish.locale.conversion_map',
465
            $config['locale_conversion'] + $container->getParameter('ezpublish.locale.conversion_map')
466
        );
467
    }
468
469
    /**
470
     * Handle helpers.
471
     *
472
     * @param array $config
473
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
474
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
475
     */
476
    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...
477
    {
478
        $loader->load('helpers.yml');
479
    }
480
481
    /**
482
     * Handles relation between SiteAccesses.
483
     * Related SiteAccesses share the same repository and root location id.
484
     *
485
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
486
     */
487
    private function handleSiteAccessesRelation(ContainerBuilder $container)
488
    {
489
        $configResolver = $container->get('ezpublish.config.resolver.core');
490
        $configResolver->setContainer($container);
491
492
        $saRelationMap = array();
493
        $saList = $container->getParameter('ezpublish.siteaccess.list');
494
        // First build the SiteAccess relation map, indexed by repository and rootLocationId.
495
        foreach ($saList as $sa) {
496
            $repository = $configResolver->getParameter('repository', 'ezsettings', $sa);
497
            if (!isset($saRelationMap[$repository])) {
498
                $saRelationMap[$repository] = array();
499
            }
500
501
            $rootLocationId = $configResolver->getParameter('content.tree_root.location_id', 'ezsettings', $sa);
502
            if (!isset($saRelationMap[$repository][$rootLocationId])) {
503
                $saRelationMap[$repository][$rootLocationId] = array();
504
            }
505
            $saRelationMap[$repository][$rootLocationId][] = $sa;
506
        }
507
        $container->setParameter('ezpublish.siteaccess.relation_map', $saRelationMap);
508
509
        // Now build the related SiteAccesses list, based on the relation map.
510
        foreach ($saList as $sa) {
511
            $repository = $configResolver->getParameter('repository', 'ezsettings', $sa);
512
            $rootLocationId = $configResolver->getParameter('content.tree_root.location_id', 'ezsettings', $sa);
513
            $container->setParameter(
514
                "ezsettings.$sa.related_siteaccesses",
515
                $saRelationMap[$repository][$rootLocationId]
516
            );
517
        }
518
    }
519
520
    /**
521
     * @param array $config
522
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
523
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
524
     */
525
    private function handleImage(array $config, ContainerBuilder $container, FileLoader $loader)
526
    {
527
        $loader->load('image.yml');
528
529
        $providers = [];
530
        if (isset($config['image_placeholder'])) {
531
            foreach ($config['image_placeholder'] as $name => $value) {
532
                if (isset($providers[$name])) {
533
                    throw new InvalidConfigurationException("A image_placeholder named $name already exists");
534
                }
535
536
                $providers[$name] = $value;
537
            }
538
        }
539
540
        $container->setParameter('image_alias.placeholder_providers', $providers);
541
    }
542
543
    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...
544
    {
545
        $loader->load('url_checker.yml');
546
    }
547
548
    private function buildPolicyMap(ContainerBuilder $container)
549
    {
550
        $policiesBuilder = new PoliciesConfigBuilder($container);
551
        foreach ($this->policyProviders as $provider) {
552
            $provider->addPolicies($policiesBuilder);
553
        }
554
    }
555
556
    /**
557
     * Adds a new policy provider to the internal collection.
558
     * One can call this method from a bundle `build()` method.
559
     *
560
     * ```php
561
     * public function build(ContainerBuilder $container)
562
     * {
563
     *     $ezExtension = $container->getExtension('ezpublish');
564
     *     $ezExtension->addPolicyProvider($myPolicyProvider);
565
     * }
566
     * ```
567
     *
568
     * @since 6.0
569
     *
570
     * @param PolicyProviderInterface $policyProvider
571
     */
572
    public function addPolicyProvider(PolicyProviderInterface $policyProvider)
573
    {
574
        $this->policyProviders[] = $policyProvider;
575
    }
576
577
    /**
578
     * Adds a new config parser to the internal collection.
579
     * One can call this method from a bundle `build()` method.
580
     *
581
     * ```php
582
     * public function build(ContainerBuilder $container)
583
     * {
584
     *     $ezExtension = $container->getExtension('ezpublish');
585
     *     $ezExtension->addConfigParser($myConfigParser);
586
     * }
587
     * ```
588
     *
589
     * @since 6.0
590
     *
591
     * @param \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface $configParser
592
     */
593
    public function addConfigParser(ParserInterface $configParser)
594
    {
595
        $this->configParsers[] = $configParser;
596
    }
597
598
    /**
599
     * Adds new default settings to the internal collection.
600
     * One can call this method from a bundle `build()` method.
601
     *
602
     * ```php
603
     * public function build(ContainerBuilder $container)
604
     * {
605
     *     $ezExtension = $container->getExtension('ezpublish');
606
     *     $ezExtension->addDefaultSettings(
607
     *         __DIR__ . '/Resources/config',
608
     *         ['default_settings.yml']
609
     *     );
610
     * }
611
     * ```
612
     *
613
     * @since 6.0
614
     *
615
     * @param string $fileLocation
616
     * @param array $files
617
     */
618
    public function addDefaultSettings($fileLocation, array $files)
619
    {
620
        $this->defaultSettingsCollection[$fileLocation] = $files;
621
    }
622
623
    public function addSiteAccessConfigurationFilter(SiteAccessConfigurationFilter $filter)
624
    {
625
        $this->siteaccessConfigurationFilters[] = $filter;
626
    }
627
628
    /**
629
     * @param array $config
630
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
631
     */
632
    private function registerUrlAliasConfiguration(array $config, ContainerBuilder $container)
633
    {
634
        if (!isset($config['url_alias'])) {
635
            $config['url_alias'] = ['slug_converter' => []];
636
        }
637
638
        $container->setParameter('ezpublish.url_alias.slug_converter', $config['url_alias']['slug_converter']);
639
    }
640
641
    private function isRichTextBundleEnabled(ContainerBuilder $container)
642
    {
643
        return $container->hasParameter('kernel.bundles')
644
            && array_key_exists(
645
                'EzPlatformRichTextBundle',
646
                $container->getParameter('kernel.bundles')
647
            );
648
    }
649
650
    /**
651
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
652
     */
653
    private function prependTranslatorConfiguration(ContainerBuilder $container)
654
    {
655
        if (!$container->hasExtension('framework')) {
656
            return;
657
        }
658
659
        $fileSystem = new Filesystem();
660
        $translationsPath = $container->getParameterBag()->get('kernel.root_dir') . '/../vendor/ezplatform-i18n';
661
662
        if ($fileSystem->exists($translationsPath)) {
663
            $container->prependExtensionConfig('framework', ['translator' => ['paths' => [$translationsPath]]]);
664
        }
665
    }
666
667
    /**
668
     * @param array $config
669
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
670
     */
671
    private function registerUrlWildcardsConfiguration(array $config, ContainerBuilder $container): void
672
    {
673
        $container->setParameter('ezpublish.url_wildcards.enabled', $config['url_wildcards']['enabled'] ?? false);
674
    }
675
676
    /**
677
     * Loads configuration for UrlWildcardsRouter service if enabled.
678
     *
679
     * @param array $config
680
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
681
     * @param \Symfony\Component\DependencyInjection\Loader\FileLoader $loader
682
     */
683
    private function handleUrlWildcards(array $config, ContainerBuilder $container, Loader\YamlFileLoader $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...
684
    {
685
        if ($container->getParameter('ezpublish.url_wildcards.enabled')) {
686
            $loader->load('url_wildcard.yml');
687
        }
688
    }
689
}
690