Check if Flarum is in debug mode.
public inDebugMode ( ) : boolean | ||
Результат | boolean |
public function handle(Exception $e) { if ($e instanceof JsonApiSerializableInterface) { $status = $e->getStatusCode(); $errors = $e->getErrors(); } elseif ($e instanceof ValidationException) { $status = 422; $errors = $e->errors()->toArray(); $errors = array_map(function ($field, $messages) { return ['detail' => implode("\n", $messages), 'source' => ['pointer' => '/data/attributes/' . $field]]; }, array_keys($errors), $errors); } elseif ($e instanceof ModelNotFoundException) { $status = 404; $errors = []; } else { $status = 500; $error = ['code' => $status, 'title' => 'Internal Server Error']; if ($this->app->inDebugMode()) { $error['detail'] = (string) $e; } $errors = [$error]; } $document = new Document(); $document->setErrors($errors); return new JsonApiResponse($document, $status); }
/** * {@inheritdoc} */ protected function getDefaultAttributes($model) { $attributes = ['title' => $this->settings->get('forum_title'), 'description' => $this->settings->get('forum_description'), 'baseUrl' => $url = $this->app->url(), 'basePath' => parse_url($url, PHP_URL_PATH) ?: '', 'debug' => $this->app->inDebugMode(), 'apiUrl' => $this->app->url('api'), 'welcomeTitle' => $this->settings->get('welcome_title'), 'welcomeMessage' => $this->settings->get('welcome_message'), 'themePrimaryColor' => $this->settings->get('theme_primary_color'), 'themeSecondaryColor' => $this->settings->get('theme_secondary_color'), 'logoUrl' => $this->getLogoUrl(), 'faviconUrl' => $this->getFaviconUrl(), 'headerHtml' => $this->settings->get('custom_header'), 'allowSignUp' => (bool) $this->settings->get('allow_sign_up'), 'defaultRoute' => $this->settings->get('default_route'), 'canViewDiscussions' => $this->actor->can('viewDiscussions'), 'canStartDiscussion' => $this->actor->can('startDiscussion')]; if ($this->actor->can('administrate')) { $attributes['adminUrl'] = $this->app->url('admin'); $attributes['version'] = $this->app->version(); } return $attributes; }
/** * {@inheritdoc} */ protected function getDefaultAttributes($model) { $gate = $this->gate->forUser($this->actor); $attributes = ['title' => $this->settings->get('forum_title'), 'description' => $this->settings->get('forum_description'), 'baseUrl' => $url = $this->app->url(), 'basePath' => parse_url($url, PHP_URL_PATH) ?: '', 'debug' => $this->app->inDebugMode(), 'apiUrl' => $this->app->url('api'), 'welcomeTitle' => $this->settings->get('welcome_title'), 'welcomeMessage' => $this->settings->get('welcome_message'), 'themePrimaryColor' => $this->settings->get('theme_primary_color'), 'allowSignUp' => (bool) $this->settings->get('allow_sign_up'), 'defaultRoute' => $this->settings->get('default_route'), 'canViewDiscussions' => $gate->allows('viewDiscussions') || $this->actor->hasPermissionLike('viewDiscussions'), 'canStartDiscussion' => $gate->allows('startDiscussion') || $this->actor->hasPermissionLike('startDiscussion')]; if ($gate->allows('administrate')) { $attributes['adminUrl'] = $this->app->url('admin'); $attributes['version'] = $this->app->version(); } return $attributes; }
/** * {@inheritdoc} */ protected function getMiddleware(Application $app) { $pipe = new MiddlewarePipe(); $path = parse_url($app->url(), PHP_URL_PATH); $errorDir = __DIR__ . '/../../error'; if (!$app->isInstalled()) { $app->register('Flarum\\Install\\InstallServiceProvider'); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.install.routes')])); $pipe->pipe($path, new HandleErrors($errorDir, true)); } elseif ($app->isUpToDate() && !$app->isDownForMaintenance()) { $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\RememberFromCookie')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithSession')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\SetLocale')); event(new ConfigureMiddleware($pipe, $path, $this)); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')])); $pipe->pipe($path, new HandleErrors($errorDir, $app->inDebugMode())); } else { $pipe->pipe($path, function () use($errorDir) { return new HtmlResponse(file_get_contents($errorDir . '/503.html', 503)); }); } return $pipe; }
/** * {@inheritdoc} */ protected function getMiddleware(Application $app) { $pipe = new MiddlewarePipe(); if ($app->isInstalled()) { $app->register('Flarum\\Admin\\AdminServiceProvider'); $adminPath = parse_url($app->url('admin'), PHP_URL_PATH); $routes = $app->make('flarum.admin.routes'); $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithCookie')); $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody')); $pipe->pipe($adminPath, $app->make('Flarum\\Admin\\Middleware\\RequireAdministrateAbility')); $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', compact('routes'))); $pipe->pipe(new HandleErrors(__DIR__ . '/../../error', $app->inDebugMode())); } return $pipe; }
/** * {@inheritdoc} */ protected function getMiddleware(Application $app) { $pipe = new MiddlewarePipe(); $installed = $app->isInstalled(); $basePath = parse_url($app->url(), PHP_URL_PATH); if ($installed) { $app->register('Flarum\\Forum\\ForumServiceProvider'); $routes = $app->make('flarum.forum.routes'); $pipe->pipe($basePath, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithCookie')); $pipe->pipe($basePath, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody')); } else { $app->register('Flarum\\Install\\InstallServiceProvider'); $routes = $app->make('flarum.install.routes'); } $pipe->pipe($basePath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', compact('routes'))); $pipe->pipe(new HandleErrors(__DIR__ . '/../../error', $app->inDebugMode() || !$installed)); return $pipe; }
/** * {@inheritdoc} */ protected function getMiddleware(Application $app) { $pipe = new MiddlewarePipe(); if ($app->isInstalled()) { $adminPath = parse_url($app->url('admin'), PHP_URL_PATH); $errorDir = __DIR__ . '/../../error'; if ($app->isUpToDate()) { $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithCookie')); $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody')); $pipe->pipe($adminPath, $app->make('Flarum\\Admin\\Middleware\\RequireAdministrateAbility')); $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.admin.routes')])); $pipe->pipe($adminPath, new HandleErrors($errorDir, $app->inDebugMode())); } else { $app->register('Flarum\\Update\\UpdateServiceProvider'); $pipe->pipe($adminPath, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.update.routes')])); $pipe->pipe($adminPath, new HandleErrors($errorDir, true)); } } return $pipe; }
/** * Get the string contents of the view. * * @param Request $request * @return string */ public function render(Request $request) { $forum = $this->getForumDocument($request); $this->view->share('translator', $this->locales->getTranslator()); $this->view->share('allowJs', !array_get($request->getQueryParams(), 'nojs')); $this->view->share('forum', array_get($forum, 'data')); $this->view->share('debug', $this->app->inDebugMode()); $view = $this->view->file(__DIR__ . '/../../../views/app.blade.php'); $view->title = $this->buildTitle(array_get($forum, 'data.attributes.title')); $view->description = $this->description; $view->modules = $this->modules; $view->payload = $this->buildPayload($request, $forum); $view->layout = $this->buildLayout(); $baseUrl = array_get($forum, 'data.attributes.baseUrl'); $view->cssUrls = $this->buildCssUrls($baseUrl); $view->jsUrls = $this->buildJsUrls($baseUrl); $view->head = implode("\n", $this->head); $view->foot = implode("\n", $this->foot); return $view->render(); }