mirror of
https://github.com/flarum/core.git
synced 2025-10-18 10:16:09 +02:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<?php namespace Flarum\Core;
|
||||
|
||||
use Flarum\Core\Settings\MemoryCacheSettingsRepository;
|
||||
use Flarum\Core\Settings\DatabaseSettingsRepository;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Support\ServiceProvider;
|
||||
use Flarum\Extend;
|
||||
@@ -31,6 +33,14 @@ class CoreServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('Flarum\Core\Settings\SettingsRepository', function() {
|
||||
return new MemoryCacheSettingsRepository(
|
||||
new DatabaseSettingsRepository(
|
||||
$this->app->make('Illuminate\Database\ConnectionInterface')
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
$this->app->singleton('flarum.forum', 'Flarum\Core\Forum');
|
||||
|
||||
// TODO: probably use Illuminate's AggregateServiceProvider
|
||||
|
@@ -3,7 +3,6 @@
|
||||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Flarum\Core\Exceptions\ValidationFailureException;
|
||||
use LogicException;
|
||||
|
||||
/**
|
||||
|
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Flarum\Core;
|
||||
namespace Flarum\Core\Settings;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
||||
class DatabaseSettingsRepository implements SettingsRepositoryInterface
|
||||
class DatabaseSettingsRepository implements SettingsRepository
|
||||
{
|
||||
protected $database;
|
||||
|
||||
@@ -13,6 +13,11 @@ class DatabaseSettingsRepository implements SettingsRepositoryInterface
|
||||
$this->database = $connection;
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
return $this->database->table('config')->lists('value', 'key');
|
||||
}
|
||||
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if (is_null($value = $this->database->table('config')->where('key', $key)->pluck('value'))) {
|
45
src/Core/Settings/MemoryCacheSettingsRepository.php
Normal file
45
src/Core/Settings/MemoryCacheSettingsRepository.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Flarum\Core\Settings;
|
||||
|
||||
class MemoryCacheSettingsRepository implements SettingsRepository
|
||||
{
|
||||
protected $inner;
|
||||
|
||||
protected $isCached;
|
||||
|
||||
protected $cache = [];
|
||||
|
||||
public function __construct(SettingsRepository $inner)
|
||||
{
|
||||
$this->inner = $inner;
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
if (!$this->isCached) {
|
||||
$this->cache = $this->inner->all();
|
||||
$this->isCached = true;
|
||||
}
|
||||
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if (array_key_exists($key, $this->cache)) {
|
||||
return $this->cache[$key];
|
||||
} else if (!$this->isCached) {
|
||||
return array_get($this->all(), $key, $default);
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->cache[$key] = $value;
|
||||
|
||||
$this->inner->set($key, $value);
|
||||
}
|
||||
}
|
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Flarum\Core;
|
||||
namespace Flarum\Core\Settings;
|
||||
|
||||
interface SettingsRepositoryInterface
|
||||
interface SettingsRepository
|
||||
{
|
||||
public function all();
|
||||
|
||||
public function get($key, $default = null);
|
||||
|
||||
public function set($key, $value);
|
@@ -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) {
|
||||
|
@@ -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')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user