Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Zur aktuellen Revision | 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;
150 lars 31
    private bool $rejected = false;
148 lars 32
 
33
    /** @var StampInterface[] */
34
    private array $stamps = [];
35
 
36
    public function __construct(RawMessage $message, Envelope $envelope, string $transport, bool $queued = false)
37
    {
38
        $this->message = $message;
39
        $this->envelope = $envelope;
40
        $this->transport = $transport;
41
        $this->queued = $queued;
42
    }
43
 
44
    public function getMessage(): RawMessage
45
    {
46
        return $this->message;
47
    }
48
 
49
    public function setMessage(RawMessage $message): void
50
    {
51
        $this->message = $message;
52
    }
53
 
54
    public function getEnvelope(): Envelope
55
    {
56
        return $this->envelope;
57
    }
58
 
59
    public function setEnvelope(Envelope $envelope): void
60
    {
61
        $this->envelope = $envelope;
62
    }
63
 
64
    public function getTransport(): string
65
    {
66
        return $this->transport;
67
    }
68
 
69
    public function isQueued(): bool
70
    {
71
        return $this->queued;
72
    }
73
 
150 lars 74
    public function isRejected(): bool
75
    {
76
        return $this->rejected;
77
    }
78
 
79
    public function reject(): void
80
    {
81
        $this->rejected = true;
82
        $this->stopPropagation();
83
    }
84
 
148 lars 85
    public function addStamp(StampInterface $stamp): void
86
    {
87
        if (!$this->queued) {
150 lars 88
            throw new LogicException(sprintf('Cannot call "%s()" on a message that is not meant to be queued.', __METHOD__));
148 lars 89
        }
90
 
91
        $this->stamps[] = $stamp;
92
    }
93
 
94
    /**
95
     * @return StampInterface[]
96
     */
97
    public function getStamps(): array
98
    {
99
        if (!$this->queued) {
100
            throw new LogicException(sprintf('Cannot call "%s()" on a message that is not meant to be queued.', __METHOD__));
101
        }
102
 
103
        return $this->stamps;
104
    }
105
}