@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | $options = $this->getOptions(); |
24 | 24 | if (isset($options['apns.proxy_host_url'])) { |
25 | 25 | // Override CURL options to connect to a HTTP/1.1 to HTTP/2 proxy |
26 | - $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'] . '/3/device/' . $this->getAddress(); |
|
26 | + $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'].'/3/device/'.$this->getAddress(); |
|
27 | 27 | $curl_options[CURLOPT_PORT] = $options['apns.proxy_host_port'] ?? 443; |
28 | 28 | // Use HTTP/1.1 instead of HTTP/2 |
29 | 29 | $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; |
30 | - $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
30 | + $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
31 | 31 | } |
32 | 32 | else { |
33 | 33 | $version_info = curl_version(); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | // Get the UID from the client certificate we use for authentication, this |
40 | 40 | // is set to the bundle ID. |
41 | - $options=$this->getOptions(); |
|
41 | + $options = $this->getOptions(); |
|
42 | 42 | $cert_filename = $options['apns.certificate']; |
43 | 43 | $cert_file_contents = file_get_contents($cert_filename); |
44 | 44 | if (false === $cert_file_contents) { |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
50 | - $cert=openssl_x509_parse( $cert_file_contents ); |
|
50 | + $cert = openssl_x509_parse($cert_file_contents); |
|
51 | 51 | if (false === $cert) { |
52 | 52 | throw new RuntimeException('Error parsing APNS client certificate'); |
53 | 53 | } |
@@ -72,42 +72,42 @@ discard block |
||
72 | 72 | $authProvider = AuthProvider\Certificate::create($authProviderOptions); |
73 | 73 | |
74 | 74 | // Create the push message |
75 | - $alert=Alert::create(); |
|
75 | + $alert = Alert::create(); |
|
76 | 76 | $alert->setBody($this->getText()); |
77 | 77 | // Note: It is possible to specify a title and a subtitle: $alert->setTitle() && $alert->setSubtitle() |
78 | 78 | // The tiqr service currently does not implement this. |
79 | - $payload=Payload::create()->setAlert($alert); |
|
79 | + $payload = Payload::create()->setAlert($alert); |
|
80 | 80 | $payload->setSound('default'); |
81 | 81 | foreach ($this->getCustomProperties() as $name => $value) { |
82 | 82 | $payload->setCustomValue($name, $value); |
83 | 83 | } |
84 | 84 | $this->logger->debug(sprintf('JSON Payload: %s', $payload->toJson())); |
85 | - $notification=new Notification($payload, $this->getAddress()); |
|
85 | + $notification = new Notification($payload, $this->getAddress()); |
|
86 | 86 | // Set expiration to 30 seconds from now, same as Message_APNS |
87 | 87 | $now = new DateTime(); |
88 | - $expirationInstant=$now->add(new DateInterval('PT30S')); |
|
88 | + $expirationInstant = $now->add(new DateInterval('PT30S')); |
|
89 | 89 | $notification->setExpirationAt($expirationInstant); |
90 | 90 | |
91 | 91 | // Send the push message |
92 | 92 | $client = new Client($authProvider, $options['apns.environment'] == 'production', $curl_options); |
93 | 93 | $client->addNotification($notification); |
94 | - $responses=$client->push(); |
|
95 | - if ( sizeof($responses) != 1) { |
|
96 | - $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses)) ); |
|
94 | + $responses = $client->push(); |
|
95 | + if (sizeof($responses) != 1) { |
|
96 | + $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses))); |
|
97 | 97 | if (sizeof($responses) == 0) { |
98 | 98 | $this->logger->warning('Could not determine whether the notification was sent'); |
99 | 99 | return; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | /** @var \Pushok\Response $response */ |
103 | - $response = reset($responses); // Get first response from the array |
|
104 | - $deviceToken=$response->getDeviceToken() ?? ''; |
|
103 | + $response = reset($responses); // Get first response from the array |
|
104 | + $deviceToken = $response->getDeviceToken() ?? ''; |
|
105 | 105 | // A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0 |
106 | - $apnsId=$response->getApnsId() ?? ''; |
|
106 | + $apnsId = $response->getApnsId() ?? ''; |
|
107 | 107 | // Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.) |
108 | - $statusCode=$response->getStatusCode(); |
|
108 | + $statusCode = $response->getStatusCode(); |
|
109 | 109 | $this->logger->info(sprintf('Got response with ApnsId "%s", status %s for deviceToken "%s"', $apnsId, $statusCode, $deviceToken)); |
110 | - if ( strcasecmp($deviceToken, $this->getAddress()) ) { |
|
110 | + if (strcasecmp($deviceToken, $this->getAddress())) { |
|
111 | 111 | $this->logger->warning(sprintf('Unexpected deviceToken in response. Expected: "%s"; got: "%s"', $this->getAddress(), $deviceToken)); |
112 | 112 | } |
113 | 113 | if ($statusCode == 200) { |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | - $reasonPhrase=$response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
119 | - $errorReason=$response->getErrorReason(); // E.g. Unregistered |
|
120 | - $errorDescription=$response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
118 | + $reasonPhrase = $response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
119 | + $errorReason = $response->getErrorReason(); // E.g. Unregistered |
|
120 | + $errorDescription = $response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
121 | 121 | |
122 | 122 | $this->logger->error(sprintf('Error sending APNS2 push notification. APNS ID: "%s"; deviceToken: "%s"; Error: "%s" "%s" "%s"', $apnsId, $deviceToken, $reasonPhrase, $errorReason, $errorDescription)); |
123 | 123 | throw new RuntimeException( |
@@ -28,8 +28,7 @@ |
||
28 | 28 | // Use HTTP/1.1 instead of HTTP/2 |
29 | 29 | $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; |
30 | 30 | $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
31 | - } |
|
32 | - else { |
|
31 | + } else { |
|
33 | 32 | $version_info = curl_version(); |
34 | 33 | if ($version_info['features'] & CURL_VERSION_HTTP2 == 0) { |
35 | 34 | throw new RuntimeException('APNS2 requires HTTP/2 support in curl'); |