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 22
33namespace Embed \ImageInfo ;
44
5+ use GuzzleHttp \Client ;
56use GuzzleHttp \Pool ;
67use GuzzleHttp \Exception \RequestException ;
78
@@ -12,16 +13,28 @@ class Guzzle5 implements ImageInfoInterface
1213{
1314 use UtilsTrait;
1415
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+
1529 /**
1630 * {@inheritdoc}
1731 */
1832 public static function getImagesInfo (array $ urls , array $ config = null )
1933 {
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+ ]);
2337
24- $ client = $ config ['client ' ];
2538 $ result = [];
2639
2740 // Build parallel requests
Original file line number Diff line number Diff line change @@ -29,9 +29,7 @@ public function testGuzzle()
2929 {
3030 $ info = Embed \ImageInfo \Guzzle5::getImagesInfo ([[
3131 'value ' => self ::TEST_IMAGE_URL ,
32- ]], [
33- 'client ' => new \GuzzleHttp \Client (),
34- ]);
32+ ]]);
3533
3634 $ this ->assertEquals ($ info [0 ], [
3735 'width ' => self ::TEST_IMAGE_WIDTH ,
@@ -67,9 +65,6 @@ public function testBase64ImagesGuzzle()
6765 ],
6866 'image ' => [
6967 'class ' => 'Embed\ImageInfo\Guzzle5 ' ,
70- 'config ' => [
71- 'client ' => new \GuzzleHttp \Client (),
72- ],
7368 ],
7469 ]);
7570
You can’t perform that action at this time.
0 commit comments