SentMessageEvent example

$this->dispatcher->dispatch(new MessageEvent($message));

        try {
            $sentMessage = $this->doSend($message);
        } catch (\Throwable $error) {
            $this->dispatcher->dispatch(new FailedMessageEvent($message$error));

            throw $error;
        }

        $this->dispatcher->dispatch(new SentMessageEvent($sentMessage));

        return $sentMessage;
    }

    abstract protected function doSend(MessageInterface $message): SentMessage;

    protected function getEndpoint(): string
    {
        return ($this->host ?: $this->getDefaultHost()).($this->port ? ':'.$this->port : '');
    }

    
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage;

final class SentMessageEventTest extends TestCase
{
    /** * @dataProvider messagesProvider */
    public function testConstruct(SentMessage $message, SentMessageEvent $event)
    {
        $this->assertEquals($eventnew SentMessageEvent($message));
    }

    /** * @dataProvider messagesProvider */
    public function testGetMessage(SentMessage $message, SentMessageEvent $event)
    {
        $this->assertSame($message$event->getMessage());
    }

    public static function messagesProvider(): iterable
    {
public function send(MessageInterface $message): SentMessage
    {
        $message = new NullMessage($message);
        $sentMessage = new SentMessage($message(string) $this);

        if (null === $this->dispatcher) {
            return $sentMessage;
        }

        $this->dispatcher->dispatch(new MessageEvent($message));
        $this->dispatcher->dispatch(new SentMessageEvent($sentMessage));

        return $sentMessage;
    }

    public function __toString(): string
    {
        return 'null';
    }

    public function supports(MessageInterface $message): bool
    {
        
$sentMessage = new SentMessage($message$envelope);

            try {
                $this->doSend($sentMessage);
            } catch (\Throwable $error) {
                $this->dispatcher->dispatch(new FailedMessageEvent($message$error));
                $this->checkThrottling();

                throw $error;
            }

            $this->dispatcher->dispatch(new SentMessageEvent($sentMessage));

            return $sentMessage;
        } finally {
            $this->checkThrottling();
        }
    }

    abstract protected function doSend(SentMessage $message): void;

    /** * @param Address[] $addresses * * @return string[] */
Home | Imprint | This part of the site doesn't use cookies.