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 | const HEADER_APNS_PUSH_TYPE = 'apns-push-type'; |
||
33 | |||
34 | /** |
||
35 | * Request headers. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | private $headers = []; |
||
40 | |||
41 | /** |
||
42 | * Request uri. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $uri; |
||
47 | |||
48 | /** |
||
49 | * Request body. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $body; |
||
54 | |||
55 | /** |
||
56 | * Curl options. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | private $options; |
||
61 | |||
62 | public function __construct(Notification $notification, $isProductionEnv) |
||
84 | |||
85 | /** |
||
86 | * Add request header. |
||
87 | * |
||
88 | * @param string $key |
||
89 | * @param $value |
||
90 | */ |
||
91 | public function addHeader(string $key, $value) |
||
95 | |||
96 | /** |
||
97 | * Add request headers. |
||
98 | * |
||
99 | * @param array $headers |
||
100 | */ |
||
101 | public function addHeaders(array $headers) |
||
105 | |||
106 | /** |
||
107 | * Get request headers. |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | public function getHeaders(): array |
||
115 | |||
116 | /** |
||
117 | * Add request option. |
||
118 | * |
||
119 | * @param string $key |
||
120 | * @param $value |
||
121 | */ |
||
122 | public function addOption(string $key, $value) |
||
126 | |||
127 | /** |
||
128 | * Add request options. |
||
129 | * |
||
130 | * @param array $options |
||
131 | */ |
||
132 | public function addOptions(array $options) |
||
136 | |||
137 | /** |
||
138 | * Get request options. |
||
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | public function getOptions(): array |
||
146 | |||
147 | /** |
||
148 | * Get decorated request headers. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | public function getDecoratedHeaders(): array |
||
160 | |||
161 | /** |
||
162 | * Get request uri. |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | public function getUri(): string |
||
170 | |||
171 | /** |
||
172 | * Get request body. |
||
173 | * |
||
174 | * @return string |
||
175 | */ |
||
176 | public function getBody(): string |
||
180 | |||
181 | /** |
||
182 | * Get Url for APNs production server. |
||
183 | * |
||
184 | * @param Notification $notification |
||
185 | * @return string |
||
186 | */ |
||
187 | private function getProductionUrl(Notification $notification) |
||
191 | |||
192 | /** |
||
193 | * Get Url for APNs sandbox server. |
||
194 | * |
||
195 | * @param Notification $notification |
||
196 | * @return string |
||
197 | */ |
||
198 | private function getSandboxUrl(Notification $notification) |
||
202 | |||
203 | /** |
||
204 | * Get Url path. |
||
205 | * |
||
206 | * @param Notification $notification |
||
207 | * @return mixed |
||
208 | */ |
||
209 | private function getUrlPath(Notification $notification) |
||
213 | |||
214 | /** |
||
215 | * Prepare APNs headers before sending request. |
||
216 | * |
||
217 | * @param Notification $notification |
||
218 | */ |
||
219 | private function prepareApnsHeaders(Notification $notification) |
||
248 | } |
||
249 |