-
-
Notifications
You must be signed in to change notification settings - Fork 254
/
MessageIterator.php
49 lines (41 loc) · 1.36 KB
/
MessageIterator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Ddeboer\Imap;
use Ddeboer\Imap\Message\PartInterface;
/**
* @extends \ArrayIterator<int, MessageInterface>
*/
final class MessageIterator extends \ArrayIterator implements MessageIteratorInterface
{
private ImapResourceInterface $resource;
/**
* Constructor.
*
* @param ImapResourceInterface $resource IMAP resource
* @param int[] $messageNumbers Array of message numbers
*/
public function __construct(ImapResourceInterface $resource, array $messageNumbers)
{
$this->resource = $resource;
parent::__construct($messageNumbers);
}
/**
* Get current message.
*
* @return MessageInterface<PartInterface>
*/
public function current(): MessageInterface
{
$current = parent::current();
if (!\is_int($current)) {
throw new Exception\OutOfBoundsException(\sprintf(
'The current value "%s" isn\'t an integer and doesn\'t represent a message;'
. ' try to cycle this "%s" with a native php function like foreach or with the method getArrayCopy(),'
. ' or check it by calling the methods valid().',
\get_debug_type($current),
self::class
));
}
return new Message($this->resource, $current);
}
}