mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-17 13:08:16 +01:00
Extract method to check if Guzzle is installed
This commit is contained in:
parent
308b15a5d8
commit
961b8a8278
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Cerbero\JsonParser\Concerns;
|
||||
|
||||
use Cerbero\JsonParser\Exceptions\SourceException;
|
||||
use Cerbero\JsonParser\Exceptions\GuzzleRequiredException;
|
||||
use GuzzleHttp\Client;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
@ -18,15 +18,25 @@ trait GuzzleAware
|
||||
* Abort if Guzzle is not loaded
|
||||
*
|
||||
* @return void
|
||||
* @throws SourceException
|
||||
* @throws GuzzleRequiredException
|
||||
*/
|
||||
protected function requireGuzzle(): void
|
||||
{
|
||||
if (!class_exists(Client::class)) {
|
||||
throw SourceException::requireGuzzle();
|
||||
if (!$this->guzzleIsInstalled()) {
|
||||
throw new GuzzleRequiredException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether Guzzle is installed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function guzzleIsInstalled(): bool
|
||||
{
|
||||
return class_exists(Client::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the JSON response of the given URL
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user