ProviderBasedGenerator.php in Zircon Profile 8.0
File
vendor/symfony-cmf/routing/ProviderBasedGenerator.php
View source
<?php
namespace Symfony\Cmf\Component\Routing;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Route as SymfonyRoute;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Psr\Log\LoggerInterface;
class ProviderBasedGenerator extends UrlGenerator implements VersatileGeneratorInterface {
protected $provider;
public function __construct(RouteProviderInterface $provider, LoggerInterface $logger = null) {
$this->provider = $provider;
$this->logger = $logger;
$this->context = new RequestContext();
}
public function generate($name, $parameters = array(), $absolute = false) {
if ($name instanceof SymfonyRoute) {
$route = $name;
}
elseif (null === ($route = $this->provider
->getRouteByName($name, $parameters))) {
throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
}
$compiledRoute = $route
->compile();
$hostTokens = $compiledRoute
->getHostTokens();
$debug_message = $this
->getRouteDebugMessage($name);
return $this
->doGenerate($compiledRoute
->getVariables(), $route
->getDefaults(), $route
->getRequirements(), $compiledRoute
->getTokens(), $parameters, $debug_message, $absolute, $hostTokens);
}
public function supports($name) {
return is_string($name) || $name instanceof SymfonyRoute;
}
public function getRouteDebugMessage($name, array $parameters = array()) {
if (is_scalar($name)) {
return $name;
}
if (is_array($name)) {
return serialize($name);
}
if ($name instanceof RouteObjectInterface) {
return 'Route with key ' . $name
->getRouteKey();
}
if ($name instanceof SymfonyRoute) {
return 'Route with pattern ' . $name
->getPattern();
}
return get_class($name);
}
}