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\Infrastructure\Notification\Strategy\Push; |
16
|
|
|
|
17
|
|
|
use Acme\App\Core\Port\Notification\Client\Push\PushNotifierInterface; |
18
|
|
|
use Acme\App\Core\Port\Notification\NotificationInterface; |
19
|
|
|
use Acme\App\Infrastructure\Notification\NotificationType; |
20
|
|
|
use Acme\App\Infrastructure\Notification\Settings\NotificationSettingsServiceInterface; |
21
|
|
|
use Acme\App\Infrastructure\Notification\Strategy\AbstractNotificationStrategy; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Coen Moij |
25
|
|
|
* @author Herberto Graca <[email protected]> |
26
|
|
|
* @author Nicolae Nichifor |
27
|
|
|
*/ |
28
|
|
|
final class PushNotificationStrategy extends AbstractNotificationStrategy |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var NotificationType |
32
|
|
|
*/ |
33
|
|
|
private $type; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var PushNotifierInterface |
37
|
|
|
*/ |
38
|
|
|
private $pushNotifier; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var NotificationSettingsServiceInterface |
42
|
|
|
*/ |
43
|
|
|
private $PushNotificationSettingsService; |
44
|
|
|
|
45
|
|
|
public function __construct( |
46
|
|
|
PushNotifierInterface $pushNotifier, |
47
|
|
|
NotificationSettingsServiceInterface $pushNotificationSettingsService |
48
|
|
|
) { |
49
|
|
|
$this->type = NotificationType::push(); |
50
|
|
|
$this->pushNotifier = $pushNotifier; |
51
|
|
|
$this->PushNotificationSettingsService = $pushNotificationSettingsService; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getType(): NotificationType |
55
|
|
|
{ |
56
|
|
|
return $this->type; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function notify(NotificationInterface $notification): void |
60
|
|
|
{ |
61
|
|
|
$this->pushNotifier->sendNotification($this->generateNotificationMessage($notification)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function canHandleNotification(NotificationInterface $notification): bool |
65
|
|
|
{ |
66
|
|
|
$hasPushNotificationsEnabled = $this->PushNotificationSettingsService->hasNotificationsEnabled( |
67
|
|
|
$notification->getDestinationUserId() |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
return $hasPushNotificationsEnabled && parent::canHandleNotification($notification); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|