Skip to content

Instantly share code, notes, and snippets.

@alongosz
Created July 18, 2017 09:43
Show Gist options
  • Save alongosz/a6ca06dc34c7d8135503a3ee43751213 to your computer and use it in GitHub Desktop.
Save alongosz/a6ca06dc34c7d8135503a3ee43751213 to your computer and use it in GitHub Desktop.
eZ\Bundle\EzPublishCoreBundle\Routing\DefaultRouter::generate suggestion
<?php
try {
$url = parent::generate($name, $parameters, $referenceType);
// Now putting back SiteAccess URI if needed.
if ($isSiteAccessAware && $siteAccess && $siteAccess->matcher instanceof URILexer) {
if ($referenceType === self::ABSOLUTE_URL || $referenceType === self::NETWORK_PATH) {
$scheme = $context->getScheme();
$port = '';
if ($scheme === 'http' && $this->context->getHttpPort() != 80) {
$port = ':' . $this->context->getHttpPort();
} elseif ($scheme === 'https' && $this->context->getHttpsPort() != 443) {
$port = ':' . $this->context->getHttpsPort();
}
$base = $context->getHost() . $port . $context->getBaseUrl();
} else {
$base = $context->getBaseUrl();
}
$linkUri = $base ? substr($url, strpos($url, $base) + strlen($base)) : $url;
$url = str_replace($linkUri, $siteAccess->matcher->analyseLink($linkUri), $url);
}
return $url;
} finally {
// Switch back to original context, for next links generation.
$this->setContext($originalContext);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment