Completed
Push — master ( a60272...c7b9bc )
by André
128:32 queued 99:17
created

Content   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
B addSemanticConfig() 0 26 1
C mapConfig() 0 31 7
1
<?php
2
3
/**
4
 * File containing the Content 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\Configuration\Parser;
10
11
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\AbstractParser;
12
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
13
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
14
15
/**
16
 * Configuration parser handling content related config.
17
 */
18
class Content extends AbstractParser
19
{
20
    /**
21
     * Adds semantic configuration definition.
22
     *
23
     * @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeBuilder Node just under ezpublish.system.<siteaccess>
24
     */
25
    public function addSemanticConfig(NodeBuilder $nodeBuilder)
26
    {
27
        $nodeBuilder
28
            ->arrayNode('content')
29
                ->info('Content related configuration')
30
                ->children()
31
                    ->booleanNode('view_cache')->end()
32
                    ->booleanNode('ttl_cache')->end()
33
                    ->scalarNode('default_ttl')->info('Default value for TTL cache, in seconds')->end()
34
                    ->arrayNode('tree_root')
35
                        ->canBeUnset()
36
                        ->children()
37
                            ->integerNode('location_id')
38
                                ->info("Root locationId for routing and link generation.\nUseful for multisite apps with one repository.")
39
                                ->isRequired()
40
                            ->end()
41
                            ->arrayNode('excluded_uri_prefixes')
42
                                ->info("URI prefixes that are allowed to be outside the content tree\n(useful for content sharing between multiple sites).\nPrefixes are not case sensitive")
43
                                ->example(array('/media/images', '/products'))
44
                                ->prototype('scalar')->end()
45
                            ->end()
46
                        ->end()
47
                    ->end()
48
                ->end()
49
            ->end();
50
    }
51
52
    public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer)
53
    {
54
        if (!empty($scopeSettings['content'])) {
55
            if (isset($scopeSettings['content']['view_cache'])) {
56
                $contextualizer->setContextualParameter('content.view_cache', $currentScope, $scopeSettings['content']['view_cache']);
57
            }
58
59
            if (isset($scopeSettings['content']['ttl_cache'])) {
60
                $contextualizer->setContextualParameter('content.ttl_cache', $currentScope, $scopeSettings['content']['ttl_cache']);
61
            }
62
63
            if (isset($scopeSettings['content']['default_ttl'])) {
64
                $contextualizer->setContextualParameter('content.default_ttl', $currentScope, $scopeSettings['content']['default_ttl']);
65
            }
66
67
            if (isset($scopeSettings['content']['tree_root'])) {
68
                $contextualizer->setContextualParameter(
69
                    'content.tree_root.location_id',
70
                    $currentScope,
71
                    $scopeSettings['content']['tree_root']['location_id']
72
                );
73
                if (isset($scopeSettings['content']['tree_root']['excluded_uri_prefixes'])) {
74
                    $contextualizer->setContextualParameter(
75
                        'content.tree_root.excluded_uri_prefixes',
76
                        $currentScope,
77
                        $scopeSettings['content']['tree_root']['excluded_uri_prefixes']
78
                    );
79
                }
80
            }
81
        }
82
    }
83
}
84