public function parametersToString(array $parameters) { $pieces = array(); foreach ($parameters as $key => $val) { $pieces[] = sprintf('"%s": "%s"', $key, is_string($val) ? $val : json_encode($val)); } return implode(', ', $pieces); }
/** * Perform the matching of a route and return a set of routing parameters if a valid one is found. * Otherwise exceptions get thrown. * * @param HttpRequest $request * * @throws \Exception * * @return array */ protected function handleRouting(HttpRequest $request) { $this->router = $this->serviceManager->get('Router'); $this->router->warmUp($this->getCacheDir()); try { // Lets load up our router and match the appropriate route $parameters = $this->router->matchRequest($request); if (!empty($parameters)) { if (null !== $this->logger) { $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->router->parametersToString($parameters))); } } } catch (ResourceNotFoundException $e) { $routeUri = $this->router->generate('Framework_404'); $parameters = $this->router->matchRequest($request::create($routeUri)); } catch (\Exception $e) { throw $e; } $parameters['_route_params'] = $parameters; return $parameters; }