Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 150 | Details | Vergleich mit vorheriger | 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\Event;
13
 
14
use Symfony\Component\Mailer\Envelope;
15
use Symfony\Component\Mailer\Exception\LogicException;
16
use Symfony\Component\Messenger\Stamp\StampInterface;
17
use Symfony\Component\Mime\RawMessage;
18
use Symfony\Contracts\EventDispatcher\Event;
19
 
20
/**
21
 * Allows the transformation of a Message and the Envelope before the email is sent.
22
 *
23
 * @author Fabien Potencier <fabien@symfony.com>
24
 */
25
final class MessageEvent extends Event
26
{
27
    private RawMessage $message;
28
    private Envelope $envelope;
29
    private string $transport;
30
    private bool $queued;
31
 
32
    /** @var StampInterface[] */
33
    private array $stamps = [];
34
 
35
    public function __construct(RawMessage $message, Envelope $envelope, string $transport, bool $queued = false)
36
    {
37
        $this->message = $message;
38
        $this->envelope = $envelope;
39
        $this->transport = $transport;
40
        $this->queued = $queued;
41
    }
42
 
43
    public function getMessage(): RawMessage
44
    {
45
        return $this->message;
46
    }
47
 
48
    public function setMessage(RawMessage $message): void
49
    {
50
        $this->message = $message;
51
    }
52
 
53
    public function getEnvelope(): Envelope
54
    {
55
        return $this->envelope;
56
    }
57
 
58
    public function setEnvelope(Envelope $envelope): void
59
    {
60
        $this->envelope = $envelope;
61
    }
62
 
63
    public function getTransport(): string
64
    {
65
        return $this->transport;
66
    }
67
 
68
    public function isQueued(): bool
69
    {
70
        return $this->queued;
71
    }
72
 
73
    public function addStamp(StampInterface $stamp): void
74
    {
75
        if (!$this->queued) {
200 lars 76
            throw new LogicException(sprintf('Cannot call "%s()" on a message that is not meant to be queued', __METHOD__));
148 lars 77
        }
78
 
79
        $this->stamps[] = $stamp;
80
    }
81
 
82
    /**
83
     * @return StampInterface[]
84
     */
85
    public function getStamps(): array
86
    {
87
        if (!$this->queued) {
88
            throw new LogicException(sprintf('Cannot call "%s()" on a message that is not meant to be queued.', __METHOD__));
89
        }
90
 
91
        return $this->stamps;
92
    }
93
}