merged branch gnutix/2.3 (PR #8339)
This PR was submitted for the 2.3 branch but it was merged into the master branch instead (closes #8339). Discussion ---------- [Routing] Add an extension-point for DI into the Matcher/Generator Dumpers | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - The Routing's MatcherDumper and GeneratorDumper classes are instantiated very deeply into the `Router::getGenerator()` and `Router::getMatcher()` methods. This pull requests aims to : 1. separate the instances creation 2. ease overriding (lesser risks of changes at framework updates) 3. ease dependencies injection for these classes (as we can't inject dependencies in another way, be it service definition, compiler pass or whatever I'm aware of). An example of usage would be the following : https://gist.github.com/gnutix/5844630 It's a real case I'm having in my company's current project. Commits ------- 5a03a7f [Routing] Add an extension-point for DI into the Matcher/Generator Dumpers
This commit is contained in:
commit
465965a71b
@ -16,7 +16,9 @@ use Symfony\Component\Config\ConfigCache;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
|
use Symfony\Component\Routing\Generator\ConfigurableRequirementsInterface;
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
use Symfony\Component\Routing\Generator\Dumper\GeneratorDumperInterface;
|
||||||
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
|
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
|
* The Router class is an example of the integration of all pieces of the
|
||||||
@ -233,7 +235,7 @@ class Router implements RouterInterface
|
|||||||
$class = $this->options['matcher_cache_class'];
|
$class = $this->options['matcher_cache_class'];
|
||||||
$cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
|
$cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
|
||||||
if (!$cache->isFresh($class)) {
|
if (!$cache->isFresh($class)) {
|
||||||
$dumper = new $this->options['matcher_dumper_class']($this->getRouteCollection());
|
$dumper = $this->getMatcherDumperInstance();
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
'class' => $class,
|
'class' => $class,
|
||||||
@ -265,7 +267,7 @@ class Router implements RouterInterface
|
|||||||
$class = $this->options['generator_cache_class'];
|
$class = $this->options['generator_cache_class'];
|
||||||
$cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
|
$cache = new ConfigCache($this->options['cache_dir'].'/'.$class.'.php', $this->options['debug']);
|
||||||
if (!$cache->isFresh($class)) {
|
if (!$cache->isFresh($class)) {
|
||||||
$dumper = new $this->options['generator_dumper_class']($this->getRouteCollection());
|
$dumper = $this->getGeneratorDumperInstance();
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
'class' => $class,
|
'class' => $class,
|
||||||
@ -286,4 +288,20 @@ class Router implements RouterInterface
|
|||||||
|
|
||||||
return $this->generator;
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user