@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | $this->size = $size; |
| 25 | 25 | |
| 26 | 26 | $that = $this; |
| 27 | - $pos =& $this->position; |
|
| 28 | - $input->on('data', function ($data) use ($that, &$pos, $size) { |
|
| 27 | + $pos = & $this->position; |
|
| 28 | + $input->on('data', function($data) use ($that, &$pos, $size) { |
|
| 29 | 29 | $that->emit('data', array($data)); |
| 30 | 30 | |
| 31 | 31 | $pos += \strlen($data); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $that->handleEnd(); |
| 34 | 34 | } |
| 35 | 35 | }); |
| 36 | - $input->on('error', function ($error) use ($that) { |
|
| 36 | + $input->on('error', function($error) use ($that) { |
|
| 37 | 37 | $that->emit('error', array($error)); |
| 38 | 38 | $that->close(); |
| 39 | 39 | }); |
@@ -66,46 +66,46 @@ |
||
| 66 | 66 | return $dest; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function close() |
|
| 70 | - { |
|
| 71 | - if ($this->closed) { |
|
| 72 | - return; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $this->closed = true; |
|
| 76 | - |
|
| 77 | - // stop listening for incoming events |
|
| 78 | - $this->input->removeListener('data', array($this, 'handleData')); |
|
| 79 | - $this->input->removeListener('error', array($this, 'handleError')); |
|
| 80 | - $this->input->removeListener('end', array($this, 'handleEnd')); |
|
| 81 | - $this->input->removeListener('close', array($this, 'close')); |
|
| 82 | - |
|
| 83 | - // resume the stream to ensure we discard everything from incoming connection |
|
| 84 | - if ($this->paused) { |
|
| 85 | - $this->paused = false; |
|
| 86 | - $this->input->resume(); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $this->emit('close'); |
|
| 90 | - $this->removeAllListeners(); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** @internal */ |
|
| 94 | - public function handleData($data) |
|
| 95 | - { |
|
| 69 | + public function close() |
|
| 70 | + { |
|
| 71 | + if ($this->closed) { |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $this->closed = true; |
|
| 76 | + |
|
| 77 | + // stop listening for incoming events |
|
| 78 | + $this->input->removeListener('data', array($this, 'handleData')); |
|
| 79 | + $this->input->removeListener('error', array($this, 'handleError')); |
|
| 80 | + $this->input->removeListener('end', array($this, 'handleEnd')); |
|
| 81 | + $this->input->removeListener('close', array($this, 'close')); |
|
| 82 | + |
|
| 83 | + // resume the stream to ensure we discard everything from incoming connection |
|
| 84 | + if ($this->paused) { |
|
| 85 | + $this->paused = false; |
|
| 86 | + $this->input->resume(); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $this->emit('close'); |
|
| 90 | + $this->removeAllListeners(); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** @internal */ |
|
| 94 | + public function handleData($data) |
|
| 95 | + { |
|
| 96 | 96 | $this->emit('data', array($data)); |
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** @internal */ |
|
| 100 | - public function handleEnd() |
|
| 101 | - { |
|
| 102 | - $this->emit('end'); |
|
| 103 | - $this->close(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** @internal */ |
|
| 107 | - public function handleError(\Exception $e) |
|
| 108 | - { |
|
| 109 | - $this->emit('error', array($e)); |
|
| 110 | - } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** @internal */ |
|
| 100 | + public function handleEnd() |
|
| 101 | + { |
|
| 102 | + $this->emit('end'); |
|
| 103 | + $this->close(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** @internal */ |
|
| 107 | + public function handleError(\Exception $e) |
|
| 108 | + { |
|
| 109 | + $this->emit('error', array($e)); |
|
| 110 | + } |
|
| 111 | 111 | } |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | { |
| 75 | 75 | if (($this->transferredLength + \strlen($data)) > $this->maxLength) { |
| 76 | 76 | // Only emit data until the value of 'Content-Length' is reached, the rest will be ignored |
| 77 | - $data = (string)\substr($data, 0, $this->maxLength - $this->transferredLength); |
|
| 77 | + $data = (string) \substr($data, 0, $this->maxLength - $this->transferredLength); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | if ($data !== '') { |
@@ -251,14 +251,14 @@ |
||
| 251 | 251 | * Filter out any configuration middleware, no need to run requests through something that isn't |
| 252 | 252 | * doing anything with the request. |
| 253 | 253 | */ |
| 254 | - $middleware = \array_filter($middleware, function ($handler) { |
|
| 254 | + $middleware = \array_filter($middleware, function($handler) { |
|
| 255 | 255 | return !($handler instanceof StreamingRequestMiddleware); |
| 256 | 256 | }); |
| 257 | 257 | |
| 258 | 258 | $this->streamingServer = new StreamingServer($loop, new MiddlewareRunner($middleware)); |
| 259 | 259 | |
| 260 | 260 | $that = $this; |
| 261 | - $this->streamingServer->on('error', function ($error) use ($that) { |
|
| 261 | + $this->streamingServer->on('error', function($error) use ($that) { |
|
| 262 | 262 | $that->emit('error', array($error)); |
| 263 | 263 | }); |
| 264 | 264 | } |
@@ -235,7 +235,7 @@ |
||
| 235 | 235 | */ |
| 236 | 236 | public function patch($url, array $headers = array(), $body = '') |
| 237 | 237 | { |
| 238 | - return $this->requestMayBeStreaming('PATCH', $url , $headers, $body); |
|
| 238 | + return $this->requestMayBeStreaming('PATCH', $url, $headers, $body); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | private function createTimerCallback() |
| 241 | 241 | { |
| 242 | 242 | $timers = $this->timerEvents; |
| 243 | - $this->timerCallback = function ($_, $__, $timer) use ($timers) { |
|
| 243 | + $this->timerCallback = function($_, $__, $timer) use ($timers) { |
|
| 244 | 244 | \call_user_func($timer->getCallback(), $timer); |
| 245 | 245 | |
| 246 | 246 | if (!$timer->isPeriodic() && $timers->contains($timer)) { |
@@ -258,9 +258,9 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | private function createStreamCallback() |
| 260 | 260 | { |
| 261 | - $read =& $this->readListeners; |
|
| 262 | - $write =& $this->writeListeners; |
|
| 263 | - $this->streamCallback = function ($stream, $flags) use (&$read, &$write) { |
|
| 261 | + $read = & $this->readListeners; |
|
| 262 | + $write = & $this->writeListeners; |
|
| 263 | + $this->streamCallback = function($stream, $flags) use (&$read, &$write) { |
|
| 264 | 264 | $key = (int) $stream; |
| 265 | 265 | |
| 266 | 266 | if (Event::READ === (Event::READ & $flags) && isset($read[$key])) { |
@@ -39,12 +39,12 @@ |
||
| 39 | 39 | // This is tested using child processes, so coverage is actually 100%, see BinTest. |
| 40 | 40 | // @codeCoverageIgnoreStart |
| 41 | 41 | $hasRun = false; |
| 42 | - $loop->futureTick(function () use (&$hasRun) { |
|
| 42 | + $loop->futureTick(function() use (&$hasRun) { |
|
| 43 | 43 | $hasRun = true; |
| 44 | 44 | }); |
| 45 | 45 | |
| 46 | - $stopped =& self::$stopped; |
|
| 47 | - register_shutdown_function(function () use ($loop, &$hasRun, &$stopped) { |
|
| 46 | + $stopped = & self::$stopped; |
|
| 47 | + register_shutdown_function(function() use ($loop, &$hasRun, &$stopped) { |
|
| 48 | 48 | // Don't run if we're coming from a fatal error (uncaught exception). |
| 49 | 49 | $error = error_get_last(); |
| 50 | 50 | if ((isset($error['type']) ? $error['type'] : 0) & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR)) { |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | $that = $this; |
| 118 | 118 | $timers = $this->timers; |
| 119 | - $callback = function () use ($timer, $timers, $that) { |
|
| 119 | + $callback = function() use ($timer, $timers, $that) { |
|
| 120 | 120 | \call_user_func($timer->getCallback(), $timer); |
| 121 | 121 | |
| 122 | 122 | if ($timers->contains($timer)) { |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | { |
| 144 | 144 | $timer = new Timer($interval, $callback, true); |
| 145 | 145 | |
| 146 | - $callback = function () use ($timer) { |
|
| 146 | + $callback = function() use ($timer) { |
|
| 147 | 147 | \call_user_func($timer->getCallback(), $timer); |
| 148 | 148 | }; |
| 149 | 149 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | if (!isset($this->signalEvents[$signal])) { |
| 187 | 187 | $signals = $this->signals; |
| 188 | 188 | $this->signalEvents[$signal] = \uv_signal_init($this->uv); |
| 189 | - \uv_signal_start($this->signalEvents[$signal], function () use ($signals, $signal) { |
|
| 189 | + \uv_signal_start($this->signalEvents[$signal], function() use ($signals, $signal) { |
|
| 190 | 190 | $signals->call($signal); |
| 191 | 191 | }, $signal); |
| 192 | 192 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | private function addStream($stream) |
| 245 | 245 | { |
| 246 | 246 | if (!isset($this->streamEvents[(int) $stream])) { |
| 247 | - $this->streamEvents[(int)$stream] = \uv_poll_init_socket($this->uv, $stream); |
|
| 247 | + $this->streamEvents[(int) $stream] = \uv_poll_init_socket($this->uv, $stream); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | if ($this->streamEvents[(int) $stream] !== false) { |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | */ |
| 295 | 295 | private function createStreamListener() |
| 296 | 296 | { |
| 297 | - $callback = function ($event, $status, $events, $stream) { |
|
| 297 | + $callback = function($event, $status, $events, $stream) { |
|
| 298 | 298 | // libuv automatically stops polling on error, re-enable polling to match other loop implementations |
| 299 | 299 | if ($status !== 0) { |
| 300 | 300 | $this->pollStream($stream); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | public function addReadStream($stream, $listener) |
| 75 | 75 | { |
| 76 | - $key = (int)$stream; |
|
| 76 | + $key = (int) $stream; |
|
| 77 | 77 | |
| 78 | 78 | if (isset($this->readStreams[$key])) { |
| 79 | 79 | return; |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | private function getStreamListenerClosure($stream, $listener) |
| 94 | 94 | { |
| 95 | - return function () use ($stream, $listener) { |
|
| 95 | + return function() use ($stream, $listener) { |
|
| 96 | 96 | \call_user_func($listener, $stream); |
| 97 | 97 | }; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | public function addWriteStream($stream, $listener) |
| 101 | 101 | { |
| 102 | - $key = (int)$stream; |
|
| 102 | + $key = (int) $stream; |
|
| 103 | 103 | |
| 104 | 104 | if (isset($this->writeStreams[$key])) { |
| 105 | 105 | return; |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | public function removeReadStream($stream) |
| 114 | 114 | { |
| 115 | - $key = (int)$stream; |
|
| 115 | + $key = (int) $stream; |
|
| 116 | 116 | |
| 117 | 117 | if (!isset($this->readStreams[$key])) { |
| 118 | 118 | return; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | public function removeWriteStream($stream) |
| 126 | 126 | { |
| 127 | - $key = (int)$stream; |
|
| 127 | + $key = (int) $stream; |
|
| 128 | 128 | |
| 129 | 129 | if (!isset($this->writeStreams[$key])) { |
| 130 | 130 | return; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | $that = $this; |
| 142 | 142 | $timers = $this->timers; |
| 143 | - $callback = function () use ($timer, $timers, $that) { |
|
| 143 | + $callback = function() use ($timer, $timers, $that) { |
|
| 144 | 144 | \call_user_func($timer->getCallback(), $timer); |
| 145 | 145 | |
| 146 | 146 | if ($timers->contains($timer)) { |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | $timer = new Timer($interval, $callback, true); |
| 160 | 160 | |
| 161 | - $callback = function () use ($timer) { |
|
| 161 | + $callback = function() use ($timer) { |
|
| 162 | 162 | \call_user_func($timer->getCallback(), $timer); |
| 163 | 163 | }; |
| 164 | 164 | |