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\LocaleBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Sylius\Bundle\LocaleBundle\Controller\LocaleController; |
15
|
|
|
use Sylius\Bundle\LocaleBundle\Form\Type\LocaleChoiceType; |
16
|
|
|
use Sylius\Bundle\LocaleBundle\Form\Type\LocaleType; |
17
|
|
|
use Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration\ResourceConfigurationGenerator; |
18
|
|
|
use Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration\SyliusResource; |
19
|
|
|
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; |
20
|
|
|
use Sylius\Component\Locale\Model\Locale; |
21
|
|
|
use Sylius\Component\Locale\Model\LocaleInterface; |
22
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
23
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
24
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* This class contains the configuration information for the bundle. |
28
|
|
|
* |
29
|
|
|
* This information is solely responsible for how the different configuration |
30
|
|
|
* sections are normalized, and merged. |
31
|
|
|
* |
32
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class Configuration implements ConfigurationInterface |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function getConfigTreeBuilder() |
40
|
|
|
{ |
41
|
|
|
$treeBuilder = new TreeBuilder(); |
42
|
|
|
$rootNode = $treeBuilder->root('sylius_locale'); |
43
|
|
|
|
44
|
|
|
$rootNode |
45
|
|
|
->children() |
46
|
|
|
->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end() |
47
|
|
|
->scalarNode('storage')->defaultValue('sylius.storage.session')->end() |
48
|
|
|
->end() |
49
|
|
|
; |
50
|
|
|
|
51
|
|
|
$this->addResourcesSection($rootNode); |
52
|
|
|
|
53
|
|
|
return $treeBuilder; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param ArrayNodeDefinition $rootDefinition |
58
|
|
|
*/ |
59
|
|
|
private function addResourcesSection(ArrayNodeDefinition $rootDefinition) |
60
|
|
|
{ |
61
|
|
|
$resourceConfigurationGenerator = new ResourceConfigurationGenerator(); |
62
|
|
|
|
63
|
|
|
$resourcesDefinition = $resourceConfigurationGenerator->initResourcesConfiguration($rootDefinition); |
64
|
|
|
|
65
|
|
|
$localeResource = new SyliusResource('locale', Locale::class, LocaleInterface::class); |
66
|
|
|
$localeResource->useController(LocaleController::class); |
67
|
|
|
$localeResource->useDefaultRepository(); |
|
|
|
|
68
|
|
|
$localeResource->useDefaultFactory(); |
69
|
|
|
$localeResource->addForm('default', LocaleType::class, ['sylius']); |
70
|
|
|
$localeResource->addForm('choice', LocaleChoiceType::class); |
71
|
|
|
|
72
|
|
|
$resourceConfigurationGenerator->addSyliusResource($resourcesDefinition, $localeResource); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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: