Implements Symfony\Component\Routing\Generator\UrlGeneratorInterface::generate().
Overrides ProviderBasedGenerator::generate
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));
}
// The Route has a cache of its own and is not recompiled as long as it does
// not get modified.
$compiledRoute = $route
->compile();
$hostTokens = $compiledRoute
->getHostTokens();
$route_requirements = $route
->getRequirements();
// We need to bypass the doGenerate() method's handling of absolute URLs as
// we handle that ourselves after processing the path.
if (isset($route_requirements['_scheme'])) {
$scheme_req = $route_requirements['_scheme'];
unset($route_requirements['_scheme']);
}
$path = $this
->doGenerate($compiledRoute
->getVariables(), $route
->getDefaults(), $route_requirements, $compiledRoute
->getTokens(), $parameters, $name, FALSE, $hostTokens);
// The URL returned from doGenerate() will include the base path if there is
// one (i.e., if running in a subdirectory) so we need to strip that off
// before processing the path.
$base_url = $this->context
->getBaseUrl();
if (!empty($base_url) && strpos($path, $base_url) === 0) {
$path = substr($path, strlen($base_url));
}
$path = $this
->processPath($path);
if (!$absolute || !($host = $this->context
->getHost())) {
return $base_url . $path;
}
// Prepare an absolute URL by getting the correct scheme, host and port from
// the request context.
$scheme = $this->context
->getScheme();
if (isset($scheme_req) && ($req = strtolower($scheme_req)) && $scheme !== $req) {
$scheme = $req;
}
$port = '';
if ('http' === $scheme && 80 != $this->context
->getHttpPort()) {
$port = ':' . $this->context
->getHttpPort();
}
elseif ('https' === $scheme && 443 != $this->context
->getHttpsPort()) {
$port = ':' . $this->context
->getHttpsPort();
}
return $scheme . '://' . $host . $port . $base_url . $path;
}