コード例 #1
0
 public function resolve(RouteMatch $routeMatch)
 {
     $name = $routeMatch->getMatchedRouteName();
     if (strpos(strrev($name), '/') === 0) {
         return $name . 'index' . $this->suffix;
     } else {
         return $name . $this->suffix;
     }
 }
コード例 #2
0
ファイル: Route.php プロジェクト: impress-php/framework
 public static function controller($controllerClassName, array $options = array())
 {
     $controllerClassName = trim($controllerClassName, "\\");
     $class = "\\App\\Http\\Controllers\\" . $controllerClassName;
     $classMethods = get_class_methods($class);
     if (is_null($classMethods)) {
         return null;
     }
     $diffClassMethods = array_merge(get_class_methods('\\Impress\\Framework\\Http\\Controller') ?: [], get_class_methods(get_parent_class($class)) ?: [], ['__construct', '__destruct', '__clone', '__get', '__set', '__call', '__callStatic', '__sleep', '__wakeup', '__clone']);
     $classMethods = array_unique(array_diff($classMethods, $diffClassMethods));
     if (!$classMethods) {
         return null;
     }
     $routes = array();
     foreach ($classMethods as $m) {
         if (!preg_match('/([a-z])/', substr($m, 0, 1))) {
             continue;
         }
         $methodStr = trim(strtolower(preg_replace('/([A-Z])/', '_$1', $m)), '_');
         if (($pos = strpos($methodStr, "_")) === false) {
             continue;
         }
         $method = strtolower(substr($methodStr, 0, $pos));
         $path = substr($methodStr, $pos + 1);
         $path = rtrim($path, "index");
         $controller = "{$controllerClassName}@{$m}";
         //name
         if (isset($options['name']) || isset($options['as'])) {
             if (isset($options['as'])) {
                 $options['name'] = $options['as'];
             }
             $options['name'] = $options['name'] . "@{$m}";
         }
         $routes[] = RouteMatch::addRoute(self::makeRouteMatchOptions($path, $controller, $method, $options));
     }
     return $routes;
 }
コード例 #3
0
ファイル: RouteCache.php プロジェクト: impress-php/framework
 public static function work($routesFile)
 {
     if (env("ROUTES_NO_CACHE", false)) {
         self::workRoute($routesFile);
     } else {
         self::makeCache($routesFile) ?: RouteMatch::setRoutes(self::$cacheRoutesContent);
     }
 }