Skip to content

Commit 40b598c

Browse files
Dorian Villetfabpot
authored andcommitted
Add an extension-point for DI into the Matcher/Generator Dumpers
1 parent 31ac13b commit 40b598c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Symfony/Component/Routing/Router.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use Psr\Log\LoggerInterface;
1717
use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
1818
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
19+
use Symfony\Component\Routing\Generator\Dumper\GeneratorDumperInterface;
1920
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
21+
use Symfony\Component\Routing\Matcher\Dumper\MatcherDumperInterface;
2022

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

238240
$options = array(
239241
'class' => $class,
@@ -265,7 +267,7 @@ public function getGenerator()
265267
$class = $this->options['generator_cache_class'];
266268
$cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
267269
if (!$cache->isFresh($class)) {
268-
$dumper = new $this->options['generator_dumper_class']($this->getRouteCollection());
270+
$dumper = $this->getGeneratorDumperInstance();
269271

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

287289
return $this->generator;
288290
}
291+
292+
/**
293+
* @return GeneratorDumperInterface
294+
*/
295+
protected function getGeneratorDumperInstance()
296+
{
297+
return new $this->options['generator_dumper_class']($this->getRouteCollection());
298+
}
299+
300+
/**
301+
* @return MatcherDumperInterface
302+
*/
303+
protected function getMatcherDumperInstance()
304+
{
305+
return new $this->options['matcher_dumper_class']($this->getRouteCollection());
306+
}
289307
}

0 commit comments

Comments
 (0)