diff --git a/src/Admin/AdminServiceProvider.php b/src/Admin/AdminServiceProvider.php
index 103bd35df..8e8e598f7 100644
--- a/src/Admin/AdminServiceProvider.php
+++ b/src/Admin/AdminServiceProvider.php
@@ -63,7 +63,7 @@ class AdminServiceProvider extends AbstractServiceProvider
$this->app->bind('flarum.admin.error_handler', function () {
return new HttpMiddleware\HandleErrors(
$this->app->make(Registry::class),
- $this->app['flarum']->inDebugMode() ? $this->app->make(WhoopsFormatter::class) : $this->app->make(ViewFormatter::class),
+ $this->app['flarum.config']->inDebugMode() ? $this->app->make(WhoopsFormatter::class) : $this->app->make(ViewFormatter::class),
$this->app->tagged(Reporter::class)
);
});
diff --git a/src/Api/ApiServiceProvider.php b/src/Api/ApiServiceProvider.php
index 4737d2e8c..83b74f1ce 100644
--- a/src/Api/ApiServiceProvider.php
+++ b/src/Api/ApiServiceProvider.php
@@ -59,7 +59,7 @@ class ApiServiceProvider extends AbstractServiceProvider
$this->app->bind('flarum.api.error_handler', function () {
return new HttpMiddleware\HandleErrors(
$this->app->make(Registry::class),
- new JsonApiFormatter($this->app['flarum']->inDebugMode()),
+ new JsonApiFormatter($this->app['flarum.config']->inDebugMode()),
$this->app->tagged(Reporter::class)
);
});
diff --git a/src/Api/Serializer/ForumSerializer.php b/src/Api/Serializer/ForumSerializer.php
index 9fb0b3fa0..65d53b3fa 100644
--- a/src/Api/Serializer/ForumSerializer.php
+++ b/src/Api/Serializer/ForumSerializer.php
@@ -10,6 +10,7 @@
namespace Flarum\Api\Serializer;
use Flarum\Foundation\Application;
+use Flarum\Foundation\Config;
use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;
@@ -21,9 +22,9 @@ class ForumSerializer extends AbstractSerializer
protected $type = 'forums';
/**
- * @var Application
+ * @var Config
*/
- protected $app;
+ protected $config;
/**
* @var SettingsRepositoryInterface
@@ -36,13 +37,13 @@ class ForumSerializer extends AbstractSerializer
protected $url;
/**
- * @param Application $app
+ * @param Config $config
* @param SettingsRepositoryInterface $settings
* @param UrlGenerator $url
*/
- public function __construct(Application $app, SettingsRepositoryInterface $settings, UrlGenerator $url)
+ public function __construct(Config $config, SettingsRepositoryInterface $settings, UrlGenerator $url)
{
- $this->app = $app;
+ $this->config = $config;
$this->settings = $settings;
$this->url = $url;
}
@@ -66,7 +67,7 @@ class ForumSerializer extends AbstractSerializer
'showLanguageSelector' => (bool) $this->settings->get('show_language_selector', true),
'baseUrl' => $url = $this->url->to('forum')->base(),
'basePath' => parse_url($url, PHP_URL_PATH) ?: '',
- 'debug' => $this->app->inDebugMode(),
+ 'debug' => $this->config->inDebugMode(),
'apiUrl' => $this->url->to('api')->base(),
'welcomeTitle' => $this->settings->get('welcome_title'),
'welcomeMessage' => $this->settings->get('welcome_message'),
diff --git a/src/Console/ConsoleServiceProvider.php b/src/Console/ConsoleServiceProvider.php
index 674927538..0a6ccb5da 100644
--- a/src/Console/ConsoleServiceProvider.php
+++ b/src/Console/ConsoleServiceProvider.php
@@ -14,6 +14,7 @@ use Flarum\Database\Console\MigrateCommand;
use Flarum\Database\Console\ResetCommand;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Console\CacheClearCommand;
+use Flarum\Foundation\Console\InfoCommand;
class ConsoleServiceProvider extends AbstractServiceProvider
{
@@ -26,6 +27,7 @@ class ConsoleServiceProvider extends AbstractServiceProvider
return [
CacheClearCommand::class,
GenerateMigrationCommand::class,
+ InfoCommand::class,
MigrateCommand::class,
ResetCommand::class,
];
diff --git a/src/Forum/ForumServiceProvider.php b/src/Forum/ForumServiceProvider.php
index 1903783d6..bbe609fa5 100644
--- a/src/Forum/ForumServiceProvider.php
+++ b/src/Forum/ForumServiceProvider.php
@@ -73,7 +73,7 @@ class ForumServiceProvider extends AbstractServiceProvider
$this->app->bind('flarum.forum.error_handler', function () {
return new HttpMiddleware\HandleErrors(
$this->app->make(Registry::class),
- $this->app['flarum']->inDebugMode() ? $this->app->make(WhoopsFormatter::class) : $this->app->make(ViewFormatter::class),
+ $this->app['flarum.config']->inDebugMode() ? $this->app->make(WhoopsFormatter::class) : $this->app->make(ViewFormatter::class),
$this->app->tagged(Reporter::class)
);
});
diff --git a/src/Foundation/Console/InfoCommand.php b/src/Foundation/Console/InfoCommand.php
index cfe7671f8..a0f8d4773 100644
--- a/src/Foundation/Console/InfoCommand.php
+++ b/src/Foundation/Console/InfoCommand.php
@@ -12,6 +12,7 @@ namespace Flarum\Foundation\Console;
use Flarum\Console\AbstractCommand;
use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\Application;
+use Flarum\Foundation\Config;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableStyle;
@@ -23,15 +24,15 @@ class InfoCommand extends AbstractCommand
protected $extensions;
/**
- * @var array
+ * @var Config
*/
protected $config;
/**
* @param ExtensionManager $extensions
- * @param array $config
+ * @param Config config
*/
- public function __construct(ExtensionManager $extensions, array $config)
+ public function __construct(ExtensionManager $extensions, Config $config)
{
$this->extensions = $extensions;
$this->config = $config;
@@ -64,11 +65,11 @@ class InfoCommand extends AbstractCommand
$this->getExtensionTable()->render();
- $this->output->writeln('Base URL: '.$this->config['url']);
+ $this->output->writeln('Base URL: '.$this->config->url());
$this->output->writeln('Installation path: '.getcwd());
- $this->output->writeln('Debug mode: '.($this->config['debug'] ? 'ON' : 'off'));
+ $this->output->writeln('Debug mode: '.($this->config->inDebugMode() ? 'ON' : 'off'));
- if ($this->config['debug']) {
+ if ($this->config->inDebugMode()) {
$this->error(
"Don't forget to turn off debug mode! It should never be turned on in a production system."
);
diff --git a/src/Foundation/InstalledApp.php b/src/Foundation/InstalledApp.php
index bc1e18601..f2a024235 100644
--- a/src/Foundation/InstalledApp.php
+++ b/src/Foundation/InstalledApp.php
@@ -9,7 +9,6 @@
namespace Flarum\Foundation;
-use Flarum\Foundation\Console\InfoCommand;
use Flarum\Http\Middleware\DispatchRoute;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Console\Command;
@@ -112,21 +111,14 @@ class InstalledApp implements AppInterface
*/
public function getConsoleCommands()
{
- $commands = [];
+ return array_map(function ($command) {
+ $command = $this->container->make($command);
- // The info command is a special case, as it requires a config parameter that's only available here.
- $commands[] = $this->container->make(InfoCommand::class, ['config' => $this->config]);
-
- foreach ($this->container->make('flarum.console.commands') as $command) {
- $newCommand = $this->container->make($command);
-
- if ($newCommand instanceof Command) {
- $newCommand->setLaravel($this->container);
+ if ($command instanceof Command) {
+ $command->setLaravel($this->container);
}
- $commands[] = $newCommand;
- }
-
- return $commands;
+ return $command;
+ }, $this->container->make('flarum.console.commands'));
}
}
diff --git a/src/Frontend/Content/Assets.php b/src/Frontend/Content/Assets.php
index 50681f876..009973165 100644
--- a/src/Frontend/Content/Assets.php
+++ b/src/Frontend/Content/Assets.php
@@ -9,7 +9,7 @@
namespace Flarum\Frontend\Content;
-use Flarum\Foundation\Application;
+use Flarum\Foundation\Config;
use Flarum\Frontend\Compiler\CompilerInterface;
use Flarum\Frontend\Document;
use Illuminate\Contracts\Container\Container;
@@ -19,17 +19,17 @@ use Psr\Http\Message\ServerRequestInterface as Request;
class Assets
{
protected $container;
- protected $app;
+ protected $config;
/**
* @var \Flarum\Frontend\Assets
*/
protected $assets;
- public function __construct(Container $container, Application $app)
+ public function __construct(Container $container, Config $config)
{
$this->container = $container;
- $this->app = $app;
+ $this->config = $config;
}
public function forFrontend(string $name)
@@ -48,7 +48,7 @@ class Assets
'css' => [$this->assets->makeCss(), $this->assets->makeLocaleCss($locale)]
];
- if ($this->app->inDebugMode()) {
+ if ($this->config->inDebugMode()) {
$this->commit(Arr::flatten($compilers));
}
diff --git a/src/Http/CookieFactory.php b/src/Http/CookieFactory.php
index 4a9eff3a3..5c36cb39b 100644
--- a/src/Http/CookieFactory.php
+++ b/src/Http/CookieFactory.php
@@ -11,8 +11,7 @@ namespace Flarum\Http;
use Dflydev\FigCookies\Modifier\SameSite;
use Dflydev\FigCookies\SetCookie;
-use Flarum\Foundation\Application;
-use Illuminate\Support\Arr;
+use Flarum\Foundation\Config;
class CookieFactory
{
@@ -52,19 +51,19 @@ class CookieFactory
protected $samesite;
/**
- * @param Application $app
+ * @param Config $config
*/
- public function __construct(Application $app)
+ public function __construct(Config $config)
{
- // Parse the forum's base URL so that we can determine the optimal cookie settings
- $url = parse_url(rtrim($app->url(), '/'));
+ // If necessary, we will use the forum's base URL to determine smart defaults for cookie settings
+ $url = $config->url();
// Get the cookie settings from the config or use the default values
- $this->prefix = $app->config('cookie.name', 'flarum');
- $this->path = $app->config('cookie.path', Arr::get($url, 'path') ?: '/');
- $this->domain = $app->config('cookie.domain');
- $this->secure = $app->config('cookie.secure', Arr::get($url, 'scheme') === 'https');
- $this->samesite = $app->config('cookie.samesite');
+ $this->prefix = $config['cookie.name'] ?? 'flarum';
+ $this->path = $config['cookie.path'] ?? $url->getPath() ?: '/';
+ $this->domain = $config['cookie.domain'];
+ $this->secure = $config['cookie.secure'] ?? $url->getScheme() === 'https';
+ $this->samesite = $config['cookie.samesite'];
}
/**
diff --git a/src/Update/Controller/UpdateController.php b/src/Update/Controller/UpdateController.php
index 4668fcebb..5b5bf4959 100644
--- a/src/Update/Controller/UpdateController.php
+++ b/src/Update/Controller/UpdateController.php
@@ -11,7 +11,7 @@ namespace Flarum\Update\Controller;
use Exception;
use Flarum\Database\Console\MigrateCommand;
-use Flarum\Foundation\Application;
+use Flarum\Foundation\Config;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response;
use Laminas\Diactoros\Response\HtmlResponse;
@@ -26,18 +26,18 @@ class UpdateController implements RequestHandlerInterface
protected $command;
/**
- * @var Application
+ * @var Config
*/
- protected $app;
+ protected $config;
/**
* @param MigrateCommand $command
- * @param Application $app
+ * @param Config $config
*/
- public function __construct(MigrateCommand $command, Application $app)
+ public function __construct(MigrateCommand $command, Config $config)
{
$this->command = $command;
- $this->app = $app;
+ $this->config = $config;
}
/**
@@ -48,7 +48,7 @@ class UpdateController implements RequestHandlerInterface
{
$input = $request->getParsedBody();
- if (Arr::get($input, 'databasePassword') !== $this->app->config('database.password')) {
+ if (Arr::get($input, 'databasePassword') !== $this->config['database.password']) {
return new HtmlResponse('Incorrect database password.', 500);
}