Skip to content

Commit 1d28e6a

Browse files
committed
Merge pull request #311 from symfony-cmf/issue_290
Fix route basepaths configuration
2 parents 03a1d6f + bd6dfb0 commit 1d28e6a

File tree

6 files changed

+192
-16
lines changed

6 files changed

+192
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
* **2015-10-28**: Deprecated `cmf_routing.dynamic.persistence.phpcr.route_basepath`
5+
setting and parameter in favor of `cmf_routing.dynamic.persistence.phpcr.route_basepaths`.
6+
The old names will be kept for BC reasons and removed in 2.0.
7+
48
1.3.0-RC1
59
---------
610

DependencyInjection/CmfRoutingExtension.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,15 @@ public function loadPhpcrProvider($config, XmlFileLoader $loader, ContainerBuild
240240

241241
$container->setParameter(
242242
$this->getAlias() . '.dynamic.persistence.phpcr.route_basepaths',
243-
$config['route_basepaths']
243+
array_values(array_unique($config['route_basepaths']))
244244
);
245245

246-
$basePath = reset($config['route_basepaths']);
246+
/**
247+
* @deprecated The cmf_routing.dynamic.persistence.phpcr.route_basepath parameter is deprecated as of version 1.4 and will be removed in 2.0. Use the cmf_routing.dynamic.persistence.phpcr.route_basepaths parameter instead.
248+
*/
247249
$container->setParameter(
248250
$this->getAlias() . '.dynamic.persistence.phpcr.route_basepath',
249-
$basePath
251+
reset($config['route_basepaths'])
250252
);
251253

252254
$container->setParameter(
@@ -288,7 +290,7 @@ public function loadSonataPhpcrAdmin($config, XmlFileLoader $loader, ContainerBu
288290
return;
289291
}
290292

291-
$basePath = empty($config['admin_basepath']) ? reset($config['route_basepaths']) : $config['admin_basepath'];
293+
$basePath = $config['admin_basepath'] ?: reset($config['route_basepaths']);
292294
$container->setParameter($this->getAlias() . '.dynamic.persistence.phpcr.admin_basepath', $basePath);
293295

294296
$loader->load('admin-phpcr.xml');

DependencyInjection/Configuration.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,25 @@ public function getConfigTreeBuilder()
8181
->ifTrue(function ($v) { isset($v['route_basepath']) && isset($v['route_basepaths']); })
8282
->thenInvalid('Found values for both "route_basepath" and "route_basepaths", use "route_basepaths" instead.')
8383
->end()
84+
->beforeNormalization()
85+
->ifTrue(function ($v) { return isset($v['route_basepath']); })
86+
->then(function ($v) {
87+
@trigger_error('The route_basepath setting is deprecated as of version 1.4 and will be removed in 2.0. Use route_basepaths instead.', E_USER_DEPRECATED);
88+
89+
return $v;
90+
})
91+
->end()
8492
->children()
8593
->scalarNode('manager_name')->defaultNull()->end()
8694
->arrayNode('route_basepaths')
95+
->beforeNormalization()
96+
->ifString()
97+
->then(function ($v) { return array($v); })
98+
->end()
8799
->prototype('scalar')->end()
88100
->defaultValue(array('/cms/routes'))
89101
->end()
90-
->scalarNode('admin_basepath')->end()
102+
->scalarNode('admin_basepath')->defaultNull()->end()
91103
->scalarNode('content_basepath')->defaultValue('/cms/content')->end()
92104
->enumNode('use_sonata_admin')
93105
->beforeNormalization()

Tests/Unit/DependencyInjection/CmfRoutingExtensionTest.php

Lines changed: 113 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ public function testWhitespaceInPriorities()
115115
));
116116
}
117117

118-
public function testLoadBasePath()
118+
/**
119+
* @dataProvider getBasePathsTests
120+
*/
121+
public function testLoadBasePaths($phpcrConfig, $routeBasepathsParameter, $adminBasePathParameter)
119122
{
120123
$this->container->setParameter(
121124
'kernel.bundles',
@@ -125,22 +128,122 @@ public function testLoadBasePath()
125128
)
126129
);
127130

131+
if (!isset($phpcrConfig['enabled'])) {
132+
$phpcrConfig['enabled'] = true;
133+
}
134+
128135
$this->load(array(
129136
'dynamic' => array(
130137
'enabled' => true,
131138
'persistence' => array(
132-
'phpcr' => array(
133-
'enabled' => true,
134-
'route_basepath' => '/cms/routes',
135-
),
139+
'phpcr' => $phpcrConfig,
136140
),
137141
),
138142
));
139143

140-
$this->assertContainerBuilderHasParameter('cmf_routing.dynamic.persistence.phpcr.admin_basepath', '/cms/routes');
144+
$this->assertContainerBuilderHasParameter('cmf_routing.dynamic.persistence.phpcr.route_basepaths', $routeBasepathsParameter);
145+
$this->assertContainerBuilderHasParameter('cmf_routing.dynamic.persistence.phpcr.admin_basepath', $adminBasePathParameter);
146+
}
147+
148+
public function getBasePathsTests()
149+
{
150+
return array(
151+
array(
152+
array(),
153+
array('/cms/routes'),
154+
'/cms/routes'
155+
),
156+
157+
array(
158+
array('route_basepaths' => '/cms/test'),
159+
array('/cms/test'),
160+
'/cms/test'
161+
),
162+
163+
array(
164+
array('route_basepaths' => array('/cms/routes', '/cms/test')),
165+
array('/cms/routes', '/cms/test'),
166+
'/cms/routes'
167+
),
168+
169+
array(
170+
array('route_basepaths' => array('/cms/test', '/cms/routes')),
171+
array('/cms/test', '/cms/routes'),
172+
'/cms/test'
173+
),
174+
);
141175
}
142176

