Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
2 / 4
CRAP
62.50% covered (warning)
62.50%
10 / 16
MessageEvents
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
2 / 4
11.38
62.50% covered (warning)
62.50%
10 / 16
 add
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 getTransports
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getEvents
0.00% covered (danger)
0.00%
0 / 1
9.83
28.57% covered (danger)
28.57%
2 / 7
 getMessages
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
<?php
/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Symfony\Component\Mailer\Event;
use Symfony\Component\Mime\RawMessage;
/**
 * @author Fabien Potencier <fabien@symfony.com>
 */
class MessageEvents
{
    private $events = [];
    private $transports = [];
    public function add(MessageEvent $event): void
    {
        $this->events[] = $event;
        $this->transports[$event->getTransport()] = true;
    }
    public function getTransports(): array
    {
        return array_keys($this->transports);
    }
    /**
     * @return MessageEvent[]
     */
    public function getEvents(string $name = null): array
    {
        if (null === $name) {
            return $this->events;
        }
        $events = [];
        foreach ($this->events as $event) {
            if ($name === $event->getTransport()) {
                $events[] = $event;
            }
        }
        return $events;
    }
    /**
     * @return RawMessage[]
     */
    public function getMessages(string $name = null): array
    {
        $events = $this->getEvents($name);
        $messages = [];
        foreach ($events as $event) {
            $messages[] = $event->getMessage();
        }
        return $messages;
    }
}