From b38ade986d177c7274cd618162f3571748ecb9f7 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 24 Jun 2017 14:22:19 +0200 Subject: [PATCH] Extract Flarum\Notification namespace --- .../ListNotificationsController.php | 8 +++---- src/Api/Serializer/NotificationSerializer.php | 4 ++-- src/Core/Command/PostReplyHandler.php | 6 ++--- .../Command/ReadAllNotificationsHandler.php | 2 +- src/Core/Command/ReadNotificationHandler.php | 4 ++-- src/Core/CoreServiceProvider.php | 2 +- src/Discussion/DiscussionRenamedNotifier.php | 4 ++-- src/Event/ConfigureNotificationTypes.php | 2 +- .../Blueprint}/BlueprintInterface.php | 2 +- .../Blueprint}/DiscussionRenamedBlueprint.php | 2 +- .../Event/Sending.php} | 8 +++---- .../Notification/MailableInterface.php | 2 +- src/{Core => Notification}/Notification.php | 2 +- .../Notification/NotificationMailer.php | 2 +- .../NotificationRepository.php | 3 +-- .../NotificationServiceProvider.php | 7 +++--- .../Notification/NotificationSyncer.php | 23 +++++++++---------- src/User/User.php | 4 ++-- 18 files changed, 42 insertions(+), 45 deletions(-) rename src/{Core/Notification => Notification/Blueprint}/BlueprintInterface.php (96%) rename src/{Core/Notification => Notification/Blueprint}/DiscussionRenamedBlueprint.php (96%) rename src/{Event/NotificationWillBeSent.php => Notification/Event/Sending.php} (79%) rename src/{Core => }/Notification/MailableInterface.php (93%) rename src/{Core => Notification}/Notification.php (99%) rename src/{Core => }/Notification/NotificationMailer.php (96%) rename src/{Core/Repository => Notification}/NotificationRepository.php (96%) rename src/{Core => }/Notification/NotificationServiceProvider.php (88%) rename src/{Core => }/Notification/NotificationSyncer.php (89%) diff --git a/src/Api/Controller/ListNotificationsController.php b/src/Api/Controller/ListNotificationsController.php index c167498fe..aeca867a8 100644 --- a/src/Api/Controller/ListNotificationsController.php +++ b/src/Api/Controller/ListNotificationsController.php @@ -13,7 +13,7 @@ namespace Flarum\Api\Controller; use Flarum\Discussion\Discussion; use Flarum\User\Exception\PermissionDeniedException; -use Flarum\Core\Repository\NotificationRepository; +use Flarum\Notification\NotificationRepository; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; @@ -39,12 +39,12 @@ class ListNotificationsController extends AbstractListController public $limit = 10; /** - * @var \Flarum\Core\Repository\NotificationRepository + * @var \Flarum\Notification\NotificationRepository */ protected $notifications; /** - * @param \Flarum\Core\Repository\NotificationRepository $notifications + * @param \Flarum\Notification\NotificationRepository $notifications */ public function __construct(NotificationRepository $notifications) { @@ -80,7 +80,7 @@ class ListNotificationsController extends AbstractListController } /** - * @param \Flarum\Core\Notification[] $notifications + * @param \Flarum\Notification\Notification[] $notifications */ private function loadSubjectDiscussions(array $notifications) { diff --git a/src/Api/Serializer/NotificationSerializer.php b/src/Api/Serializer/NotificationSerializer.php index bfbd8e943..9159445a3 100644 --- a/src/Api/Serializer/NotificationSerializer.php +++ b/src/Api/Serializer/NotificationSerializer.php @@ -11,7 +11,7 @@ namespace Flarum\Api\Serializer; -use Flarum\Core\Notification; +use Flarum\Notification\Notification; use InvalidArgumentException; class NotificationSerializer extends AbstractSerializer @@ -32,7 +32,7 @@ class NotificationSerializer extends AbstractSerializer /** * {@inheritdoc} * - * @param \Flarum\Core\Notification $notification + * @param \Flarum\Notification\Notification $notification * @throws InvalidArgumentException */ protected function getDefaultAttributes($notification) diff --git a/src/Core/Command/PostReplyHandler.php b/src/Core/Command/PostReplyHandler.php index e4b3147e7..2a8314a8e 100644 --- a/src/Core/Command/PostReplyHandler.php +++ b/src/Core/Command/PostReplyHandler.php @@ -13,7 +13,7 @@ namespace Flarum\Core\Command; use DateTime; use Flarum\User\AssertPermissionTrait; -use Flarum\Core\Notification\NotificationSyncer; +use Flarum\Notification\NotificationSyncer; use Flarum\Post\CommentPost; use Flarum\Discussion\DiscussionRepository; use Flarum\Foundation\DispatchEventsTrait; @@ -32,7 +32,7 @@ class PostReplyHandler protected $discussions; /** - * @var NotificationSyncer + * @var \Flarum\Notification\NotificationSyncer */ protected $notifications; @@ -44,7 +44,7 @@ class PostReplyHandler /** * @param Dispatcher $events * @param DiscussionRepository $discussions - * @param NotificationSyncer $notifications + * @param \Flarum\Notification\NotificationSyncer $notifications * @param PostValidator $validator */ public function __construct( diff --git a/src/Core/Command/ReadAllNotificationsHandler.php b/src/Core/Command/ReadAllNotificationsHandler.php index 9269ed958..7e2255fd5 100644 --- a/src/Core/Command/ReadAllNotificationsHandler.php +++ b/src/Core/Command/ReadAllNotificationsHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Flarum\User\AssertPermissionTrait; -use Flarum\Core\Repository\NotificationRepository; +use Flarum\Notification\NotificationRepository; class ReadAllNotificationsHandler { diff --git a/src/Core/Command/ReadNotificationHandler.php b/src/Core/Command/ReadNotificationHandler.php index f70f1d6b1..d8ed0a8fa 100644 --- a/src/Core/Command/ReadNotificationHandler.php +++ b/src/Core/Command/ReadNotificationHandler.php @@ -12,7 +12,7 @@ namespace Flarum\Core\Command; use Flarum\User\AssertPermissionTrait; -use Flarum\Core\Notification; +use Flarum\Notification\Notification; class ReadNotificationHandler { @@ -20,7 +20,7 @@ class ReadNotificationHandler /** * @param ReadNotification $command - * @return \Flarum\Core\Notification + * @return \Flarum\Notification\Notification * @throws \Flarum\User\Exception\PermissionDeniedException */ public function handle(ReadNotification $command) diff --git a/src/Core/CoreServiceProvider.php b/src/Core/CoreServiceProvider.php index 82e5f6b0d..dda6e1a28 100644 --- a/src/Core/CoreServiceProvider.php +++ b/src/Core/CoreServiceProvider.php @@ -40,7 +40,7 @@ class CoreServiceProvider extends AbstractServiceProvider $this->registerAvatarsFilesystem(); - $this->app->register('Flarum\Core\Notification\NotificationServiceProvider'); + $this->app->register('Flarum\Notification\Notification\NotificationServiceProvider'); $this->app->register('Flarum\Search\SearchServiceProvider'); $this->app->register('Flarum\Formatter\FormatterServiceProvider'); } diff --git a/src/Discussion/DiscussionRenamedNotifier.php b/src/Discussion/DiscussionRenamedNotifier.php index 2cd8bdc9c..d4cc7c5e4 100755 --- a/src/Discussion/DiscussionRenamedNotifier.php +++ b/src/Discussion/DiscussionRenamedNotifier.php @@ -11,8 +11,8 @@ namespace Flarum\Discussion; -use Flarum\Core\Notification\DiscussionRenamedBlueprint; -use Flarum\Core\Notification\NotificationSyncer; +use Flarum\Notification\Blueprint\DiscussionRenamedBlueprint; +use Flarum\Notification\NotificationSyncer; use Flarum\Post\DiscussionRenamedPost; use Flarum\Discussion\Event\Renamed; use Illuminate\Contracts\Events\Dispatcher; diff --git a/src/Event/ConfigureNotificationTypes.php b/src/Event/ConfigureNotificationTypes.php index 084701f0a..3c6eec2b7 100644 --- a/src/Event/ConfigureNotificationTypes.php +++ b/src/Event/ConfigureNotificationTypes.php @@ -11,7 +11,7 @@ namespace Flarum\Event; -use Flarum\Core\Notification\BlueprintInterface; +use Flarum\Notification\Blueprint\BlueprintInterface; use InvalidArgumentException; use ReflectionClass; diff --git a/src/Core/Notification/BlueprintInterface.php b/src/Notification/Blueprint/BlueprintInterface.php similarity index 96% rename from src/Core/Notification/BlueprintInterface.php rename to src/Notification/Blueprint/BlueprintInterface.php index 67bcc31ff..ed8273396 100644 --- a/src/Core/Notification/BlueprintInterface.php +++ b/src/Notification/Blueprint/BlueprintInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification\Blueprint; /** * A notification BlueprintInterface, when instantiated, represents a notification about diff --git a/src/Core/Notification/DiscussionRenamedBlueprint.php b/src/Notification/Blueprint/DiscussionRenamedBlueprint.php similarity index 96% rename from src/Core/Notification/DiscussionRenamedBlueprint.php rename to src/Notification/Blueprint/DiscussionRenamedBlueprint.php index b642d82b9..996483c27 100644 --- a/src/Core/Notification/DiscussionRenamedBlueprint.php +++ b/src/Notification/Blueprint/DiscussionRenamedBlueprint.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification\Blueprint; use Flarum\Post\DiscussionRenamedPost; diff --git a/src/Event/NotificationWillBeSent.php b/src/Notification/Event/Sending.php similarity index 79% rename from src/Event/NotificationWillBeSent.php rename to src/Notification/Event/Sending.php index 12a90ea9d..5633ada9a 100644 --- a/src/Event/NotificationWillBeSent.php +++ b/src/Notification/Event/Sending.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Event; +namespace Flarum\Notification\Event; -use Flarum\Core\Notification\BlueprintInterface; +use Flarum\Notification\Blueprint\BlueprintInterface; -class NotificationWillBeSent +class Sending { /** * The blueprint for the notification. @@ -30,7 +30,7 @@ class NotificationWillBeSent public $users; /** - * @param BlueprintInterface $blueprint + * @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint * @param \Flarum\User\User[] $users */ public function __construct(BlueprintInterface $blueprint, array &$users) diff --git a/src/Core/Notification/MailableInterface.php b/src/Notification/MailableInterface.php similarity index 93% rename from src/Core/Notification/MailableInterface.php rename to src/Notification/MailableInterface.php index c276a32e9..0d059af8e 100644 --- a/src/Core/Notification/MailableInterface.php +++ b/src/Notification/MailableInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification; interface MailableInterface { diff --git a/src/Core/Notification.php b/src/Notification/Notification.php similarity index 99% rename from src/Core/Notification.php rename to src/Notification/Notification.php index 4429cc4b3..6a32fdd36 100644 --- a/src/Core/Notification.php +++ b/src/Notification/Notification.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core; +namespace Flarum\Notification; use Flarum\Database\AbstractModel; diff --git a/src/Core/Notification/NotificationMailer.php b/src/Notification/NotificationMailer.php similarity index 96% rename from src/Core/Notification/NotificationMailer.php rename to src/Notification/NotificationMailer.php index 327f0252e..2bee77e5a 100644 --- a/src/Core/Notification/NotificationMailer.php +++ b/src/Notification/NotificationMailer.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification; use Flarum\User\User; use Illuminate\Contracts\Mail\Mailer; diff --git a/src/Core/Repository/NotificationRepository.php b/src/Notification/NotificationRepository.php similarity index 96% rename from src/Core/Repository/NotificationRepository.php rename to src/Notification/NotificationRepository.php index 1b9fe63fb..ae70ea600 100644 --- a/src/Core/Repository/NotificationRepository.php +++ b/src/Notification/NotificationRepository.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Repository; +namespace Flarum\Notification; -use Flarum\Core\Notification; use Flarum\User\User; class NotificationRepository diff --git a/src/Core/Notification/NotificationServiceProvider.php b/src/Notification/NotificationServiceProvider.php similarity index 88% rename from src/Core/Notification/NotificationServiceProvider.php rename to src/Notification/NotificationServiceProvider.php index d8cf09474..811f3b61e 100644 --- a/src/Core/Notification/NotificationServiceProvider.php +++ b/src/Notification/NotificationServiceProvider.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification; -use Flarum\Core\Notification; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; use Flarum\User\User; @@ -33,7 +32,7 @@ class NotificationServiceProvider extends AbstractServiceProvider public function registerNotificationTypes() { $blueprints = [ - 'Flarum\Core\Notification\DiscussionRenamedBlueprint' => ['alert'] + 'Flarum\Notification\Notification\DiscussionRenamedBlueprint' => ['alert'] ]; $this->app->make('events')->fire( @@ -52,7 +51,7 @@ class NotificationServiceProvider extends AbstractServiceProvider in_array('alert', $enabled) ); - if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Core\Notification\MailableInterface')) { + if ((new ReflectionClass($blueprint))->implementsInterface('Flarum\Notification\Notification\MailableInterface')) { User::addPreference( User::getNotificationPreferenceKey($type, 'email'), 'boolval', diff --git a/src/Core/Notification/NotificationSyncer.php b/src/Notification/NotificationSyncer.php similarity index 89% rename from src/Core/Notification/NotificationSyncer.php rename to src/Notification/NotificationSyncer.php index aab276b5b..5abef59e2 100644 --- a/src/Core/Notification/NotificationSyncer.php +++ b/src/Notification/NotificationSyncer.php @@ -9,12 +9,11 @@ * file that was distributed with this source code. */ -namespace Flarum\Core\Notification; +namespace Flarum\Notification; use Carbon\Carbon; -use Flarum\Core\Notification; -use Flarum\Core\Repository\NotificationRepository; -use Flarum\Event\NotificationWillBeSent; +use Flarum\Notification\Event\Sending; +use Flarum\Notification\Blueprint\BlueprintInterface; use Flarum\User\User; /** @@ -66,11 +65,11 @@ class NotificationSyncer * visible to anyone else. If it is being made visible for the first time, * attempt to send the user an email. * - * @param BlueprintInterface $blueprint + * @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint * @param User[] $users * @return void */ - public function sync(BlueprintInterface $blueprint, array $users) + public function sync(Blueprint\BlueprintInterface $blueprint, array $users) { $attributes = $this->getAttributes($blueprint); @@ -125,7 +124,7 @@ class NotificationSyncer /** * Delete a notification for all users. * - * @param BlueprintInterface $blueprint + * @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint * @return void */ public function delete(BlueprintInterface $blueprint) @@ -165,14 +164,14 @@ class NotificationSyncer * Create a notification record and send an email (depending on user * preference) from a blueprint to a list of recipients. * - * @param BlueprintInterface $blueprint + * @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint * @param User[] $recipients */ - protected function sendNotifications(BlueprintInterface $blueprint, array $recipients) + protected function sendNotifications(Blueprint\BlueprintInterface $blueprint, array $recipients) { $now = Carbon::now('utc')->toDateTimeString(); - event(new NotificationWillBeSent($blueprint, $recipients)); + event(new Sending($blueprint, $recipients)); $attributes = $this->getAttributes($blueprint); @@ -220,10 +219,10 @@ class NotificationSyncer * Construct an array of attributes to be stored in a notification record in * the database, given a notification blueprint. * - * @param BlueprintInterface $blueprint + * @param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint * @return array */ - protected function getAttributes(BlueprintInterface $blueprint) + protected function getAttributes(Blueprint\BlueprintInterface $blueprint) { return [ 'type' => $blueprint::getType(), diff --git a/src/User/User.php b/src/User/User.php index 70396e6ff..ea222484f 100755 --- a/src/User/User.php +++ b/src/User/User.php @@ -13,7 +13,7 @@ namespace Flarum\User; use DomainException; use Flarum\Group\Group; -use Flarum\Core\Notification; +use Flarum\Notification\Notification; use Flarum\Group\Permission; use Flarum\Foundation\EventGeneratorTrait; use Flarum\Database\ScopeVisibilityTrait; @@ -632,7 +632,7 @@ class User extends AbstractModel */ public function notifications() { - return $this->hasMany('Flarum\Core\Notification'); + return $this->hasMany('Flarum\Notification\Notification'); } /**