1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\EmailCampaigns\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use ErrorException; |
7
|
|
|
use Spatie\EmailCampaigns\Models\Campaign; |
8
|
|
|
use Spatie\EmailCampaigns\Mails\CampaignMailable; |
9
|
|
|
use Spatie\EmailCampaigns\Support\Segments\Segment; |
10
|
|
|
|
11
|
|
|
class CouldNotSendCampaign extends Exception |
12
|
|
|
{ |
13
|
|
|
public static function beingSent(Campaign $campaign): self |
14
|
|
|
{ |
15
|
|
|
return new static("The campaign with id `{$campaign->id}` can't be sent, because it is already being sent."); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public static function invalidMailableClass(Campaign $campaign, string $invalidMailableClass) |
19
|
|
|
{ |
20
|
|
|
$mustExtend = CampaignMailable::class; |
21
|
|
|
|
22
|
|
|
return new static("The campaign with id `{$campaign->id}` can't be sent, because an invalid mailable class `{$invalidMailableClass}` is set. A valid mailable class must extend `{$mustExtend}`."); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public static function invalidSegmentClass(Campaign $campaign, string $invalidSegmentClass) |
26
|
|
|
{ |
27
|
|
|
$mustExtend = Segment::class; |
28
|
|
|
|
29
|
|
|
return new static("The campaign with id `{$campaign->id}` can't be sent, because an invalid segment class `{$invalidSegmentClass}` is set. A valid segment class must implement `{$mustExtend}`."); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public static function alreadySent(Campaign $campaign): self |
33
|
|
|
{ |
34
|
|
|
return new static("The campaign with id `{$campaign->id}` can't be sent, because it was already sent."); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function noListSet(Campaign $campaign) |
38
|
|
|
{ |
39
|
|
|
return new static("The campaign with id `{$campaign->id}` can't be sent, because there is no list set to send it to."); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function noSubjectSet(Campaign $campaign) |
43
|
|
|
{ |
44
|
|
|
return new static("The campaign with id `{$campaign->id}` can't be sent, because no subject has been set."); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public static function noContent(Campaign $campaign): self |
48
|
|
|
{ |
49
|
|
|
return new static("The campaign with id `{$campaign->id}` can't be sent because not content has been set."); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function invalidContent(Campaign $campaign, ErrorException $errorException): self |
53
|
|
|
{ |
54
|
|
|
return new static("The campaign with id `{$campaign->id}` can't be sent because the content isn't valid. Please check if the html is valid. DOMDocument reported: `{$errorException->getMessage()}`", 0, $errorException); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|