Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 150 | Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Component\Mailer\Transport;
13
 
14
use Symfony\Component\Mailer\Envelope;
15
use Symfony\Component\Mailer\Exception\RuntimeException;
16
use Symfony\Component\Mailer\SentMessage;
17
use Symfony\Component\Mime\Address;
18
use Symfony\Component\Mime\Email;
19
use Symfony\Component\Mime\MessageConverter;
20
use Symfony\Contracts\HttpClient\ResponseInterface;
21
 
22
/**
23
 * @author Fabien Potencier <fabien@symfony.com>
24
 */
25
abstract class AbstractApiTransport extends AbstractHttpTransport
26
{
27
    abstract protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $envelope): ResponseInterface;
28
 
29
    protected function doSendHttp(SentMessage $message): ResponseInterface
30
    {
31
        try {
32
            $email = MessageConverter::toEmail($message->getOriginalMessage());
33
        } catch (\Exception $e) {
34
            throw new RuntimeException(sprintf('Unable to send message with the "%s" transport: ', __CLASS__).$e->getMessage(), 0, $e);
35
        }
36
 
37
        return $this->doSendApi($message, $email, $message->getEnvelope());
38
    }
39
 
40
    protected function getRecipients(Email $email, Envelope $envelope): array
41
    {
42
        return array_filter($envelope->getRecipients(), function (Address $address) use ($email) {
43
            return false === \in_array($address, array_merge($email->getCc(), $email->getBcc()), true);
44
        });
45
    }
46
}