@@ -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 @@ |
||
65 | 65 | * Send request. |
66 | 66 | * |
67 | 67 | * @param Subscriber[] $subscribers |
68 | - * @param mixed $payload |
|
68 | + * @param string $payload |
|
69 | 69 | * @return \Generator |
70 | 70 | */ |
71 | 71 | protected function prepareRequests($subscribers, $payload = null) |
@@ -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 | } |
@@ -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 |
@@ -49,16 +49,16 @@ |
||
49 | 49 | */ |
50 | 50 | public function provideListeners(ListenerAcceptorInterface $listener) |
51 | 51 | { |
52 | - $listener->addListener(NotificationSent::class, function ($e) { |
|
52 | + $listener->addListener(NotificationSent::class, function($e) { |
|
53 | 53 | $this->sent($e); |
54 | 54 | }); |
55 | - $listener->addListener(NotificationDelivered::class, function ($e) { |
|
55 | + $listener->addListener(NotificationDelivered::class, function($e) { |
|
56 | 56 | $this->delivered($e); |
57 | 57 | }); |
58 | - $listener->addListener(NotificationClicked::class, function ($e) { |
|
58 | + $listener->addListener(NotificationClicked::class, function($e) { |
|
59 | 59 | $this->clicked($e); |
60 | 60 | }); |
61 | - $listener->addListener(NotificationFailed::class, function ($e) { |
|
61 | + $listener->addListener(NotificationFailed::class, function($e) { |
|
62 | 62 | $this->failed($e); |
63 | 63 | }); |
64 | 64 |
@@ -49,16 +49,20 @@ |
||
49 | 49 | */ |
50 | 50 | public function provideListeners(ListenerAcceptorInterface $listener) |
51 | 51 | { |
52 | - $listener->addListener(NotificationSent::class, function ($e) { |
|
52 | + $listener->addListener(NotificationSent::class, function ($e) |
|
53 | + { |
|
53 | 54 | $this->sent($e); |
54 | 55 | }); |
55 | - $listener->addListener(NotificationDelivered::class, function ($e) { |
|
56 | + $listener->addListener(NotificationDelivered::class, function ($e) |
|
57 | + { |
|
56 | 58 | $this->delivered($e); |
57 | 59 | }); |
58 | - $listener->addListener(NotificationClicked::class, function ($e) { |
|
60 | + $listener->addListener(NotificationClicked::class, function ($e) |
|
61 | + { |
|
59 | 62 | $this->clicked($e); |
60 | 63 | }); |
61 | - $listener->addListener(NotificationFailed::class, function ($e) { |
|
64 | + $listener->addListener(NotificationFailed::class, function ($e) |
|
65 | + { |
|
62 | 66 | $this->failed($e); |
63 | 67 | }); |
64 | 68 |
@@ -127,11 +127,11 @@ |
||
127 | 127 | foreach ($this->subscribers as $subscriber) { |
128 | 128 | $provider = $subscriber->getProvider(); |
129 | 129 | |
130 | - if (! $this->project->providerConnected($provider)) { |
|
130 | + if ( ! $this->project->providerConnected($provider)) { |
|
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | |
134 | - if (! isset($partials[$provider])) { |
|
134 | + if ( ! isset($partials[$provider])) { |
|
135 | 135 | $partials[$provider] = []; |
136 | 136 | } |
137 | 137 |
@@ -83,10 +83,14 @@ discard block |
||
83 | 83 | |
84 | 84 | $partials = $this->splitSubscribers(); |
85 | 85 | |
86 | - foreach ($partials as $provider => $subscribers) { |
|
87 | - try { |
|
86 | + foreach ($partials as $provider => $subscribers) |
|
87 | + { |
|
88 | + try |
|
89 | + { |
|
88 | 90 | $this->provider($provider)->send($this->notification, $subscribers); |
89 | - } catch (\RuntimeException $e) { |
|
91 | + } |
|
92 | + catch (\RuntimeException $e) |
|
93 | + { |
|
90 | 94 | static::emit('flush.exception', $e); |
91 | 95 | } |
92 | 96 | } |
@@ -124,20 +128,24 @@ discard block |
||
124 | 128 | $partials = []; |
125 | 129 | |
126 | 130 | /** @var Subscriber $subscriber */ |
127 | - foreach ($this->subscribers as $subscriber) { |
|
131 | + foreach ($this->subscribers as $subscriber) |
|
132 | + { |
|
128 | 133 | $provider = $subscriber->getProvider(); |
129 | 134 | |
130 | - if (! $this->project->providerConnected($provider)) { |
|
135 | + if (! $this->project->providerConnected($provider)) |
|
136 | + { |
|
131 | 137 | continue; |
132 | 138 | } |
133 | 139 | |
134 | - if (! isset($partials[$provider])) { |
|
140 | + if (! isset($partials[$provider])) |
|
141 | + { |
|
135 | 142 | $partials[$provider] = []; |
136 | 143 | } |
137 | 144 | |
138 | 145 | $partials[$provider][] = $subscriber; |
139 | 146 | |
140 | - if ($this->payloadStorage) { |
|
147 | + if ($this->payloadStorage) |
|
148 | + { |
|
141 | 149 | $this->payloadStorage->assignNotificationToSubscriber($subscriber, $this->notification); |
142 | 150 | } |
143 | 151 | } |
@@ -152,11 +160,13 @@ discard block |
||
152 | 160 | */ |
153 | 161 | protected function validate() |
154 | 162 | { |
155 | - if (is_null($this->notification)) { |
|
163 | + if (is_null($this->notification)) |
|
164 | + { |
|
156 | 165 | throw new \RuntimeException("Notification wasn't set."); |
157 | 166 | } |
158 | 167 | |
159 | - if (is_null($this->subscribers)) { |
|
168 | + if (is_null($this->subscribers)) |
|
169 | + { |
|
160 | 170 | throw new \RuntimeException('No subscribers set.'); |
161 | 171 | } |
162 | 172 | } |
@@ -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 |
@@ -74,12 +74,14 @@ discard block |
||
74 | 74 | { |
75 | 75 | $packagePath = $this->storage->getAdapter()->applyPathPrefix(static::PACKAGE_FILENAME); |
76 | 76 | |
77 | - if ($this->storage->exists(static::PACKAGE_FILENAME)) { |
|
77 | + if ($this->storage->exists(static::PACKAGE_FILENAME)) |
|
78 | + { |
|
78 | 79 | return $packagePath; |
79 | 80 | } |
80 | 81 | |
81 | 82 | $this->zip = new \ZipArchive(); |
82 | - if ($this->zip->open($packagePath, \ZipArchive::CREATE) !== true) { |
|
83 | + if ($this->zip->open($packagePath, \ZipArchive::CREATE) !== true) |
|
84 | + { |
|
83 | 85 | return false; |
84 | 86 | } |
85 | 87 | |
@@ -104,7 +106,8 @@ discard block |
||
104 | 106 | */ |
105 | 107 | protected function addIcons() |
106 | 108 | { |
107 | - foreach ($this->icons as $file) { |
|
109 | + foreach ($this->icons as $file) |
|
110 | + { |
|
108 | 111 | $this->addFile('icon.iconset/' . $file, $file); |
109 | 112 | } |
110 | 113 | } |
@@ -155,7 +158,8 @@ discard block |
||
155 | 158 | $password = $this->certificate->getPassword(); |
156 | 159 | |
157 | 160 | $certs = []; |
158 | - if (! openssl_pkcs12_read($pkcs12, $certs, $password)) { |
|
161 | + if (! openssl_pkcs12_read($pkcs12, $certs, $password)) |
|
162 | + { |
|
159 | 163 | throw new \RuntimeException(openssl_error_string()); |
160 | 164 | } |
161 | 165 | |
@@ -171,7 +175,8 @@ discard block |
||
171 | 175 | // Convert the signature from PEM to DER |
172 | 176 | $signature_pem = file_get_contents($signaturePath); |
173 | 177 | $matches = []; |
174 | - if (! preg_match('~Content-Disposition:[^\n]+\s*?([A-Za-z0-9+=/\r\n]+)\s*?-----~', $signature_pem, $matches)) { |
|
178 | + if (! preg_match('~Content-Disposition:[^\n]+\s*?([A-Za-z0-9+=/\r\n]+)\s*?-----~', $signature_pem, $matches)) |
|
179 | + { |
|
175 | 180 | throw new \RuntimeException(openssl_error_string()); |
176 | 181 | } |
177 | 182 |