mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 21:49:01 +01:00
parent
6efe100064
commit
e92cb7fb01
24
app/Exceptions/AlreadySubscribedException.php
Normal file
24
app/Exceptions/AlreadySubscribedException.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* This is the already subscribed exception class.
|
||||
*
|
||||
* @author Graham Campbell <graham@alt-three.com>
|
||||
*/
|
||||
class AlreadySubscribedException extends Exception implements ExceptionInterface
|
||||
{
|
||||
//
|
||||
}
|
@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Handlers\Commands\Subscriber;
|
||||
use CachetHQ\Cachet\Commands\Subscriber\SubscribeSubscriberCommand;
|
||||
use CachetHQ\Cachet\Commands\Subscriber\VerifySubscriberCommand;
|
||||
use CachetHQ\Cachet\Events\Subscriber\SubscriberHasSubscribedEvent;
|
||||
use CachetHQ\Cachet\Exceptions\AlreadySubscribedException;
|
||||
use CachetHQ\Cachet\Models\Subscriber;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
|
||||
@ -26,10 +27,16 @@ class SubscribeSubscriberCommandHandler
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Commands\Subscriber\SubscribeSubscriberCommand $command
|
||||
*
|
||||
* @throws \CachetHQ\Cachet\Exceptions\AlreadySubscribedException
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Subscriber
|
||||
*/
|
||||
public function handle(SubscribeSubscriberCommand $command)
|
||||
{
|
||||
if (Subscriber::where('email', $command->email)->first()) {
|
||||
throw new AlreadySubscribedException("Cannot subscribe {$command->email} because they're already subscribed.");
|
||||
}
|
||||
|
||||
$subscriber = Subscriber::create(['email' => $command->email]);
|
||||
|
||||
if ($command->verified) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user