|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Content\Newsletter; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Content\Newsletter\Exception\NewsletterRecipientNotFoundException; |
|
6
|
|
|
use Shopware\Core\Framework\Feature; |
|
7
|
|
|
use Shopware\Core\Framework\HttpException; |
|
8
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
|
|
11
|
|
|
#[Package('checkout')] |
|
12
|
|
|
class NewsletterException extends HttpException |
|
13
|
|
|
{ |
|
14
|
|
|
public const NEWSLETTER_RECIPIENT_NOT_FOUND_CODE = 'CONTENT__NEWSLETTER_RECIPIENT_NOT_FOUND'; |
|
15
|
|
|
public const NEWSLETTER_RECIPIENT_THROTTLED = 'CONTENT__NEWSLETTER_RECIPIENT_THROTTLED'; |
|
16
|
|
|
|
|
17
|
|
|
public static function recipientNotFound( |
|
18
|
|
|
string $identifier, |
|
19
|
|
|
string $value |
|
20
|
|
|
): self { |
|
21
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
22
|
|
|
return new NewsletterRecipientNotFoundException($identifier, $value); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
return new self( |
|
26
|
|
|
Response::HTTP_BAD_REQUEST, |
|
27
|
|
|
self::NEWSLETTER_RECIPIENT_NOT_FOUND_CODE, |
|
28
|
|
|
'The NewsletterRecipient with the identifier "{{ identifier }}" - {{ value }} was not found.', |
|
29
|
|
|
['identifier' => $identifier, 'value' => $value] |
|
30
|
|
|
); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public static function newsletterThrottled(int $waitTime): NewsletterException |
|
34
|
|
|
{ |
|
35
|
|
|
return new self( |
|
36
|
|
|
Response::HTTP_TOO_MANY_REQUESTS, |
|
37
|
|
|
self::NEWSLETTER_RECIPIENT_THROTTLED, |
|
38
|
|
|
'Too many requests, try again in {{ seconds }} seconds.', |
|
39
|
|
|
['seconds' => $waitTime], |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|