Neos\Flow\Mvc\Routing\Route::resolves PHP Метод

resolves() публичный Метод

If all Route Parts can resolve one or more of the $routeValues, TRUE is returned and $this->matchingURI contains the generated URI (excluding protocol and host).
public resolves ( array $routeValues ) : boolean
$routeValues array An array containing key/value pairs to be resolved to uri segments
Результат boolean TRUE if this Route corresponds to the given $routeValues, otherwise FALSE
    public function resolves(array $routeValues)
    {
        $this->resolvedUriPath = null;
        if ($this->uriPattern === null) {
            return false;
        }
        if (!$this->isParsed) {
            $this->parse();
        }
        $resolvedUriPath = '';
        $remainingDefaults = $this->defaults;
        $requireOptionalRouteParts = false;
        $matchingOptionalUriPortion = '';
        /** @var $routePart RoutePartInterface */
        foreach ($this->routeParts as $routePart) {
            if (!$routePart->resolve($routeValues)) {
                if (!$routePart->hasDefaultValue()) {
                    return false;
                }
            }
            if ($routePart->getName() !== null) {
                $remainingDefaults = Arrays::unsetValueByPath($remainingDefaults, $routePart->getName());
            }
            $routePartValue = null;
            if ($routePart->hasValue()) {
                $routePartValue = $routePart->getValue();
                if (!is_string($routePartValue)) {
                    throw new InvalidRoutePartValueException('RoutePart::getValue() must return a string after calling RoutePart::resolve(), got ' . (is_object($routePartValue) ? get_class($routePartValue) : gettype($routePartValue)) . ' for RoutePart "' . get_class($routePart) . '" in Route "' . $this->getName() . '".');
                }
            }
            $routePartDefaultValue = $routePart->getDefaultValue();
            if ($routePartDefaultValue !== null && !is_string($routePartDefaultValue)) {
                throw new InvalidRoutePartValueException('RoutePart::getDefaultValue() must return a string, got ' . (is_object($routePartDefaultValue) ? get_class($routePartDefaultValue) : gettype($routePartDefaultValue)) . ' for RoutePart "' . get_class($routePart) . '" in Route "' . $this->getName() . '".');
            }
            if (!$routePart->isOptional()) {
                $resolvedUriPath .= $routePart->hasValue() ? $routePartValue : $routePartDefaultValue;
                $requireOptionalRouteParts = false;
                continue;
            }
            if ($routePart->hasValue() && strtolower($routePartValue) !== strtolower($routePartDefaultValue)) {
                $matchingOptionalUriPortion .= $routePartValue;
                $requireOptionalRouteParts = true;
            } else {
                $matchingOptionalUriPortion .= $routePartDefaultValue;
            }
            if ($requireOptionalRouteParts) {
                $resolvedUriPath .= $matchingOptionalUriPortion;
                $matchingOptionalUriPortion = '';
            }
        }
        if ($this->compareAndRemoveMatchingDefaultValues($remainingDefaults, $routeValues) !== true) {
            return false;
        }
        if (isset($routeValues['@format']) && $routeValues['@format'] === '') {
            unset($routeValues['@format']);
        }
        // add query string
        if (count($routeValues) > 0) {
            $routeValues = Arrays::removeEmptyElementsRecursively($routeValues);
            $routeValues = $this->persistenceManager->convertObjectsToIdentityArrays($routeValues);
            if (!$this->appendExceedingArguments) {
                $internalArguments = $this->extractInternalArguments($routeValues);
                if ($routeValues !== []) {
                    return false;
                }
                $routeValues = $internalArguments;
            }
            $queryString = http_build_query($routeValues, null, '&');
            if ($queryString !== '') {
                $resolvedUriPath .= strpos($resolvedUriPath, '?') !== false ? '&' . $queryString : '?' . $queryString;
            }
        }
        $this->resolvedUriPath = $resolvedUriPath;
        return true;
    }

Usage Example

 /**
  * @test
  * @expectedException \Neos\Flow\Mvc\Exception\InvalidRoutePartValueException
  */
 public function resolvesThrowsExceptionIfRoutePartDefaultValueIsNoString()
 {
     $mockRoutePart = $this->createMock(Routing\RoutePartInterface::class);
     $mockRoutePart->expects($this->any())->method('resolve')->will($this->returnValue(true));
     $mockRoutePart->expects($this->any())->method('hasValue')->will($this->returnValue(false));
     $mockRoutePart->expects($this->once())->method('getDefaultValue')->will($this->returnValue(['not a' => 'string']));
     $this->route->setUriPattern('foo');
     $this->route->_set('isParsed', true);
     $this->route->_set('routeParts', [$mockRoutePart]);
     $this->route->resolves([]);
 }