mirror of
https://github.com/flarum/core.git
synced 2025-08-13 03:44:32 +02:00
Move command classes to domain namespaces
They will probably be refactored away at a later stage (when we get rid of the command bus). Until then, this lets us remove the Flarum\Core namespace and actually feels quite clean.
This commit is contained in:
32
src/Notification/Command/ReadAllNotifications.php
Normal file
32
src/Notification/Command/ReadAllNotifications.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Notification\Command;
|
||||
|
||||
use Flarum\User\User;
|
||||
|
||||
class ReadAllNotifications
|
||||
{
|
||||
/**
|
||||
* The user performing the action.
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @param User $actor The user performing the action.
|
||||
*/
|
||||
public function __construct(User $actor)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
}
|
||||
}
|
46
src/Notification/Command/ReadAllNotificationsHandler.php
Normal file
46
src/Notification/Command/ReadAllNotificationsHandler.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Notification\Command;
|
||||
|
||||
use Flarum\Notification\NotificationRepository;
|
||||
use Flarum\User\AssertPermissionTrait;
|
||||
|
||||
class ReadAllNotificationsHandler
|
||||
{
|
||||
use AssertPermissionTrait;
|
||||
|
||||
/**
|
||||
* @var NotificationRepository
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @param NotificationRepository $notifications
|
||||
*/
|
||||
public function __construct(NotificationRepository $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReadAllNotifications $command
|
||||
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||
*/
|
||||
public function handle(ReadAllNotifications $command)
|
||||
{
|
||||
$actor = $command->actor;
|
||||
|
||||
$this->assertRegistered($actor);
|
||||
|
||||
$this->notifications->markAllAsRead($actor);
|
||||
}
|
||||
}
|
41
src/Notification/Command/ReadNotification.php
Normal file
41
src/Notification/Command/ReadNotification.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Notification\Command;
|
||||
|
||||
use Flarum\User\User;
|
||||
|
||||
class ReadNotification
|
||||
{
|
||||
/**
|
||||
* The ID of the notification to mark as read.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $notificationId;
|
||||
|
||||
/**
|
||||
* The user performing the action.
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @param int $notificationId The ID of the notification to mark as read.
|
||||
* @param User $actor The user performing the action.
|
||||
*/
|
||||
public function __construct($notificationId, User $actor)
|
||||
{
|
||||
$this->notificationId = $notificationId;
|
||||
$this->actor = $actor;
|
||||
}
|
||||
}
|
45
src/Notification/Command/ReadNotificationHandler.php
Normal file
45
src/Notification/Command/ReadNotificationHandler.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Notification\Command;
|
||||
|
||||
use Flarum\Notification\Notification;
|
||||
use Flarum\User\AssertPermissionTrait;
|
||||
|
||||
class ReadNotificationHandler
|
||||
{
|
||||
use AssertPermissionTrait;
|
||||
|
||||
/**
|
||||
* @param ReadNotification $command
|
||||
* @return \Flarum\Notification\Notification
|
||||
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||
*/
|
||||
public function handle(ReadNotification $command)
|
||||
{
|
||||
$actor = $command->actor;
|
||||
|
||||
$this->assertRegistered($actor);
|
||||
|
||||
$notification = Notification::where('user_id', $actor->id)->findOrFail($command->notificationId);
|
||||
|
||||
Notification::where([
|
||||
'user_id' => $actor->id,
|
||||
'type' => $notification->type,
|
||||
'subject_id' => $notification->subject_id
|
||||
])
|
||||
->update(['is_read' => true]);
|
||||
|
||||
$notification->is_read = true;
|
||||
|
||||
return $notification;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user