15
15
use GuzzleHttp \Psr7 \Response as Psr7Response ;
16
16
use GuzzleHttp \Psr7 \Uri as Psr7Uri ;
17
17
use Symfony \Component \BrowserKit \AbstractBrowser as Client ;
18
- use Symfony \Component \BrowserKit \Cookie ;
19
18
use Symfony \Component \BrowserKit \Request as BrowserKitRequest ;
20
19
use Symfony \Component \BrowserKit \Response as BrowserKitResponse ;
21
20
@@ -27,10 +26,10 @@ class Guzzle extends Client
27
26
];
28
27
protected $ refreshMaxInterval = 0 ;
29
28
30
- protected $ awsCredentials = null ;
31
- protected $ awsSignature = null ;
29
+ protected $ awsCredentials ;
30
+ protected $ awsSignature ;
32
31
33
- /** @var \GuzzleHttp\Client */
32
+ /** @var GuzzleClient */
34
33
protected $ client ;
35
34
36
35
/**
@@ -49,7 +48,7 @@ public function setRefreshMaxInterval($seconds)
49
48
$ this ->refreshMaxInterval = $ seconds ;
50
49
}
51
50
52
- public function setClient (GuzzleClient & $ client )
51
+ public function setClient (GuzzleClient $ client )
53
52
{
54
53
$ this ->client = $ client ;
55
54
}
@@ -66,7 +65,7 @@ public function setClient(GuzzleClient &$client)
66
65
*/
67
66
public function setHeader ($ name , $ value )
68
67
{
69
- if (strval ( $ value) === '' ) {
68
+ if (( string ) $ value === '' ) {
70
69
$ this ->deleteHeader ($ name );
71
70
} else {
72
71
$ this ->requestOptions ['headers ' ][$ name ] = $ value ;
@@ -101,9 +100,9 @@ public function setAuth($username, $password, $type = 'basic')
101
100
/**
102
101
* Taken from Mink\BrowserKitDriver
103
102
*
104
- * @param Response $response
103
+ * @param Psr7Response $response
105
104
*
106
- * @return \Symfony\Component\BrowserKit\Response
105
+ * @return BrowserKitResponse
107
106
*/
108
107
protected function createResponse (Psr7Response $ response )
109
108
{
@@ -120,7 +119,7 @@ protected function createResponse(Psr7Response $response)
120
119
}
121
120
122
121
if (strpos ($ contentType , 'charset= ' ) === false ) {
123
- if (preg_match ('/\ <meta[^\ >]+charset *= *[" \']?([a-zA-Z\-0-9]+)/i ' , $ body , $ matches )) {
122
+ if (preg_match ('/<meta[^>]+charset *= *[" \']?([a-zA-Z\-0-9]+)/i ' , $ body , $ matches )) {
124
123
$ contentType .= ';charset= ' . $ matches [1 ];
125
124
}
126
125
$ headers ['Content-Type ' ] = [$ contentType ];
@@ -131,7 +130,7 @@ protected function createResponse(Psr7Response $response)
131
130
$ matches = [];
132
131
133
132
$ matchesMeta = preg_match (
134
- '/\ <meta[^\ >]+http-equiv="refresh" content="\s*(\d*)\s*;\s*url=(.*?)"/i ' ,
133
+ '/<meta[^>]+http-equiv="refresh" content="\s*(\d*)\s*;\s*url=(.*?)"/i ' ,
135
134
$ body ,
136
135
$ matches
137
136
);
@@ -149,7 +148,7 @@ protected function createResponse(Psr7Response $response)
149
148
$ uri = new Psr7Uri ($ this ->getAbsoluteUri ($ matches [2 ]));
150
149
$ currentUri = new Psr7Uri ($ this ->getHistory ()->current ()->getUri ());
151
150
152
- if ($ uri ->withFragment ('' ) != $ currentUri ->withFragment ('' )) {
151
+ if ($ uri ->withFragment ('' ) !== $ currentUri ->withFragment ('' )) {
153
152
$ status = 302 ;
154
153
$ headers ['Location ' ] = $ matchesMeta ? htmlspecialchars_decode ($ uri ) : (string )$ uri ;
155
154
}
@@ -196,7 +195,7 @@ protected function doRequest($request)
196
195
}
197
196
198
197
$ formData = $ this ->extractFormData ($ request );
199
- if (empty ($ multipartData ) and $ formData ) {
198
+ if (empty ($ multipartData ) && $ formData ) {
200
199
$ options ['form_params ' ] = $ formData ;
201
200
}
202
201
@@ -292,7 +291,7 @@ protected function mapFiles($requestFiles, $arrayName = '')
292
291
if (is_array ($ info )) {
293
292
if (isset ($ info ['tmp_name ' ])) {
294
293
if ($ info ['tmp_name ' ]) {
295
- $ handle = fopen ($ info ['tmp_name ' ], 'r ' );
294
+ $ handle = fopen ($ info ['tmp_name ' ], 'rb ' );
296
295
$ filename = isset ($ info ['name ' ]) ? $ info ['name ' ] : null ;
297
296
$ file = [
298
297
'name ' => $ name ,
@@ -312,7 +311,7 @@ protected function mapFiles($requestFiles, $arrayName = '')
312
311
} else {
313
312
$ files [] = [
314
313
'name ' => $ name ,
315
- 'contents ' => fopen ($ info , 'r ' )
314
+ 'contents ' => fopen ($ info , 'rb ' )
316
315
];
317
316
}
318
317
}
@@ -325,7 +324,6 @@ protected function extractCookies($host)
325
324
$ jar = [];
326
325
$ cookies = $ this ->getCookieJar ()->all ();
327
326
foreach ($ cookies as $ cookie ) {
328
- /** @var $cookie Cookie **/
329
327
$ setCookie = SetCookie::fromString ((string )$ cookie );
330
328
if (!$ setCookie ->getDomain ()) {
331
329
$ setCookie ->setDomain ($ host );
0 commit comments