1 | <?php |
||
31 | abstract class AbstractClient implements SmsNotifierInterface |
||
32 | { |
||
33 | /** |
||
34 | * @var PhoneNumberValidatorInterface |
||
35 | */ |
||
36 | private $phoneNumberValidator; |
||
37 | |||
38 | /** |
||
39 | * @var PhoneNumberUtil |
||
40 | */ |
||
41 | private $phoneNumberUtil; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | private $countryCode; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | private $defaultDestination; |
||
52 | |||
53 | public function __construct( |
||
54 | PhoneNumberValidatorInterface $phoneNumberValidator, |
||
55 | PhoneNumberUtil $phoneNumberUtil, |
||
56 | string $countryCode, |
||
57 | string $defaultDestination = null |
||
58 | ) { |
||
59 | $this->phoneNumberValidator = $phoneNumberValidator; |
||
60 | $this->phoneNumberUtil = $phoneNumberUtil; |
||
61 | $this->countryCode = $countryCode; |
||
62 | $this->defaultDestination = $defaultDestination; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @throws PhoneNumberException |
||
67 | */ |
||
68 | public function sendNotification(Sms $smsNotification): void |
||
69 | { |
||
70 | $phoneNumber = $this->formatToE164($this->defaultDestination ?? $smsNotification->getPhoneNumber()); |
||
71 | |||
72 | $this->triggerNotification($phoneNumber, $smsNotification->getContent()); |
||
73 | } |
||
74 | |||
75 | abstract public function triggerNotification(string $phoneNumber, string $content): void; |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | * |
||
80 | * @throws PhoneNumberException |
||
81 | */ |
||
82 | private function formatToE164(string $phoneNumber): string |
||
88 | |||
89 | /** |
||
90 | * @throws PhoneNumberException |
||
91 | */ |
||
92 | private function parsePhoneNumberOrThrowException(string $phoneNumber): PhoneNumber |
||
102 | } |
||
103 |