Skip to content

Commit 14288d4

Browse files
author
Aaron Scherer
committed
Fixing Config Styling
1 parent 997ce87 commit 14288d4

File tree

1 file changed

+114
-128
lines changed

1 file changed

+114
-128
lines changed

src/Aequasi/Bundle/CacheBundle/DependencyInjection/Configuration.php

Lines changed: 114 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ public function getConfigTreeBuilder()
4444
$treeBuilder = new TreeBuilder();
4545
$rootNode = $treeBuilder->root( 'cache' );
4646

47-
$rootNode->children()
48-
->append( $this->getClustersNode() )
49-
->append( $this->addSessionSupportSection() )
50-
->append( $this->addDoctrineSection() )
51-
->append( $this->addRouterSection() )
52-
->end();
47+
$rootNode
48+
->children()
49+
->append( $this->getClustersNode() )
50+
->append( $this->addSessionSupportSection() )
51+
->append( $this->addDoctrineSection() )
52+
->append( $this->addRouterSection() )
53+
->end();
5354

5455
return $treeBuilder;
5556
}
@@ -62,73 +63,74 @@ private function getClustersNode()
6263
$treeBuilder = new TreeBuilder();
6364
$node = $treeBuilder->root( 'instances' );
6465

65-
$node->requiresAtLeastOneElement()
66-
->addDefaultChildrenIfNoneSet( 'default' )
67-
->useAttributeAsKey( 'name' )
68-
->prototype( 'array' )
69-
->children()
70-
->enumNode( 'type' )
71-
->values( array( 'redis', 'file', 'memcached', 'apc' ) )
72-
->end()
73-
->scalarNode( 'id' )
74-
->defaultNull()
75-
->end()
76-
->scalarNode( 'namespace' )
77-
->defaultNull()
78-
->info( "Namespace for doctrine keys." )
79-
->end()
80-
->booleanNode( 'persistent' )
81-
->defaultNull()
82-
->info( "For Redis and Memcached: Specify if you want persistent connections" )
83-
->end()
84-
->scalarNode( 'auth_password' )
85-
->info( "For Redis: Authorization info" )
86-
->end()
87-
->scalarNode( 'directory' )
88-
->info( "For File System and PHP File: Directory to store cache." )
89-
->defaultNull()
90-
->end()
91-
->scalarNode( 'extension' )
92-
->info( "For File System and PHP File: Extension to use." )
93-
->defaultNull()
94-
->end()
95-
->arrayNode( 'options' )
96-
->info( "Options for Redis and Memcached" )
97-
->end()
98-
->arrayNode( 'hosts' )
99-
->prototype( 'array' )
100-
->children()
101-
->scalarNode( 'host' )
102-
->defaultNull()
103-
->end()
104-
->scalarNode( 'port' )
105-
->defaultNull()
106-
->validate()
107-
->ifTrue( function ( $v ) { return !is_null( $v ) && !is_numeric( $v ); } )
108-
->thenInvalid( "Host port must be numeric" )
109-
->end()
110-
->end()
111-
->scalarNode( 'weight' )
112-
->info( "For Memcached: Weight for given host." )
113-
->defaultNull()
114-
->validate()
115-
->ifTrue( function ( $v ) { return !is_null( $v ) && !is_numeric( $v ); } )
116-
->thenInvalid( 'host weight must be numeric' )
117-
->end()
118-
->end()
119-
->scalarNode( 'timeout' )
120-
->info( "For Redis and Memcache: Timeout for the given host." )
121-
->defaultNull()
122-
->validate()
123-
->ifTrue( function ( $v ) { return !is_null( $v ) && !is_numeric( $v ); } )
124-
->thenInvalid( 'host timeout must be numeric' )
125-
->end()
126-
->end()
127-
->end()
128-
->end()
129-
->end()
130-
->end()
131-
->end();
66+
$node
67+
->requiresAtLeastOneElement()
68+
->addDefaultChildrenIfNoneSet( 'default' )
69+
->useAttributeAsKey( 'name' )
70+
->prototype( 'array' )
71+
->children()
72+
->enumNode( 'type' )
73+
->values( array( 'redis', 'file', 'memcached', 'apc' ) )
74+
->end()
75+
->scalarNode( 'id' )
76+
->defaultNull()
77+
->end()
78+
->scalarNode( 'namespace' )
79+
->defaultNull()
80+
->info( "Namespace for doctrine keys." )
81+
->end()
82+
->booleanNode( 'persistent' )
83+
->defaultNull()
84+
->info( "For Redis and Memcached: Specify if you want persistent connections" )
85+
->end()
86+
->scalarNode( 'auth_password' )
87+
->info( "For Redis: Authorization info" )
88+
->end()
89+
->scalarNode( 'directory' )
90+
->info( "For File System and PHP File: Directory to store cache." )
91+
->defaultNull()
92+
->end()
93+
->scalarNode( 'extension' )
94+
->info( "For File System and PHP File: Extension to use." )
95+
->defaultNull()
96+
->end()
97+
->arrayNode( 'options' )
98+
->info( "Options for Redis and Memcached" )
99+
->end()
100+
->arrayNode( 'hosts' )
101+
->prototype( 'array' )
102+
->children()
103+
->scalarNode( 'host' )
104+
->defaultNull()
105+
->end()
106+
->scalarNode( 'port' )
107+
->defaultNull()
108+
->validate()
109+
->ifTrue( function ( $v ) { return !is_null( $v ) && !is_numeric( $v ); } )
110+
->thenInvalid( "Host port must be numeric" )
111+
->end()
112+
->end()
113+
->scalarNode( 'weight' )
114+
->info( "For Memcached: Weight for given host." )
115+
->defaultNull()
116+
->validate()
117+
->ifTrue( function ( $v ) { return !is_null( $v ) && !is_numeric( $v ); } )
118+
->thenInvalid( 'host weight must be numeric' )
119+
->end()
120+
->end()
121+
->scalarNode( 'timeout' )
122+
->info( "For Redis and Memcache: Timeout for the given host." )
123+
->defaultNull()
124+
->validate()
125+
->ifTrue( function ( $v ) { return !is_null( $v ) && !is_numeric( $v ); } )
126+
->thenInvalid( 'host timeout must be numeric' )
127+
->end()
128+
->end()
129+
->end()
130+
->end()
131+
->end()
132+
->end()
133+
->end();
132134

