1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\ThemeBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Sylius\Bundle\ThemeBundle\Configuration\ConfigurationSourceFactoryInterface; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
16
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
17
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Kamil Kokot <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
final class Configuration implements ConfigurationInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ConfigurationSourceFactoryInterface[] |
26
|
|
|
*/ |
27
|
|
|
private $configurationSourceFactories; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param ConfigurationSourceFactoryInterface[] $configurationSourceFactories |
31
|
|
|
*/ |
32
|
|
|
public function __construct(array $configurationSourceFactories = []) |
33
|
|
|
{ |
34
|
|
|
$this->configurationSourceFactories = $configurationSourceFactories; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function getConfigTreeBuilder() |
41
|
|
|
{ |
42
|
|
|
$treeBuilder = new TreeBuilder(); |
43
|
|
|
$rootNode = $treeBuilder->root('sylius_theme'); |
44
|
|
|
|
45
|
|
|
$this->addSourcesConfiguration($rootNode); |
46
|
|
|
|
47
|
|
|
$rootNode |
|
|
|
|
48
|
|
|
->children() |
49
|
|
|
->arrayNode('assets') |
50
|
|
|
->canBeDisabled() |
51
|
|
|
->end() |
52
|
|
|
->arrayNode('templating') |
53
|
|
|
->canBeDisabled() |
54
|
|
|
->end() |
55
|
|
|
->arrayNode('translations') |
56
|
|
|
->canBeDisabled() |
57
|
|
|
->end() |
58
|
|
|
->scalarNode('context') |
59
|
|
|
->defaultValue('sylius.theme.context.settable') |
60
|
|
|
->cannotBeEmpty() |
61
|
|
|
->end() |
62
|
|
|
; |
63
|
|
|
|
64
|
|
|
return $treeBuilder; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param ArrayNodeDefinition $rootNode |
69
|
|
|
*/ |
70
|
|
|
private function addSourcesConfiguration(ArrayNodeDefinition $rootNode) |
71
|
|
|
{ |
72
|
|
|
$sourcesNodeBuilder = $rootNode |
73
|
|
|
->fixXmlConfig('source') |
74
|
|
|
->children() |
75
|
|
|
->arrayNode('sources') |
76
|
|
|
->children() |
77
|
|
|
; |
78
|
|
|
|
79
|
|
|
foreach ($this->configurationSourceFactories as $sourceFactory) { |
80
|
|
|
$sourceNode = $sourcesNodeBuilder |
81
|
|
|
->arrayNode($sourceFactory->getName()) |
82
|
|
|
->canBeEnabled() |
83
|
|
|
; |
84
|
|
|
|
85
|
|
|
$sourceFactory->buildConfiguration($sourceNode); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: