/** * {@inheritDoc} */ public function match(Request $request) { $path = $request->getPathInfo(); if (StringUtils::forgetsTrailingSlash($path, $this->prefix)) { throw new HttpRedirectException($request->getBaseUrl() . $path . '/', 301); } if (StringUtils::startsWith($path, $this->prefix)) { $fragments = array_filter(explode('/', substr($path, strlen($this->prefix))), 'strlen'); if (count($fragments) <= 1 && substr($path, -1) !== '/') { throw new HttpRedirectException(RequestUtils::completeTrailingSlash($request), 301); } $controller = empty($fragments[0]) ? 'index' : $fragments[0]; $controller = $this->getController($controller); $action = empty($fragments[1]) ? 'index' : $fragments[1]; $params = array_slice($fragments, 2); return new MatchedRoute($controller, $action, $params); } return null; }
/** * {@inheritDoc} */ public function match(Request $request) { $path = $request->getPathInfo(); if (StringUtils::forgetsTrailingSlash($path, $this->prefix)) { throw new HttpRedirectException(RequestUtils::completeTrailingSlash($request), 301); } if (StringUtils::startsWith($path, $this->prefix)) { $fragments = array_filter(explode('/', substr($path, strlen($this->prefix))), 'strlen'); if (empty($fragments[0])) { $action = 'index'; $params = []; } elseif (!isset($fragments[1])) { $action = 'show'; $params = [$fragments[0]]; } else { $action = empty($fragments[1]) ? 'index' : $fragments[1]; $params = array_merge([$fragments[0]], array_slice($fragments, 2)); } return new MatchedRoute($this->controller, $action, $params); } return null; }