Skip to content

Commit 42b54cf

Browse files
committed
Merge pull request symfony#18 from lolautruche/fixCacheClearWarmup
Fixed symfony#15 When using the chain router in a compiler pass, cache warmup fails
2 parents a5810c9 + 5ec684a commit 42b54cf

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

ChainRouter.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ public function add(RouterInterface $router, $priority = 0)
7777
$this->routers[$priority] = array();
7878
}
7979

80-
if ($router instanceof RequestContextAwareInterface) {
81-
$context = $this->getContext();
82-
if (null !== $context) {
83-
$router->setContext($context);
84-
}
85-
}
86-
8780
$this->routers[$priority][] = $router;
8881
$this->sortedRouters = array();
8982
}
@@ -97,6 +90,17 @@ public function all()
9790
{
9891
if (empty($this->sortedRouters)) {
9992
$this->sortedRouters = $this->sortRouters();
93+
94+
// setContext() is done here instead of in add() to avoid fatal errors when clearing and warming up caches
95+
// See https://github.com/symfony-cmf/Routing/pull/18
96+
$context = $this->getContext();
97+
if (null !== $context) {
98+
foreach ($this->sortedRouters as $router) {
99+
if ($router instanceof RequestContextAwareInterface) {
100+
$router->setContext($context);
101+
}
102+
}
103+
}
100104
}
101105

102106
return $this->sortedRouters;
@@ -220,13 +224,13 @@ public function generate($name, $parameters = array(), $absolute = false)
220224
*/
221225
public function setContext(RequestContext $context)
222226
{
223-
$this->context = $context;
224-
225227
foreach ($this->all() as $router) {
226228
if ($router instanceof RequestContextAwareInterface) {
227229
$router->setContext($context);
228230
}
229231
}
232+
233+
$this->context = $context;
230234
}
231235

232236
/**

0 commit comments

Comments
 (0)