From e0a3fc19a469a43e8daa8688bbc833a5d8ea2267 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sun, 14 Oct 2012 03:04:34 +0200 Subject: [PATCH] Made the router lazy when setting the context Initializing the matcher and the generator to set the context does not make sense as it is set anyway when building them. This avoids initializing them in the RouterListener if you never actually use them (for instance because you use the apache matcher). --- src/Symfony/Component/Routing/Router.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index bd2c5a11bd..90984e9a4b 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -15,6 +15,8 @@ use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\ConfigCache; use Symfony\Component\HttpKernel\Log\LoggerInterface; use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\Matcher\UrlMatcherInterface; /** * The Router class is an example of the integration of all pieces of the @@ -150,8 +152,12 @@ class Router implements RouterInterface { $this->context = $context; - $this->getMatcher()->setContext($context); - $this->getGenerator()->setContext($context); + if (null !== $this->matcher) { + $this->getMatcher()->setContext($context); + } + if (null !== $this->generator) { + $this->getGenerator()->setContext($context); + } } /**