예제 #1
0
 /**
  * {@inheritDoc}
  */
 protected function getActionName(Request $request, $name)
 {
     if ($name !== strtolower($name)) {
         throw new HttpNotFoundException('The action name must contain only lowercase letters');
     }
     return StringUtils::toLowerCamelcase($name) . 'Action';
 }
예제 #2
0
 /**
  * Returns the fully qualified controller class.
  *
  * @param string $name The fragment of controller name.
  * @return string
  * @throws HttpException
  */
 protected function getController($name)
 {
     if ($name !== strtolower($name)) {
         throw new HttpNotFoundException('The controller name must contain only lowercase letters.');
     }
     $controller = sprintf('%s\\%sController', $this->namespace, StringUtils::toUpperCamelcase($name));
     if (!class_exists($controller, true)) {
         throw new HttpNotFoundException(sprintf('Controller "%s" can not be found.', $controller));
     }
     return $controller;
 }
예제 #3
0
 /**
  * {@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;
 }