1 | <?php |
||
18 | class EmailReceiveCheck extends AbstractEmailCheck |
||
19 | { |
||
20 | const CHECK = 'email-receive-check'; |
||
21 | const RECEIVE_MAX_TIME = 300; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | private $receiveMaxTime; |
||
27 | |||
28 | /** |
||
29 | * @var Mailbox; |
||
30 | */ |
||
31 | private $mailbox; |
||
32 | |||
33 | |||
34 | /** |
||
35 | * @var PersistCollectionInterface |
||
36 | */ |
||
37 | private $persistCollection; |
||
38 | |||
39 | /** |
||
40 | * @var EmailSendReceiveCollection |
||
41 | */ |
||
42 | private $emailSendReceiveCollection; |
||
43 | |||
44 | /** |
||
45 | * @param string $checkNode |
||
46 | * @param Mailbox $mailbox |
||
47 | * @param PersistCollectionInterface $persistCollection |
||
48 | * @param int $receiveMaxTime |
||
49 | */ |
||
50 | 8 | public function __construct( |
|
51 | $checkNode, |
||
52 | Mailbox $mailbox, |
||
53 | PersistCollectionInterface $persistCollection, |
||
54 | $receiveMaxTime = self::RECEIVE_MAX_TIME |
||
55 | ) { |
||
56 | 8 | parent::__construct($checkNode); |
|
57 | |||
58 | 8 | $this->setMailbox($mailbox); |
|
59 | 8 | $this->setPersistCollection($persistCollection); |
|
60 | 8 | $this->setReceiveMaxTime($receiveMaxTime); |
|
61 | 8 | } |
|
62 | |||
63 | /** |
||
64 | * Check email can send and receive messages |
||
65 | * @return bool|void |
||
66 | * @throws EmailReceiveCheckException |
||
67 | */ |
||
68 | 7 | public function check() |
|
69 | { |
||
70 | 7 | $this->setEmailSendReceiveColl($this->getPersistCollection()->load()); |
|
71 | |||
72 | /** @var EmailSendReceive $emailSendCheckI */ |
||
73 | 7 | foreach ($this->getEmailSendReceiveColl() as $emailSendCheckI) { |
|
74 | 7 | $this->performReceive($emailSendCheckI); |
|
75 | 3 | } |
|
76 | 3 | } |
|
77 | |||
78 | /** |
||
79 | * @return Mailbox |
||
80 | */ |
||
81 | 7 | public function getMailbox() |
|
82 | { |
||
83 | 7 | return $this->mailbox; |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * @return PersistCollectionInterface |
||
88 | */ |
||
89 | 7 | public function getPersistCollection() |
|
90 | { |
||
91 | 7 | return $this->persistCollection; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return int |
||
96 | */ |
||
97 | 4 | public function getReceiveMaxTime() |
|
101 | |||
102 | /** |
||
103 | * @return EmailSendReceiveCollection |
||
104 | */ |
||
105 | 7 | public function getEmailSendReceiveColl() |
|
106 | { |
||
107 | 7 | return $this->emailSendReceiveCollection; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * @param Mailbox $mailbox |
||
112 | */ |
||
113 | 8 | protected function setMailbox(Mailbox $mailbox) |
|
114 | { |
||
115 | 8 | $this->mailbox = $mailbox; |
|
116 | 8 | } |
|
117 | |||
118 | /** |
||
119 | * @param PersistCollectionInterface $persistCollection |
||
120 | */ |
||
121 | 8 | protected function setPersistCollection(PersistCollectionInterface $persistCollection) |
|
122 | { |
||
123 | 8 | $this->persistCollection = $persistCollection; |
|
124 | 8 | } |
|
125 | |||
126 | /** |
||
127 | * @param int $receiveMaxTime |
||
128 | */ |
||
129 | 8 | protected function setReceiveMaxTime($receiveMaxTime) |
|
133 | |||
134 | /** |
||
135 | * @param EmailSendReceiveCollection $emailSendReceiveC |
||
136 | */ |
||
137 | 7 | protected function setEmailSendReceiveColl(EmailSendReceiveCollection $emailSendReceiveC) |
|
138 | { |
||
139 | 7 | $this->emailSendReceiveCollection = $emailSendReceiveC; |
|
140 | 7 | } |
|
141 | |||
142 | /** |
||
143 | * @param EmailSendReceive $emailSendCheckI |
||
144 | * @throws EmailReceiveCheckException |
||
145 | */ |
||
146 | 4 | protected function timeReceiveCheck(EmailSendReceive $emailSendCheckI) |
|
164 | |||
165 | /** |
||
166 | * @param $mails |
||
167 | * @param EmailSendReceive $emailSendCheckI |
||
168 | */ |
||
169 | 3 | private function deleteReceivedEmails($mails, EmailSendReceive $emailSendCheckI) |
|
180 | |||
181 | /** |
||
182 | * @param EmailSendReceive $emailSendCheckI |
||
183 | * @throws EmailReceiveCheckException |
||
184 | */ |
||
185 | 7 | private function performReceive(EmailSendReceive $emailSendCheckI) |
|
204 | |||
205 | /** |
||
206 | * @param EmailSendReceive $emailSendCheckI |
||
207 | * @return \Closure |
||
208 | */ |
||
209 | private function findSameItemCallback(EmailSendReceive $emailSendCheckI) |
||
215 | } |
||
216 |