handle(RouterBase::getInstance()->getRequest()); } } // Set default namespace $defaultNamespace = '\\Demo\\Controllers'; parent::start($defaultNamespace); } catch(\Exception $e) { $route = RouterBase::getInstance()->getLoadedRoute(); // Otherwise use the fallback default exceptions handler if(static::$defaultExceptionHandler !== null) { static::loadExceptionHandler(static::$defaultExceptionHandler, $route, $e); } throw $e; } } protected static function loadExceptionHandler($class, $route, $e) { $class = new $class(); if(!($class instanceof IExceptionHandler)) { throw new \ErrorException('Exception handler must be an instance of \Pecee\Handler\IExceptionHandler'); } $class->handleError(RouterBase::getInstance()->getRequest(), $route, $e); } public static function defaultExceptionHandler($handler) { static::$defaultExceptionHandler = $handler; } /** * Add default middleware that will be loaded before any route * @param string|array $middlewares */ public static function defaultMiddleware($middlewares) { if(is_array($middlewares)) { static::$defaultMiddlewares = $middlewares; } else { static::$defaultMiddlewares[] = $middlewares; } } }