/** * Searches for a matching redirect for the given HTTP response * * @param Request $httpRequest * @return Response|null * @api */ public function buildResponseIfApplicable(Request $httpRequest) { try { $redirect = $this->redirectStorage->getOneBySourceUriPathAndHost($httpRequest->getRelativePath(), $httpRequest->getBaseUri()->getHost()); if ($redirect === null) { return null; } if (isset($this->featureSwitch['hitCounter']) && $this->featureSwitch['hitCounter'] === true) { $this->redirectStorage->incrementHitCount($redirect); } return $this->buildResponse($httpRequest, $redirect); } catch (\Exception $exception) { // Throw exception if it's a \Neos\RedirectHandler\Exception (used for custom exception handling) if ($exception instanceof Exception) { throw $exception; } // skip triggering the redirect if there was an error accessing the database (wrong credentials, ...) return null; } }
/** * Checks whether $routePath corresponds to this Route. * If all Route Parts match successfully TRUE is returned and * $this->matchResults contains an array combining Route default values and * calculated matchResults from the individual Route Parts. * * @param Request $httpRequest the HTTP request to match * @return boolean TRUE if this Route corresponds to the given $routePath, otherwise FALSE * @throws InvalidRoutePartValueException * @see getMatchResults() */ public function matches(Request $httpRequest) { $routePath = $httpRequest->getRelativePath(); $this->matchResults = null; if ($this->uriPattern === null) { return false; } if (!$this->isParsed) { $this->parse(); } if ($this->hasHttpMethodConstraints() && !in_array($httpRequest->getMethod(), $this->httpMethods)) { return false; } $matchResults = []; $routePath = trim($routePath, '/'); $skipOptionalParts = false; $optionalPartCount = 0; /** @var $routePart RoutePartInterface */ foreach ($this->routeParts as $routePart) { if ($routePart->isOptional()) { $optionalPartCount++; if ($skipOptionalParts) { if ($routePart->getDefaultValue() === null) { return false; } continue; } } else { $optionalPartCount = 0; $skipOptionalParts = false; } if ($routePart->match($routePath) !== true) { if ($routePart->isOptional() && $optionalPartCount === 1) { if ($routePart->getDefaultValue() === null) { return false; } $skipOptionalParts = true; } else { return false; } } $routePartValue = $routePart->getValue(); if ($routePartValue !== null) { if ($this->containsObject($routePartValue)) { throw new InvalidRoutePartValueException('RoutePart::getValue() must only return simple types after calling RoutePart::match(). RoutePart "' . get_class($routePart) . '" returned one or more objects in Route "' . $this->getName() . '".'); } $matchResults = Arrays::setValueByPath($matchResults, $routePart->getName(), $routePartValue); } } if (strlen($routePath) > 0) { return false; } $this->matchResults = Arrays::arrayMergeRecursiveOverrule($this->defaults, $matchResults); return true; }
/** * Generates the Matching cache identifier for the given Request * * @param Request $httpRequest * @return string */ protected function buildRouteCacheIdentifier(Request $httpRequest) { return md5(sprintf('%s_%s_%s', $httpRequest->getUri()->getHost(), $httpRequest->getRelativePath(), $httpRequest->getMethod())); }