mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 09:41:49 +08:00
Inject/use new config class where applicable
This commit is contained in:
parent
f869999011
commit
6639678fb2
|
@ -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)
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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,
|
||||
];
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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('<info>Base URL:</info> '.$this->config['url']);
|
||||
$this->output->writeln('<info>Base URL:</info> '.$this->config->url());
|
||||
$this->output->writeln('<info>Installation path:</info> '.getcwd());
|
||||
$this->output->writeln('<info>Debug mode:</info> '.($this->config['debug'] ? 'ON' : 'off'));
|
||||
$this->output->writeln('<info>Debug mode:</info> '.($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."
|
||||
);
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user