Skip to content

Commit 1db98dd

Browse files
committed
Merge pull request #236 from symfony-cmf/synchronized-service
use synchronized service
2 parents abf7cc2 + d85c465 commit 1db98dd

File tree

4 files changed

+21
-35
lines changed

4 files changed

+21
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
1.2.0-RC2
55
---------
66

7+
* **2014-04-14**: DynamicRouter no longer implements the ContainerAwareInterface
78
* **2014-04-11**: drop Symfony 2.2 compatibility
89

910
1.2.0-RC1

Resources/config/routing-dynamic.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<argument>%cmf_routing.uri_filter_regexp%</argument>
6969
<argument type="service" id="event_dispatcher" on-invalid="ignore"/>
7070
<argument type="service" id="cmf_routing.route_provider"/>
71-
<call method="setContainer"><argument type="service" id="service_container"/></call>
71+
<call method="setRequest"><argument type="service" id="request" on-invalid="null" strict="false"/></call>
7272
<call method="addRouteEnhancer">
7373
<argument type="service" id="cmf_routing.enhancer.route_content"/>
7474
<argument>100</argument>

Routing/DynamicRouter.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
use Symfony\Component\HttpFoundation\Request;
1616

17-
use Symfony\Component\DependencyInjection\ContainerInterface;
18-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
19-
2017
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
2118

2219
use Symfony\Cmf\Component\Routing\DynamicRouter as BaseDynamicRouter;
@@ -30,7 +27,7 @@
3027
* @author Lukas Smith
3128
* @author Nacho Martìn
3229
*/
33-
class DynamicRouter extends BaseDynamicRouter implements ContainerAwareInterface
30+
class DynamicRouter extends BaseDynamicRouter
3431
{
3532
/**
3633
* key for the request attribute that contains the route document
@@ -50,22 +47,9 @@ class DynamicRouter extends BaseDynamicRouter implements ContainerAwareInterface
5047
const CONTENT_TEMPLATE = 'contentTemplate';
5148

5249
/**
53-
* To get the request from, as its not available immediately
54-
*
55-
* @var ContainerInterface
56-
*/
57-
protected $container;
58-
59-
/**
60-
* TODO: use synchronized service once we up the minimum requirement to symfony 2.3
61-
* https://github.com/symfony-cmf/RoutingBundle/issues/177
62-
*
63-
* @param ContainerInterface $container
50+
* @var Request
6451
*/
65-
public function setContainer(ContainerInterface $container = null)
66-
{
67-
$this->container = $container;
68-
}
52+
protected $request;
6953

7054
/**
7155
* Put content and template name into the request attributes instead of the
@@ -124,12 +108,24 @@ protected function cleanDefaults($defaults, Request $request = null)
124108
return $defaults;
125109
}
126110

111+
/**
112+
* @param Request $request
113+
*/
114+
public function setRequest(Request $request = null)
115+
{
116+
$this->request = $request;
117+
}
118+
119+
/**
120+
* @return Request
121+
* @throws \Symfony\Component\Routing\Exception\ResourceNotFoundException
122+
*/
127123
public function getRequest()
128124
{
129-
if (!$request = $this->container->get('request')) {
125+
if (null === $this->request) {
130126
throw new ResourceNotFoundException('Request object not available from container');
131127
}
132128

133-
return $request;
129+
return $this->request;
134130
}
135131
}

Tests/Unit/Routing/DynamicRouterTest.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ public function setUp()
4949
$this->generator = $this->buildMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
5050

5151
$this->request = Request::create('/foo');
52-
$this->container = $this->buildMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
5352
$this->context = $this->buildMock('Symfony\\Component\\Routing\\RequestContext');
5453
$this->eventDispatcher = $this->buildMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
5554
$this->router = new DynamicRouter($this->context, $this->matcher, $this->generator, '', $this->eventDispatcher);
56-
$this->router->setContainer($this->container);
55+
$this->router->setRequest($this->request);
5756
}
5857

5958
private function assertRequestAttributes($request)
@@ -66,12 +65,6 @@ private function assertRequestAttributes($request)
6665

6766
public function testMatch()
6867
{
69-
$this->container->expects($this->once())
70-
->method('get')
71-
->with('request')
72-
->will($this->returnValue($this->request))
73-
;
74-
7568
$this->eventDispatcher->expects($this->once())
7669
->method('dispatch')
7770
->with(Events::PRE_DYNAMIC_MATCH, $this->equalTo(new RouterMatchEvent()))
@@ -101,11 +94,7 @@ public function testMatchRequest()
10194
*/
10295
public function testMatchNoRequest()
10396
{
104-
$this->container->expects($this->once())
105-
->method('get')
106-
->with('request')
107-
->will($this->returnValue(null))
108-
;
97+
$this->router->setRequest(null);
10998

11099
$this->eventDispatcher->expects($this->once())
111100
->method('dispatch')

0 commit comments

Comments
 (0)