Пример #1
0
 /**
  * Resolve finding informations
  * resolve, baseRoute, middlewares, config, attributes
  */
 public function resolve()
 {
     $this->baseRoute = null;
     foreach ($this->route->getFullRoutes() as $route) {
         // get the latest module and route base
         if ($route->hasProperty('module')) {
             $this->module = $route->getProperty('module');
         }
         // stack all the handlers
         foreach ($route->getLevel()->getHandlers() as $name => $handler) {
             $this->handlers[$name] = $handler;
         }
         // if has parameter base, and it's true, set base route to the current route.
         if ($route->hasProperty('base') && $route->getProperty('base') === true) {
             $this->baseRoute = $route->getAbsoluteName();
         }
         foreach ($route->getLevel()->getMiddlewares() as $middleware) {
             $this->middlewares[] = $middleware;
         }
         // append all route middlewares
         foreach ($route->getProperty('middleware') as $middleware) {
             $this->middlewares[] = $middleware;
         }
         foreach ($route->getAttributes() as $key => $value) {
             $this->attributes[$key] = $value;
         }
         // pass conig.
         if ($route->hasProperty('config')) {
             $this->config = array_merge($this->config, $route->getProperty('config'));
         }
     }
 }
Пример #2
0
 /**
  * Inversely add middleware on upper route
  * If there's this level is on the top (not route dependant), register middleware on app
  * @param mixed $middleware
  * @return $this
  */
 public function addMiddleware($middleware)
 {
     if ($this->route) {
         $this->route->addMiddleware($middleware);
     } else {
         $this->middlewares[] = $middleware;
     }
     return $this;
 }