133135
return $node;
134136
}
@@ -143,18 +145,13 @@ private function addSessionSupportSection()
143145
$tree = new TreeBuilder();
144146
$node = $tree->root( 'session' );
145147

146-
$node->addDefaultsIfNotSet()
147-
->children()
148-
->scalarNode( 'instance' )
149-
->isRequired()
150-
->end()
151-
->scalarNode( 'prefix' )
152-
->defaultValue( "session_" )
153-
->end()
154-
->scalarNode( 'ttl' )
155-
->end()
156-
->end()
157-
->end();
148+
$node
149+
->addDefaultsIfNotSet()
150+
->children()
151+
->scalarNode( 'instance' )->isRequired()->end()
152+
->scalarNode( 'prefix' )->defaultValue( "session_" )->end()
153+
->scalarNode( 'ttl' )->end()
154+
->end();
158155

159156
return $node;
160157
}
@@ -169,39 +166,32 @@ private function addDoctrineSection()
169166
$tree = new TreeBuilder();
170167
$node = $tree->root( 'doctrine' );
171168

172-
foreach (array( 'metadata', 'result', 'query' ) as $type) {
173-
$node->children()
174-
->arrayNode( $type )
175-
->canBeUnset()
176-
->children()
177-
->scalarNode( 'instance' )
178-
->isRequired()
179-
->end()
180-
->end()
181-
->children()
182-
->arrayNode( 'entity_managers' )
183-
->defaultValue( array() )
184-
->beforeNormalization()
185-
->ifString()
186-
->then( function ( $v ) { return (array)$v; } )
187-
->end()
188-
->prototype( 'scalar' )
189-
->end()
190-
->end()
191-
->end()
192-
->children()
193-
->arrayNode( 'document_managers' )
194-
->defaultValue( array() )
195-
->beforeNormalization()
196-
->ifString()
197-
->then( function ( $v ) { return (array)$v; } )
198-
->end()
199-
->prototype( 'scalar' )
200-
->end()
201-
->end()
202-
->end()
203-
->end()
204-
->end();
169+
$types = array('metadata', 'result', 'query');
170+
foreach ($types as $type) {
171+
$node
172+
->children()
173+
->arrayNode( $type )
174+
->canBeUnset()
175+
->children()
176+
->scalarNode( 'instance' )->isRequired()->end()
177+
->arrayNode( 'entity_managers' )
178+
->defaultValue( array() )
179+
->beforeNormalization()
180+
->ifString()
181+
->then( function ( $v ) { return (array)$v; } )
182+
->end()
183+
->prototype( 'scalar' )->end()
184+
->end()
185+
->arrayNode( 'document_managers' )
186+
->defaultValue( array() )
187+
->beforeNormalization()
188+
->ifString()
189+
->then( function ( $v ) { return (array)$v; } )
190+
->end()
191+
->prototype( 'scalar' )->end()
192+
->end()
193+
->end()
194+
->end();
205195
}
206196

207197
return $node;
@@ -217,16 +207,12 @@ private function addRouterSection()
217207
$tree = new TreeBuilder();
218208
$node = $tree->root( 'router' );
219209

220-
$node->addDefaultsIfNotSet()
221-
->children()
222-
->scalarNode( 'instance' )
223-
->defaultNull()
224-
->end()
225-
->booleanNode( 'enabled' )
226-
->defaultFalse()
227-
->end()
228-
->end()
229-
->end();
210+
$node
211+
->addDefaultsIfNotSet()
212+
->children()
213+
->scalarNode( 'instance' )->defaultNull()->end()
214+
->booleanNode( 'enabled' )->defaultFalse()->end()
215+
->end();
230216

231217
return $node;
232218
}

0 commit comments

Comments
 (0)