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\Settings; |
16
|
|
|
|
17
|
|
|
use Acme\App\Core\Port\Persistence\UserKeyValueStorageInterface; |
18
|
|
|
use Acme\App\Core\SharedKernel\Component\User\Domain\User\UserId; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Coen Moij |
22
|
|
|
* @author Herberto Graca <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
final class SmsNotificationSettingsService implements NotificationSettingsServiceInterface |
25
|
|
|
{ |
26
|
|
|
private const NAMESPACE = 'sms'; |
27
|
|
|
private const KEY = 'enabled'; |
28
|
|
|
private const ENABLED = '1'; |
29
|
|
|
private const DISABLED = '0'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var UserKeyValueStorageInterface |
33
|
|
|
*/ |
34
|
|
|
private $storage; |
35
|
|
|
|
36
|
|
|
public function __construct(UserKeyValueStorageInterface $storage) |
37
|
|
|
{ |
38
|
|
|
$this->storage = $storage; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function hasNotificationsEnabled(UserId $userId): bool |
42
|
|
|
{ |
43
|
|
|
return $this->storage->get($userId, self::NAMESPACE, self::KEY) !== self::DISABLED; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function enableNotifications(UserId $userId): void |
47
|
|
|
{ |
48
|
|
|
$this->storage->set($userId, self::NAMESPACE, self::KEY, self::ENABLED); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function disableNotifications(UserId $userId): void |
52
|
|
|
{ |
53
|
|
|
$this->storage->set($userId, self::NAMESPACE, self::KEY, self::DISABLED); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|