@@ -68,7 +68,7 @@ |
||
68 | 68 | /** |
69 | 69 | * Send data to provider. |
70 | 70 | * |
71 | - * @param array $subscribers |
|
71 | + * @param Subscriber[] $subscribers |
|
72 | 72 | * @param \Closure $success |
73 | 73 | * @param \Closure $fail |
74 | 74 | */ |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function setProject(Project $project) |
45 | 45 | { |
46 | - $this->project = $project; |
|
46 | + $this->project = $project; |
|
47 | 47 | |
48 | 48 | return $this; |
49 | 49 | } |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | protected function flush(array $subscribers, \Closure $success = null, \Closure $fail = null) |
76 | 76 | { |
77 | 77 | if (is_null($success)) { |
78 | - $success = function ($response, $index) {}; |
|
78 | + $success = function($response, $index) {}; |
|
79 | 79 | } |
80 | 80 | if (is_null($fail)) { |
81 | - $fail = function ($reason, $index) {}; |
|
81 | + $fail = function($reason, $index) {}; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | $pool = new Pool(static::$browser, $this->prepareRequests($subscribers), [ |
@@ -74,11 +74,17 @@ |
||
74 | 74 | */ |
75 | 75 | protected function flush(array $subscribers, \Closure $success = null, \Closure $fail = null) |
76 | 76 | { |
77 | - if (is_null($success)) { |
|
78 | - $success = function ($response, $index) {}; |
|
77 | + if (is_null($success)) |
|
78 | + { |
|
79 | + $success = function ($response, $index) |
|
80 | + { |
|
81 | +}; |
|
79 | 82 | } |
80 | - if (is_null($fail)) { |
|
81 | - $fail = function ($reason, $index) {}; |
|
83 | + if (is_null($fail)) |
|
84 | + { |
|
85 | + $fail = function ($reason, $index) |
|
86 | + { |
|
87 | +}; |
|
82 | 88 | } |
83 | 89 | |
84 | 90 | $pool = new Pool(static::$browser, $this->prepareRequests($subscribers), [ |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | $this->flush( |
67 | 67 | $subscribers, |
68 | - function (Response $response, $index) use ($notification) { |
|
68 | + function(Response $response, $index) use ($notification) { |
|
69 | 69 | try { |
70 | 70 | if ($response->getStatusCode() != 201) { |
71 | 71 | $response = json_decode($response->getBody()); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | Driver::emit(new NotificationFailed($notification)); |
83 | 83 | } |
84 | 84 | }, |
85 | - function ($reason, $index) use ($notification) { |
|
85 | + function($reason, $index) use ($notification) { |
|
86 | 86 | Driver::emit(new NotificationFailed($notification)); |
87 | 87 | } |
88 | 88 | ); |
@@ -31,7 +31,8 @@ discard block |
||
31 | 31 | */ |
32 | 32 | protected static function initBrowser(array $config) |
33 | 33 | { |
34 | - if (static::$browser) { |
|
34 | + if (static::$browser) |
|
35 | + { |
|
35 | 36 | return; |
36 | 37 | } |
37 | 38 | |
@@ -65,12 +66,16 @@ discard block |
||
65 | 66 | |
66 | 67 | $this->flush( |
67 | 68 | $subscribers, |
68 | - function (Response $response, $index) use ($notification) { |
|
69 | - try { |
|
70 | - if ($response->getStatusCode() != 201) { |
|
69 | + function (Response $response, $index) use ($notification) |
|
70 | + { |
|
71 | + try |
|
72 | + { |
|
73 | + if ($response->getStatusCode() != 201) |
|
74 | + { |
|
71 | 75 | $response = json_decode($response->getBody()); |
72 | 76 | |
73 | - if (json_last_error() !== JSON_ERROR_NONE) { |
|
77 | + if (json_last_error() !== JSON_ERROR_NONE) |
|
78 | + { |
|
74 | 79 | throw new \Exception('Firefox: bad json'); |
75 | 80 | } |
76 | 81 | |
@@ -78,11 +83,14 @@ discard block |
||
78 | 83 | } |
79 | 84 | |
80 | 85 | Driver::emit(new NotificationSent($notification)); |
81 | - } catch (\Exception $e) { |
|
86 | + } |
|
87 | + catch (\Exception $e) |
|
88 | + { |
|
82 | 89 | Driver::emit(new NotificationFailed($notification)); |
83 | 90 | } |
84 | 91 | }, |
85 | - function ($reason, $index) use ($notification) { |
|
92 | + function ($reason, $index) use ($notification) |
|
93 | + { |
|
86 | 94 | Driver::emit(new NotificationFailed($notification)); |
87 | 95 | } |
88 | 96 | ); |
@@ -100,7 +108,8 @@ discard block |
||
100 | 108 | $headers = static::$headers; |
101 | 109 | $content = ''; |
102 | 110 | |
103 | - foreach ($subscribers as $subscriber) { |
|
111 | + foreach ($subscribers as $subscriber) |
|
112 | + { |
|
104 | 113 | $headers['Content-Length'] = strlen($content); |
105 | 114 | |
106 | 115 | yield new Request('POST', $this->getUrl($subscriber), $headers, $content); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | $this->flush( |
69 | 69 | $subscribers, |
70 | - function (Response $response, $index) use ($notification, $total) { |
|
70 | + function(Response $response, $index) use ($notification, $total) { |
|
71 | 71 | try { |
72 | 72 | $response = json_decode($response->getBody()); |
73 | 73 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | Driver::emit(new NotificationFailed($notification, $this->calculateChunkSize($index, $total))); |
87 | 87 | } |
88 | 88 | }, |
89 | - function ($reason, $index) use ($notification, $total) { |
|
89 | + function($reason, $index) use ($notification, $total) { |
|
90 | 90 | Driver::emit(new NotificationFailed($notification, $this->calculateChunkSize($index, $total))); |
91 | 91 | } |
92 | 92 | ); |
@@ -31,7 +31,8 @@ discard block |
||
31 | 31 | */ |
32 | 32 | protected static function initBrowser(array $config) |
33 | 33 | { |
34 | - if (static::$browser) { |
|
34 | + if (static::$browser) |
|
35 | + { |
|
35 | 36 | return; |
36 | 37 | } |
37 | 38 | |
@@ -67,26 +68,34 @@ discard block |
||
67 | 68 | |
68 | 69 | $this->flush( |
69 | 70 | $subscribers, |
70 | - function (Response $response, $index) use ($notification, $total) { |
|
71 | - try { |
|
71 | + function (Response $response, $index) use ($notification, $total) |
|
72 | + { |
|
73 | + try |
|
74 | + { |
|
72 | 75 | $response = json_decode($response->getBody()); |
73 | 76 | |
74 | - if (json_last_error() !== JSON_ERROR_NONE) { |
|
77 | + if (json_last_error() !== JSON_ERROR_NONE) |
|
78 | + { |
|
75 | 79 | throw new \Exception(); |
76 | 80 | } |
77 | 81 | |
78 | - if ($response->success > 0) { |
|
82 | + if ($response->success > 0) |
|
83 | + { |
|
79 | 84 | Driver::emit(new NotificationSent($notification, (int) $response->success)); |
80 | 85 | } |
81 | 86 | |
82 | - if ($response->failure > 0) { |
|
87 | + if ($response->failure > 0) |
|
88 | + { |
|
83 | 89 | Driver::emit(new NotificationFailed($notification, (int) $response->failure)); |
84 | 90 | } |
85 | - } catch (\Exception $e) { |
|
91 | + } |
|
92 | + catch (\Exception $e) |
|
93 | + { |
|
86 | 94 | Driver::emit(new NotificationFailed($notification, $this->calculateChunkSize($index, $total))); |
87 | 95 | } |
88 | 96 | }, |
89 | - function ($reason, $index) use ($notification, $total) { |
|
97 | + function ($reason, $index) use ($notification, $total) |
|
98 | + { |
|
90 | 99 | Driver::emit(new NotificationFailed($notification, $this->calculateChunkSize($index, $total))); |
91 | 100 | } |
92 | 101 | ); |
@@ -104,7 +113,8 @@ discard block |
||
104 | 113 | $url = $this->config['url']; |
105 | 114 | $headers = static::$headers; |
106 | 115 | |
107 | - foreach ($this->batch($subscribers) as $index => $chunk) { |
|
116 | + foreach ($this->batch($subscribers) as $index => $chunk) |
|
117 | + { |
|
108 | 118 | $content = $this->getRequestContent($chunk); |
109 | 119 | $headers['Content-Length'] = strlen($content); |
110 | 120 | |
@@ -127,11 +137,16 @@ discard block |
||
127 | 137 | $offset = ($index + 1) * $chunkSize; |
128 | 138 | $chunks = ceil($total / $chunkSize); |
129 | 139 | |
130 | - if ($offset <= $total) { |
|
140 | + if ($offset <= $total) |
|
141 | + { |
|
131 | 142 | $return = $chunkSize; |
132 | - } elseif ($offset > $total + $chunkSize) { |
|
143 | + } |
|
144 | + elseif ($offset > $total + $chunkSize) |
|
145 | + { |
|
133 | 146 | $return = 0; |
134 | - } else { |
|
147 | + } |
|
148 | + else |
|
149 | + { |
|
135 | 150 | $return = $total - ($chunks - 1) * $chunkSize; |
136 | 151 | } |
137 | 152 | |
@@ -149,7 +164,8 @@ discard block |
||
149 | 164 | $tokens = []; |
150 | 165 | |
151 | 166 | /** @var Subscriber $subscriber */ |
152 | - foreach ($subscribers as $subscriber) { |
|
167 | + foreach ($subscribers as $subscriber) |
|
168 | + { |
|
153 | 169 | $tokens[] = $subscriber->getToken(); |
154 | 170 | } |
155 | 171 |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function getProvider($name) |
59 | 59 | { |
60 | - if (! $this->providerConnected($name)) { |
|
60 | + if ( ! $this->providerConnected($name)) { |
|
61 | 61 | throw new \RuntimeException("Unsupported provider '{$name}'"); |
62 | 62 | } |
63 | 63 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | { |
83 | 83 | $providersFactory = new ProvidersFactory($this); |
84 | 84 | |
85 | - if (! empty($this->config['providers']) && is_array($this->config['providers'])) { |
|
85 | + if ( ! empty($this->config['providers']) && is_array($this->config['providers'])) { |
|
86 | 86 | foreach ($this->config['providers'] as $name => $options) { |
87 | 87 | $this->providers[$name] = $providersFactory->make($name, $options)->setProject($this); |
88 | 88 | } |
@@ -57,7 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function getProvider($name) |
59 | 59 | { |
60 | - if (! $this->providerConnected($name)) { |
|
60 | + if (! $this->providerConnected($name)) |
|
61 | + { |
|
61 | 62 | throw new \RuntimeException("Unsupported provider '{$name}'"); |
62 | 63 | } |
63 | 64 | |
@@ -82,8 +83,10 @@ discard block |
||
82 | 83 | { |
83 | 84 | $providersFactory = new ProvidersFactory($this); |
84 | 85 | |
85 | - if (! empty($this->config['providers']) && is_array($this->config['providers'])) { |
|
86 | - foreach ($this->config['providers'] as $name => $options) { |
|
86 | + if (! empty($this->config['providers']) && is_array($this->config['providers'])) |
|
87 | + { |
|
88 | + foreach ($this->config['providers'] as $name => $options) |
|
89 | + { |
|
87 | 90 | $this->providers[$name] = $providersFactory->make($name, $options)->setProject($this); |
88 | 91 | } |
89 | 92 | } |
@@ -63,7 +63,8 @@ |
||
63 | 63 | */ |
64 | 64 | protected function limitString($value, $limit = 10, $end = '...') |
65 | 65 | { |
66 | - if (mb_strwidth($value, 'UTF-8') <= $limit) { |
|
66 | + if (mb_strwidth($value, 'UTF-8') <= $limit) |
|
67 | + { |
|
67 | 68 | return $value; |
68 | 69 | } |
69 | 70 |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $password = $this->certificate->getPassword(); |
156 | 156 | |
157 | 157 | $certs = []; |
158 | - if (! openssl_pkcs12_read($pkcs12, $certs, $password)) { |
|
158 | + if ( ! openssl_pkcs12_read($pkcs12, $certs, $password)) { |
|
159 | 159 | throw new \RuntimeException(openssl_error_string()); |
160 | 160 | } |
161 | 161 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | // Convert the signature from PEM to DER |
172 | 172 | $signature_pem = file_get_contents($signaturePath); |
173 | 173 | $matches = []; |
174 | - if (! preg_match('~Content-Disposition:[^\n]+\s*?([A-Za-z0-9+=/\r\n]+)\s*?-----~', $signature_pem, $matches)) { |
|
174 | + if ( ! preg_match('~Content-Disposition:[^\n]+\s*?([A-Za-z0-9+=/\r\n]+)\s*?-----~', $signature_pem, $matches)) { |
|
175 | 175 | throw new \RuntimeException(openssl_error_string()); |
176 | 176 | } |
177 | 177 |
@@ -67,12 +67,14 @@ discard block |
||
67 | 67 | { |
68 | 68 | $packagePath = $this->storage->getAdapter()->applyPathPrefix(static::PACKAGE_FILENAME); |
69 | 69 | |
70 | - if ($this->storage->has(static::PACKAGE_FILENAME)) { |
|
70 | + if ($this->storage->has(static::PACKAGE_FILENAME)) |
|
71 | + { |
|
71 | 72 | return $packagePath; |
72 | 73 | } |
73 | 74 | |
74 | 75 | $this->zip = new \ZipArchive(); |
75 | - if ($this->zip->open($packagePath, \ZipArchive::CREATE) !== true) { |
|
76 | + if ($this->zip->open($packagePath, \ZipArchive::CREATE) !== true) |
|
77 | + { |
|
76 | 78 | return false; |
77 | 79 | } |
78 | 80 | |
@@ -97,7 +99,8 @@ discard block |
||
97 | 99 | */ |
98 | 100 | protected function addIcons() |
99 | 101 | { |
100 | - foreach ($this->icons as $file) { |
|
102 | + foreach ($this->icons as $file) |
|
103 | + { |
|
101 | 104 | $this->addFile('icon.iconset/' . $file, $file); |
102 | 105 | } |
103 | 106 | } |
@@ -148,7 +151,8 @@ discard block |
||
148 | 151 | $password = $this->certificate->getPassword(); |
149 | 152 | |
150 | 153 | $certs = []; |
151 | - if (! openssl_pkcs12_read($pkcs12, $certs, $password)) { |
|
154 | + if (! openssl_pkcs12_read($pkcs12, $certs, $password)) |
|
155 | + { |
|
152 | 156 | throw new \RuntimeException(openssl_error_string()); |
153 | 157 | } |
154 | 158 | |
@@ -164,7 +168,8 @@ discard block |
||
164 | 168 | // Convert the signature from PEM to DER |
165 | 169 | $signature_pem = file_get_contents($signaturePath); |
166 | 170 | $matches = []; |
167 | - if (! preg_match('~Content-Disposition:[^\n]+\s*?([A-Za-z0-9+=/\r\n]+)\s*?-----~', $signature_pem, $matches)) { |
|
171 | + if (! preg_match('~Content-Disposition:[^\n]+\s*?([A-Za-z0-9+=/\r\n]+)\s*?-----~', $signature_pem, $matches)) |
|
172 | + { |
|
168 | 173 | throw new \RuntimeException(openssl_error_string()); |
169 | 174 | } |
170 | 175 |
@@ -70,7 +70,7 @@ |
||
70 | 70 | */ |
71 | 71 | protected function getApnsResource() |
72 | 72 | { |
73 | - if (! is_resource($this->apnsResource)) { |
|
73 | + if ( ! is_resource($this->apnsResource)) { |
|
74 | 74 | $this->apnsResource = $this->createStreamClient(); |
75 | 75 | } |
76 | 76 |
@@ -54,7 +54,8 @@ discard block |
||
54 | 54 | { |
55 | 55 | $length = strlen($binaryMessage); |
56 | 56 | |
57 | - if ($length > self::PAYLOAD_MAX_BYTES) { |
|
57 | + if ($length > self::PAYLOAD_MAX_BYTES) |
|
58 | + { |
|
58 | 59 | throw new \InvalidArgumentException( |
59 | 60 | sprintf('The maximum size allowed for a notification payload is %s bytes; Apple Push Notification Service refuses any notification that exceeds this limit.', self::PAYLOAD_MAX_BYTES) |
60 | 61 | ); |
@@ -70,7 +71,8 @@ discard block |
||
70 | 71 | */ |
71 | 72 | protected function getApnsResource() |
72 | 73 | { |
73 | - if (! is_resource($this->apnsResource)) { |
|
74 | + if (! is_resource($this->apnsResource)) |
|
75 | + { |
|
74 | 76 | $this->apnsResource = $this->createStreamClient(); |
75 | 77 | } |
76 | 78 | |
@@ -114,7 +116,8 @@ discard block |
||
114 | 116 | */ |
115 | 117 | public function close() |
116 | 118 | { |
117 | - if (is_resource($this->apnsResource)) { |
|
119 | + if (is_resource($this->apnsResource)) |
|
120 | + { |
|
118 | 121 | fclose($this->apnsResource); |
119 | 122 | } |
120 | 123 | } |
@@ -43,9 +43,12 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function getP12Certificate() |
45 | 45 | { |
46 | - try { |
|
46 | + try |
|
47 | + { |
|
47 | 48 | return $this->storage->get($this->paths['p12']); |
48 | - } catch (\Exception $e) { |
|
49 | + } |
|
50 | + catch (\Exception $e) |
|
51 | + { |
|
49 | 52 | return ''; |
50 | 53 | } |
51 | 54 | } |
@@ -57,9 +60,12 @@ discard block |
||
57 | 60 | */ |
58 | 61 | public function getPassword() |
59 | 62 | { |
60 | - try { |
|
63 | + try |
|
64 | + { |
|
61 | 65 | return $this->storage->get($this->paths['password']); |
62 | - } catch (\Exception $e) { |
|
66 | + } |
|
67 | + catch (\Exception $e) |
|
68 | + { |
|
63 | 69 | return ''; |
64 | 70 | } |
65 | 71 | } |
@@ -71,9 +77,12 @@ discard block |
||
71 | 77 | */ |
72 | 78 | public function getPemCertificate() |
73 | 79 | { |
74 | - try { |
|
80 | + try |
|
81 | + { |
|
75 | 82 | return $this->storage->get($this->paths['pem']); |
76 | - } catch (\Exception $e) { |
|
83 | + } |
|
84 | + catch (\Exception $e) |
|
85 | + { |
|
77 | 86 | return ''; |
78 | 87 | } |
79 | 88 | } |
@@ -49,11 +49,15 @@ discard block |
||
49 | 49 | $payload = new Payload($notification); |
50 | 50 | $payload = json_encode($payload); |
51 | 51 | |
52 | - foreach ($this->prepareRequests($subscribers, $payload) as $message) { |
|
53 | - try { |
|
52 | + foreach ($this->prepareRequests($subscribers, $payload) as $message) |
|
53 | + { |
|
54 | + try |
|
55 | + { |
|
54 | 56 | $stream->write($message); |
55 | 57 | Driver::emit(new NotificationSent($notification)); |
56 | - } catch (\Exception $e) { |
|
58 | + } |
|
59 | + catch (\Exception $e) |
|
60 | + { |
|
57 | 61 | Driver::emit(new NotificationFailed($notification)); |
58 | 62 | } |
59 | 63 | } |
@@ -70,10 +74,14 @@ discard block |
||
70 | 74 | */ |
71 | 75 | protected function prepareRequests($subscribers, $payload = null) |
72 | 76 | { |
73 | - foreach ($subscribers as $subscriber) { |
|
74 | - try { |
|
77 | + foreach ($subscribers as $subscriber) |
|
78 | + { |
|
79 | + try |
|
80 | + { |
|
75 | 81 | yield chr(0) . chr(0) . chr(32) . pack('H*', $subscriber->getToken()) . chr(0) . chr(strlen($payload)) . $payload; |
76 | - } catch (\Exception $e) { |
|
82 | + } |
|
83 | + catch (\Exception $e) |
|
84 | + { |
|
77 | 85 | } |
78 | 86 | } |
79 | 87 | } |