/** * Merges all routes in $routesConfiguration with the sub routes in $subRoutesConfiguration * * @param array $routesConfiguration * @param array $subRoutesConfiguration * @param string $subRouteKey the key of the sub route: <subRouteKey> * @return array the merged route configuration * @author Bastian Waidelich <*****@*****.**> */ protected function buildSubrouteConfigurations(array $routesConfiguration, array $subRoutesConfiguration, $subRouteKey) { $mergedSubRoutesConfiguration = array(); foreach ($subRoutesConfiguration as $subRouteConfiguration) { foreach ($routesConfiguration as $routeConfiguration) { $name = isset($routeConfiguration['name']) ? $routeConfiguration['name'] : $routeConfiguration; $name .= ' :: '; $name .= isset($subRouteConfiguration['name']) ? $subRouteConfiguration['name'] : 'Subroute'; $uriPattern = str_replace('<' . $subRouteKey . '>', $subRouteConfiguration['uriPattern'], $routeConfiguration['uriPattern']); $defaults = isset($routeConfiguration['defaults']) ? $routeConfiguration['defaults'] : array(); if (isset($subRouteConfiguration['defaults'])) { $defaults = \F3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($defaults, $subRouteConfiguration['defaults']); } $routeParts = isset($routeConfiguration['routeParts']) ? $routeConfiguration['routeParts'] : array(); if (isset($subRouteConfiguration['routeParts'])) { $routeParts = \F3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($routeParts, $subRouteConfiguration['routeParts']); } $mergedSubRoutesConfiguration[] = array('name' => $name, 'uriPattern' => $uriPattern, 'defaults' => $defaults, 'routeParts' => $routeParts); } } return $mergedSubRoutesConfiguration; }
/** * Builds the URI * * @return string The URI * @api * @author Bastian Waidelich <*****@*****.**> */ public function build() { $arguments = array(); if ($this->addQueryString === TRUE) { $arguments = $this->request->getArguments(); foreach ($this->argumentsToBeExcludedFromQueryString as $argumentToBeExcluded) { unset($arguments[$argumentToBeExcluded]); } } $arguments = \F3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($arguments, $this->arguments); $uri = $this->router->resolve($arguments); $this->lastArguments = $arguments; if ($this->section !== '') { $uri .= '#' . $this->section; } if (!$this->environment->isRewriteEnabled()) { $uri = 'index.php/' . $uri; } if ($this->createAbsoluteUri === TRUE) { $uri = $this->request->getBaseUri() . $uri; } return $uri; }
/** * Checks whether $requestPath 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 string $requestPath the request path without protocol, host and query string * @return boolean TRUE if this Route corresponds to the given $requestPath, otherwise FALSE * @author Bastian Waidelich <*****@*****.**> * @see getMatchResults() */ public function matches($requestPath) { $this->matchResults = NULL; if ($requestPath === NULL) { return FALSE; } if ($this->uriPattern === NULL) { return FALSE; } if (!$this->isParsed) { $this->parse(); } $matchResults = array(); $requestPath = trim($requestPath, '/'); $skipOptionalParts = FALSE; $optionalPartCount = 0; 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($requestPath)) { if ($routePart->isOptional() && $optionalPartCount === 1) { if ($routePart->getDefaultValue() === NULL) { return FALSE; } $skipOptionalParts = TRUE; } else { return FALSE; } } if ($routePart->getValue() !== NULL) { $matchResults[$routePart->getName()] = $routePart->getValue(); } } if (strlen($requestPath) > 0) { return FALSE; } $this->matchResults = \F3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($this->defaults, $matchResults); return TRUE; }
/** * Takes the raw request data and - depending on the request method * maps them into the request object. Afterwards all mapped arguments * can be retrieved by the getArgument(s) method, no matter if they * have been GET, POST or PUT arguments before. * * @param \F3\FLOW3\MVC\Web\Request $request The web request which will contain the arguments * @return void * @author Robert Lemke <*****@*****.**> */ protected function setArgumentsFromRawRequestData(\F3\FLOW3\MVC\Web\Request $request) { foreach ($request->getRequestUri()->getArguments() as $argumentName => $argumentValue) { $request->setArgument($argumentName, $argumentValue); } switch ($request->getMethod()) { case 'POST': foreach ($this->environment->getRawPostArguments() as $argumentName => $argumentValue) { $request->setArgument($argumentName, $argumentValue); } foreach ($this->environment->getUploadedFiles() as $argumentName => $argumentValue) { if ($request->hasArgument($argumentName)) { $existingArgumentValue = $request->getArgument($argumentName); if (is_array($existingArgumentValue)) { $request->setArgument($argumentName, \F3\FLOW3\Utility\Arrays::arrayMergeRecursiveOverrule($existingArgumentValue, $argumentValue)); } } else { $request->setArgument($argumentName, $argumentValue); } } break; # case 'PUT' : # $putArguments = array(); # parse_str(file_get_contents("php://input"), $putArguments); # foreach ($putArguments as $argumentName => $argumentValue) { # $request->setArgument($argumentName, $argumentValue); # } # break; } }