Add Interface suffix to SettingsRepository

This commit is contained in:
Toby Zerner 2015-10-19 14:58:47 +10:30
parent c0bf875890
commit 0e06d70b73
19 changed files with 64 additions and 63 deletions

View File

@ -19,7 +19,7 @@ use Illuminate\Contracts\Events\Dispatcher;
use Psr\Http\Message\ServerRequestInterface as Request;
use Flarum\Core\Permission;
use Flarum\Api\Client;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Event\PrepareUnserializedSettings;
class ClientController extends BaseClientController
@ -46,7 +46,7 @@ class ClientController extends BaseClientController
Application $app,
Client $apiClient,
LocaleManager $locales,
SettingsRepository $settings,
SettingsRepositoryInterface $settings,
Dispatcher $events,
Repository $cache,
ExtensionManager $extensions

View File

@ -12,7 +12,7 @@ namespace Flarum\Api\Controller;
use Flarum\Core\Access\AssertPermissionTrait;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Event\SettingWasSet;
use Flarum\Event\PrepareSerializedSetting;
use Illuminate\Contracts\Events\Dispatcher;
@ -24,7 +24,7 @@ class SetSettingsController implements ControllerInterface
use AssertPermissionTrait;
/**
* @var \Flarum\Settings\SettingsRepository
* @var \Flarum\Settings\SettingsRepositoryInterface
*/
protected $settings;
@ -34,9 +34,9 @@ class SetSettingsController implements ControllerInterface
protected $dispatcher;
/**
* @param SettingsRepository $settings
* @param SettingsRepositoryInterface $settings
*/
public function __construct(SettingsRepository $settings, Dispatcher $dispatcher)
public function __construct(SettingsRepositoryInterface $settings, Dispatcher $dispatcher)
{
$this->settings = $settings;
$this->dispatcher = $dispatcher;

View File

@ -12,7 +12,7 @@ namespace Flarum\Api\Serializer;
use Flarum\Foundation\Application;
use Flarum\Core\Access\Gate;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
class ForumSerializer extends AbstractSerializer
{
@ -32,16 +32,16 @@ class ForumSerializer extends AbstractSerializer
protected $app;
/**
* @var SettingsRepository
* @var SettingsRepositoryInterface
*/
protected $settings;
/**
* @param Gate $gate
* @param Application $app
* @param SettingsRepository $settings
* @param SettingsRepositoryInterface $settings
*/
public function __construct(Gate $gate, Application $app, SettingsRepository $settings)
public function __construct(Gate $gate, Application $app, SettingsRepositoryInterface $settings)
{
$this->gate = $gate;
$this->app = $app;

View File

@ -14,7 +14,7 @@ use Carbon\Carbon;
use Flarum\Core\Discussion;
use Flarum\Core\User;
use Flarum\Event\ScopeHiddenDiscussionVisibility;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Eloquent\Builder;
@ -26,7 +26,7 @@ class DiscussionPolicy extends AbstractPolicy
protected $model = Discussion::class;
/**
* @var SettingsRepository
* @var SettingsRepositoryInterface
*/
protected $settings;
@ -41,10 +41,10 @@ class DiscussionPolicy extends AbstractPolicy
protected $events;
/**
* @param SettingsRepository $settings
* @param SettingsRepositoryInterface $settings
* @param Gate $gate
*/
public function __construct(SettingsRepository $settings, Gate $gate, Dispatcher $events)
public function __construct(SettingsRepositoryInterface $settings, Gate $gate, Dispatcher $events)
{
$this->settings = $settings;
$this->gate = $gate;

View File

@ -14,7 +14,7 @@ use Carbon\Carbon;
use Flarum\Core\Post;
use Flarum\Core\User;
use Flarum\Event\ScopePostVisibility;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Events\Dispatcher;
class PostPolicy extends AbstractPolicy
@ -25,7 +25,7 @@ class PostPolicy extends AbstractPolicy
protected $model = Post::class;
/**
* @var SettingsRepository
* @var SettingsRepositoryInterface
*/
protected $settings;
@ -35,10 +35,10 @@ class PostPolicy extends AbstractPolicy
protected $gate;
/**
* @param SettingsRepository $settings
* @param SettingsRepositoryInterface $settings
* @param Gate $gate
*/
public function __construct(SettingsRepository $settings, Gate $gate)
public function __construct(SettingsRepositoryInterface $settings, Gate $gate)
{
$this->settings = $settings;
$this->gate = $gate;

View File

@ -16,7 +16,7 @@ use Flarum\Core\AuthToken;
use Flarum\Core\Validator\UserValidator;
use Flarum\Event\UserWillBeSaved;
use Flarum\Core\Support\DispatchEventsTrait;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Core\Exception\PermissionDeniedException;
use Illuminate\Contracts\Events\Dispatcher;
@ -26,7 +26,7 @@ class RegisterUserHandler
use AssertPermissionTrait;
/**
* @var SettingsRepository
* @var SettingsRepositoryInterface
*/
protected $settings;
@ -37,10 +37,10 @@ class RegisterUserHandler
/**
* @param Dispatcher $events
* @param SettingsRepository $settings
* @param SettingsRepositoryInterface $settings
* @param UserValidator $validator
*/
public function __construct(Dispatcher $events, SettingsRepository $settings, UserValidator $validator)
public function __construct(Dispatcher $events, SettingsRepositoryInterface $settings, UserValidator $validator)
{
$this->events = $events;
$this->settings = $settings;

View File

@ -10,7 +10,7 @@
namespace Flarum\Core\Command;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Core\PasswordToken;
use Flarum\Core\Repository\UserRepository;
use Illuminate\Contracts\Mail\Mailer;
@ -28,7 +28,7 @@ class RequestPasswordResetHandler
protected $users;
/**
* @var SettingsRepository
* @var SettingsRepositoryInterface
*/
protected $settings;
@ -49,12 +49,12 @@ class RequestPasswordResetHandler
/**
* @param UserRepository $users
* @param SettingsRepository $settings
* @param SettingsRepositoryInterface $settings
* @param Mailer $mailer
* @param UrlGenerator $url
* @param TranslatorInterface $translator
*/
public function __construct(UserRepository $users, SettingsRepository $settings, Mailer $mailer, UrlGenerator $url, TranslatorInterface $translator)
public function __construct(UserRepository $users, SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, TranslatorInterface $translator)
{
$this->users = $users;
$this->settings = $settings;

View File

@ -16,7 +16,7 @@ use Flarum\Core\User;
use Flarum\Event\UserEmailChangeWasRequested;
use Flarum\Event\UserWasRegistered;
use Flarum\Forum\UrlGenerator;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Mail\Message;
@ -25,7 +25,7 @@ use Symfony\Component\Translation\TranslatorInterface;
class EmailConfirmationMailer
{
/**
* @var SettingsRepository
* @var SettingsRepositoryInterface
*/
protected $settings;
@ -45,12 +45,12 @@ class EmailConfirmationMailer
protected $translator;
/**
* @param \Flarum\Settings\SettingsRepository $settings
* @param \Flarum\Settings\SettingsRepositoryInterface $settings
* @param Mailer $mailer
* @param UrlGenerator $url
* @param TranslatorInterface $translator
*/
public function __construct(SettingsRepository $settings, Mailer $mailer, UrlGenerator $url, TranslatorInterface $translator)
public function __construct(SettingsRepositoryInterface $settings, Mailer $mailer, UrlGenerator $url, TranslatorInterface $translator)
{
$this->settings = $settings;
$this->mailer = $mailer;

View File

@ -11,7 +11,7 @@
namespace Flarum\Database;
use Illuminate\Database\Schema\Builder;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
abstract class AbstractMigration
{
@ -21,15 +21,15 @@ abstract class AbstractMigration
protected $schema;
/**
* @var SettingsRepository
* @var SettingsRepositoryInterface
*/
protected $settings;
/**
* @param Builder $schema
* @param SettingsRepository $settings
* @param SettingsRepositoryInterface $settings
*/
public function __construct(Builder $schema, SettingsRepository $settings)
public function __construct(Builder $schema, SettingsRepositoryInterface $settings)
{
$this->schema = $schema;
$this->settings = $settings;

View File

@ -15,7 +15,7 @@ use Flarum\Event\ExtensionWasDisabled;
use Flarum\Event\ExtensionWasEnabled;
use Flarum\Event\ExtensionWasUninstalled;
use Flarum\Foundation\Application;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Database\Migrator;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
@ -38,7 +38,7 @@ class ExtensionManager
*/
protected $filesystem;
public function __construct(SettingsRepository $config, Application $app, Migrator $migrator, Dispatcher $dispatcher, Filesystem $filesystem)
public function __construct(SettingsRepositoryInterface $config, Application $app, Migrator $migrator, Dispatcher $dispatcher, Filesystem $filesystem)
{
$this->config = $config;
$this->app = $app;

View File

@ -14,7 +14,7 @@ use Flarum\Api\Client;
use Flarum\Formatter\Formatter;
use Flarum\Foundation\Application;
use Flarum\Locale\LocaleManager;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Http\Controller\AbstractClientController;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Events\Dispatcher;
@ -43,7 +43,7 @@ class ClientController extends AbstractClientController
Application $app,
Client $api,
LocaleManager $locales,
SettingsRepository $settings,
SettingsRepositoryInterface $settings,
Dispatcher $events,
Repository $cache,
Formatter $formatter

View File

@ -107,18 +107,8 @@ abstract class AbstractServer
$app->register('Illuminate\View\ViewServiceProvider');
$app->register('Illuminate\Validation\ValidationServiceProvider');
if ($app->isInstalled()) {
$settings = $app->make('Flarum\Settings\SettingsRepository');
try {
$version = $settings->get('version');
} finally {
if (! isset($version) || $version !== $app->version()) {
die('run upgrade script');
// $command = $app->make('Flarum\Console\Command\UpgradeCommand');
// $command->upgrade();
}
}
if ($app->isInstalled() && $app->isUpToDate()) {
$settings = $app->make('Flarum\Settings\SettingsRepositoryInterface');
$config->set('mail.driver', $settings->get('mail_driver'));
$config->set('mail.host', $settings->get('mail_host'));

View File

@ -110,6 +110,17 @@ class Application extends Container implements ApplicationContract
return $this->bound('flarum.config');
}
public function isUpToDate()
{
$settings = $this->make('Flarum\Settings\SettingsRepositoryInterface');
try {
$version = $settings->get('version');
} finally {
return isset($version) && $version === $this->version();
}
}
/**
* @param string $key
* @param mixed $default
@ -600,7 +611,7 @@ class Application extends Container implements ApplicationContract
*/
public function isDownForMaintenance()
{
return file_exists($this->storagePath().'/framework/down');
return false;
}
/**

View File

@ -20,7 +20,7 @@ use Flarum\Event\ConfigureClientView;
use Flarum\Foundation\Application;
use Flarum\Locale\JsCompiler as LocaleJsCompiler;
use Flarum\Locale\LocaleManager;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Events\Dispatcher;
use Psr\Http\Message\ServerRequestInterface as Request;
@ -82,7 +82,7 @@ abstract class AbstractClientController extends AbstractHtmlController
protected $locales;
/**
* @var \Flarum\Settings\SettingsRepository
* @var \Flarum\Settings\SettingsRepositoryInterface
*/
protected $settings;
@ -100,7 +100,7 @@ abstract class AbstractClientController extends AbstractHtmlController
* @param \Flarum\Foundation\Application $app
* @param Client $api
* @param LocaleManager $locales
* @param \Flarum\Settings\SettingsRepository $settings
* @param \Flarum\Settings\SettingsRepositoryInterface $settings
* @param Dispatcher $events
* @param Repository $cache
*/
@ -108,7 +108,7 @@ abstract class AbstractClientController extends AbstractHtmlController
Application $app,
Client $api,
LocaleManager $locales,
SettingsRepository $settings,
SettingsRepositoryInterface $settings,
Dispatcher $events,
Repository $cache
) {

View File

@ -13,7 +13,7 @@ namespace Flarum\Settings;
use Illuminate\Database\ConnectionInterface;
class DatabaseSettingsRepository implements SettingsRepository
class DatabaseSettingsRepository implements SettingsRepositoryInterface
{
protected $database;

View File

@ -11,7 +11,7 @@
namespace Flarum\Settings;
class MemoryCacheSettingsRepository implements SettingsRepository
class MemoryCacheSettingsRepository implements SettingsRepositoryInterface
{
protected $inner;
@ -19,7 +19,7 @@ class MemoryCacheSettingsRepository implements SettingsRepository
protected $cache = [];
public function __construct(SettingsRepository $inner)
public function __construct(SettingsRepositoryInterface $inner)
{
$this->inner = $inner;
}

View File

@ -11,7 +11,7 @@
namespace Flarum\Settings;
interface SettingsRepository
interface SettingsRepositoryInterface
{
public function all();

View File

@ -19,7 +19,7 @@ class SettingsServiceProvider extends AbstractServiceProvider
*/
public function register()
{
$this->app->singleton('Flarum\Settings\SettingsRepository', function () {
$this->app->singleton('Flarum\Settings\SettingsRepositoryInterface', function () {
return new MemoryCacheSettingsRepository(
new DatabaseSettingsRepository(
$this->app->make('Illuminate\Database\ConnectionInterface')
@ -27,6 +27,6 @@ class SettingsServiceProvider extends AbstractServiceProvider
);
});
$this->app->alias('Flarum\Settings\SettingsRepository', 'flarum.settings');
$this->app->alias('Flarum\Settings\SettingsRepositoryInterface', 'flarum.settings');
}
}

View File

@ -2,7 +2,7 @@
namespace tests\Flarum\Core\Settings;
use Flarum\Settings\MemoryCacheSettingsRepository;
use Flarum\Settings\SettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Mockery as m;
use tests\Test\TestCase;
@ -13,7 +13,7 @@ class MemoryCacheSettingsRepositoryTest extends TestCase
public function init()
{
$this->baseRepository = m::mock(\Flarum\Settings\SettingsRepository::class);
$this->baseRepository = m::mock(\Flarum\Settings\SettingsRepositoryInterface::class);
$this->repository = new MemoryCacheSettingsRepository($this->baseRepository);
}