1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Explicit Architecture POC, |
7
|
|
|
* which is created on top of the Symfony Demo application. |
8
|
|
|
* |
9
|
|
|
* (c) Herberto Graça <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Acme\App\Core\Component\Blog\Application\Notification\NewComment\Push; |
16
|
|
|
|
17
|
|
|
use Acme\App\Core\Component\Blog\Application\Notification\NewComment\NewCommentNotification; |
18
|
|
|
use Acme\App\Core\Port\Notification\Client\Push\PushNotification; |
19
|
|
|
use Acme\App\Core\Port\Translation\TranslatorInterface; |
20
|
|
|
|
21
|
|
|
final class NewCommentPushGenerator |
22
|
|
|
{ |
23
|
|
|
// Unfortunately we need to make these public, otherwise we can't test it without reflection |
24
|
|
|
public const NOTIFICATION_NAME = 'NEW_COMMENT'; |
25
|
|
|
public const TITLE_TRANSLATION_KEY = 'blog.push.new_comment.title'; |
26
|
|
|
public const MESSAGE_TRANSLATION_KEY = 'blog.push.new_comment.message'; |
27
|
|
|
public const DATA_KEY_POST_ID = 'post_id'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var TranslatorInterface |
31
|
|
|
*/ |
32
|
|
|
private $translator; |
33
|
|
|
|
34
|
|
|
public function __construct(TranslatorInterface $translator) |
35
|
|
|
{ |
36
|
|
|
$this->translator = $translator; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function generate(NewCommentNotification $notification): PushNotification |
40
|
|
|
{ |
41
|
|
|
return new PushNotification( |
42
|
|
|
self::NOTIFICATION_NAME, |
43
|
|
|
$this->translator->translate(self::TITLE_TRANSLATION_KEY), |
44
|
|
|
$this->translator->translate(self::MESSAGE_TRANSLATION_KEY), |
45
|
|
|
$notification->getDestinationUserId(), |
46
|
|
|
[ |
47
|
|
|
self::DATA_KEY_POST_ID => (string) $notification->getPostId(), |
48
|
|
|
] |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|