Neos\Flow\Mvc\Routing\DynamicRoutePart::findValueToMatch PHP Method

findValueToMatch() protected method

If a split string is set, only the first part of the value until location of the splitString is returned. This method can be overridden by custom RoutePartHandlers to implement custom matching mechanisms.
protected findValueToMatch ( string $routePath ) : string
$routePath string The request path to be matched
return string value to match, or an empty string if $routePath is empty or split string was not found
    protected function findValueToMatch($routePath)
    {
        if (!isset($routePath) || $routePath === '' || $routePath[0] === '/') {
            return '';
        }
        $valueToMatch = $routePath;
        if ($this->splitString !== '') {
            $splitStringPosition = strpos($valueToMatch, $this->splitString);
            if ($splitStringPosition !== false) {
                $valueToMatch = substr($valueToMatch, 0, $splitStringPosition);
            }
        }
        if (strpos($valueToMatch, '/') !== false) {
            return '';
        }
        return $valueToMatch;
    }

Usage Example

 /**
  * Returns the first part of $routePath that should be evaluated in matchValue().
  * If no split string is set (route part is the last in the routes uriPattern), the complete $routePart is returned.
  * Otherwise the part is returned that matches the specified uriPattern of this route part.
  *
  * @param string $routePath The request path to be matched
  * @return string value to match, or an empty string if $routePath is empty, split string was not found or uriPattern could not be matched
  * @api
  */
 protected function findValueToMatch($routePath)
 {
     if (!isset($routePath) || $routePath === '' || $routePath[0] === '/') {
         return '';
     }
     if ($this->getUriPattern() === '') {
         return parent::findValueToMatch($routePath);
     }
     $regexPattern = preg_quote($this->getUriPattern(), '/');
     $regexPattern = preg_replace('/\\\\{[^}]+\\\\}/', '[^\\/]+', $regexPattern);
     if ($this->splitString !== '') {
         $regexPattern .= '(?=' . preg_quote($this->splitString, '/') . ')';
     }
     $matches = [];
     preg_match('/^' . $regexPattern . '/', trim($routePath, '/'), $matches);
     return isset($matches[0]) ? $matches[0] : '';
 }