1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Facebook\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class CouldNotCreateButton. |
9
|
|
|
*/ |
10
|
|
|
class CouldNotCreateButton extends Exception |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Thrown when the button title is not provided. |
14
|
|
|
* |
15
|
|
|
* @return static |
16
|
|
|
*/ |
17
|
|
|
public static function titleNotProvided(): self |
18
|
|
|
{ |
19
|
|
|
return new static('Button title was not provided, A 20 character limited title should be provided.'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Thrown when the button type is "web_url" but the url is not provided. |
24
|
|
|
* |
25
|
|
|
* @return static |
26
|
|
|
*/ |
27
|
|
|
public static function urlNotProvided(): self |
28
|
|
|
{ |
29
|
|
|
return new static('Your button type is `web_url` but the url is not provided.'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Thrown when the button type is "phone_number" but the number is not provided. |
34
|
|
|
* |
35
|
|
|
* @return static |
36
|
|
|
*/ |
37
|
|
|
public static function phoneNumberNotProvided(): self |
38
|
|
|
{ |
39
|
|
|
return new static('Your button type is `phone_number` but the phone number is not provided.'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Thrown when the button type is "postback" but the postback data is not provided. |
44
|
|
|
* |
45
|
|
|
* @return static |
46
|
|
|
*/ |
47
|
|
|
public static function postbackNotProvided(): self |
48
|
|
|
{ |
49
|
|
|
return new static('Your button type is `postback` but the postback data is not provided.'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Thrown when the title characters limit is exceeded. |
54
|
|
|
* |
55
|
|
|
* @param string $title |
56
|
|
|
* |
57
|
|
|
* @return static |
58
|
|
|
*/ |
59
|
|
|
public static function titleLimitExceeded(string $title): self |
60
|
|
|
{ |
61
|
|
|
$count = mb_strlen($title); |
62
|
|
|
|
63
|
|
|
return new static( |
64
|
|
|
"Your title was {$count} characters long, which exceeds the 20 character limit. Please check the button template docs for more information." |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Thrown when the payload characters limit is exceeded. |
70
|
|
|
* |
71
|
|
|
* @param mixed $data |
72
|
|
|
* |
73
|
|
|
* @return static |
74
|
|
|
*/ |
75
|
|
|
public static function payloadLimitExceeded($data): self |
76
|
|
|
{ |
77
|
|
|
$count = mb_strlen($data); |
78
|
|
|
|
79
|
|
|
return new static( |
80
|
|
|
"Your payload was {$count} characters long, which exceeds the 1000 character limit. Please check the button template docs for more information." |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Thrown when the URL provided is not valid. |
86
|
|
|
* |
87
|
|
|
* @param string $url |
88
|
|
|
* |
89
|
|
|
* @return static |
90
|
|
|
*/ |
91
|
|
|
public static function invalidUrlProvided(string $url): self |
92
|
|
|
{ |
93
|
|
|
return new static("`{$url}` is not a valid URL. Please check and provide a valid URL"); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Thrown when the phone number provided is of invalid format. |
98
|
|
|
* |
99
|
|
|
* @param string $phoneNumber |
100
|
|
|
* |
101
|
|
|
* @return static |
102
|
|
|
*/ |
103
|
|
|
public static function invalidPhoneNumberProvided(string $phoneNumber): self |
104
|
|
|
{ |
105
|
|
|
return new static( |
106
|
|
|
"Provided phone number `{$phoneNumber}` format is invalid.". |
107
|
|
|
"Format must be '+' prefix followed by the country code, area code and local number.". |
108
|
|
|
'Please check the button template docs for more information.' |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|