@@ -37,7 +37,7 @@ |
||
37 | 37 | */ |
38 | 38 | private static function handler($uri) |
39 | 39 | { |
40 | - return function (\Exception $e) use ($uri) { |
|
40 | + return function(\Exception $e) use ($uri) { |
|
41 | 41 | if ($e instanceof TimeoutException) { |
42 | 42 | throw new \RuntimeException( |
43 | 43 | 'Connection to ' . $uri . ' timed out after ' . $e->getTimeout() . ' seconds (ETIMEDOUT)', |
@@ -57,7 +57,7 @@ |
||
57 | 57 | |
58 | 58 | $promise = $this->connect(); |
59 | 59 | $promise->then( |
60 | - function (ConnectionInterface $stream) use ($requestData, &$streamRef, &$stateRef, &$pendingWrites, $that) { |
|
60 | + function(ConnectionInterface $stream) use ($requestData, &$streamRef, &$stateRef, &$pendingWrites, $that) { |
|
61 | 61 | $streamRef = $stream; |
62 | 62 | |
63 | 63 | $stream->on('drain', array($that, 'handleDrain')); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | $defaults = array_merge( |
30 | 30 | array( |
31 | - 'Host' => $this->getHost().$port, |
|
31 | + 'Host' => $this->getHost() . $port, |
|
32 | 32 | 'User-Agent' => 'ReactPHP/1', |
33 | 33 | ), |
34 | 34 | $connectionHeaders, |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | // assume "/" path by default, but allow "OPTIONS *" |
75 | 75 | if ($path === null) { |
76 | - $path = ($this->method === 'OPTIONS' && $queryString === null) ? '*': '/'; |
|
76 | + $path = ($this->method === 'OPTIONS' && $queryString === null) ? '*' : '/'; |
|
77 | 77 | } |
78 | 78 | if ($queryString !== null) { |
79 | 79 | $path .= '?' . $queryString; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $data = ''; |
95 | 95 | $data .= "{$this->method} {$this->getPath()} HTTP/{$this->protocolVersion}\r\n"; |
96 | 96 | foreach ($headers as $name => $values) { |
97 | - foreach ((array)$values as $value) { |
|
97 | + foreach ((array) $values as $value) { |
|
98 | 98 | $data .= "$name: $value\r\n"; |
99 | 99 | } |
100 | 100 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | { |
120 | 120 | if (null !== $auth = $this->getUrlUserPass()) { |
121 | 121 | return array( |
122 | - 'Authorization' => 'Basic ' . base64_encode($auth['user'].':'.$auth['pass']), |
|
122 | + 'Authorization' => 'Basic ' . base64_encode($auth['user'] . ':' . $auth['pass']), |
|
123 | 123 | ); |
124 | 124 | } |
125 | 125 |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | public function send(RequestInterface $request) |
69 | 69 | { |
70 | - $deferred = new Deferred(function () use (&$deferred) { |
|
70 | + $deferred = new Deferred(function() use (&$deferred) { |
|
71 | 71 | if (isset($deferred->pending)) { |
72 | 72 | $deferred->pending->cancel(); |
73 | 73 | unset($deferred->pending); |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | $deferred->numRequests = 0; |
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)->then( |
84 | - function (ResponseInterface $response) use ($deferred, $loop, &$timeout) { |
|
84 | + function(ResponseInterface $response) use ($deferred, $loop, &$timeout) { |
|
85 | 85 | if (isset($deferred->timeout)) { |
86 | 86 | $loop->cancelTimer($deferred->timeout); |
87 | 87 | unset($deferred->timeout); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $timeout = -1; |
90 | 90 | $deferred->resolve($response); |
91 | 91 | }, |
92 | - function ($e) use ($deferred, $loop, &$timeout) { |
|
92 | + function($e) use ($deferred, $loop, &$timeout) { |
|
93 | 93 | if (isset($deferred->timeout)) { |
94 | 94 | $loop->cancelTimer($deferred->timeout); |
95 | 95 | unset($deferred->timeout); |
@@ -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, &$timeout) { |
|
109 | + $body->on('close', function() use ($that, $deferred, &$timeout) { |
|
110 | 110 | if ($timeout >= 0) { |
111 | 111 | $that->applyTimeout($deferred, $timeout); |
112 | 112 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function applyTimeout(Deferred $deferred, $timeout) |
128 | 128 | { |
129 | - $deferred->timeout = $this->loop->addTimer($timeout, function () use ($timeout, $deferred) { |
|
129 | + $deferred->timeout = $this->loop->addTimer($timeout, function() use ($timeout, $deferred) { |
|
130 | 130 | $deferred->reject(new \RuntimeException( |
131 | 131 | 'Request timed out after ' . $timeout . ' seconds' |
132 | 132 | )); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $promise = $this->sender->send($request); |
148 | 148 | |
149 | 149 | if (!$this->streaming) { |
150 | - $promise = $promise->then(function ($response) use ($deferred, $that) { |
|
150 | + $promise = $promise->then(function($response) use ($deferred, $that) { |
|
151 | 151 | return $that->bufferResponse($response, $deferred); |
152 | 152 | }); |
153 | 153 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $deferred->pending = $promise; |
156 | 156 | |
157 | 157 | return $promise->then( |
158 | - function (ResponseInterface $response) use ($request, $that, $deferred) { |
|
158 | + function(ResponseInterface $response) use ($request, $that, $deferred) { |
|
159 | 159 | return $that->onResponse($response, $request, $deferred); |
160 | 160 | } |
161 | 161 | ); |
@@ -187,10 +187,10 @@ discard block |
||
187 | 187 | // buffer stream and resolve with buffered body |
188 | 188 | $maximumSize = $this->maximumSize; |
189 | 189 | $promise = \React\Promise\Stream\buffer($stream, $maximumSize)->then( |
190 | - function ($body) use ($response) { |
|
190 | + function($body) use ($response) { |
|
191 | 191 | return $response->withBody(new BufferedBody($body)); |
192 | 192 | }, |
193 | - function ($e) use ($stream, $maximumSize) { |
|
193 | + function($e) use ($stream, $maximumSize) { |
|
194 | 194 | // try to close stream if buffering fails (or is cancelled) |
195 | 195 | $stream->close(); |
196 | 196 |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $this->parser = new RequestHeaderParser(); |
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 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | // cancel pending promise once connection closes |
160 | 160 | if ($response instanceof CancellablePromiseInterface) { |
161 | - $conn->on('close', function () use ($response) { |
|
161 | + $conn->on('close', function() use ($response) { |
|
162 | 162 | $response->cancel(); |
163 | 163 | }); |
164 | 164 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $that = $this; |
177 | 177 | $response->then( |
178 | - function ($response) use ($that, $conn, $request) { |
|
178 | + function($response) use ($that, $conn, $request) { |
|
179 | 179 | if (!$response instanceof ResponseInterface) { |
180 | 180 | $message = 'The response callback is expected to resolve with an object implementing Psr\Http\Message\ResponseInterface, but resolved with "%s" instead.'; |
181 | 181 | $message = \sprintf($message, \is_object($response) ? \get_class($response) : \gettype($response)); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | } |
187 | 187 | $that->handleResponse($conn, $request, $response); |
188 | 188 | }, |
189 | - function ($error) use ($that, $conn, $request) { |
|
189 | + function($error) use ($that, $conn, $request) { |
|
190 | 190 | $message = 'The response callback is expected to resolve with an object implementing Psr\Http\Message\ResponseInterface, but rejected with "%s" instead.'; |
191 | 191 | $message = \sprintf($message, \is_object($error) ? \get_class($error) : \gettype($error)); |
192 | 192 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | // assign default "Server" header automatically |
249 | 249 | if (!$response->hasHeader('Server')) { |
250 | 250 | $response = $response->withHeader('Server', 'ReactPHP/1'); |
251 | - } elseif ($response->getHeaderLine('Server') === ''){ |
|
251 | + } elseif ($response->getHeaderLine('Server') === '') { |
|
252 | 252 | $response = $response->withoutHeader('Server'); |
253 | 253 | } |
254 | 254 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | if (!$response->hasHeader('Date')) { |
257 | 257 | // IMF-fixdate = day-name "," SP date1 SP time-of-day SP GMT |
258 | 258 | $response = $response->withHeader('Date', gmdate('D, d M Y H:i:s') . ' GMT'); |
259 | - } elseif ($response->getHeaderLine('Date') === ''){ |
|
259 | + } elseif ($response->getHeaderLine('Date') === '') { |
|
260 | 260 | $response = $response->withoutHeader('Date'); |
261 | 261 | } |
262 | 262 | |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | // 304 Not Modified: preserve explicit Content-Length and preserve missing header if body is empty |
270 | 270 | } elseif ($body->getSize() !== null) { |
271 | 271 | // assign Content-Length header when using a "normal" buffered body string |
272 | - $response = $response->withHeader('Content-Length', (string)$body->getSize()); |
|
272 | + $response = $response->withHeader('Content-Length', (string) $body->getSize()); |
|
273 | 273 | } elseif (!$response->hasHeader('Content-Length') && $version === '1.1') { |
274 | 274 | // assign chunked transfer-encoding if no 'content-length' is given for HTTP/1.1 responses |
275 | 275 | $chunked = true; |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | if (($code === Response::STATUS_SWITCHING_PROTOCOLS || ($method === 'CONNECT' && $code >= 200 && $code < 300)) && $body instanceof HttpBodyStream && $body->input instanceof WritableStreamInterface) { |
311 | 311 | if ($request->getBody()->isReadable()) { |
312 | 312 | // request is still streaming => wait for request close before forwarding following data from connection |
313 | - $request->getBody()->on('close', function () use ($connection, $body) { |
|
313 | + $request->getBody()->on('close', function() use ($connection, $body) { |
|
314 | 314 | if ($body->input->isWritable()) { |
315 | 315 | $connection->pipe($body->input); |
316 | 316 | $connection->resume(); |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | if ($persist) { |
373 | 373 | $body->pipe($connection, array('end' => false)); |
374 | 374 | $parser = $this->parser; |
375 | - $body->on('end', function () use ($connection, $parser, $body) { |
|
375 | + $body->on('end', function() use ($connection, $parser, $body) { |
|
376 | 376 | $connection->removeListener('close', array($body, 'close')); |
377 | 377 | $parser->handle($connection); |
378 | 378 | }); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | if ($size !== null && $size !== 0) { |
81 | 81 | // automatically assign a "Content-Length" request header if the body size is known and non-empty |
82 | - $request = $request->withHeader('Content-Length', (string)$size); |
|
82 | + $request = $request->withHeader('Content-Length', (string) $size); |
|
83 | 83 | } elseif ($size === 0 && \in_array($request->getMethod(), array('POST', 'PUT', 'PATCH'))) { |
84 | 84 | // only assign a "Content-Length: 0" request header if the body is expected for certain methods |
85 | 85 | $request = $request->withHeader('Content-Length', '0'); |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | $headers[$name] = implode(', ', $values); |
97 | 97 | } |
98 | 98 | |
99 | - $requestStream = $this->http->request($request->getMethod(), (string)$request->getUri(), $headers, $request->getProtocolVersion()); |
|
99 | + $requestStream = $this->http->request($request->getMethod(), (string) $request->getUri(), $headers, $request->getProtocolVersion()); |
|
100 | 100 | |
101 | - $deferred = new Deferred(function ($_, $reject) use ($requestStream) { |
|
101 | + $deferred = new Deferred(function($_, $reject) use ($requestStream) { |
|
102 | 102 | // close request stream if request is cancelled |
103 | 103 | $reject(new \RuntimeException('Request cancelled')); |
104 | 104 | $requestStream->close(); |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $deferred->reject($error); |
109 | 109 | }); |
110 | 110 | |
111 | - $requestStream->on('response', function (ResponseInterface $response, ReadableStreamInterface $body) use ($deferred, $request) { |
|
111 | + $requestStream->on('response', function(ResponseInterface $response, ReadableStreamInterface $body) use ($deferred, $request) { |
|
112 | 112 | $length = null; |
113 | 113 | $code = $response->getStatusCode(); |
114 | 114 | if ($request->getMethod() === 'HEAD' || ($code >= 100 && $code < 200) || $code == Response::STATUS_NO_CONTENT || $code == Response::STATUS_NOT_MODIFIED) { |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | $body->pipe($requestStream); |
135 | 135 | $requestStream->write(''); |
136 | 136 | |
137 | - $body->on('close', $close = function () use ($deferred, $requestStream) { |
|
137 | + $body->on('close', $close = function() use ($deferred, $requestStream) { |
|
138 | 138 | $deferred->reject(new \RuntimeException('Request failed because request body closed unexpectedly')); |
139 | 139 | $requestStream->close(); |
140 | 140 | }); |
141 | - $body->on('error', function ($e) use ($deferred, $requestStream, $close, $body) { |
|
141 | + $body->on('error', function($e) use ($deferred, $requestStream, $close, $body) { |
|
142 | 142 | $body->removeListener('close', $close); |
143 | 143 | $deferred->reject(new \RuntimeException('Request failed because request body reported an error', 0, $e)); |
144 | 144 | $requestStream->close(); |
145 | 145 | }); |
146 | - $body->on('end', function () use ($close, $body) { |
|
146 | + $body->on('end', function() use ($close, $body) { |
|
147 | 147 | $body->removeListener('close', $close); |
148 | 148 | }); |
149 | 149 | } else { |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | } |
153 | 153 | } else { |
154 | 154 | // body is fully buffered => write as one chunk |
155 | - $requestStream->end((string)$body); |
|
155 | + $requestStream->end((string) $body); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | return $deferred->promise(); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $buffer = ''; |
30 | 30 | $maxSize = $this->maxSize; |
31 | 31 | $that = $this; |
32 | - $conn->on('data', $fn = function ($data) use (&$buffer, &$fn, $conn, $maxSize, $that) { |
|
32 | + $conn->on('data', $fn = function($data) use (&$buffer, &$fn, $conn, $maxSize, $that) { |
|
33 | 33 | // append chunk of data to buffer and look for end of request headers |
34 | 34 | $buffer .= $data; |
35 | 35 | $endOfHeader = \strpos($buffer, "\r\n\r\n"); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | |
58 | 58 | try { |
59 | 59 | $request = $that->parseRequest( |
60 | - (string)\substr($buffer, 0, $endOfHeader + 2), |
|
60 | + (string) \substr($buffer, 0, $endOfHeader + 2), |
|
61 | 61 | $conn->getRemoteAddress(), |
62 | 62 | $conn->getLocalAddress() |
63 | 63 | ); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | if ($request->hasHeader('Transfer-Encoding')) { |
75 | 75 | $contentLength = null; |
76 | 76 | } elseif ($request->hasHeader('Content-Length')) { |
77 | - $contentLength = (int)$request->getHeaderLine('Content-Length'); |
|
77 | + $contentLength = (int) $request->getHeaderLine('Content-Length'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | if ($contentLength === 0) { |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | } elseif ($request->hasHeader('Content-Length')) { |
271 | 271 | $string = $request->getHeaderLine('Content-Length'); |
272 | 272 | |
273 | - if ((string)(int)$string !== $string) { |
|
273 | + if ((string) (int) $string !== $string) { |
|
274 | 274 | // Content-Length value is not an integer or not a single integer |
275 | 275 | throw new \InvalidArgumentException('The value of `Content-Length` is not valid', Response::STATUS_BAD_REQUEST); |
276 | 276 | } |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | { |
75 | 75 | $var = \ini_get('max_input_vars'); |
76 | 76 | if ($var !== false) { |
77 | - $this->maxInputVars = (int)$var; |
|
77 | + $this->maxInputVars = (int) $var; |
|
78 | 78 | } |
79 | 79 | $var = \ini_get('max_input_nesting_level'); |
80 | 80 | if ($var !== false) { |
81 | - $this->maxInputNestingLevel = (int)$var; |
|
81 | + $this->maxInputNestingLevel = (int) $var; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | if ($uploadMaxFilesize === null) { |
@@ -86,18 +86,18 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | $this->uploadMaxFilesize = IniUtil::iniSizeToBytes($uploadMaxFilesize); |
89 | - $this->maxFileUploads = $maxFileUploads === null ? (\ini_get('file_uploads') === '' ? 0 : (int)\ini_get('max_file_uploads')) : (int)$maxFileUploads; |
|
89 | + $this->maxFileUploads = $maxFileUploads === null ? (\ini_get('file_uploads') === '' ? 0 : (int) \ini_get('max_file_uploads')) : (int) $maxFileUploads; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | public function parse(ServerRequestInterface $request) |
93 | 93 | { |
94 | 94 | $contentType = $request->getHeaderLine('content-type'); |
95 | - if(!\preg_match('/boundary="?(.*?)"?$/', $contentType, $matches)) { |
|
95 | + if (!\preg_match('/boundary="?(.*?)"?$/', $contentType, $matches)) { |
|
96 | 96 | return $request; |
97 | 97 | } |
98 | 98 | |
99 | 99 | $this->request = $request; |
100 | - $this->parseBody('--' . $matches[1], (string)$request->getBody()); |
|
100 | + $this->parseBody('--' . $matches[1], (string) $request->getBody()); |
|
101 | 101 | |
102 | 102 | $request = $this->request; |
103 | 103 | $this->request = null; |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | return; |
139 | 139 | } |
140 | 140 | |
141 | - $headers = $this->parseHeaders((string)substr($chunk, 0, $pos)); |
|
142 | - $body = (string)\substr($chunk, $pos + 4); |
|
141 | + $headers = $this->parseHeaders((string) substr($chunk, 0, $pos)); |
|
142 | + $body = (string) \substr($chunk, $pos + 4); |
|
143 | 143 | |
144 | 144 | if (!isset($headers['content-disposition'])) { |
145 | 145 | return; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | )); |
248 | 248 | |
249 | 249 | if (\strtoupper($name) === 'MAX_FILE_SIZE') { |
250 | - $this->maxFileSize = (int)$value; |
|
250 | + $this->maxFileSize = (int) $value; |
|
251 | 251 | |
252 | 252 | if ($this->maxFileSize === 0) { |
253 | 253 | $this->maxFileSize = null; |
@@ -50,16 +50,16 @@ |
||
50 | 50 | $sizeLimit = 0; |
51 | 51 | } |
52 | 52 | |
53 | - return Stream\buffer($body, $sizeLimit)->then(function ($buffer) use ($request, $stack) { |
|
53 | + return Stream\buffer($body, $sizeLimit)->then(function($buffer) use ($request, $stack) { |
|
54 | 54 | $request = $request->withBody(new BufferedBody($buffer)); |
55 | 55 | |
56 | 56 | return $stack($request); |
57 | - }, function ($error) use ($stack, $request, $body) { |
|
57 | + }, function($error) use ($stack, $request, $body) { |
|
58 | 58 | // On buffer overflow keep the request body stream in, |
59 | 59 | // but ignore the contents and wait for the close event |
60 | 60 | // before passing the request on to the next middleware. |
61 | 61 | if ($error instanceof OverflowException) { |
62 | - return Stream\first($body, 'close')->then(function () use ($stack, $request) { |
|
62 | + return Stream\first($body, 'close')->then(function() use ($stack, $request) { |
|
63 | 63 | return $stack($request); |
64 | 64 | }); |
65 | 65 | } |