Skip to content

[Mailer] Renamed getName() to toString() #33419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(EventDispatcherInterface $eventDispatcher, LoggerInt
$this->onDoSend = $onDoSend;
}

public function getName(): string
public function __toString(): string
{
return 'dummy://local';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(string $accessKey, string $secretKey, string $region
parent::__construct($client, $dispatcher, $logger);
}

public function getName(): string
public function __toString(): string
{
return sprintf('api://%s@ses?region=%s', $this->accessKey, $this->region);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(string $accessKey, string $secretKey, string $region
parent::__construct($client, $dispatcher, $logger);
}

public function getName(): string
public function __toString(): string
{
return sprintf('http://%s@ses?region=%s', $this->accessKey, $this->region);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
parent::__construct($client, $dispatcher, $logger);
}

public function getName(): string
public function __toString(): string
{
return sprintf('api://mandrill');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
parent::__construct($client, $dispatcher, $logger);
}

public function getName(): string
public function __toString(): string
{
return sprintf('http://mandrill');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(string $key, string $domain, string $region = null,
parent::__construct($client, $dispatcher, $logger);
}

public function getName(): string
public function __toString(): string
{
return sprintf('api://%s@mailgun?region=%s', $this->domain, $this->region);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(string $key, string $domain, string $region = null,
parent::__construct($client, $dispatcher, $logger);
}

public function getName(): string
public function __toString(): string
{
return sprintf('http://%s@mailgun?region=%s', $this->domain, $this->region);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
parent::__construct($client, $dispatcher, $logger);
}

public function getName(): string
public function __toString(): string
{
return sprintf('api://postmark');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ public function unsupportedSchemeProvider(): iterable
'The "foo" scheme is not supported for mailer "sendgrid". Supported schemes are: "api", "smtp", "smtps".',
];
}

public function incompleteDsnProvider(): iterable
{
yield [new Dsn('api', 'sendgrid')];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(string $key, HttpClientInterface $client = null, Eve
parent::__construct($client, $dispatcher, $logger);
}

public function getName(): string
public function __toString(): string
{
return sprintf('api://sendgrid');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CHANGELOG
* Added PHPUnit constraints
* Added `MessageDataCollector`
* Added `MessageEvents` and `MessageLoggerListener` to allow collecting sent emails
* [BC BREAK] `TransportInterface` has a new `getName()` method
* [BC BREAK] `TransportInterface` has a new `__toString()` method
* [BC BREAK] Classes `AbstractApiTransport` and `AbstractHttpTransport` moved under `Transport` sub-namespace.
* [BC BREAK] Transports depend on `Symfony\Contracts\EventDispatcher\EventDispatcherInterface`
instead of `Symfony\Component\EventDispatcher\EventDispatcherInterface`.
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Mailer/Event/MessageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ final class MessageEvent extends Event
{
private $message;
private $envelope;
private $transportName;
private $transport;
private $queued;

public function __construct(RawMessage $message, SmtpEnvelope $envelope, string $transportName, bool $queued = false)
public function __construct(RawMessage $message, SmtpEnvelope $envelope, string $transport, bool $queued = false)
{
$this->message = $message;
$this->envelope = $envelope;
$this->transportName = $transportName;
$this->transport = $transport;
$this->queued = $queued;
}

Expand All @@ -55,9 +55,9 @@ public function setEnvelope(SmtpEnvelope $envelope): void
$this->envelope = $envelope;
}

public function getTransportName(): string
public function getTransport(): string
{
return $this->transportName;
return $this->transport;
}

public function isQueued(): bool
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Mailer/Event/MessageEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MessageEvents
public function add(MessageEvent $event): void
{
$this->events[] = $event;
$this->transports[$event->getTransportName()] = true;
$this->transports[$event->getTransport()] = true;
}

public function getTransports(): array
Expand All @@ -43,7 +43,7 @@ public function getEvents(string $name = null): array

$events = [];
foreach ($this->events as $event) {
if ($name === $event->getTransportName()) {
if ($name === $event->getTransport()) {
$events[] = $event;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): void
throw new TransportException('Cannot send message without a valid envelope.', 0, $e);
}
}
$event = new MessageEvent($message, $envelope, $this->transport->getName(), true);
$event = new MessageEvent($message, $envelope, (string) $this->transport, true);
$this->dispatcher->dispatch($event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testCreate(Dsn $dsn, TransportInterface $transport): void

$this->assertEquals($transport, $factory->create($dsn));
if ('smtp' !== $dsn->getScheme() && 'smtps' !== $dsn->getScheme()) {
$this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', $transport->getName());
$this->assertStringMatchesFormat($dsn->getScheme().'://%S'.$dsn->getHost().'%S', (string) $transport);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public function testSendNoTransports()
new FailoverTransport([]);
}

public function testGetName()
public function testToString()
{
$t1 = $this->createMock(TransportInterface::class);
$t1->expects($this->once())->method('getName')->willReturn('t1://local');
$t1->expects($this->once())->method('__toString')->willReturn('t1://local');
$t2 = $this->createMock(TransportInterface::class);
$t2->expects($this->once())->method('getName')->willReturn('t2://local');
$t2->expects($this->once())->method('__toString')->willReturn('t2://local');
$t = new FailoverTransport([$t1, $t2]);
$this->assertEquals('t1://local || t2://local', $t->getName());
$this->assertEquals('t1://local || t2://local', (string) $t);
}

public function testSendFirstWork()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

class NullTransportTest extends TestCase
{
public function testName()
public function testToString()
{
$t = new NullTransport();
$this->assertEquals('smtp://null', $t->getName());
$this->assertEquals('smtp://null', (string) $t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public function testSendNoTransports()
new RoundRobinTransport([]);
}

public function testGetName()
public function testToString()
{
$t1 = $this->createMock(TransportInterface::class);
$t1->expects($this->once())->method('getName')->willReturn('t1://local');
$t1->expects($this->once())->method('__toString')->willReturn('t1://local');
$t2 = $this->createMock(TransportInterface::class);
$t2->expects($this->once())->method('getName')->willReturn('t2://local');
$t2->expects($this->once())->method('__toString')->willReturn('t2://local');
$t = new RoundRobinTransport([$t1, $t2]);
$this->assertEquals('t1://local && t2://local', $t->getName());
$this->assertEquals('t1://local && t2://local', (string) $t);
}

public function testSendAlternate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

class SendmailTransportTest extends TestCase
{
public function testName()
public function testToString()
{
$t = new SendmailTransport();
$this->assertEquals('smtp://sendmail', $t->getName());
$this->assertEquals('smtp://sendmail', (string) $t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@

class EsmtpTransportTest extends TestCase
{
public function testName()
public function testToString()
{
$t = new EsmtpTransport();
$this->assertEquals('smtp://localhost', $t->getName());
$this->assertEquals('smtp://localhost', (string) $t);

$t = new EsmtpTransport('example.com');
if (\defined('OPENSSL_VERSION_NUMBER')) {
$this->assertEquals('smtps://example.com', $t->getName());
$this->assertEquals('smtps://example.com', (string) $t);
} else {
$this->assertEquals('smtp://example.com', $t->getName());
$this->assertEquals('smtp://example.com', (string) $t);
}

$t = new EsmtpTransport('example.com', 2525);
$this->assertEquals('smtp://example.com:2525', $t->getName());
$this->assertEquals('smtp://example.com:2525', (string) $t);

$t = new EsmtpTransport('example.com', 0, true);
$this->assertEquals('smtps://example.com', $t->getName());
$this->assertEquals('smtps://example.com', (string) $t);

$t = new EsmtpTransport('example.com', 0, false);
$this->assertEquals('smtp://example.com', $t->getName());
$this->assertEquals('smtp://example.com', (string) $t);

$t = new EsmtpTransport('example.com', 466, true);
$this->assertEquals('smtps://example.com:466', $t->getName());
$this->assertEquals('smtps://example.com:466', (string) $t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

class SmtpTransportTest extends TestCase
{
public function testName()
public function testToString()
{
$t = new SmtpTransport();
$this->assertEquals('smtps://localhost', $t->getName());
$this->assertEquals('smtps://localhost', (string) $t);

$t = new SmtpTransport((new SocketStream())->setHost('127.0.0.1')->setPort(2525)->disableTls());
$this->assertEquals('smtp://127.0.0.1:2525', $t->getName());
$this->assertEquals('smtp://127.0.0.1:2525', (string) $t);
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/Tests/TransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
throw new \BadMethodCallException('This method newer should be called.');
}

public function getName(): string
public function __toString(): string
{
return sprintf('dummy://local');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
}
}

$event = new MessageEvent($message, $envelope, $this->getName());
$event = new MessageEvent($message, $envelope, (string) $this);
$this->dispatcher->dispatch($event);
$envelope = $event->getEnvelope();
if (!$envelope->getRecipients()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/Transport/NullTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function doSend(SentMessage $message): void
{
}

public function getName(): string
public function __toString(): string
{
return 'smtp://null';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
throw new TransportException('All transports failed.');
}

public function getName(): string
public function __toString(): string
{
return implode(' '.$this->getNameSymbol().' ', array_map(function (TransportInterface $transport) {
return $transport->getName();
return (string) $transport;
}, $this->transports));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Mailer/Transport/SendmailTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
return parent::send($message, $envelope);
}

public function getName(): string
public function __toString(): string
{
if ($this->transport) {
return $this->transport->getName();
return (string) $this->transport;
}

return 'smtp://sendmail';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
return $message;
}

public function getName(): string
public function __toString(): string
{
if ($this->stream instanceof SocketStream) {
$name = sprintf('smtp%s://%s', ($tls = $this->stream->isTLS()) ? 's' : '', $this->stream->getHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ interface TransportInterface
*/
public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentMessage;

public function getName(): string;
public function __toString(): string;
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy