Inject SettingsRepository where possible

This commit is contained in:
Franz Liedke 2015-07-16 00:32:50 +02:00
parent 31e9f44dfb
commit c2bf0b6b3a
3 changed files with 40 additions and 12 deletions

View File

@ -1,5 +1,6 @@
<?php namespace Flarum\Core\Users\Commands;
use Flarum\Core\Settings\SettingsRepository;
use Flarum\Core\Users\PasswordToken;
use Flarum\Core\Users\UserRepository;
use Illuminate\Contracts\Mail\Mailer;
@ -15,19 +16,31 @@ class RequestPasswordResetHandler
*/
protected $users;
/**
* @var SettingsRepository
*/
protected $settings;
/**
* @var Mailer
*/
protected $mailer;
/**
* @var UrlGeneratorInterface
*/
protected $url;
/**
* @param UserRepository $users
* @param SettingsRepository $settings
* @param Mailer $mailer
* @param UrlGeneratorInterface $url
*/
public function __construct(UserRepository $users, Mailer $mailer, UrlGeneratorInterface $url)
public function __construct(UserRepository $users, SettingsRepository $settings, Mailer $mailer, UrlGeneratorInterface $url)
{
$this->users = $users;
$this->settings = $settings;
$this->mailer = $mailer;
$this->url = $url;
}
@ -53,8 +66,8 @@ class RequestPasswordResetHandler
// password route be part of core??
$data = [
'username' => $user->username,
'url' => Core::config('base_url').'/reset/'.$token->id,
'forumTitle' => Core::config('forum_title')
'url' => $this->settings->get('base_url').'/reset/'.$token->id,
'forumTitle' => $this->settings->get('forum_title'),
];
$this->mailer->send(['text' => 'flarum::emails.resetPassword'], $data, function (Message $message) use ($user) {

View File

@ -1,5 +1,6 @@
<?php namespace Flarum\Core\Users\Listeners;
use Flarum\Core\Settings\SettingsRepository;
use Flarum\Core\Users\Events\UserWasRegistered;
use Flarum\Core\Users\Events\UserEmailChangeWasRequested;
use Flarum\Core;
@ -11,16 +12,23 @@ use Illuminate\Mail\Message;
class EmailConfirmationMailer
{
/**
* @var SettingsRepository
*/
protected $settings;
/**
* @var Mailer
*/
protected $mailer;
/**
* @param SettingsRepository $settings
* @param Mailer $mailer
*/
public function __construct(Mailer $mailer)
public function __construct(SettingsRepository $settings, Mailer $mailer)
{
$this->settings = $settings;
$this->mailer = $mailer;
}
@ -90,8 +98,8 @@ class EmailConfirmationMailer
// email route be part of core??
return [
'username' => $user->username,
'url' => Core::config('base_url').'/confirm/'.$token->id,
'forumTitle' => Core::config('forum_title')
'url' => $this->settings->get('base_url').'/confirm/'.$token->id,
'forumTitle' => $this->settings->get('forum_title')
];
}
}

View File

@ -5,6 +5,7 @@ use Flarum\Assets\AssetManager;
use Flarum\Assets\JsCompiler;
use Flarum\Assets\LessCompiler;
use Flarum\Core;
use Flarum\Core\Settings\SettingsRepository;
use Flarum\Core\Users\User;
use Flarum\Locale\JsCompiler as LocaleJsCompiler;
use Flarum\Locale\LocaleManager;
@ -61,14 +62,20 @@ abstract class ClientAction extends HtmlAction
*/
protected $locales;
/**
* @var SettingsRepository
*/
protected $settings;
/**
* @param Client $apiClient
* @param LocaleManager $locales
*/
public function __construct(Client $apiClient, LocaleManager $locales)
public function __construct(Client $apiClient, LocaleManager $locales, SettingsRepository $settings)
{
$this->apiClient = $apiClient;
$this->locales = $locales;
$this->settings = $settings;
}
/**
@ -156,7 +163,7 @@ abstract class ClientAction extends HtmlAction
$assets->addLess("@$name: $value;");
}
$assets->addLess(Core::config('custom_less'));
$assets->addLess($this->settings->get('custom_less'));
}
/**
@ -168,10 +175,10 @@ abstract class ClientAction extends HtmlAction
protected function getLessVariables()
{
return [
'fl-primary-color' => Core::config('theme_primary_color', '#000'),
'fl-secondary-color' => Core::config('theme_secondary_color', '#000'),
'fl-dark-mode' => Core::config('theme_dark_mode') ? 'true' : 'false',
'fl-colored-header' => Core::config('theme_colored_header') ? 'true' : 'false'
'fl-primary-color' => $this->settings->get('theme_primary_color', '#000'),
'fl-secondary-color' => $this->settings->get('theme_secondary_color', '#000'),
'fl-dark-mode' => $this->settings->get('theme_dark_mode') ? 'true' : 'false',
'fl-colored-header' => $this->settings->get('theme_colored_header') ? 'true' : 'false'
];
}