eZ\Publish\Core\Repository\URLWildcardService::translate PHP Method

translate() public method

Translates an url to an existing uri resource based on the source/destination patterns of the url wildcard.
public translate ( mixed $url ) : eZ\Publish\API\Repository\Values\Content\URLWildcardTranslationResult
$url mixed
return eZ\Publish\API\Repository\Values\Content\URLWildcardTranslationResult
    public function translate($url)
    {
        $spiUrlWildcards = $this->urlWildcardHandler->loadAll();
        // sorts wildcards by length of source URL string
        // @todo sort by specificity of the pattern?
        uasort($spiUrlWildcards, function (SPIUrlWildcard $w1, SPIUrlWildcard $w2) {
            return strlen($w2->sourceUrl) - strlen($w1->sourceUrl);
        });
        foreach ($spiUrlWildcards as $wildcard) {
            if ($uri = $this->match($url, $wildcard)) {
                return new URLWildcardTranslationResult(array('uri' => $uri, 'forward' => $wildcard->forward));
            }
        }
        throw new NotFoundException('URLWildcard', $url);
    }