Created
August 5, 2014 15:54
-
-
Save wizhippo/ad216e0867fff7490a97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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