Skip to content

Commit 7896ad8

Browse files
committed
refactor configuration to prepare for orm. fix #105
1 parent 12f5436 commit 7896ad8

File tree

9 files changed

+130
-84
lines changed

9 files changed

+130
-84
lines changed

Admin/RouteAdmin.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
1010
use Symfony\Component\HttpFoundation\Request;
1111
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
12+
use PHPCR\Util\PathHelper;
1213

1314
class RouteAdmin extends Admin
1415
{
@@ -74,7 +75,8 @@ protected function configureDatagridFilters(DatagridMapper $datagridMapper)
7475

7576
public function setRouteRoot($routeRoot)
7677
{
77-
$this->routeRoot = $routeRoot;
78+
// TODO: fix widget to show root node when root is selectable
79+
$this->routeRoot = PathHelper::getParentPath($routeRoot);
7880
}
7981

8082
public function setContentRoot($contentRoot)

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Changelog
66
RoutingBundle\Document\Route and RedirectRoute in favor of
77
RoutingBundle\Doctrine\Phpcr\Route resp. RedirectRoute and also moved the
88
PHPCR-ODM specific listeners and repository implementations to Doctrine\Phpcr
9+
Configuration was cleaned up as well. PHPCR specific configurations moved
10+
into dynamic.phpcr_provider: use_sonata_admin, 'manager_registry,
11+
manager_name, route_basepath, content_basepath.
12+
In preparation of other route provider support, you need to at least set
13+
`phpcr_provider: ~` to have the PHPCR provider loaded.
14+
Dropped redundant routing_repositoryroot.
915

1016
1.1.0-beta1
1117
-----------

DependencyInjection/CmfRoutingExtension.php

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ public function load(array $configs, ContainerBuilder $container)
4949
$resources = $container->getParameter('twig.form.resources');
5050
$container->setParameter('twig.form.resources', array_merge($resources, array('CmfRoutingBundle:Form:terms_form_type.html.twig')));
5151
}
52-
53-
if ($config['use_sonata_admin']) {
54-
$this->loadSonataAdmin($config, $loader, $container);
55-
}
5652
}
5753

5854
public function setupFormTypes(array $config, ContainerBuilder $container, LoaderInterface $loader)
@@ -93,22 +89,18 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
9389
$container->setParameter($this->getAlias() . '.defined_templates_class', $controllerForTemplates);
9490
$container->setParameter($this->getAlias() . '.uri_filter_regexp', $config['uri_filter_regexp']);
9591

96-
$loader->load('cmf_routing.xml');
97-
$container->setParameter($this->getAlias() . '.routing_repositoryroot', $config['routing_repositoryroot']);
98-
if (isset($config['locales']) && $config['locales']) {
99-
$container->setParameter($this->getAlias() . '.locales', $config['locales']);
100-
} else {
101-
$container->removeDefinition('cmf_routing.phpcrodm_route_locale_listener');
102-
}
92+
$loader->load('dynamic_routing.xml');
10393

104-
$container->setAlias('cmf_routing.route_provider', $config['route_provider_service_id']);
105-
$container->setAlias('cmf_routing.content_repository', $config['content_repository_service_id']);
94+
if (isset($config['phpcr_provider'])) {
95+
$this->loadPhpcrProvider($config['phpcr_provider'], $loader, $container);
96+
}
10697

107-
$routeProvider = $container->getDefinition($this->getAlias() . '.default_route_provider');
108-
$routeProvider->replaceArgument(0, new Reference($config['manager_registry']));
109-
$contentRepository = $container->getDefinition($this->getAlias() . '.default_content_repository');
110-
$contentRepository->replaceArgument(0, new Reference($config['manager_registry']));
111-
$container->setParameter($this->getAlias() . '.manager_name', $config['manager_name']);
98+
if (isset($config['route_provider_service_id'])) {
99+
$container->setAlias('cmf_routing.route_provider', $config['route_provider_service_id']);
100+
}
101+
if (isset($config['content_repository_service_id'])) {
102+
$container->setAlias('cmf_routing.content_repository', $config['content_repository_service_id']);
103+
}
112104

