1 | <?php |
||
7 | class DomainWhitelisting implements ThreadSetting, \JsonSerializable |
||
8 | { |
||
9 | const TYPE_ADD = 'add'; |
||
10 | const TYPE_REMOVE = 'remove'; |
||
11 | |||
12 | const WHITELISTED_DOMAINS = 'whitelisted_domains'; |
||
13 | const DOMAIN_ACTION_TYPE = 'domain_action_type'; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $action; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | private $domains = []; |
||
24 | |||
25 | /** |
||
26 | * |
||
27 | * @param string $action |
||
28 | * @param array $domains |
||
29 | * |
||
30 | * @throws \InvalidArgumentException |
||
31 | */ |
||
32 | 9 | public function __construct($domains, $action = DomainWhitelisting::TYPE_ADD) |
|
40 | |||
41 | /** |
||
42 | * |
||
43 | * @return array |
||
44 | */ |
||
45 | 1 | public function getDomains() |
|
46 | { |
||
47 | 1 | return $this->domains; |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | 2 | public function getAction() |
|
55 | { |
||
56 | 2 | return $this->action; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * |
||
61 | * @param string $action |
||
62 | * |
||
63 | * @throws \InvalidArgumentException |
||
64 | */ |
||
65 | 9 | public static function validateAction($action) |
|
71 | |||
72 | /** |
||
73 | * |
||
74 | * @param array $domains |
||
75 | * |
||
76 | * @throws \InvalidArgumentException |
||
77 | */ |
||
78 | 8 | public static function validateDomains($domains) |
|
79 | { |
||
80 | 8 | if(!is_array($domains)) { |
|
81 | 1 | throw new \InvalidArgumentException('Domains must be a array.'); |
|
82 | } |
||
83 | |||
84 | //https://developers.facebook.com/docs/messenger-platform/thread-settings/domain-whitelisting |
||
85 | 7 | foreach($domains as $domain) { |
|
86 | 7 | if(!preg_match('#^https:\/\/#', $domain)) { |
|
87 | 1 | throw new \InvalidArgumentException('Each domain must be a "https" protocol.'); |
|
88 | } |
||
89 | 7 | } |
|
90 | 6 | } |
|
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | */ |
||
95 | 2 | public function jsonSerialize() |
|
102 | } |
||
103 | |||
104 |