143-
public function testLoadBasePaths()
177+
/**
178+
* @dataProvider getBasePathsMergingTests
179+
*/
180+
public function testRouteBasepathsMerging($phpcrConfig1, $phpcrConfig2, $routeBasepathsParameter, $adminBasePathParameter)
181+
{
182+
$this->container->setParameter(
183+
'kernel.bundles',
184+
array(
185+
'CmfRoutingBundle' => true,
186+
'SonataDoctrinePHPCRAdminBundle' => true,
187+
)
188+
);
189+
190+
if (!isset($phpcrConfig1['enabled'])) {
191+
$phpcrConfig1['enabled'] = true;
192+
}
193+
if (!isset($phpcrConfig2['enabled'])) {
194+
$phpcrConfig2['enabled'] = true;
195+
}
196+
197+
$configs = array(
198+
array(
199+
'dynamic' => array(
200+
'enabled' => true,
201+
'persistence' => array('phpcr' => $phpcrConfig1),
202+
),
203+
),
204+
array(
205+
'dynamic' => array(
206+
'enabled' => true,
207+
'persistence' => array('phpcr' => $phpcrConfig2),
208+
),
209+
),
210+
);
211+
212+
foreach ($this->container->getExtensions() as $extension) {
213+
$extension->load($configs, $this->container);
214+
}
215+
216+
$this->assertContainerBuilderHasParameter('cmf_routing.dynamic.persistence.phpcr.route_basepaths', $routeBasepathsParameter);
217+
$this->assertContainerBuilderHasParameter('cmf_routing.dynamic.persistence.phpcr.admin_basepath', $adminBasePathParameter);
218+
}
219+
220+
public function getBasePathsMergingTests()
221+
{
222+
return array(
223+
array(
224+
array('route_basepaths' => array('/cms/test')),
225+
array('route_basepaths' => array('/cms/test2')),
226+
array('/cms/test', '/cms/test2'),
227+
'/cms/test'
228+
),
229+
230+
array(
231+
array('route_basepaths' => array('/cms/test')),
232+
array('route_basepaths' => array('/cms/test2', '/cms/test3')),
233+
array('/cms/test', '/cms/test2', '/cms/test3'),
234+
'/cms/test'
235+
),
236+
237+
array(
238+
array(),
239+
array('route_basepaths' => array('/cms/test')),
240+
array('/cms/test'),
241+
'/cms/test'
242+
),
243+
);
244+
}
245+
246+
public function testLegacyRouteBasepath()
144247
{
145248
$this->container->setParameter(
146249
'kernel.bundles',
@@ -155,15 +258,14 @@ public function testLoadBasePaths()
155258
'enabled' => true,
156259
'persistence' => array(
157260
'phpcr' => array(
158-
'enabled' => true,
159-
'route_basepaths' => array('/cms/routes', '/cms/test'),
261+
'route_basepath' => '/cms/test'
160262
),
161263
),
162264
),
163265
));
164266

165-
$this->assertContainerBuilderHasParameter('cmf_routing.dynamic.persistence.phpcr.admin_basepath', '/cms/routes');
166-
$this->assertContainerBuilderHasParameter('cmf_routing.dynamic.persistence.phpcr.route_basepaths', array('/cms/routes', '/cms/test'));
267+
$this->assertContainerBuilderHasParameter('cmf_routing.dynamic.persistence.phpcr.route_basepaths', array('/cms/test'));
268+
$this->assertContainerBuilderHasParameter('cmf_routing.dynamic.persistence.phpcr.admin_basepath', '/cms/test');
167269
}
168270

169271
public function testInitializerEnabled()

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function testSupportsAllConfigFormats()
5757
'/simple',
5858
),
5959
'content_basepath' => '/cms/content',
60+
'admin_basepath' => null,
6061
'manager_name' => null,
6162
'use_sonata_admin' => false,
6263
'enable_initializer' => true,

UPGRADE-1.3.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
UPGRADE FROM 1.2 TO 1.3
2+
=======================
3+
4+
Configuration
5+
-------------
6+
7+
* Renamed the `cmf_routing.dynamic.persistence.phpcr.route_basepath` setting
8+
to `route_basepaths`.
9+
10+
**Before**
11+
```yaml
12+
cmf_routing:
13+
dynamic:
14+
persistence:
15+
phpcr:
16+
route_basepath: /cms/custom
17+
```
18+
19+
```xml
20+
<config xmlns="http://cmf.symfony.com/schema/dic/routing">
21+
<dynamic>
22+
<persistence>
23+
<phpcr route-basepath="/cms/custom" />
24+
</persistence>
25+
</dynamic>
26+
</config>
27+
```
28+
29+
**After**
30+
```yaml
31+
cmf_routing:
32+
dynamic:
33+
persistence:
34+
phpcr:
35+
route_basepaths: /cms/custom
36+
```
37+
38+
```xml
39+
<config xmlns="http://cmf.symfony.com/schema/dic/routing">
40+
<dynamic>
41+
<persistence>
42+
<phpcr>
43+
<route-basepath>/cms/custom</route-basepath>
44+
</phpcr>
45+
</persistence>
46+
</dynamic>
47+
</config>
48+
```
49+
50+
DependencyInjection
51+
-------------------
52+
53+
* Renamed the `cmf_routing.dynamic.persistence.phpcr.route_basepath` parameter
54+
to `cmf_routing.dynamic.persistence.phpcr.route_basepaths` and changed its
55+
type to an array.

0 commit comments

Comments
 (0)