/** * Return the rule corresponding route parameter. * @param string $ruleParameter * @param Route $route * @return mixed */ private function getRuleCorrespondingRouteParameter($ruleParameter, Route $route) { if (isset($this->pathParameters[$ruleParameter]) && !empty($this->pathParameters[$ruleParameter])) { return $this->pathParameters[$ruleParameter]; } return $route->getDefaultValue($ruleParameter); }
/** * Returns the expected uri path to validate against the route path. * @param \Brickoo\Component\Routing\Route\Route $route * @param array $pathParameters the path parameters to use * @throws \Brickoo\Component\Routing\Route\Exception\RouteRequiredParametersMissingException * @return string the uri path expected */ private function getExpectedRoutePath(Route $route, $pathParameters) { $routePath = $route->getPath(); $pathParameters = array_merge($route->getDefaultValues(), $pathParameters); foreach ($pathParameters as $parameter => $value) { $routePath = str_replace("{" . $parameter . "}", $value, $routePath); } $matches = []; if (preg_match_all("~(\\{(?<missingParameters>[\\w]+)\\})~", $routePath, $matches) > 0) { throw new RouteRequiredParametersMissingException($route->getName(), $matches["missingParameters"]); } return $routePath; }