Skip to content

Commit 7c6a4fe

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: (35 commits) fix: Improve FR validators translation [Notifier] Add push channel to notifier Fix CS [Lock] Split PdoStore into DoctrineDbalStore [Cache] Split PdoAdapter into DoctrineDbalAdapter Add swedish translation for issue #43458 [HttpClient] fix collecting debug info on destruction of CurlResponse Fix CS added missing thai translations Add missing translations for Chinese (zh_TW) [DependencyInjection] fix "url" env var processor update translation [Serializer] symfony#36594 attributes cache breaks normalization Remove untranslated translation for Afrikaans [Validator] Add missing validator polish translation [Security,Validator] Added missing Latvian translations #41053 Add the missing translations for Indonesian (id) [Validator] Add missing Lithuanian translation [Validator] Add missing Czech translation replace "ispravna" with "važeća" in translating "valid HTML/CSS" ...
2 parents fafe08c + 62cf714 commit 7c6a4fe

File tree

7 files changed

+243
-0
lines changed

7 files changed

+243
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `SentMessageEvent` and `FailedMessageEvent`
8+
* Add `push` channel
89

910
5.3
1011
---

Channel/PushChannel.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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\Notifier\Channel;
13+
14+
use Symfony\Component\Notifier\Message\PushMessage;
15+
use Symfony\Component\Notifier\Notification\Notification;
16+
use Symfony\Component\Notifier\Notification\PushNotificationInterface;
17+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
18+
19+
/**
20+
* @author Tomas Norkūnas <norkunas.tom@gmail.com>
21+
*/
22+
class PushChannel extends AbstractChannel
23+
{
24+
public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void
25+
{
26+
$message = null;
27+
if ($notification instanceof PushNotificationInterface) {
28+
$message = $notification->asPushMessage($recipient, $transportName);
29+
}
30+
31+
if (null === $message) {
32+
$message = PushMessage::fromNotification($notification);
33+
}
34+
35+
if (null !== $transportName) {
36+
$message->transport($transportName);
37+
}
38+
39+
if (null === $this->bus) {
40+
$this->transport->send($message);
41+
} else {
42+
$this->bus->dispatch($message);
43+
}
44+
}
45+
46+
public function supports(Notification $notification, RecipientInterface $recipient): bool
47+
{
48+
return true;
49+
}
50+
}

