/** * Tries to match a URL path with a set of routes. * * If the matcher can not find information, it must throw one of the * exceptions documented below. * * @param string $pathinfo The path info to be parsed (raw format, i.e. not * urldecoded) * * @return array An array of parameters * * @throws ResourceNotFoundException If the resource could not be found * @throws MethodNotAllowedException If the resource was found but the * request method is not allowed */ public function match($pathinfo) { $urlMatcher = new UrlMatcher($this->routeCollection, $this->getContext()); $result = $urlMatcher->match($pathinfo); if (!empty($result)) { try { // The route matches, now check if it actually exists $result['content'] = $this->contentManager->findActiveBySlug($result['slug']); } catch (NoResultException $e) { try { //is it directory index if (substr($result['slug'], -1) == '/' || $result['slug'] == '') { $result['content'] = $this->contentManager->findActiveBySlug($result['slug'] . 'index'); } else { if ($this->contentManager->findActiveBySlug($result['slug'] . '/index')) { $redirect = new RedirectResponse($this->request->getBaseUrl() . "/" . $result['slug'] . '/'); $redirect->sendHeaders(); exit; } } } catch (NoResultException $ex) { try { $result['content'] = $this->contentManager->findActiveByAlias($result['slug']); } catch (NoResultException $ex) { throw new ResourceNotFoundException('No page found for slug ' . $pathinfo); } } } } return $result; }
/** * Tries to match a URL path with a set of routes. * * If the matcher can not find information, it must throw one of the * exceptions documented below. * * @param string $pathinfo The path info to be parsed (raw format, i.e. not * urldecoded) * * @return array An array of parameters * * @throws ResourceNotFoundException If the resource could not be found */ public function match($pathinfo) { $urlMatcher = new UrlMatcher($this->routeCollection, $this->getContext()); $result = $urlMatcher->match($pathinfo); if (!empty($result)) { // The route matches, now check if it actually exists $slug = $result['slug']; try { //is it directory index if (substr($slug, -1) == '/') { $slug = rtrim($slug, '/'); } $result['content'] = $this->contentManager->findActiveBySlug($slug); } catch (NoResultException $e) { try { $result['content'] = $this->contentManager->findActiveByAlias($slug); } catch (NoResultException $ex) { throw new ResourceNotFoundException('No page found for slug ' . $pathinfo); } } } return $result; }