From 0e06d70b7321b62bbb7dc5bf7d4a5082246e9d47 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 19 Oct 2015 14:58:47 +1030 Subject: [PATCH] Add Interface suffix to SettingsRepository --- .../core/src/Admin/Controller/ClientController.php | 4 ++-- .../src/Api/Controller/SetSettingsController.php | 8 ++++---- .../core/src/Api/Serializer/ForumSerializer.php | 8 ++++---- .../core/src/Core/Access/DiscussionPolicy.php | 8 ++++---- framework/core/src/Core/Access/PostPolicy.php | 8 ++++---- .../core/src/Core/Command/RegisterUserHandler.php | 8 ++++---- .../Core/Command/RequestPasswordResetHandler.php | 8 ++++---- .../src/Core/Listener/EmailConfirmationMailer.php | 8 ++++---- framework/core/src/Database/AbstractMigration.php | 8 ++++---- framework/core/src/Extension/ExtensionManager.php | 4 ++-- .../core/src/Forum/Controller/ClientController.php | 4 ++-- framework/core/src/Foundation/AbstractServer.php | 14 ++------------ framework/core/src/Foundation/Application.php | 13 ++++++++++++- .../Http/Controller/AbstractClientController.php | 8 ++++---- .../src/Settings/DatabaseSettingsRepository.php | 2 +- .../src/Settings/MemoryCacheSettingsRepository.php | 4 ++-- ...ository.php => SettingsRepositoryInterface.php} | 2 +- .../core/src/Settings/SettingsServiceProvider.php | 4 ++-- .../Settings/MemoryCacheSettingsRepositoryTest.php | 4 ++-- 19 files changed, 64 insertions(+), 63 deletions(-) rename framework/core/src/Settings/{SettingsRepository.php => SettingsRepositoryInterface.php} (91%) diff --git a/framework/core/src/Admin/Controller/ClientController.php b/framework/core/src/Admin/Controller/ClientController.php index 61a0aaa66..efa3636f5 100644 --- a/framework/core/src/Admin/Controller/ClientController.php +++ b/framework/core/src/Admin/Controller/ClientController.php @@ -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 diff --git a/framework/core/src/Api/Controller/SetSettingsController.php b/framework/core/src/Api/Controller/SetSettingsController.php index b82d2ded1..3d5289439 100644 --- a/framework/core/src/Api/Controller/SetSettingsController.php +++ b/framework/core/src/Api/Controller/SetSettingsController.php @@ -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; diff --git a/framework/core/src/Api/Serializer/ForumSerializer.php b/framework/core/src/Api/Serializer/ForumSerializer.php index 82b0414aa..933317e9e 100644 --- a/framework/core/src/Api/Serializer/ForumSerializer.php +++ b/framework/core/src/Api/Serializer/ForumSerializer.php @@ -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; diff --git a/framework/core/src/Core/Access/DiscussionPolicy.php b/framework/core/src/Core/Access/DiscussionPolicy.php index a8f0e4550..fc2c7ec21 100644 --- a/framework/core/src/Core/Access/DiscussionPolicy.php +++ b/framework/core/src/Core/Access/DiscussionPolicy.php @@ -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; diff --git a/framework/core/src/Core/Access/PostPolicy.php b/framework/core/src/Core/Access/PostPolicy.php index 9e9f51190..26709745b 100644 --- a/framework/core/src/Core/Access/PostPolicy.php +++ b/framework/core/src/Core/Access/PostPolicy.php @@ -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; diff --git a/framework/core/src/Core/Command/RegisterUserHandler.php b/framework/core/src/Core/Command/RegisterUserHandler.php index d4b3dd8b9..f8164abb7 100644 --- a/framework/core/src/Core/Command/RegisterUserHandler.php +++ b/framework/core/src/Core/Command/RegisterUserHandler.php @@ -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; diff --git a/framework/core/src/Core/Command/RequestPasswordResetHandler.php b/framework/core/src/Core/Command/RequestPasswordResetHandler.php index 93598a135..a75c9dcf5 100644 --- a/framework/core/src/Core/Command/RequestPasswordResetHandler.php +++ b/framework/core/src/Core/Command/RequestPasswordResetHandler.php @@ -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; diff --git a/framework/core/src/Core/Listener/EmailConfirmationMailer.php b/framework/core/src/Core/Listener/EmailConfirmationMailer.php index d34f282ec..4a9398d21 100755 --- a/framework/core/src/Core/Listener/EmailConfirmationMailer.php +++ b/framework/core/src/Core/Listener/EmailConfirmationMailer.php @@ -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; diff --git a/framework/core/src/Database/AbstractMigration.php b/framework/core/src/Database/AbstractMigration.php index b7c903365..1062ee1cb 100644 --- a/framework/core/src/Database/AbstractMigration.php +++ b/framework/core/src/Database/AbstractMigration.php @@ -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; diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index b9760d37b..68ee7bd99 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -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; diff --git a/framework/core/src/Forum/Controller/ClientController.php b/framework/core/src/Forum/Controller/ClientController.php index 0aa7bfff5..2dbce6454 100644 --- a/framework/core/src/Forum/Controller/ClientController.php +++ b/framework/core/src/Forum/Controller/ClientController.php @@ -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 diff --git a/framework/core/src/Foundation/AbstractServer.php b/framework/core/src/Foundation/AbstractServer.php index 53d706642..5dfda65c0 100644 --- a/framework/core/src/Foundation/AbstractServer.php +++ b/framework/core/src/Foundation/AbstractServer.php @@ -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')); diff --git a/framework/core/src/Foundation/Application.php b/framework/core/src/Foundation/Application.php index e107723be..ccb018c7e 100644 --- a/framework/core/src/Foundation/Application.php +++ b/framework/core/src/Foundation/Application.php @@ -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; } /** diff --git a/framework/core/src/Http/Controller/AbstractClientController.php b/framework/core/src/Http/Controller/AbstractClientController.php index 8caad8c4b..4512f8d8c 100644 --- a/framework/core/src/Http/Controller/AbstractClientController.php +++ b/framework/core/src/Http/Controller/AbstractClientController.php @@ -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 ) { diff --git a/framework/core/src/Settings/DatabaseSettingsRepository.php b/framework/core/src/Settings/DatabaseSettingsRepository.php index 5498bff7a..3179d23b9 100644 --- a/framework/core/src/Settings/DatabaseSettingsRepository.php +++ b/framework/core/src/Settings/DatabaseSettingsRepository.php @@ -13,7 +13,7 @@ namespace Flarum\Settings; use Illuminate\Database\ConnectionInterface; -class DatabaseSettingsRepository implements SettingsRepository +class DatabaseSettingsRepository implements SettingsRepositoryInterface { protected $database; diff --git a/framework/core/src/Settings/MemoryCacheSettingsRepository.php b/framework/core/src/Settings/MemoryCacheSettingsRepository.php index 5cd3de01c..4caf6d937 100644 --- a/framework/core/src/Settings/MemoryCacheSettingsRepository.php +++ b/framework/core/src/Settings/MemoryCacheSettingsRepository.php @@ -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; } diff --git a/framework/core/src/Settings/SettingsRepository.php b/framework/core/src/Settings/SettingsRepositoryInterface.php similarity index 91% rename from framework/core/src/Settings/SettingsRepository.php rename to framework/core/src/Settings/SettingsRepositoryInterface.php index 90cb38d1a..f42012353 100644 --- a/framework/core/src/Settings/SettingsRepository.php +++ b/framework/core/src/Settings/SettingsRepositoryInterface.php @@ -11,7 +11,7 @@ namespace Flarum\Settings; -interface SettingsRepository +interface SettingsRepositoryInterface { public function all(); diff --git a/framework/core/src/Settings/SettingsServiceProvider.php b/framework/core/src/Settings/SettingsServiceProvider.php index f5d2eb90d..b5a4a8e33 100644 --- a/framework/core/src/Settings/SettingsServiceProvider.php +++ b/framework/core/src/Settings/SettingsServiceProvider.php @@ -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'); } } diff --git a/framework/core/tests/Flarum/Core/Settings/MemoryCacheSettingsRepositoryTest.php b/framework/core/tests/Flarum/Core/Settings/MemoryCacheSettingsRepositoryTest.php index 9af362269..125071278 100644 --- a/framework/core/tests/Flarum/Core/Settings/MemoryCacheSettingsRepositoryTest.php +++ b/framework/core/tests/Flarum/Core/Settings/MemoryCacheSettingsRepositoryTest.php @@ -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); }