Skip to content

Commit 9ed4f48

Browse files
committed
the client is optional in guzzle5 imageinfo class
1 parent ed29188 commit 9ed4f48

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/ImageInfo/Guzzle5.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Embed\ImageInfo;
44

5+
use GuzzleHttp\Client;
56
use GuzzleHttp\Pool;
67
use 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

tests/ImageInfoTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)