1 | <?php |
||
20 | class Request |
||
21 | { |
||
22 | const APNS_DEVELOPMENT_SERVER = 'https://api.development.push.apple.com'; |
||
23 | const APNS_PRODUCTION_SERVER = 'https://api.push.apple.com'; |
||
24 | const APNS_PORT = 443; |
||
25 | const APNS_PATH_SCHEMA = '/3/device/{token}'; |
||
26 | |||
27 | const HEADER_APNS_ID = 'apns-id'; |
||
28 | const HEADER_APNS_EXPIRATION = 'apns-expiration'; |
||
29 | const HEADER_APNS_PRIORITY = 'apns-priority'; |
||
30 | const HEADER_APNS_TOPIC = 'apns-topic'; |
||
31 | const HEADER_APNS_COLLAPSE_ID = 'apns-collapse-id'; |
||
32 | |||
33 | /** |
||
34 | * Request headers. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | private $headers = []; |
||
39 | |||
40 | /** |
||
41 | * Request uri. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $uri; |
||
46 | |||
47 | /** |
||
48 | * Request body. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $body; |
||
53 | |||
54 | /** |
||
55 | * Curl options. |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | private $options; |
||
60 | |||
61 | public function __construct(Notification $notification, $isProductionEnv) |
||
83 | |||
84 | /** |
||
85 | * Add request header. |
||
86 | * |
||
87 | * @param string $key |
||
88 | * @param $value |
||
89 | */ |
||
90 | public function addHeader(string $key, $value) |
||
94 | |||
95 | /** |
||
96 | * Add request headers. |
||
97 | * |
||
98 | * @param array $headers |
||
99 | */ |
||
100 | public function addHeaders(array $headers) |
||
104 | |||
105 | /** |
||
106 | * Get request headers. |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | public function getHeaders(): array |
||
114 | |||
115 | /** |
||
116 | * Add request option. |
||
117 | * |
||
118 | * @param string $key |
||
119 | * @param $value |
||
120 | */ |
||
121 | public function addOption(string $key, $value) |
||
125 | |||
126 | /** |
||
127 | * Add request options. |
||
128 | * |
||
129 | * @param array $options |
||
130 | */ |
||
131 | public function addOptions(array $options) |
||
135 | |||
136 | /** |
||
137 | * Get request options. |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | public function getOptions(): array |
||
145 | |||
146 | /** |
||
147 | * Get decorated request headers. |
||
148 | * |
||
149 | * @return array |
||
150 | */ |
||
151 | public function getDecoratedHeaders(): array |
||
159 | |||
160 | /** |
||
161 | * Get request uri. |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | public function getUri(): string |
||
169 | |||
170 | /** |
||
171 | * Get request body. |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | public function getBody(): string |
||
179 | |||
180 | /** |
||
181 | * Get Url for APNs production server. |
||
182 | * |
||
183 | * @param Notification $notification |
||
184 | * @return string |
||
185 | */ |
||
186 | private function getProductionUrl(Notification $notification) |
||
190 | |||
191 | /** |
||
192 | * Get Url for APNs sandbox server. |
||
193 | * |
||
194 | * @param Notification $notification |
||
195 | * @return string |
||
196 | */ |
||
197 | private function getSandboxUrl(Notification $notification) |
||
201 | |||
202 | /** |
||
203 | * Get Url path. |
||
204 | * |
||
205 | * @param Notification $notification |
||
206 | * @return mixed |
||
207 | */ |
||
208 | private function getUrlPath(Notification $notification) |
||
212 | |||
213 | /** |
||
214 | * Prepare APNs headers before sending request. |
||
215 | * |
||
216 | * @param Notification $notification |
||
217 | */ |
||
218 | private function prepareApnsHeaders(Notification $notification) |
||
236 | } |
||
237 |