1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Doctrine Naming Strategy Bundle, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2015 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace RunOpenCode\Bundle\DoctrineNamingStrategy\DependencyInjection; |
11
|
|
|
|
12
|
|
|
use RunOpenCode\Bundle\DoctrineNamingStrategy\NamingStrategy\NamerCollection; |
13
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
14
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
15
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
16
|
|
|
|
17
|
|
|
class Configuration implements ConfigurationInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function getConfigTreeBuilder() |
23
|
|
|
{ |
24
|
|
|
$treeBuilder = new TreeBuilder(); |
25
|
|
|
|
26
|
|
|
$rootNode = $treeBuilder->root('run_open_code_doctrine_naming_strategy'); |
27
|
|
|
|
28
|
|
|
$rootNode |
29
|
|
|
->children() |
30
|
|
|
->append($this->getUnderscoredBundlePrefixDefinition()) |
31
|
|
|
->append($this->getUnderscoredClassNamespacePrefixDefinition()) |
32
|
|
|
->append($this->getNamerCollectionDefinition()) |
33
|
|
|
->end() |
34
|
|
|
->end(); |
35
|
|
|
|
36
|
|
|
return $treeBuilder; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function getUnderscoredBundlePrefixDefinition() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$node = new ArrayNodeDefinition('run_open_code_doctrine_naming_strategy'); |
42
|
|
|
|
43
|
|
|
$node |
44
|
|
|
->children() |
45
|
|
|
->enumNode('case') |
46
|
|
|
->info('Which case to use, lowercase or uppercase. Default is lowercase.') |
47
|
|
|
->values(array('lowercase', 'uppercase')) |
48
|
|
|
->defaultValue('lowercase') |
49
|
|
|
->end() |
50
|
|
|
->arrayNode('map') |
51
|
|
|
->info('Map of short bundle names and prefixes, if you do not want to use full bundle name in prefix. Useful when bundle name is too long, considering that, per example, MySQL has 60 chars table name limit.') |
52
|
|
|
->useAttributeAsKey('name') |
53
|
|
|
->prototype('scalar')->end() |
54
|
|
|
->end() |
55
|
|
|
->arrayNode('whitelist') |
56
|
|
|
->info('Define for which bundles to apply prefixes.') |
57
|
|
|
->prototype('scalar')->end() |
58
|
|
|
->end() |
59
|
|
|
->arrayNode('blacklist') |
60
|
|
|
->info('Define for which bundles not to apply prefixes.') |
61
|
|
|
->prototype('scalar')->end() |
62
|
|
|
->end() |
63
|
|
|
->end() |
64
|
|
|
->end(); |
65
|
|
|
|
66
|
|
|
return $node; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function getUnderscoredClassNamespacePrefixDefinition() |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$node = new ArrayNodeDefinition('underscored_class_namespace_prefix'); |
72
|
|
|
|
73
|
|
|
$node |
74
|
|
|
->children() |
75
|
|
|
->enumNode('case') |
76
|
|
|
->info('Which case to use, lowercase or uppercase. Default is lowercase.') |
77
|
|
|
->values(array('lowercase', 'uppercase')) |
78
|
|
|
->defaultValue('lowercase') |
79
|
|
|
->end() |
80
|
|
|
->arrayNode('map') |
81
|
|
|
->requiresAtLeastOneElement() |
82
|
|
|
->info('Map of FQCNs prefixes and table prefixes to use for naming.') |
83
|
|
|
->useAttributeAsKey('name') |
84
|
|
|
->prototype('scalar')->end() |
85
|
|
|
->end() |
86
|
|
|
->arrayNode('whitelist') |
87
|
|
|
->info('Define for which FQCNs prefixes table prefixes should be applied.') |
88
|
|
|
->prototype('scalar')->end() |
89
|
|
|
->end() |
90
|
|
|
->arrayNode('blacklist') |
91
|
|
|
->info('Define for which FQCNs prefixes not to apply table prefixes.') |
92
|
|
|
->prototype('scalar')->end() |
93
|
|
|
->end() |
94
|
|
|
->end() |
95
|
|
|
->end(); |
96
|
|
|
|
97
|
|
|
return $node; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
protected function getNamerCollectionDefinition() |
101
|
|
|
{ |
102
|
|
|
$node = new ArrayNodeDefinition('namer_collection'); |
103
|
|
|
|
104
|
|
|
$node |
105
|
|
|
->children() |
106
|
|
|
->scalarNode('default') |
107
|
|
|
->info('Default namer which will determine default name.') |
108
|
|
|
->defaultValue('doctrine.orm.naming_strategy.underscore') |
109
|
|
|
->end() |
110
|
|
|
->arrayNode('namers') |
111
|
|
|
->requiresAtLeastOneElement() |
112
|
|
|
->info('Concurrent namers (referenced as service) which will propose different name, if applicable.') |
113
|
|
|
->prototype('scalar')->end() |
114
|
|
|
->end() |
115
|
|
|
->enumNode('concatenation') |
116
|
|
|
->info('How to concatenate join table names and join key column names considering that different naming strategies can be included in mix.') |
117
|
|
|
->values(array(NamerCollection::UNDERSCORE, NamerCollection::NOTHING, NamerCollection::UCFIRST)) |
118
|
|
|
->defaultValue(NamerCollection::UNDERSCORE) |
119
|
|
|
->end() |
120
|
|
|
->end() |
121
|
|
|
->end(); |
122
|
|
|
|
123
|
|
|
return $node; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
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.