Skip to content

Commit

Permalink
Made the router lazy when setting the context
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
stof authored and fabpot committed Oct 14, 2012
1 parent ee75975 commit e0a3fc1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Symfony/Component/Routing/Router.php
Expand Up @@ -15,6 +15,8 @@
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
Expand Down Expand Up @@ -150,8 +152,12 @@ public function setContext(RequestContext $context)
{
$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);
}
}

/**
Expand Down

0 comments on commit e0a3fc1

Please sign in to comment.