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

Commit de7435d

Browse files
committed
Split compiler passes
1 parent c37c4d0 commit de7435d

File tree

5 files changed

+104
-68
lines changed

5 files changed

+104
-68
lines changed

CmfRoutingAutoBundle.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414

1515
use Symfony\Component\HttpKernel\Bundle\Bundle;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
17-
use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Compiler\AutoRoutePass;
1817
use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;
18+
use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Compiler\ServicePass;
19+
use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Compiler\AdapterPass;
1920

2021
class CmfRoutingAutoBundle extends Bundle
2122
{
2223
public function build(ContainerBuilder $container)
2324
{
2425
parent::build($container);
25-
$container->addCompilerPass(new AutoRoutePass());
26+
$container->addCompilerPass(new ServicePass());
27+
$container->addCompilerPass(new AdapterPass());
2628
$this->buildPhpcrCompilerPass($container);
2729
}
2830

DependencyInjection/Compiler/AutoRoutePass.php renamed to DependencyInjection/Compiler/AdapterPass.php

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@
1919
/**
2020
* @author Daniel Leech <[email protected]>
2121
*/
22-
class AutoRoutePass implements CompilerPassInterface
22+
class AdapterPass 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)
3125
{
3226
if (!$container->hasDefinition(
3327
'cmf_routing_auto.auto_route_manager'
@@ -66,41 +60,4 @@ private function registerAdapter(ContainerBuilder $container)
6660
$managerDef = $container->getDefinition('cmf_routing_auto.auto_route_manager');
6761
$container->setAlias('cmf_routing_auto.adapter', $adapterId);
6862
}
69-
70-
private function registerServices(ContainerBuilder $container)
71-
{
72-
if (!$container->hasDefinition(
73-
'cmf_routing_auto.service_registry'
74-
)) {
75-
return;
76-
}
77-
78-
$builderUnitChainFactory = $container->getDefinition(
79-
'cmf_routing_auto.service_registry'
80-
);
81-
82-
$types = array(
83-
'token_provider' => 'registerTokenProvider',
84-
'defunct_route_handler' => 'registerDefunctRouteHandler',
85-
'conflict_resolver' => 'registerConflictResolver',
86-
);
87-
88-
foreach ($types as $type => $registerMethod) {
89-
$ids = $container->findTaggedServiceIds('cmf_routing_auto.'.$type);
90-
foreach ($ids as $id => $attributes) {
91-
if (!isset($attributes[0]['alias'])) {
92-
throw new \InvalidArgumentException(sprintf(
93-
'No "alias" specified for auto route "%s" service: "%s"',
94-
str_replace('_', ' ', $type),
95-
$id
96-
));
97-
}
98-
99-
$builderUnitChainFactory->addMethodCall(
100-
$registerMethod,
101-
array($attributes[0]['alias'], new Reference($id))
102-
);
103-
}
104-
}
105-
}
10663
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2014 Symfony CMF
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
13+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Compiler;
14+
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17+
use Symfony\Component\DependencyInjection\Reference;
18+
19+
/**
20+
* @author Daniel Leech <[email protected]>
21+
*/
22+
class ServicePass implements CompilerPassInterface
23+
{
24+
public function process(ContainerBuilder $container)
25+
{
26+
if (!$container->hasDefinition(
27+
'cmf_routing_auto.service_registry'
28+
)) {
29+
return;
30+
}
31+
32+
$builderUnitChainFactory = $container->getDefinition(
33+
'cmf_routing_auto.service_registry'
34+
);
35+
36+
$types = array(
37+
'token_provider' => 'registerTokenProvider',
38+
'defunct_route_handler' => 'registerDefunctRouteHandler',
39+
'conflict_resolver' => 'registerConflictResolver',
40+
);
41+
42+
foreach ($types as $type => $registerMethod) {
43+
$ids = $container->findTaggedServiceIds('cmf_routing_auto.'.$type);
44+
foreach ($ids as $id => $attributes) {
45+
if (!isset($attributes[0]['alias'])) {
46+
throw new \InvalidArgumentException(sprintf(
47+
'No "alias" specified for auto route "%s" service: "%s"',
48+
str_replace('_', ' ', $type),
49+
$id
50+
));
51+
}
52+
53+
$builderUnitChainFactory->addMethodCall(
54+
$registerMethod,
55+
array($attributes[0]['alias'], new Reference($id))
56+
);
57+
}
58+
}
59+
}
60+
}

Tests/Unit/DependencyInjection/Compiler/AutoRoutePassTest.php renamed to Tests/Unit/DependencyInjection/Compiler/AdapterPassTest.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,18 @@
11
<?php
22

33
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\DependencyInjection\Compiler;
4-
use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Compiler\AutoRoutePass;
54
use Symfony\Component\DependencyInjection\Definition;
65
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
76
use Symfony\Component\DependencyInjection\ContainerBuilder;
87
use Symfony\Component\DependencyInjection\Reference;
98
use Symfony\Component\DependencyInjection\Alias;
9+
use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Compiler\AdapterPass;
1010

1111
class AutoRoutePassTest extends AbstractCompilerPassTestCase
1212
{
1313
protected function registerCompilerPass(ContainerBuilder $container)
1414
{
15-
$container->addCompilerPass(new AutoRoutePass());
16-
}
17-
18-
public function testServiceRegistration()
19-
{
20-
$serviceRegistryDefinition = new Definition();
21-
$this->setDefinition('cmf_routing_auto.service_registry', $serviceRegistryDefinition);
22-
23-
$tokenProviderDefinition = new Definition();
24-
$tokenProviderDefinition->addTag('cmf_routing_auto.token_provider', array('alias' => 'foobar'));
25-
$this->setDefinition('some_token_provider', $tokenProviderDefinition);
26-
$this->compile();
27-
28-
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
29-
'cmf_routing_auto.service_registry',
30-
'registerTokenProvider',
31-
array(
32-
'foobar',
33-
new Reference('some_token_provider')
34-
)
35-
);
15+
$container->addCompilerPass(new AdapterPass());
3616
}
3717

3818
/**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\DependencyInjection\Compiler;
4+
use Symfony\Component\DependencyInjection\Definition;
5+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Reference;
8+
use Symfony\Component\DependencyInjection\Alias;
9+
use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Compiler\ServicePass;
10+
11+
class ServicePassTest extends AbstractCompilerPassTestCase
12+
{
13+
protected function registerCompilerPass(ContainerBuilder $container)
14+
{
15+
$container->addCompilerPass(new ServicePass());
16+
}
17+
18+
public function testServiceRegistration()
19+
{
20+
$serviceRegistryDefinition = new Definition();
21+
$this->setDefinition('cmf_routing_auto.service_registry', $serviceRegistryDefinition);
22+
23+
$tokenProviderDefinition = new Definition();
24+
$tokenProviderDefinition->addTag('cmf_routing_auto.token_provider', array('alias' => 'foobar'));
25+
$this->setDefinition('some_token_provider', $tokenProviderDefinition);
26+
$this->compile();
27+
28+
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
29+
'cmf_routing_auto.service_registry',
30+
'registerTokenProvider',
31+
array(
32+
'foobar',
33+
new Reference('some_token_provider')
34+
)
35+
);
36+
}
37+
}

0 commit comments

Comments
 (0)