-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathArrayBackend.php
More file actions
67 lines (56 loc) · 1.72 KB
/
Copy pathArrayBackend.php
File metadata and controls
67 lines (56 loc) · 1.72 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
namespace Genkgo\Mail\Protocol\Smtp\Backend;
use Genkgo\Mail\EmailAddress;
use Genkgo\Mail\MessageInterface;
use Genkgo\Mail\Protocol\Smtp\BackendInterface;
final class ArrayBackend implements BackendInterface
{
/**
* @var array<string, bool>
*/
private $addresses;
/**
* @var \ArrayAccess<string, array<string, array<int, MessageInterface>>>
*/
private $backend;
/**
* @param array<int, string> $addresses
* @param \ArrayAccess<string, array<string, array<int, MessageInterface>>> $backend
*/
public function __construct(array $addresses, \ArrayAccess $backend)
{
$addresses = \array_combine(
$addresses,
\array_fill(0, \count($addresses), true)
);
$this->addresses = $addresses;
$this->backend = $backend;
}
/**
* @param EmailAddress $mailbox
* @return bool
*/
public function contains(EmailAddress $mailbox): bool
{
return isset($this->addresses[(string)$mailbox]);
}
/**
* @param EmailAddress $mailbox
* @param MessageInterface $message
* @param string $folder
*/
public function store(EmailAddress $mailbox, MessageInterface $message, string $folder): void
{
if (!isset($this->addresses[(string)$mailbox])) {
throw new \UnexpectedValueException('Unknown mailbox');
}
if (!isset($this->backend[(string)$mailbox])) {
$this->backend[(string)$mailbox] = [];
}
if (!isset($this->backend[(string)$mailbox][$folder])) {
$this->backend[(string)$mailbox][$folder] = [];
}
$this->backend[(string)$mailbox][$folder][] = $message;
}
}