예제 #1
0
 public function sortRoutes()
 {
     if (empty($this->routes)) {
         if ($files = $this->resolver->getRoutes()) {
             foreach ($files as $file) {
                 $dir = dirname($file, 2);
                 /** @var Router $router */
                 $router = (new Injector())->make('Minute\\Routing\\Router');
                 require_once $file;
                 $routes = $router->getRouteCollection();
                 /** @var Route $route */
                 foreach ($routes as $route) {
                     $method = $route->getMethods()[0];
                     $defaults = $route->getDefaults();
                     if ($controller = $defaults['controller']) {
                         $parts = explode('@', $controller, 2);
                         list($classPath, $fn) = [$this->utils->unixPath($parts[0]), $parts[1] ?? 'index'];
                     } else {
                         list($classPath, $fn) = [null, 'index'];
                     }
                     $classPath = preg_replace('/\\.php$/', '', $classPath);
                     $path = $this->utils->unixPath(sprintf('%s/Controller/%s.php', $dir, $classPath));
                     $action = [$this->resolver->getController($classPath), $fn];
                     $this->routes[] = array_merge($defaults, ['route' => $route, 'controller' => $controller, 'dir' => $dir, 'path' => $path, 'classPath' => $classPath, 'fn' => $fn, 'action' => $action, 'method' => $method]);
                 }
             }
         }
     }
     return $this->routes;
 }
예제 #2
0
 /**
  * Find all route.php files and add them to route collection
  */
 public function compile()
 {
     if ($files = $this->resolver->getRoutes()) {
         /** @noinspection PhpUnusedLocalVariableInspection - is accessed in routes.php file */
         $router = $this;
         foreach ($files as $file) {
             require_once $file;
         }
     }
     return $this;
 }