113105
$dynamic = $container->getDefinition($this->getAlias().'.dynamic_router');
114106

@@ -134,16 +126,41 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
134126
}
135127
}
136128

137-
public function loadSonataAdmin($config, XmlFileLoader $loader, ContainerBuilder $container)
129+
public function loadPhpcrProvider($config, XmlFileLoader $loader, ContainerBuilder $container)
130+
{
131+
$loader->load('provider_phpcr.xml');
132+
133+
$container->setParameter($this->getAlias() . '.phpcr_provider.route_basepath', $config['route_basepath']);
134+
$container->setParameter($this->getAlias() . '.phpcr_provider.content_basepath', $config['content_basepath']);
135+
136+
$routeProvider = $container->getDefinition($this->getAlias() . '.phpcr_route_provider');
137+
$routeProvider->replaceArgument(0, new Reference($config['manager_registry']));
138+
$contentRepository = $container->getDefinition($this->getAlias() . '.phpcr_content_repository');
139+
$contentRepository->replaceArgument(0, new Reference($config['manager_registry']));
140+
$container->setParameter($this->getAlias() . '.manager_name', $config['manager_name']);
141+
142+
$container->setAlias($this->getAlias() . '.route_provider', $this->getAlias() . '.phpcr_route_provider');
143+
$container->setAlias($this->getAlias() . '.content_repository', $this->getAlias() . '.phpcr_content_repository');
144+
145+
if (isset($config['locales']) && $config['locales']) {
146+
$container->setParameter($this->getAlias() . '.locales', $config['locales']);
147+
} else {
148+
$container->removeDefinition('cmf_routing.phpcrodm_route_locale_listener');
149+
}
150+
151+
if ($config['use_sonata_admin']) {
152+
$this->loadSonataPhpcrAdmin($config, $loader, $container);
153+
}
154+
}
155+
156+
public function loadSonataPhpcrAdmin($config, XmlFileLoader $loader, ContainerBuilder $container)
138157
{
139158
$bundles = $container->getParameter('kernel.bundles');
140159
if ('auto' === $config['use_sonata_admin'] && !isset($bundles['SonataDoctrinePHPCRAdminBundle'])) {
141160
return;
142161
}
143162

144-
$loader->load('routing-admin.xml');
145-
$container->setParameter($this->getAlias() . '.content_basepath', $config['content_basepath']);
146-
$container->setParameter($this->getAlias() . '.route_basepath', $config['route_basepath']);
163+
$loader->load('admin_phpcr.xml');
147164
}
148165

149166
/**

DependencyInjection/Configuration.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,31 @@ public function getConfigTreeBuilder()
5858
->useAttributeAsKey('alias')
5959
->prototype('scalar')->end()
6060
->end()
61-
->scalarNode('manager_registry')->defaultValue('doctrine_phpcr')->end()
62-
->scalarNode('manager_name')->defaultValue('default')->end()
61+
->arrayNode('phpcr_provider')
62+
->children()
63+
->scalarNode('manager_registry')->defaultValue('doctrine_phpcr')->end()
64+
->scalarNode('manager_name')->defaultValue('default')->end()
65+
->scalarNode('route_basepath')->defaultValue('/cms/routes')->end()
66+
->scalarNode('content_basepath')->defaultValue('/cms/content')->end()
67+
->enumNode('use_sonata_admin')
68+
->values(array(true, false, 'auto'))
69+
->defaultValue('auto')
70+
->end()
71+
->end()
72+
->end()
6373
->scalarNode('uri_filter_regexp')->defaultValue('')->end()
64-
->scalarNode('route_provider_service_id')->defaultValue('cmf_routing.default_route_provider')->end()
74+
->scalarNode('route_provider_service_id')->end()
6575
->arrayNode('route_filters_by_id')
6676
->canBeUnset()
6777
->useAttributeAsKey('id')
6878
->prototype('scalar')->end()
6979
->end()
70-
->scalarNode('content_repository_service_id')->defaultValue('cmf_routing.default_content_repository')->end()
71-
->scalarNode('routing_repositoryroot')->defaultValue('/cms/routes')->end()
80+
->scalarNode('content_repository_service_id')->end()
7281
->arrayNode('locales')
7382
->prototype('scalar')->end()
7483
->end()
7584
->end()
7685
->end()
77-
->enumNode('use_sonata_admin')
78-
->values(array(true, false, 'auto'))
79-
->defaultValue('auto')
80-
->end()
81-
->scalarNode('content_basepath')->defaultValue('/cms/content')->end()
82-
// TODO: fix widget to show root node when root is selectable, then use routing_repositoryroot for both
83-
->scalarNode('route_basepath')->defaultValue('/cms')->end()
8486
->end()
8587
;
8688

Resources/config/routing-admin.xml renamed to Resources/config/admin_phpcr.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
</call>
2525

2626
<call method="setContentRoot">
27-
<argument>%cmf_routing.content_basepath%</argument>
27+
<argument>%cmf_routing.phpcr_provider.content_basepath%</argument>
2828
</call>
2929

3030
<call method="setRouteRoot">
31-
<argument>%cmf_routing.route_basepath%</argument>
31+
<argument>%cmf_routing.phpcr_provider.route_basepath%</argument>
3232
</call>
3333
<call method="setControllerResolver">
3434
<argument type="service" id="controller_resolver" />
@@ -46,7 +46,7 @@
4646
</call>
4747

4848
<call method="setRouteRoot">
49-
<argument>%cmf_routing.route_basepath%</argument>
49+
<argument>%cmf_routing.phpcr_provider.route_basepath%</argument>
5050
</call>
5151
</service>
5252

Resources/config/cmf_routing.xml renamed to Resources/config/dynamic_routing.xml

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55

66
<parameters>
77
<parameter key="cmf_routing.dynamic_router_class">Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter</parameter>
8-
<parameter key="cmf_routing.route_entity_class">null</parameter>
8+
<parameter key="cmf_routing.route_model_class">null</parameter>
99
<parameter key="cmf_routing.uri_filter_regexp">null</parameter>
1010
<parameter key="cmf_routing.nested_matcher_class">Symfony\Cmf\Component\Routing\NestedMatcher\NestedMatcher</parameter>
1111
<parameter key="cmf_routing.final_matcher_class">Symfony\Cmf\Component\Routing\NestedMatcher\UrlMatcher</parameter>
1212
<parameter key="cmf_routing.url_matcher_class">Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher</parameter>
1313
<parameter key="cmf_routing.generator_class">Symfony\Cmf\Bundle\RoutingBundle\Routing\ContentAwareGenerator</parameter>
14-
<parameter key="cmf_routing.route_provider_class">Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RouteProvider</parameter>
15-
<parameter key="cmf_routing.content_repository_class">Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\ContentRepository</parameter>
16-
<parameter key="cmf_routing.phpcrodm_route_idprefix_listener_class">Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\IdPrefixListener</parameter>
17-
<parameter key="cmf_routing.phpcrodm_route_locale_listener_class">Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\LocaleListener</parameter>
1814
<parameter key="cmf_routing.enhancer_route_content_class">Symfony\Cmf\Component\Routing\Enhancer\RouteContentEnhancer</parameter>
1915
<parameter key="cmf_routing.enhancer_explicit_template_class">Symfony\Cmf\Component\Routing\Enhancer\FieldPresenceEnhancer</parameter>
2016
<parameter key="cmf_routing.enhancer_controllers_by_type_class">Symfony\Cmf\Component\Routing\Enhancer\FieldMapEnhancer</parameter>
@@ -68,56 +64,24 @@
6864
<call method="setFinalMatcher"><argument type="service" id="cmf_routing.final_matcher"/></call>
6965
</service>
7066

67+
<service id="cmf_routing.matcher.dummy_collection" class="Symfony\Component\Routing\RouteCollection" public="false"/>
68+
<service id="cmf_routing.matcher.dummy_context" class="Symfony\Component\Routing\RequestContext" public="false"/>
69+
7170
<service id="cmf_routing.final_matcher" class="%cmf_routing.final_matcher_class%">
7271
<argument type="service" id="cmf_routing.matcher.dummy_collection"/>
7372
<argument type="service" id="cmf_routing.matcher.dummy_context"/>
7473
</service>
7574

76-
<service id="cmf_routing.matcher.dummy_collection" class="Symfony\Component\Routing\RouteCollection" public="false"/>
77-
<service id="cmf_routing.matcher.dummy_context" class="Symfony\Component\Routing\RequestContext" public="false"/>
78-
7975
<service id="cmf_routing.generator" class="%cmf_routing.generator_class%">
8076
<argument type="service" id="cmf_routing.route_provider" />
8177
<argument type="service" id="logger" on-invalid="ignore" />
8278
<call method="setContainer"><argument type="service" id="service_container"/></call>
8379
<call method="setContentRepository"><argument type="service" id="cmf_routing.content_repository"/></call>
8480
</service>
8581

86-
<service id="cmf_routing.default_route_provider" class="%cmf_routing.route_provider_class%">
87-
<argument/>
88-
<argument>%cmf_routing.route_entity_class%</argument>
89-
<call method="setManagerName"><argument>%cmf_routing.manager_name%</argument></call>
90-
<call method="setPrefix"><argument>%cmf_routing.routing_repositoryroot%</argument></call>
91-
</service>
92-
93-
<service id="cmf_routing.default_content_repository" class="%cmf_routing.content_repository_class%">
94-
<argument/>
95-
<call method="setManagerName"><argument>%cmf_routing.manager_name%</argument></call>
96-
</service>
97-
98-
<service id="cmf_routing.phpcrodm_route_idprefix_listener" class="%cmf_routing.phpcrodm_route_idprefix_listener_class%">
99-
<argument>%cmf_routing.routing_repositoryroot%</argument>
100-
<tag name="doctrine_phpcr.event_listener" event="postLoad" />
101-
<tag name="doctrine_phpcr.event_listener" event="postPersist" />
102-
</service>
103-
104-
<service id="cmf_routing.phpcrodm_route_locale_listener" class="%cmf_routing.phpcrodm_route_locale_listener_class%">
105-
<argument>%cmf_routing.routing_repositoryroot%</argument>
106-
<argument>%cmf_routing.locales%</argument>
107-
<tag name="doctrine_phpcr.event_listener" event="postLoad" />
108-
<tag name="doctrine_phpcr.event_listener" event="postPersist" />
109-
<tag name="doctrine_phpcr.event_listener" event="postMove" />
110-
</service>
111-
11282
<service id="cmf_routing.redirect_controller" class="%cmf_routing.redirect_controller_class%">
11383
<argument type="service" id="router" />
11484
</service>
11585

116-
<service id="cmf_routing.initializer" class="Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer">
117-
<argument type="collection">
118-
<argument>%cmf_routing.routing_repositoryroot%</argument>
119-
</argument>
120-
<tag name="doctrine_phpcr.initializer"/>
121-
</service>
12286
</services>
12387
</container>

Resources/config/provider_phpcr.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<parameters>
7+
<parameter key="cmf_routing.route_provider_class">Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RouteProvider</parameter>
8+
<parameter key="cmf_routing.content_repository_class">Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\ContentRepository</parameter>
9+
<parameter key="cmf_routing.phpcrodm_route_idprefix_listener_class">Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\IdPrefixListener</parameter>
10+
<parameter key="cmf_routing.phpcrodm_route_locale_listener_class">Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\LocaleListener</parameter>
11+
</parameters>
12+
13+
<services>
14+
15+
<service id="cmf_routing.phpcr_route_provider" class="%cmf_routing.route_provider_class%">
16+
<argument/>
17+
<argument>%cmf_routing.route_model_class%</argument>
18+
<call method="setManagerName"><argument>%cmf_routing.manager_name%</argument></call>
19+
<call method="setPrefix"><argument>%cmf_routing.phpcr_provider.route_basepath%</argument></call>
20+
</service>
21+
22+
<service id="cmf_routing.phpcr_content_repository" class="%cmf_routing.content_repository_class%">
23+
<argument/>
24+
<call method="setManagerName"><argument>%cmf_routing.manager_name%</argument></call>
25+
</service>
26+
27+
<service id="cmf_routing.phpcrodm_route_idprefix_listener" class="%cmf_routing.phpcrodm_route_idprefix_listener_class%">
28+
<argument>%cmf_routing.phpcr_provider.route_basepath%</argument>
29+
<tag name="doctrine_phpcr.event_listener" event="postLoad" />
30+
<tag name="doctrine_phpcr.event_listener" event="postPersist" />
31+
</service>
32+
33+
<service id="cmf_routing.phpcrodm_route_locale_listener" class="%cmf_routing.phpcrodm_route_locale_listener_class%">
34+
<argument>%cmf_routing.phpcr_provider.route_basepath%</argument>
35+
<argument>%cmf_routing.locales%</argument>
36+
<tag name="doctrine_phpcr.event_listener" event="postLoad" />
37+
<tag name="doctrine_phpcr.event_listener" event="postPersist" />
38+
<tag name="doctrine_phpcr.event_listener" event="postMove" />
39+
</service>
40+
41+
<service id="cmf_routing.initializer" class="Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer">
42+
<argument type="collection">
43+
<argument>%cmf_routing.phpcr_provider.route_basepath%</argument>
44+
</argument>
45+
<tag name="doctrine_phpcr.initializer"/>
46+
</service>
47+
48+
</services>
49+
</container>

Tests/DependencyInjection/CmfRoutingExtensionTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,22 @@ public function testLoadDefault()
2727
$builder = $this->getBuilder(
2828
array(
2929
array(
30-
'dynamic' => array(),
31-
'use_sonata_admin' => false,
30+
'dynamic' => array(
31+
'phpcr_provider' => array(
32+
'use_sonata_admin' => false,
33+
),
34+
),
3235
)
3336
)
3437
);
3538

3639
$this->assertTrue($builder->hasAlias('cmf_routing.route_provider'));
3740
$alias = $builder->getAlias('cmf_routing.route_provider');
38-
$this->assertEquals('cmf_routing.default_route_provider', $alias->__toString());
41+
$this->assertEquals('cmf_routing.phpcr_route_provider', $alias->__toString());
3942

4043
$this->assertTrue($builder->hasAlias('cmf_routing.content_repository'));
4144
$alias = $builder->getAlias('cmf_routing.content_repository');
42-
$this->assertEquals('cmf_routing.default_content_repository', $alias->__toString());
45+
$this->assertEquals('cmf_routing.phpcr_content_repository', $alias->__toString());
4346

4447
$this->assertTrue($builder->getParameter('cmf_routing.replace_symfony_router'));
4548

@@ -75,8 +78,10 @@ public function testLoadConfigured()
7578
'dynamic' => array(
7679
'route_provider_service_id' => 'test_route_provider_service',
7780
'content_repository_service_id' => 'test_content_repository_service',
81+
'phpcr_provider' => array(
82+
'use_sonata_admin' => false,
83+
),
7884
),
79-
'use_sonata_admin' => false,
8085
'chain' => array(
8186
'routers_by_id' => $providedRouters = array(
8287
'router.custom' => 200,

Tests/Functional/config/cmf-routing.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ cmf_routing:
1111
Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute: cmf_routing.redirect_controller:redirectAction
1212
templates_by_class:
1313
Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Testdoc\Content: TestBundle:Content:index.html.twig
14-
routing_repositoryroot: /test/routing
14+
phpcr_provider:
15+
route_basepath: /test/routing

0 commit comments

Comments
 (0)