function Router::getGenerator
Gets the UrlGenerator instance associated with this Router.
File
-
vendor/
symfony/ routing/ Router.php, line 236
Class
- Router
- The Router class is an example of the integration of all pieces of the routing system for easier use.
Namespace
Symfony\Component\RoutingCode
public function getGenerator() : UrlGeneratorInterface {
if (isset($this->generator)) {
return $this->generator;
}
if (null === $this->options['cache_dir']) {
$routes = $this->getRouteCollection();
$compiled = is_a($this->options['generator_class'], CompiledUrlGenerator::class, true);
if ($compiled) {
$generatorDumper = new CompiledUrlGeneratorDumper($routes);
$routes = array_merge($generatorDumper->getCompiledRoutes(), $generatorDumper->getCompiledAliases());
}
$this->generator = new $this->options['generator_class']($routes, $this->context, $this->logger, $this->defaultLocale);
}
else {
$cache = $this->getConfigCacheFactory()
->cache($this->options['cache_dir'] . '/url_generating_routes.php', function (ConfigCacheInterface $cache) {
$dumper = $this->getGeneratorDumperInstance();
$cache->write($dumper->dump(), $this->getRouteCollection()
->getResources());
unset(self::$cache[$cache->getPath()]);
});
$this->generator = new $this->options['generator_class'](self::getCompiledRoutes($cache->getPath()), $this->context, $this->logger, $this->defaultLocale);
}
if ($this->generator instanceof ConfigurableRequirementsInterface) {
$this->generator
->setStrictRequirements($this->options['strict_requirements']);
}
return $this->generator;
}