Exception/UnsupportedSchemeException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ class UnsupportedSchemeException extends LogicException
116116
'class' => Bridge\Octopush\OctopushTransportFactory::class,
117117
'package' => 'symfony/octopush-notifier',
118118
],
119+
'onesignal' => [
120+
'class' => Bridge\OneSignal\OneSignalTransportFactory::class,
121+
'package' => 'symfony/one-signal-notifier',
122+
],
119123
'ovhcloud' => [
120124
'class' => Bridge\OvhCloud\OvhCloudTransportFactory::class,
121125
'package' => 'symfony/ovh-cloud-notifier',

Message/PushMessage.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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\Notifier\Message;
13+
14+
use Symfony\Component\Notifier\Notification\Notification;
15+
16+
/**
17+
* @author Tomas Norkūnas <norkunas.tom@gmail.com>
18+
*/
19+
final class PushMessage implements MessageInterface
20+
{
21+
private $transport;
22+
private $subject;
23+
private $content;
24+
private $options;
25+
private $notification;
26+
27+
public function __construct(string $subject, string $content, MessageOptionsInterface $options = null)
28+
{
29+
$this->subject = $subject;
30+
$this->content = $content;
31+
$this->options = $options;
32+
}
33+
34+
public static function fromNotification(Notification $notification): self
35+
{
36+
$message = new self($notification->getSubject(), $notification->getContent());
37+
$message->notification = $notification;
38+
39+
return $message;
40+
}
41+
42+
public function getRecipientId(): ?string
43+
{
44+
return $this->options ? $this->options->getRecipientId() : null;
45+
}
46+
47+
public function subject(string $subject): self
48+
{
49+
$this->subject = $subject;
50+
51+
return $this;
52+
}
53+
54+
public function getSubject(): string
55+
{
56+
return $this->subject;
57+
}
58+
59+
public function content(string $content): self
60+
{
61+
$this->content = $content;
62+
63+
return $this;
64+
}
65+
66+
public function getContent(): string
67+
{
68+
return $this->content;
69+
}
70+
71+
public function options(MessageOptionsInterface $options): self
72+
{
73+
$this->options = $options;
74+
75+
return $this;
76+
}
77+
78+
public function getOptions(): ?MessageOptionsInterface
79+
{
80+
return $this->options;
81+
}
82+
83+
public function transport(?string $transport): self
84+
{
85+
$this->transport = $transport;
86+
87+
return $this;
88+
}
89+
90+
public function getTransport(): ?string
91+
{
92+
return $this->transport;
93+
}
94+
95+
public function getNotification(): ?Notification
96+
{
97+
return $this->notification;
98+
}
99+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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\Notifier\Notification;
13+
14+
use Symfony\Component\Notifier\Message\PushMessage;
15+
use Symfony\Component\Notifier\Recipient\RecipientInterface;
16+
17+
interface PushNotificationInterface
18+
{
19+
public function asPushMessage(RecipientInterface $recipient, string $transport = null): ?PushMessage;
20+
}

Tests/Exception/UnsupportedSchemeExceptionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Symfony\Component\Notifier\Bridge\Mobyt\MobytTransportFactory;
3939
use Symfony\Component\Notifier\Bridge\Nexmo\NexmoTransportFactory;
4040
use Symfony\Component\Notifier\Bridge\Octopush\OctopushTransportFactory;
41+
use Symfony\Component\Notifier\Bridge\OneSignal\OneSignalTransportFactory;
4142
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransportFactory;
4243
use Symfony\Component\Notifier\Bridge\RocketChat\RocketChatTransportFactory;
4344
use Symfony\Component\Notifier\Bridge\Sendinblue\SendinblueTransportFactory;
@@ -91,6 +92,7 @@ public static function setUpBeforeClass(): void
9192
MobytTransportFactory::class => false,
9293
NexmoTransportFactory::class => false,
9394
OctopushTransportFactory::class => false,
95+
OneSignalTransportFactory::class => false,
9496
OvhCloudTransportFactory::class => false,
9597
RocketChatTransportFactory::class => false,
9698
SendinblueTransportFactory::class => false,
@@ -150,6 +152,7 @@ public function messageWhereSchemeIsPartOfSchemeToPackageMapProvider(): \Generat
150152
yield ['mobyt', 'symfony/mobyt-notifier'];
151153
yield ['nexmo', 'symfony/nexmo-notifier'];
152154
yield ['octopush', 'symfony/octopush-notifier'];
155+
yield ['onesignal', 'symfony/one-signal-notifier'];
153156
yield ['ovhcloud', 'symfony/ovh-cloud-notifier'];
154157
yield ['rocketchat', 'symfony/rocket-chat-notifier'];
155158
yield ['sendinblue', 'symfony/sendinblue-notifier'];

Tests/Message/PushMessageTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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\Notifier\Tests\Message;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Message\PushMessage;
16+
use Symfony\Component\Notifier\Notification\Notification;
17+
18+
/**
19+
* @author Tomas Norkūnas <norkunas.tom@gmail.com>
20+
*/
21+
class PushMessageTest extends TestCase
22+
{
23+
public function testCanBeConstructed()
24+
{
25+
$message = new PushMessage('Hello', 'World');
26+
27+
$this->assertSame('Hello', $message->getSubject());
28+
$this->assertSame('World', $message->getContent());
29+
}
30+
31+
public function testSetSubject()
32+
{
33+
$message = new PushMessage('Hello', 'World');
34+
$message->subject('dlrow olleH');
35+
36+
$this->assertSame('dlrow olleH', $message->getSubject());
37+
}
38+
39+
public function testSetContent()
40+
{
41+
$message = new PushMessage('Hello', 'World');
42+
$message->content('dlrow olleH');
43+
44+
$this->assertSame('dlrow olleH', $message->getContent());
45+
}
46+
47+
public function testSetTransport()
48+
{
49+
$message = new PushMessage('Hello', 'World');
50+
$message->transport('next_one');
51+
52+
$this->assertSame('next_one', $message->getTransport());
53+
}
54+
55+
public function testCreateFromNotification()
56+
{
57+
$notification = new Notification('Hello');
58+
$notification->content('World');
59+
60+
$message = PushMessage::fromNotification($notification);
61+
62+
$this->assertSame('Hello', $message->getSubject());
63+
$this->assertSame('World', $message->getContent());
64+
$this->assertSame($notification, $message->getNotification());
65+
}
66+
}

0 commit comments

Comments
 (0)