Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 29e2d88

Browse files
committed
Sulu changes
1 parent 71ca30c commit 29e2d88

File tree

10 files changed

+85
-15
lines changed

10 files changed

+85
-15
lines changed

DependencyInjection/CmfRoutingAutoExtension.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,15 @@ public function load(array $configs, ContainerBuilder $container)
5151
}
5252
}
5353
$container->setParameter('cmf_routing_auto.metadata.loader.resources', $resources);
54+
$container->setParameter('cmf_routing_auto.adapter_name', $config['adapter']);
5455

5556
$hasProvider = false;
57+
5658
if ($this->isConfigEnabled($container, $config['persistence']['phpcr'])) {
5759
$hasProvider = true;
5860
$loader->load('phpcr-odm.xml');
5961
$container->setParameter('cmf_routing_auto.persistence.phpcr.route_basepath', $config['persistence']['phpcr']['route_basepath']);
6062
}
61-
62-
if (!$hasProvider) {
63-
throw new InvalidConfigurationException(
64-
'The RoutingAutoBundle requires that you enable one of the persistence layers in your application configuration. ' .
65-
'See the documentation for more information'
66-
);
67-
}
6863
}
6964

7065
protected function findMappingFiles($bundles)

DependencyInjection/Compiler/AutoRoutePass.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,45 @@
2222
class AutoRoutePass implements CompilerPassInterface
2323
{
2424
public function process(ContainerBuilder $container)
25+
{
26+
$this->registerServices($container);
27+
$this->registerAdapter($container);
28+
}
29+
30+
private function registerAdapter(ContainerBuilder $container)
31+
{
32+
$adapter = $container->getParameter('cmf_routing_auto.adapter_name');
33+
$adapterId = null;
34+
$adapterNames = array();
35+
$ids = $container->findTaggedServiceIds('cmf_routing_auto.adapter');
36+
37+
foreach ($ids as $id => $attributes) {
38+
if (!isset($attributes[0]['alias'])) {
39+
throw new \InvalidArgumentException(sprintf(
40+
'No "name" specified for auto route adapter "%s"',
41+
$id
42+
));
43+
}
44+
45+
$alias = $attributes[0]['alias'];
46+
$adapterNames[] = $alias;
47+
if ($adapter === $alias) {
48+
$adapterId = $id;
49+
}
50+
}
51+
52+
if (null === $adapterId) {
53+
throw new \RuntimeException(sprintf(
54+
'Could not find configured adapter "%s", available adapters: "%s"',
55+
$adapter,
56+
implode('", "', $adapterNames)
57+
));
58+
}
59+
60+
$container->setAlias('cmf_routing_auto.adapter', $adapterId);
61+
}
62+
63+
private function registerServices(ContainerBuilder $container)
2564
{
2665
if (!$container->hasDefinition(
2766
'cmf_routing_auto.service_registry'

DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public function getConfigTreeBuilder()
2626
{
2727
$treeBuilder = new TreeBuilder();
2828
$treeBuilder->root('cmf_routing_auto')
29+
->addDefaultsIfNotSet()
2930
->children()
31+
->scalarNode('adapter')
32+
->defaultValue('doctrine_phpcr_odm')
33+
->end()
3034
->booleanNode('auto_mapping')->defaultTrue()->end()
3135
->arrayNode('mapping')
3236
->fixXmlConfig('resource')

Doctrine/Phpcr/AutoRouteListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function onFlush(ManagerEventArgs $args)
6969

7070
// refactor this.
7171
foreach ($uriContextCollection->getUriContexts() as $uriContext) {
72+
var_dump('123');
7273
$autoRoute = $uriContext->getAutoRoute();
7374
$dm->persist($autoRoute);
7475
$uow->computeChangeSets();

Resources/config/auto_route.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<parameter key="cmf_routing_auto.phpcrodm_auto_route_listener.class">Symfony\Cmf\Bundle\RoutingAutoBundle\Doctrine\Phpcr\AutoRouteListener</parameter>
99
<parameter key="cmf_routing_auto.auto_route_manager.class">Symfony\Cmf\Component\RoutingAuto\AutoRouteManager</parameter>
1010
<parameter key="cmf_routing_auto.service_registry.class">Symfony\Cmf\Component\RoutingAuto\ServiceRegistry</parameter>
11-
<parameter key="cmf_routing_auto.adapter.phpcr_odm.class">Symfony\Cmf\Bundle\RoutingAutoBundle\Adapter\PhpcrOdmAdapter</parameter>
1211
<parameter key="cmf_routing_auto.uri_generator.class">Symfony\Cmf\Component\RoutingAuto\UriGenerator</parameter>
1312

1413
<parameter key="cmf_routing_auto.metadata.loader.yaml.class">Symfony\Cmf\Component\RoutingAuto\Mapping\Loader\YmlFileLoader</parameter>
@@ -35,15 +34,15 @@
3534
id="cmf_routing_auto.auto_route_manager"
3635
class="Symfony\Cmf\Component\RoutingAuto\AutoRouteManager"
3736
>
38-
<argument type="service" id="cmf_routing_auto.adapter.phpcr_odm"/>
37+
<argument type="service" id="cmf_routing_auto.adapter" />
3938
<argument type="service" id="cmf_routing_auto.uri_generator" />
4039
<argument type="service" id="cmf_routing_auto.defunct_route_handler.delegating" />
4140
</service>
4241

4342
<!-- URL Generator -->
4443
<service id="cmf_routing_auto.uri_generator" class="%cmf_routing_auto.uri_generator.class%">
4544
<argument type="service" id="cmf_routing_auto.metadata.factory" />
46-
<argument type="service" id="cmf_routing_auto.adapter.phpcr_odm" />
45+
<argument type="service" id="cmf_routing_auto.adapter" />
4746
<argument type="service" id="cmf_routing_auto.service_registry" />
4847
</service>
4948

Resources/config/conflict_resolvers.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<services>
1414

1515
<service id="cmf_routing_auto.conflict_resolver.auto_increment" class="%cmf_routing_auto.conflict_resolver.auto_increment.class%">
16-
<argument type="service" id="cmf_routing_auto.adapter.phpcr_odm" />
16+
<argument type="service" id="cmf_routing_auto.adapter" />
1717
<tag name="cmf_routing_auto.conflict_resolver" alias="auto_increment" />
1818
</service>
1919

Resources/config/defunct_route_handlers.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
<services>
1515

1616
<service id="cmf_routing_auto.defunct_route_handler.remove" class="%cmf_routing_auto.defunct_route_handler.remove.class%">
17-
<argument type="service" id="cmf_routing_auto.adapter.phpcr_odm" />
17+
<argument type="service" id="cmf_routing_auto.adapter" />
1818
<tag name="cmf_routing_auto.defunct_route_handler" alias="remove" />
1919
</service>
2020

2121
<service id="cmf_routing_auto.defunct_route_handler.leave_redirect" class="%cmf_routing_auto.defunct_route_handler.leave_redirect.class%">
22-
<argument type="service" id="cmf_routing_auto.adapter.phpcr_odm" />
22+
<argument type="service" id="cmf_routing_auto.adapter" />
2323
<tag name="cmf_routing_auto.defunct_route_handler" alias="leave_redirect" />
2424
</service>
2525

2626
<service id="cmf_routing_auto.defunct_route_handler.delegating" class="%cmf_routing_auto.defunct_route_handler.delegating.class%">
2727
<argument type="service" id="cmf_routing_auto.metadata.factory" />
28-
<argument type="service" id="cmf_routing_auto.adapter.phpcr_odm" />
28+
<argument type="service" id="cmf_routing_auto.adapter" />
2929
<argument type="service" id="cmf_routing_auto.service_registry" />
3030
</service>
3131

Resources/config/phpcr-odm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<service id="cmf_routing_auto.adapter.phpcr_odm" class="%cmf_routing_auto.adapter.phpcr_odm.class%">
1616
<argument type="service" id="doctrine_phpcr.odm.default_document_manager"/>
1717
<argument>%cmf_routing_auto.persistence.phpcr.route_basepath%</argument>
18+
<tag name="cmf_routing_auto.adapter" alias="doctrine_phpcr_odm" />
1819
</service>
1920

2021
<service id="cmf_routing_auto.phpcrodm_auto_route_listener" class="%cmf_routing_auto.phpcrodm_auto_route_listener.class%">

Tests/Unit/DependencyInjection/Compiler/AutoRoutePassTest.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected function registerCompilerPass(ContainerBuilder $container)
1414
$container->addCompilerPass(new AutoRoutePass());
1515
}
1616

17-
public function testRegistration()
17+
public function testServiceRegistration()
1818
{
1919
$serviceRegistryDefinition = new Definition();
2020
$this->setDefinition('cmf_routing_auto.service_registry', $serviceRegistryDefinition);
@@ -32,6 +32,36 @@ public function testRegistration()
3232
new Reference('some_token_provider')
3333
)
3434
);
35+
}
36+
37+
/**
38+
* @expectedException \RuntimeException
39+
* @expectedExceptionMessage Could not find configured adapter "bar", available adapters: "foobar"
40+
*/
41+
public function testAdapterRegistrationUnknownAdapter()
42+
{
43+
$managerDef = new Definition();
44+
$this->setDefinition('cmf_routing_auto.auto_route_manager', $managerDef);
45+
$this->container->setParameter('cmf_routing_auto.adapter_name', 'bar');
46+
47+
$adapterDef = new Definition();
48+
$adapterDef->addTag('cmf_routing_auto.adapter', array('alias' => 'foobar'));
49+
$this->setDefinition('some_adapter', $adapterDef);
50+
$this->compile();
51+
}
52+
53+
public function testAdapterRegistration()
54+
{
55+
$managerDef = new Definition();
56+
$managerDef->setArguments(array(0, 1, 2));
57+
$this->setDefinition('cmf_routing_auto.auto_route_manager', $managerDef);
58+
$this->container->setParameter('cmf_routing_auto.adapter', 'foobar');
59+
60+
$adapterDef = new Definition();
61+
$adapterDef->addTag('cmf_routing_auto.adapter', array('alias' => 'foobar'));
62+
$this->setDefinition('some_adapter', $adapterDef);
63+
$this->compile();
3564

65+
$this->assertEquals(new Reference('some_adapter'), $managerDef->getArgument(0));
3666
}
3767
}

Tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protected function getConfiguration()
3131
public function testSupportsAllConfigFormats()
3232
{
3333
$expectedConfiguration = array(
34+
'adapter' => 'doctrine_phpcr_odm',
3435
'auto_mapping' => false,
3536
'mapping' => array(
3637
'resources' => array(

0 commit comments

Comments
 (0)