Skip to content

Instantly share code, notes, and snippets.

@wizhippo
Created August 5, 2014 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizhippo/ad216e0867fff7490a97 to your computer and use it in GitHub Desktop.
Save wizhippo/ad216e0867fff7490a97 to your computer and use it in GitHub Desktop.
<?php
namespace Tocom\Bundle\AssociateSiteBundle\SiteAccess\Matcher;
use eZ\Bundle\EzPublishCoreBundle\SiteAccess\Matcher;
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher\URIElement as BaseMatcher;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
class URIElement extends BaseMatcher implements Matcher
{
/**
* HTTPRequest
*
* @var \Symfony\Component\HttpFoundation\Request
*/
private $httpRequest = null;
/**
* Injects the http request object to match against.
*
* @param \Symfony\Component\HttpFoundation\Request
*/
public function setHttpRequest( HttpRequest $httpRequest = null ) {
$this->httpRequest = $httpRequest;
}
/**
* Registers the matching configuration associated with the matcher.
*
* @param mixed $matchingConfiguration
*/
public function setMatchingConfiguration( $matchingConfiguration ) {
}
/**
* Analyses $linkUri when generating a link to a route, in order to have the siteaccess part back in the URI.
*
* @param string $linkUri
*
* @return string The modified link URI
*/
public function analyseLink( $linkUri )
{
$baseUrl = "";
if ($this->httpRequest !== null) {
$baseUrl = $this->httpRequest->getBaseUrl();
if (substr($linkUri, 0, strlen($baseUrl)) == $baseUrl) {
$linkUri = substr($linkUri, strlen($baseUrl));
} else {
$baseUrl = "";
}
}
$linkUri = parent::analyseLink($linkUri);
return "{$baseUrl}{$linkUri}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment