Skip to content

Commit

Permalink
Add an extension-point for DI into the Matcher/Generator Dumpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorian Villet authored and fabpot committed Jun 24, 2013
1 parent 31ac13b commit 40b598c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Symfony/Component/Routing/Router.php
Expand Up @@ -16,7 +16,9 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Generator\Dumper\GeneratorDumperInterface;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface;

/**
* The Router class is an example of the integration of all pieces of the
Expand Down Expand Up @@ -233,7 +235,7 @@ public function getMatcher()
$class = $this->options['matcher_cache_class'];
$cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
if (!$cache->isFresh($class)) {
$dumper = new $this->options['matcher_dumper_class']($this->getRouteCollection());
$dumper = $this->getMatcherDumperInstance();

$options = array(
'class' => $class,
Expand Down Expand Up @@ -265,7 +267,7 @@ public function getGenerator()
$class = $this->options['generator_cache_class'];
$cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
if (!$cache->isFresh($class)) {
$dumper = new $this->options['generator_dumper_class']($this->getRouteCollection());
$dumper = $this->getGeneratorDumperInstance();

$options = array(
'class' => $class,
Expand All @@ -286,4 +288,20 @@ public function getGenerator()

return $this->generator;
}

/**
* @return GeneratorDumperInterface
*/
protected function getGeneratorDumperInstance()
{
return new $this->options['generator_dumper_class']($this->getRouteCollection());
}

/**
* @return MatcherDumperInterface
*/
protected function getMatcherDumperInstance()
{
return new $this->options['matcher_dumper_class']($this->getRouteCollection());
}
}

0 comments on commit 40b598c

Please sign in to comment.