Exemple #1
0
 protected function createCommand(Route $route)
 {
     $class = "App\\" . ucfirst($route->getModule()) . "\\Execuor\\" . ucfirst($route->getController()) . "Execuor";
     $method = $route->getAction();
     $controller = $this->get($class);
     //$controller->callMiddleware();
     $action = [$controller, $method];
     return $action;
 }
Exemple #2
0
 protected function createAction(Route $route)
 {
     $class = "App\\" . ucfirst($route->getModule()) . "\\Controller\\" . ucfirst($route->getPrefix()) . "\\" . ucfirst($route->getController()) . "Controller";
     $method = $route->getAction();
     $controller = $this->get($class);
     $controller->callMiddleware();
     $action = [$controller, $method];
     return $action;
 }
Exemple #3
0
 /**
 * 类似下面这种形式的配置文件
     ['route' => '/', 'module'=> 'core', 'controller' => 'index', 'action' => 'index'],
     ['route' => 'user/<id:\d+>/', 'module'=> 'user', 'controller' => 'user', 'action' => 'show', 'params' => ['param1'=>'p1', 'param2'=>'p2']],
     ['route' => 'product/list', 'module'=> 'product', 'controller' => 'product', 'action' => 'index', 'params' => ['param1'=>'p1', 'param2'=>'p2']]
 */
 public function addRoute($config = [])
 {
     if (count($config) < 3) {
         throw new Exception("route config is not valid");
     }
     list($method, $pattern, $mca) = $config;
     $template = '/' . trim($pattern, '/') . '/';
     $routeObject = new Route();
     $routeObject->setPrefix($this->_prefix);
     $routeObject->setRoute($pattern);
     $routeObject->setPattern($pattern);
     $routeObject->setMethod($method);
     $tmp = explode('/', $mca);
     if (count($tmp) < 3) {
         throw new Exception("route mca is not valid");
     }
     $routeObject->setModule($tmp[0]);
     $routeObject->setController($tmp[1]);
     $routeObject->setAction($tmp[2]);
     if (preg_match_all('/<(\\w+):?(.*?)?>/', $pattern, $matches)) {
         $params = [];
         for ($i = 0; $i < count($matches[0]); $i++) {
             $params[$i] = $matches[1][$i];
             $reg = $matches[2][$i] ? $matches[2][$i] : '.*';
             $pattern = str_replace($matches[0][$i], "({$reg})", $pattern);
             $template = str_replace($matches[0][$i], "{{$matches[1][$i]}}", $template);
         }
         $pattern = str_replace('/', '\\/', $pattern);
         $pattern = "/^{$pattern}\$/";
         $routeObject->setPattern($pattern);
         $routeObject->setTemplate($template);
         $routeObject->setRegular(true);
         $routeObject->setParams($params);
     }
     $this->_routes[$pattern] = $routeObject;
 }
Exemple #4
0
 protected function createAction(Route $route)
 {
     $class = "App\\" . ucfirst($route->getModule()) . "\\Controller\\" . ucfirst($route->getPrefix()) . "\\" . ucfirst($route->getController()) . "Controller";
     if (!class_exists($class)) {
         $prefixs = $route->getALLPrefix();
         if ($prefixs) {
             foreach ($prefixs as $v) {
                 $class = "App\\" . ucfirst($route->getModule()) . "\\Controller\\" . ucfirst($v) . "\\" . ucfirst($route->getController()) . "Controller";
                 if (class_exists($class)) {
                     $route->setPrefix($v);
                     break;
                 }
             }
         }
     }
     $method = $route->getAction();
     $controller = $this->get($class);
     $controller->callMiddleware();
     $action = [$controller, $method];
     return $action;
 }
Exemple #5
0
 public function getRouteByPath($path = '/')
 {
     $mca = explode('/', $path);
     $route = new Route();
     $route->setModule(!empty($mca[0]) ? $mca[0] : $this->getDefaultModule());
     $route->setController(!empty($mca[1]) ? $mca[1] : $this->getDefaultController());
     $route->setAction(!empty($mca[2]) ? $mca[2] : $this->getDefaultAction());
     return $route;
 }
Exemple #6
0
 public function setRoute(\Kerisy\Core\Route $route)
 {
     $this->setParams($route->getParams());
     $this->_route = $route;
 }