@@ -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 | }); |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | { |
84 | 84 | $var = \ini_get('max_input_vars'); |
85 | 85 | if ($var !== false) { |
86 | - $this->maxInputVars = (int)$var; |
|
86 | + $this->maxInputVars = (int) $var; |
|
87 | 87 | } |
88 | 88 | $var = \ini_get('max_input_nesting_level'); |
89 | 89 | if ($var !== false) { |
90 | - $this->maxInputNestingLevel = (int)$var; |
|
90 | + $this->maxInputNestingLevel = (int) $var; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | if ($uploadMaxFilesize === null) { |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | $this->uploadMaxFilesize = IniUtil::iniSizeToBytes($uploadMaxFilesize); |
98 | - $this->maxFileUploads = $maxFileUploads === null ? (\ini_get('file_uploads') === '' ? 0 : (int)\ini_get('max_file_uploads')) : (int)$maxFileUploads; |
|
98 | + $this->maxFileUploads = $maxFileUploads === null ? (\ini_get('file_uploads') === '' ? 0 : (int) \ini_get('max_file_uploads')) : (int) $maxFileUploads; |
|
99 | 99 | |
100 | 100 | $this->maxMultipartBodyParts = $this->maxInputVars + $this->maxFileUploads; |
101 | 101 | } |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | public function parse(ServerRequestInterface $request) |
104 | 104 | { |
105 | 105 | $contentType = $request->getHeaderLine('content-type'); |
106 | - if(!\preg_match('/boundary="?(.*?)"?$/', $contentType, $matches)) { |
|
106 | + if (!\preg_match('/boundary="?(.*?)"?$/', $contentType, $matches)) { |
|
107 | 107 | return $request; |
108 | 108 | } |
109 | 109 | |
110 | 110 | $this->request = $request; |
111 | - $this->parseBody('--' . $matches[1], (string)$request->getBody()); |
|
111 | + $this->parseBody('--' . $matches[1], (string) $request->getBody()); |
|
112 | 112 | |
113 | 113 | $request = $this->request; |
114 | 114 | $this->request = null; |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | - $headers = $this->parseHeaders((string)substr($chunk, 0, $pos)); |
|
159 | - $body = (string)\substr($chunk, $pos + 4); |
|
158 | + $headers = $this->parseHeaders((string) substr($chunk, 0, $pos)); |
|
159 | + $body = (string) \substr($chunk, $pos + 4); |
|
160 | 160 | |
161 | 161 | if (!isset($headers['content-disposition'])) { |
162 | 162 | return; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | )); |
265 | 265 | |
266 | 266 | if (\strtoupper($name) === 'MAX_FILE_SIZE') { |
267 | - $this->maxFileSize = (int)$value; |
|
267 | + $this->maxFileSize = (int) $value; |
|
268 | 268 | |
269 | 269 | if ($this->maxFileSize === 0) { |
270 | 270 | $this->maxFileSize = null; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | if ($size !== null && $size !== 0) { |
88 | 88 | // automatically assign a "Content-Length" request header if the body size is known and non-empty |
89 | - $request = $request->withHeader('Content-Length', (string)$size); |
|
89 | + $request = $request->withHeader('Content-Length', (string) $size); |
|
90 | 90 | } elseif ($size === 0 && \in_array($request->getMethod(), array('POST', 'PUT', 'PATCH'))) { |
91 | 91 | // only assign a "Content-Length: 0" request header if the body is expected for certain methods |
92 | 92 | $request = $request->withHeader('Content-Length', '0'); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | $requestStream = $this->http->request($request); |
107 | 107 | |
108 | - $deferred = new Deferred(function ($_, $reject) use ($requestStream) { |
|
108 | + $deferred = new Deferred(function($_, $reject) use ($requestStream) { |
|
109 | 109 | // close request stream if request is cancelled |
110 | 110 | $reject(new \RuntimeException('Request cancelled')); |
111 | 111 | $requestStream->close(); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $deferred->reject($error); |
116 | 116 | }); |
117 | 117 | |
118 | - $requestStream->on('response', function (ResponseInterface $response) use ($deferred, $request) { |
|
118 | + $requestStream->on('response', function(ResponseInterface $response) use ($deferred, $request) { |
|
119 | 119 | $deferred->resolve($response); |
120 | 120 | }); |
121 | 121 | |
@@ -131,16 +131,16 @@ discard block |
||
131 | 131 | $body->pipe($requestStream); |
132 | 132 | $requestStream->write(''); |
133 | 133 | |
134 | - $body->on('close', $close = function () use ($deferred, $requestStream) { |
|
134 | + $body->on('close', $close = function() use ($deferred, $requestStream) { |
|
135 | 135 | $deferred->reject(new \RuntimeException('Request failed because request body closed unexpectedly')); |
136 | 136 | $requestStream->close(); |
137 | 137 | }); |
138 | - $body->on('error', function ($e) use ($deferred, $requestStream, $close, $body) { |
|
138 | + $body->on('error', function($e) use ($deferred, $requestStream, $close, $body) { |
|
139 | 139 | $body->removeListener('close', $close); |
140 | 140 | $deferred->reject(new \RuntimeException('Request failed because request body reported an error', 0, $e)); |
141 | 141 | $requestStream->close(); |
142 | 142 | }); |
143 | - $body->on('end', function () use ($close, $body) { |
|
143 | + $body->on('end', function() use ($close, $body) { |
|
144 | 144 | $body->removeListener('close', $close); |
145 | 145 | }); |
146 | 146 | } else { |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | } |
150 | 150 | } else { |
151 | 151 | // body is fully buffered => write as one chunk |
152 | - $requestStream->end((string)$body); |
|
152 | + $requestStream->end((string) $body); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | return $deferred->promise(); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function send(RequestInterface $request) |
70 | 70 | { |
71 | 71 | $state = new ClientRequestState(); |
72 | - $deferred = new Deferred(function () use ($state) { |
|
72 | + $deferred = new Deferred(function() use ($state) { |
|
73 | 73 | if ($state->pending !== null) { |
74 | 74 | $state->pending->cancel(); |
75 | 75 | $state->pending = null; |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | }); |
78 | 78 | |
79 | 79 | // use timeout from options or default to PHP's default_socket_timeout (60) |
80 | - $timeout = (float)($this->timeout !== null ? $this->timeout : ini_get("default_socket_timeout")); |
|
80 | + $timeout = (float) ($this->timeout !== null ? $this->timeout : ini_get("default_socket_timeout")); |
|
81 | 81 | |
82 | 82 | $loop = $this->loop; |
83 | 83 | $this->next($request, $deferred, $state)->then( |
84 | - function (ResponseInterface $response) use ($state, $deferred, $loop, &$timeout) { |
|
84 | + function(ResponseInterface $response) use ($state, $deferred, $loop, &$timeout) { |
|
85 | 85 | if ($state->timeout !== null) { |
86 | 86 | $loop->cancelTimer($state->timeout); |
87 | 87 | $state->timeout = null; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $timeout = -1; |
90 | 90 | $deferred->resolve($response); |
91 | 91 | }, |
92 | - function ($e) use ($state, $deferred, $loop, &$timeout) { |
|
92 | + function($e) use ($state, $deferred, $loop, &$timeout) { |
|
93 | 93 | if ($state->timeout !== null) { |
94 | 94 | $loop->cancelTimer($state->timeout); |
95 | 95 | $state->timeout = null; |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $body = $request->getBody(); |
107 | 107 | if ($body instanceof ReadableStreamInterface && $body->isReadable()) { |
108 | 108 | $that = $this; |
109 | - $body->on('close', function () use ($that, $deferred, $state, &$timeout) { |
|
109 | + $body->on('close', function() use ($that, $deferred, $state, &$timeout) { |
|
110 | 110 | if ($timeout >= 0) { |
111 | 111 | $that->applyTimeout($deferred, $state, $timeout); |
112 | 112 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function applyTimeout(Deferred $deferred, ClientRequestState $state, $timeout) |
127 | 127 | { |
128 | - $state->timeout = $this->loop->addTimer($timeout, function () use ($timeout, $deferred, $state) { |
|
128 | + $state->timeout = $this->loop->addTimer($timeout, function() use ($timeout, $deferred, $state) { |
|
129 | 129 | $deferred->reject(new \RuntimeException( |
130 | 130 | 'Request timed out after ' . $timeout . ' seconds' |
131 | 131 | )); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $promise = $this->sender->send($request); |
147 | 147 | |
148 | 148 | if (!$this->streaming) { |
149 | - $promise = $promise->then(function ($response) use ($deferred, $state, $that) { |
|
149 | + $promise = $promise->then(function($response) use ($deferred, $state, $that) { |
|
150 | 150 | return $that->bufferResponse($response, $deferred, $state); |
151 | 151 | }); |
152 | 152 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $state->pending = $promise; |
155 | 155 | |
156 | 156 | return $promise->then( |
157 | - function (ResponseInterface $response) use ($request, $that, $deferred, $state) { |
|
157 | + function(ResponseInterface $response) use ($request, $that, $deferred, $state) { |
|
158 | 158 | return $that->onResponse($response, $request, $deferred, $state); |
159 | 159 | } |
160 | 160 | ); |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | $closer = null; |
187 | 187 | $maximumSize = $this->maximumSize; |
188 | 188 | |
189 | - return $state->pending = new Promise(function ($resolve, $reject) use ($body, $maximumSize, $response, &$closer) { |
|
189 | + return $state->pending = new Promise(function($resolve, $reject) use ($body, $maximumSize, $response, &$closer) { |
|
190 | 190 | // resolve with current buffer when stream closes successfully |
191 | 191 | $buffer = ''; |
192 | - $body->on('close', $closer = function () use (&$buffer, $response, $maximumSize, $resolve, $reject) { |
|
192 | + $body->on('close', $closer = function() use (&$buffer, $response, $maximumSize, $resolve, $reject) { |
|
193 | 193 | $resolve($response->withBody(new BufferedBody($buffer))); |
194 | 194 | }); |
195 | 195 | |
196 | 196 | // buffer response body data in memory |
197 | - $body->on('data', function ($data) use (&$buffer, $maximumSize, $body, $closer, $reject) { |
|
197 | + $body->on('data', function($data) use (&$buffer, $maximumSize, $body, $closer, $reject) { |
|
198 | 198 | $buffer .= $data; |
199 | 199 | |
200 | 200 | // close stream and reject promise if limit is exceeded |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | }); |
213 | 213 | |
214 | 214 | // reject buffering if body emits error |
215 | - $body->on('error', function (\Exception $e) use ($reject) { |
|
215 | + $body->on('error', function(\Exception $e) use ($reject) { |
|
216 | 216 | $reject(new \RuntimeException( |
217 | 217 | 'Error while buffering response body: ' . $e->getMessage(), |
218 | 218 | $e->getCode(), |
219 | 219 | $e |
220 | 220 | )); |
221 | 221 | }); |
222 | - }, function () use ($body, &$closer) { |
|
222 | + }, function() use ($body, &$closer) { |
|
223 | 223 | // cancelled buffering: remove close handler to avoid resolving, then close and reject |
224 | 224 | assert($closer instanceof \Closure); |
225 | 225 | $body->removeListener('close', $closer); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $this->parser = new RequestHeaderParser($this->clock); |
111 | 111 | |
112 | 112 | $that = $this; |
113 | - $this->parser->on('headers', function (ServerRequestInterface $request, ConnectionInterface $conn) use ($that) { |
|
113 | + $this->parser->on('headers', function(ServerRequestInterface $request, ConnectionInterface $conn) use ($that) { |
|
114 | 114 | $that->handleRequest($conn, $request); |
115 | 115 | }); |
116 | 116 | |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | // cancel pending promise once connection closes |
160 | - $connectionOnCloseResponseCancelerHandler = function () {}; |
|
160 | + $connectionOnCloseResponseCancelerHandler = function() {}; |
|
161 | 161 | if ($response instanceof PromiseInterface && \method_exists($response, 'cancel')) { |
162 | - $connectionOnCloseResponseCanceler = function () use ($response) { |
|
162 | + $connectionOnCloseResponseCanceler = function() use ($response) { |
|
163 | 163 | $response->cancel(); |
164 | 164 | }; |
165 | - $connectionOnCloseResponseCancelerHandler = function () use ($connectionOnCloseResponseCanceler, $conn) { |
|
165 | + $connectionOnCloseResponseCancelerHandler = function() use ($connectionOnCloseResponseCanceler, $conn) { |
|
166 | 166 | if ($connectionOnCloseResponseCanceler !== null) { |
167 | 167 | $conn->removeListener('close', $connectionOnCloseResponseCanceler); |
168 | 168 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | $that = $this; |
184 | 184 | $response->then( |
185 | - function ($response) use ($that, $conn, $request) { |
|
185 | + function($response) use ($that, $conn, $request) { |
|
186 | 186 | if (!$response instanceof ResponseInterface) { |
187 | 187 | $message = 'The response callback is expected to resolve with an object implementing Psr\Http\Message\ResponseInterface, but resolved with "%s" instead.'; |
188 | 188 | $message = \sprintf($message, \is_object($response) ? \get_class($response) : \gettype($response)); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | } |
194 | 194 | $that->handleResponse($conn, $request, $response); |
195 | 195 | }, |
196 | - function ($error) use ($that, $conn, $request) { |
|
196 | + function($error) use ($that, $conn, $request) { |
|
197 | 197 | $message = 'The response callback is expected to resolve with an object implementing Psr\Http\Message\ResponseInterface, but rejected with "%s" instead.'; |
198 | 198 | $message = \sprintf($message, \is_object($error) ? \get_class($error) : \gettype($error)); |
199 | 199 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | // assign default "Server" header automatically |
256 | 256 | if (!$response->hasHeader('Server')) { |
257 | 257 | $response = $response->withHeader('Server', 'ReactPHP/1'); |
258 | - } elseif ($response->getHeaderLine('Server') === ''){ |
|
258 | + } elseif ($response->getHeaderLine('Server') === '') { |
|
259 | 259 | $response = $response->withoutHeader('Server'); |
260 | 260 | } |
261 | 261 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | if (!$response->hasHeader('Date')) { |
264 | 264 | // IMF-fixdate = day-name "," SP date1 SP time-of-day SP GMT |
265 | 265 | $response = $response->withHeader('Date', gmdate('D, d M Y H:i:s', (int) $this->clock->now()) . ' GMT'); |
266 | - } elseif ($response->getHeaderLine('Date') === ''){ |
|
266 | + } elseif ($response->getHeaderLine('Date') === '') { |
|
267 | 267 | $response = $response->withoutHeader('Date'); |
268 | 268 | } |
269 | 269 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | // 304 Not Modified: preserve explicit Content-Length and preserve missing header if body is empty |
279 | 279 | } elseif ($body->getSize() !== null) { |
280 | 280 | // assign Content-Length header when using a "normal" buffered body string |
281 | - $response = $response->withHeader('Content-Length', (string)$body->getSize()); |
|
281 | + $response = $response->withHeader('Content-Length', (string) $body->getSize()); |
|
282 | 282 | } elseif (!$response->hasHeader('Content-Length') && $version === '1.1') { |
283 | 283 | // assign chunked transfer-encoding if no 'content-length' is given for HTTP/1.1 responses |
284 | 284 | $chunked = true; |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | if (($code === Response::STATUS_SWITCHING_PROTOCOLS || ($method === 'CONNECT' && $code >= 200 && $code < 300)) && $body instanceof HttpBodyStream && $body->input instanceof WritableStreamInterface) { |
320 | 320 | if ($request->getBody()->isReadable()) { |
321 | 321 | // request is still streaming => wait for request close before forwarding following data from connection |
322 | - $request->getBody()->on('close', function () use ($connection, $body) { |
|
322 | + $request->getBody()->on('close', function() use ($connection, $body) { |
|
323 | 323 | if ($body->input->isWritable()) { |
324 | 324 | $connection->pipe($body->input); |
325 | 325 | $connection->resume(); |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | if ($persist) { |
395 | 395 | $body->pipe($connection, array('end' => false)); |
396 | 396 | $parser = $this->parser; |
397 | - $body->on('end', function () use ($connection, $parser, $body) { |
|
397 | + $body->on('end', function() use ($connection, $parser, $body) { |
|
398 | 398 | $connection->removeListener('close', array($body, 'close')); |
399 | 399 | $parser->handle($connection); |
400 | 400 | }); |
@@ -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])) { |