1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Leogout\Bundle\SeoBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Description of Configuration. |
11
|
|
|
* |
12
|
|
|
* @author: leogout |
13
|
|
|
*/ |
14
|
|
|
class Configuration implements ConfigurationInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritdoc} |
18
|
|
|
*/ |
19
|
|
|
public function getConfigTreeBuilder() |
20
|
|
|
{ |
21
|
|
|
$treeBuilder = new TreeBuilder(); |
22
|
|
|
$rootNode = $treeBuilder->root('leogout_seo'); |
23
|
|
|
|
24
|
|
|
$this->configureGeneralTree($rootNode); |
25
|
|
|
$this->configureBasicTree($rootNode); |
26
|
|
|
$this->configureOgTree($rootNode); |
27
|
|
|
$this->configureTwitterTree($rootNode); |
28
|
|
|
|
29
|
|
|
return $treeBuilder; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param ArrayNodeDefinition $rootNode |
34
|
|
|
*/ |
35
|
|
|
protected function configureGeneralTree(ArrayNodeDefinition $rootNode) |
36
|
|
|
{ |
37
|
|
|
$generalNode = $rootNode->children()->arrayNode('general'); |
38
|
|
|
$generalNode->addDefaultsIfNotSet() |
39
|
|
|
->children() |
40
|
|
|
->scalarNode('title')->cannotBeEmpty()->end() |
41
|
|
|
->scalarNode('description')->cannotBeEmpty()->end() |
42
|
|
|
->scalarNode('image')->cannotBeEmpty()->end() |
43
|
|
|
->end(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param ArrayNodeDefinition $rootNode |
48
|
|
|
*/ |
49
|
|
|
protected function configureBasicTree(ArrayNodeDefinition $rootNode) |
50
|
|
|
{ |
51
|
|
|
$basicNode = $rootNode->children()->arrayNode('basic'); |
52
|
|
|
$basicNode->children() |
53
|
|
|
->scalarNode('title')->cannotBeEmpty()->end() |
54
|
|
|
->scalarNode('description')->cannotBeEmpty()->end() |
55
|
|
|
->scalarNode('keywords')->cannotBeEmpty()->end() |
56
|
|
|
->arrayNode('robots') |
57
|
|
|
->children() |
58
|
|
|
->booleanNode('index')->defaultTrue()->end() |
59
|
|
|
->booleanNode('follow')->defaultTrue()->end() |
60
|
|
|
->end() |
61
|
|
|
->end() |
62
|
|
|
->scalarNode('canonical')->cannotBeEmpty()->end() |
63
|
|
|
->end(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param ArrayNodeDefinition $rootNode |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
protected function configureOgTree(ArrayNodeDefinition $rootNode) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$ogNode = $rootNode->children()->arrayNode('og'); |
72
|
|
|
$ogNode->children() |
73
|
|
|
->scalarNode('title')->cannotBeEmpty()->end() |
74
|
|
|
->scalarNode('description')->cannotBeEmpty()->end() |
75
|
|
|
->scalarNode('image')->cannotBeEmpty()->end() |
76
|
|
|
->scalarNode('type')->cannotBeEmpty()->end() |
77
|
|
|
->scalarNode('url')->cannotBeEmpty()->end() |
78
|
|
|
->end(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param ArrayNodeDefinition $rootNode |
83
|
|
|
*/ |
84
|
|
View Code Duplication |
protected function configureTwitterTree(ArrayNodeDefinition $rootNode) |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$twitterNode = $rootNode->children()->arrayNode('twitter'); |
87
|
|
|
$twitterNode->children() |
88
|
|
|
->scalarNode('title')->cannotBeEmpty()->end() |
89
|
|
|
->scalarNode('description')->cannotBeEmpty()->end() |
90
|
|
|
->scalarNode('image')->cannotBeEmpty()->end() |
91
|
|
|
->scalarNode('card')->cannotBeEmpty()->end() |
92
|
|
|
->scalarNode('site')->cannotBeEmpty()->end() |
93
|
|
|
->end(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
|
98
|
|
|
|
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
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.