File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Embed \ImageInfo ;
4
4
5
+ use GuzzleHttp \Client ;
5
6
use GuzzleHttp \Pool ;
6
7
use GuzzleHttp \Exception \RequestException ;
7
8
@@ -12,16 +13,28 @@ class Guzzle5 implements ImageInfoInterface
12
13
{
13
14
use UtilsTrait;
14
15
16
+ protected static $ config = [
17
+ 'verify ' => false ,
18
+ 'timeout ' => 10 ,
19
+ 'connect_timeout ' => 20 ,
20
+ 'headers ' => [
21
+ 'User-Agent ' => 'Embed PHP Library ' ,
22
+ ],
23
+ 'allow_redirects ' => [
24
+ 'max ' => 20 ,
25
+ 'referer ' => true ,
26
+ ],
27
+ ];
28
+
15
29
/**
16
30
* {@inheritdoc}
17
31
*/
18
32
public static function getImagesInfo (array $ urls , array $ config = null )
19
33
{
20
- if ( $ config === null || ! isset ($ config ['client ' ]) || !( $ config ['client ' ] instanceof \ GuzzleHttp \Client)) {
21
- throw new \ RuntimeException ( ' Guzzle client not passed in config. ' );
22
- }
34
+ $ client = isset ($ config ['client ' ]) ? $ config ['client ' ] : new Client ([
35
+ ' defaults ' => static :: $ config,
36
+ ]);
23
37
24
- $ client = $ config ['client ' ];
25
38
$ result = [];
26
39
27
40
// Build parallel requests
Original file line number Diff line number Diff line change @@ -29,9 +29,7 @@ public function testGuzzle()
29
29
{
30
30
$ info = Embed \ImageInfo \Guzzle5::getImagesInfo ([[
31
31
'value ' => self ::TEST_IMAGE_URL ,
32
- ]], [
33
- 'client ' => new \GuzzleHttp \Client (),
34
- ]);
32
+ ]]);
35
33
36
34
$ this ->assertEquals ($ info [0 ], [
37
35
'width ' => self ::TEST_IMAGE_WIDTH ,
@@ -67,9 +65,6 @@ public function testBase64ImagesGuzzle()
67
65
],
68
66
'image ' => [
69
67
'class ' => 'Embed\ImageInfo\Guzzle5 ' ,
70
- 'config ' => [
71
- 'client ' => new \GuzzleHttp \Client (),
72
- ],
73
68
],
74
69
]);
75
70
You can’t perform that action at this time.
0 commit comments