@@ -24,6 +24,8 @@ discard block |
||
24 | 24 | * |
25 | 25 | * {@inheritdoc} |
26 | 26 | * @see \Generics\Streams\HttpStream::setHeader() |
27 | + * @param string $headerName |
|
28 | + * @param string $headerValue |
|
27 | 29 | * @return HttpClient |
28 | 30 | */ |
29 | 31 | public function setHeader($headerName, $headerValue) |
@@ -61,6 +63,7 @@ discard block |
||
61 | 63 | |
62 | 64 | /** |
63 | 65 | * Adjust the headers by injecting default values for missing keys. |
66 | + * @param string $requestType |
|
64 | 67 | */ |
65 | 68 | private function adjustHeaders($requestType) |
66 | 69 | { |
@@ -64,23 +64,23 @@ |
||
64 | 64 | */ |
65 | 65 | private function adjustHeaders($requestType) |
66 | 66 | { |
67 | - if (! array_key_exists('Accept', $this->headers) && $requestType != 'HEAD') { |
|
67 | + if (!array_key_exists('Accept', $this->headers) && $requestType != 'HEAD') { |
|
68 | 68 | $this->setHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'); |
69 | 69 | } |
70 | 70 | |
71 | - if (! array_key_exists('Accept-Language', $this->headers) && $requestType != 'HEAD') { |
|
71 | + if (!array_key_exists('Accept-Language', $this->headers) && $requestType != 'HEAD') { |
|
72 | 72 | $this->setHeader('Accept-Language', 'en-US;q=0.7,en;q=0.3'); |
73 | 73 | } |
74 | 74 | |
75 | - if (! array_key_exists('User-Agent', $this->headers) && $requestType != 'HEAD') { |
|
75 | + if (!array_key_exists('User-Agent', $this->headers) && $requestType != 'HEAD') { |
|
76 | 76 | $this->setHeader('User-Agent', 'phpGenerics 1.0'); |
77 | 77 | } |
78 | 78 | |
79 | - if (! array_key_exists('Connection', $this->headers) || strlen($this->headers['Connection']) == 0) { |
|
79 | + if (!array_key_exists('Connection', $this->headers) || strlen($this->headers['Connection']) == 0) { |
|
80 | 80 | $this->adjustConnectionHeader($requestType); |
81 | 81 | } |
82 | 82 | |
83 | - if (! array_key_exists('Accept-Encoding', $this->headers)) { |
|
83 | + if (!array_key_exists('Accept-Encoding', $this->headers)) { |
|
84 | 84 | $encoding = ""; |
85 | 85 | if (function_exists('gzinflate')) { |
86 | 86 | $encoding = 'gzip, deflate'; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $this->handle = $clientHandle; |
37 | 37 | $this->conntected = false; |
38 | 38 | |
39 | - if (! is_resource($clientHandle)) { |
|
39 | + if (!is_resource($clientHandle)) { |
|
40 | 40 | parent::__construct($endpoint); |
41 | 41 | } |
42 | 42 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | if (!is_resource($this->handle)) { |
52 | 52 | throw new SocketException("Socket is not available"); |
53 | 53 | } |
54 | - if (! @socket_connect($this->handle, $this->endpoint->getAddress(), $this->endpoint->getPort())) { |
|
54 | + if (!@socket_connect($this->handle, $this->endpoint->getAddress(), $this->endpoint->getPort())) { |
|
55 | 55 | $code = socket_last_error($this->handle); |
56 | 56 | throw new SocketException(socket_strerror($code), array(), $code); |
57 | 57 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function disconnect() |
67 | 67 | { |
68 | - if (! $this->conntected) { |
|
68 | + if (!$this->conntected) { |
|
69 | 69 | throw new SocketException("Socket is not connected"); |
70 | 70 | } |
71 | 71 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function isWriteable():bool |
101 | 101 | { |
102 | - if (! $this->isConnected()) { |
|
102 | + if (!$this->isConnected()) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | $this->handle = $clientHandle; |
25 | 25 | $this->conntected = false; |
26 | 26 | |
27 | - if (! is_resource($clientHandle)) { |
|
27 | + if (!is_resource($clientHandle)) { |
|
28 | 28 | parent::__construct($endpoint); |
29 | 29 | } |
30 | 30 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function disconnect() |
48 | 48 | { |
49 | - if (! $this->conntected) { |
|
49 | + if (!$this->conntected) { |
|
50 | 50 | throw new SocketException("Socket is not connected"); |
51 | 51 | } |
52 | 52 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function isWriteable():bool |
82 | 82 | { |
83 | - if (! $this->isConnected()) { |
|
83 | + if (!$this->isConnected()) { |
|
84 | 84 | return false; |
85 | 85 | } |
86 | 86 |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function read($length = 1, $offset = null): string |
52 | 52 | { |
53 | - return stream_get_contents($this->handle, $length, $offset == null ? - 1 : intval($offset)); |
|
53 | + return stream_get_contents($this->handle, $length, $offset == null ? -1 : intval($offset)); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function isOpen(): bool |
62 | 62 | { |
63 | - return is_resource($this->handle) && ! feof($this->handle); |
|
63 | + return is_resource($this->handle) && !feof($this->handle); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function ready(): bool |
82 | 82 | { |
83 | - if (! is_resource($this->handle)) { |
|
83 | + if (!is_resource($this->handle)) { |
|
84 | 84 | return false; |
85 | 85 | } |
86 | 86 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | return false; |
101 | 101 | } |
102 | 102 | |
103 | - if (! in_array($this->handle, $read)) { |
|
103 | + if (!in_array($this->handle, $read)) { |
|
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public function write($buffer) |
161 | 161 | { |
162 | - if(!$this->isWriteable()) { |
|
162 | + if (!$this->isWriteable()) { |
|
163 | 163 | throw new SocketException("Stream is not ready for writing"); |
164 | 164 | } |
165 | 165 | $len = strlen($buffer); |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function isWriteable(): bool |
185 | 185 | { |
186 | - if (! is_resource($this->handle)) { |
|
186 | + if (!is_resource($this->handle)) { |
|
187 | 187 | return false; |
188 | 188 | } |
189 | 189 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | return false; |
204 | 204 | } |
205 | 205 | |
206 | - if (! in_array($this->handle, $write)) { |
|
206 | + if (!in_array($this->handle, $write)) { |
|
207 | 207 | return false; |
208 | 208 | } |
209 | 209 |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | 'rqtype' => $requestType, |
130 | 130 | 'path' => $this->path, |
131 | 131 | 'proto' => $this->protocol, |
132 | - 'query' => (strlen($this->queryString) ? '?' . $this->queryString : '') |
|
132 | + 'query' => (strlen($this->queryString) ? '?'.$this->queryString : '') |
|
133 | 133 | )); |
134 | 134 | |
135 | 135 | // Add the host part |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $numBytes = 1; |
185 | 185 | $start = time(); |
186 | 186 | while (true) { |
187 | - if (! $this->checkConnection($start)) { |
|
187 | + if (!$this->checkConnection($start)) { |
|
188 | 188 | continue; |
189 | 189 | } |
190 | 190 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $start = time(); // we have readen something => adjust timeout start point |
198 | 198 | $tmp .= $c; |
199 | 199 | |
200 | - if (! $delimiterFound) { |
|
200 | + if (!$delimiterFound) { |
|
201 | 201 | $this->handleHeader($delimiterFound, $numBytes, $tmp); |
202 | 202 | } |
203 | 203 | |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | |
306 | 306 | $ms = $this->appendPayloadToRequest($ms); |
307 | 307 | |
308 | - if (! $this->isConnected()) { |
|
308 | + if (!$this->isConnected()) { |
|
309 | 309 | $this->connect(); |
310 | 310 | } |
311 | 311 | |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | */ |
331 | 331 | private function checkConnection($start): bool |
332 | 332 | { |
333 | - if (! $this->ready()) { |
|
333 | + if (!$this->ready()) { |
|
334 | 334 | if (time() - $start > $this->timeout) { |
335 | 335 | $this->disconnect(); |
336 | 336 | throw new HttpException("Connection timed out!"); |