1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2018 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic |
||
6 | * |
||
7 | * @link http://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\EmailBundle\Swiftmailer\Momentum\Callback; |
||
13 | |||
14 | use Mautic\EmailBundle\Swiftmailer\SendGrid\Exception\ResponseItemException; |
||
15 | use Symfony\Component\HttpFoundation\Request; |
||
16 | |||
17 | class ResponseItems implements \Iterator |
||
18 | { |
||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | private $position = 0; |
||
23 | |||
24 | /** |
||
25 | * @var ResponseItem[] |
||
26 | */ |
||
27 | private $items = []; |
||
28 | |||
29 | public function __construct(Request $request) |
||
30 | { |
||
31 | $payload = $request->request->all(); |
||
32 | foreach ($payload as $item) { |
||
33 | $msys = $item['msys']; |
||
34 | if (isset($msys['message_event'])) { |
||
35 | $event = $msys['message_event']; |
||
36 | } elseif (isset($msys['unsubscribe_event'])) { |
||
37 | $event = $msys['unsubscribe_event']; |
||
38 | } else { |
||
39 | continue; |
||
40 | } |
||
41 | |||
42 | if (isset($event['rcpt_type']) && 'to' !== $event['rcpt_type']) { |
||
43 | // Ignore cc/bcc |
||
44 | |||
45 | continue; |
||
46 | } |
||
47 | |||
48 | $bounceClass = isset($event['bounce_class']) ? (int) $event['bounce_class'] : null; |
||
49 | if (empty($event['type']) || !CallbackEnum::shouldBeEventProcessed($event['type'], $bounceClass)) { |
||
50 | continue; |
||
51 | } |
||
52 | |||
53 | try { |
||
54 | $this->items[] = new ResponseItem($event); |
||
55 | } catch (ResponseItemException $e) { |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
Loading history...
|
|||
56 | } |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Return the current element. |
||
62 | * |
||
63 | * @see http://php.net/manual/en/iterator.current.php |
||
64 | * |
||
65 | * @return ResponseItem |
||
66 | */ |
||
67 | public function current() |
||
68 | { |
||
69 | return $this->items[$this->position]; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Move forward to next element. |
||
74 | * |
||
75 | * @see http://php.net/manual/en/iterator.next.php |
||
76 | */ |
||
77 | public function next() |
||
78 | { |
||
79 | ++$this->position; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Return the key of the current element. |
||
84 | * |
||
85 | * @see http://php.net/manual/en/iterator.key.php |
||
86 | * |
||
87 | * @return int |
||
88 | */ |
||
89 | public function key() |
||
90 | { |
||
91 | return $this->position; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Checks if current position is valid. |
||
96 | * |
||
97 | * @see http://php.net/manual/en/iterator.valid.php |
||
98 | * |
||
99 | * @return bool |
||
100 | */ |
||
101 | public function valid() |
||
102 | { |
||
103 | return isset($this->items[$this->position]); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Rewind the Iterator to the first element. |
||
108 | * |
||
109 | * @see http://php.net/manual/en/iterator.rewind.php |
||
110 | */ |
||
111 | public function rewind() |
||
112 | { |
||
113 | $this->position = 0; |
||
114 | } |
||
115 | } |
||
116 |