Added AlreadySubscribedException

Closes #1201
This commit is contained in:
Graham Campbell 2015-12-06 18:01:33 +00:00
parent 6efe100064
commit e92cb7fb01
2 changed files with 31 additions and 0 deletions

View 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
{
//
}

View File

@ -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) {