addRoutingMiddleware(); /** * Add Error Handling Middleware * * @param bool $displayErrorDetails -> Should be set to false in production * @param bool $logErrors -> Parameter is passed to the default ErrorHandler * @param bool $logErrorDetails -> Display error details in error log * which can be replaced by a callable of your choice. * Note: This middleware should be added last. It will not handle any exceptions/errors * for middleware added after it. */ $errorMiddleware = self::$app->addErrorMiddleware( env('displayError', false), env('logErrors', false), env('logErrorDetails', false) ); } private static function loadEnv() { try { self::$env = Dotenv::createImmutable(__DIR__ . '/..')->load(); } catch (InvalidPathException $e) { // no env file present } } public static function app() { return self::$app; } public static function env(string $key, $default = null) { $value = getenv($key); if ($value === false) { return $default; } switch (strtolower($value)) { case 'true': case '(true)': return true; case 'false': case '(false)': return false; case 'empty': case '(empty)': return ''; case 'null': case '(null)': return; } // if (Str::startsWith($value, '"') && Str::endsWith($value, '"')) { // return substr($value, 1, -1); // } return $value; } public static function run() { self::_build(); self::$app->run(); } }