Esempio n. 1
0
 public static function boot(Route $route)
 {
     if (!empty($route->middleware())) {
         foreach ($route->middleware() as $middleware) {
             self::$name = $middleware;
             $namespace = File::find($middleware, 'Middleware');
             $class = new $namespace();
             $call = $class->run(self::$request, self::$response);
             if (is_subclass_of($call, Middleware::class) !== TRUE) {
                 throw new MiddlewareException("':middleware' does not return instance of Stativo\\App\\Middleware", [':middleware' => $middleware]);
             }
         }
     }
     return TRUE;
 }
Esempio n. 2
0
 /**
  * Configuration handler
  *
  * Loads configuration from an array file en returns
  *
  * @uses  Stativo\Helpers\File
  * @uses  Stativo\Helpers\MainException
  *
  * @param  string $config config file name
  * @return collection collection of config file
  */
 public static function config($config)
 {
     $file = File::find($config, 'Config', true);
     if (file_exists($file) === false) {
         throw new \Stativo\Helpers\MainException('Cannot find `:file` config. Path: :path', [':file' => $config, ':path' => $file]);
     }
     return collect(include $file);
 }
Esempio n. 3
0
 /**
  * Constructing Auth
  */
 public function __construct()
 {
     $ns = \Stativo\Helpers\File::find('User', 'Model');
     $this->_userModel = new $ns();
     $this->_config = config('auth');
 }
Esempio n. 4
0
 /**
  * Will execute the called request, also checks if the request
  * parameters are correct (like: Method and Middleware)
  *
  * @uses Stativo\Core\Middleware
  * @uses Stativo\Core\Route
  * @uses Stativo\Helpers\HttpException
  * @uses Stativo\Helpers\MiddlewareException
  * @return this
  */
 public function execute()
 {
     self::$_server = $_SERVER;
     self::$_get = $_GET;
     self::$_post = $_POST;
     self::$_put = $_POST;
     self::$_delete = $_POST;
     // Check if HTTP methods are set
     if (isset(self::$_post['__method'])) {
         // if __method isset, then use them
         if (strtolower(self::$_post['__method']) == strtolower(Route::PUT) or strtolower(self::$_post['__method']) == strtolower(Route::DELETE)) {
             self::$_method = self::$_post['__method'];
         } else {
             // Use default method
             self::$_method = $_SERVER['REQUEST_METHOD'];
         }
     } else {
         // Use default method
         self::$_method = $_SERVER['REQUEST_METHOD'];
     }
     unset(self::$_post['__method']);
     unset(self::$_put['__method']);
     unset(self::$_delete['__method']);
     // Match URI's in Stativo\Core\Route
     $match = $this->process_uri(Request::instance());
     // Check matches
     if ($match === null) {
         // Throw Stativo\Helpers\HttpException (404)
         throw new HttpException(404, 'URI /:uri is not found!', array(':uri' => $this->uri()));
     } else {
         // Match successful!
         $controller = '';
         $action = 'index';
         if (isset($match['params']['directory'])) {
             $controller .= str_replace('/', '\\', $match['params']['directory'] . '/');
             unset($match['params']['directory']);
         }
         if (isset($match['params']['controller'])) {
             $controller .= $match['params']['controller'];
             unset($match['params']['controller']);
         }
         if (isset($match['params']['action'])) {
             $action = $match['params']['action'];
             unset($match['params']['action']);
         }
         // Get current route
         $route = Route::current();
         // Check methods, if they compare then launch class and action
         if ($route->_method === Route::ANY or in_array(self::$_method, !is_array($route->_method) ? array($route->_method) : $route->_method)) {
             if ($middleware = Middleware::boot($route)) {
                 self::$_params = $match['params'];
                 // Find required controller
                 $controller = File::find($controller, 'Controller');
                 // Call classes
                 $class = new $controller();
                 $class->{$action}();
                 \Stativo\Helpers\Power::runOff();
             } else {
                 throw new MiddlewareException("':middleware' encountered an error!", [':middleware' => Middleware::$name]);
             }
         } else {
             // Throw Stativo\Helpers\HttpException, method mismatch
             throw new HttpException(500, 'Route method mismatch, Expected: :method request', [':method' => is_array($route->_method) ? implode(', ', $route->_method) : $route->_method]);
         }
     }
     return Response::instance();
 }
Esempio n. 5
0
 /**
  * Returns view rendered by Blade on the View layer
  *
  * @param  mixed
  * @return void
  */
 function view($view)
 {
     $v = new Blade(File::find($view, 'View', true, true), APPPATH . 'Cache');
     return $v->view()->make($view);
 }