File tree Expand file tree Collapse file tree 8 files changed +409
-0
lines changed Expand file tree Collapse file tree 8 files changed +409
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Vonage \Messages \Webhook ;
6+
7+ use InvalidArgumentException ;
8+ use Vonage \Webhook \Factory as WebhookFactory ;
9+
10+ class Factory extends WebhookFactory
11+ {
12+ protected static array $ classMap = [
13+ 'sms ' => 'Vonage\Messages\Webhook\InboundSMS ' ,
14+ 'mms ' => 'Vonage\Messages\Webhook\InboundMMS ' ,
15+ 'rcs ' => 'Vonage\Messages\Webhook\InboundRCS ' ,
16+ 'whatsapp ' => 'Vonage\Messages\Webhook\InboundWhatsApp ' ,
17+ 'messenger ' => 'Vonage\Messages\Webhook\InboundMessenger ' ,
18+ 'viber_service ' => 'Vonage\Messages\Webhook\InboundViber '
19+ ];
20+
21+ public static function createFromArray (array $ data ): mixed
22+ {
23+ if (!isset ($ data ['channel ' ])) {
24+ throw new InvalidArgumentException ("The 'channel' key is missing in the incoming data. " );
25+ }
26+
27+ $ channel = $ data ['channel ' ];
28+
29+ if (!array_key_exists ($ channel , self ::$ classMap )) {
30+ throw new InvalidArgumentException ("Unable to determine incoming webhook type for channel: {$ channel }" );
31+ }
32+
33+ return new self::$ classMap [$ channel ]();
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Vonage \Messages \Webhook ;
6+
7+ use Vonage \Entity \Hydrator \ArrayHydrateInterface ;
8+
9+ final class InboundMMS implements ArrayHydrateInterface
10+ {
11+ protected ?array $ data = null ;
12+
13+ public function fromArray (array $ data ): self
14+ {
15+ $ this ->data = $ data ;
16+ return $ this ;
17+ }
18+
19+ public function toArray (): array
20+ {
21+ return $ this ->data ;
22+ }
23+
24+ public function __get ($ name )
25+ {
26+ return $ this ->data [$ name ];
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Vonage \Messages \Webhook ;
6+
7+ use Vonage \Entity \Hydrator \ArrayHydrateInterface ;
8+
9+ final class InboundMessenger implements ArrayHydrateInterface
10+ {
11+ protected ?array $ data = null ;
12+
13+ public function fromArray (array $ data ): self
14+ {
15+ $ this ->data = $ data ;
16+ return $ this ;
17+ }
18+
19+ public function toArray (): array
20+ {
21+ return $ this ->data ;
22+ }
23+
24+ public function __get ($ name )
25+ {
26+ return $ this ->data [$ name ];
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Vonage \Messages \Webhook ;
6+
7+ use Vonage \Entity \Hydrator \ArrayHydrateInterface ;
8+
9+ final class InboundRCS implements ArrayHydrateInterface
10+ {
11+ protected ?array $ data = null ;
12+
13+ public function fromArray (array $ data ): self
14+ {
15+ $ this ->data = $ data ;
16+ return $ this ;
17+ }
18+
19+ public function toArray (): array
20+ {
21+ return $ this ->data ;
22+ }
23+
24+ public function __get ($ name )
25+ {
26+ return $ this ->data [$ name ];
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Vonage \Messages \Webhook ;
6+
7+ use Vonage \Entity \Hydrator \ArrayHydrateInterface ;
8+
9+ final class InboundSMS implements ArrayHydrateInterface
10+ {
11+ protected ?array $ data = null ;
12+
13+ public function fromArray (array $ data ): self
14+ {
15+ $ this ->data = $ data ;
16+ return $ this ;
17+ }
18+
19+ public function toArray (): array
20+ {
21+ return $ this ->data ;
22+ }
23+
24+ public function __get ($ name )
25+ {
26+ return $ this ->data [$ name ];
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Vonage \Messages \Webhook ;
6+
7+ use Vonage \Entity \Hydrator \ArrayHydrateInterface ;
8+
9+ final class InboundViber implements ArrayHydrateInterface
10+ {
11+ protected ?array $ data = null ;
12+
13+ public function fromArray (array $ data ): self
14+ {
15+ $ this ->data = $ data ;
16+ return $ this ;
17+ }
18+
19+ public function toArray (): array
20+ {
21+ return $ this ->data ;
22+ }
23+
24+ public function __get ($ name )
25+ {
26+ return $ this ->data [$ name ];
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Vonage \Messages \Webhook ;
6+
7+ use Vonage \Entity \Hydrator \ArrayHydrateInterface ;
8+
9+ final class InboundWhatsApp implements ArrayHydrateInterface
10+ {
11+ protected ?array $ data = null ;
12+
13+ public function fromArray (array $ data ): self
14+ {
15+ $ this ->data = $ data ;
16+ return $ this ;
17+ }
18+
19+ public function toArray (): array
20+ {
21+ return $ this ->data ;
22+ }
23+
24+ public function __get ($ name )
25+ {
26+ return $ this ->data [$ name ];
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments