1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the badams/symfony-amazon-sdk-mailer package. |
5
|
|
|
* |
6
|
|
|
* (c) Byron Adams <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Badams\AmazonMailerSdk; |
13
|
|
|
|
14
|
|
|
use Aws\Credentials\CredentialProvider; |
15
|
|
|
use Aws\Credentials\Credentials; |
16
|
|
|
use Symfony\Component\Mailer\Exception\UnsupportedSchemeException; |
17
|
|
|
use Symfony\Component\Mailer\Transport\AbstractTransportFactory; |
18
|
|
|
use Symfony\Component\Mailer\Transport\Dsn; |
19
|
|
|
use Symfony\Component\Mailer\Transport\TransportInterface; |
20
|
|
|
|
21
|
|
|
final class SesSdkTransportFactory extends AbstractTransportFactory |
22
|
|
|
{ |
23
|
|
|
public function create(Dsn $dsn): TransportInterface |
24
|
|
|
{ |
25
|
|
|
if (!$this->supports($dsn)) { |
26
|
|
|
throw new UnsupportedSchemeException($dsn); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
return new SesSdkTransport($this->getCredentials($dsn), $dsn->getHost(), $this->dispatcher, $this->logger); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function getCredentials(Dsn $dsn): callable |
33
|
|
|
{ |
34
|
|
|
$user = $dsn->getUser(); |
35
|
|
|
$password = $dsn->getPassword(); |
36
|
|
|
$credentialType = $dsn->getOption('credentials'); |
37
|
|
|
|
38
|
|
|
if (null !== $user || null !== $password) { |
39
|
|
|
return CredentialProvider::fromCredentials(new Credentials($user, $password)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
switch ($credentialType) { |
43
|
|
|
case 'env': |
44
|
|
|
return CredentialProvider::env(); |
45
|
|
|
case 'instance': |
46
|
|
|
return CredentialProvider::instanceProfile(); |
47
|
|
|
case 'ecs': |
48
|
|
|
return CredentialProvider::ecsCredentials(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return CredentialProvider::defaultProvider(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function getSupportedSchemes(): array |
55
|
|
|
{ |
56
|
|
|
return ['ses+sdk']; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|