mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-17 21:18:41 +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;
|
namespace Cerbero\JsonParser\Concerns;
|
||||||
|
|
||||||
use Cerbero\JsonParser\Exceptions\SourceException;
|
use Cerbero\JsonParser\Exceptions\GuzzleRequiredException;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\RequestInterface;
|
use Psr\Http\Message\RequestInterface;
|
||||||
@ -18,15 +18,25 @@ trait GuzzleAware
|
|||||||
* Abort if Guzzle is not loaded
|
* Abort if Guzzle is not loaded
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws SourceException
|
* @throws GuzzleRequiredException
|
||||||
*/
|
*/
|
||||||
protected function requireGuzzle(): void
|
protected function requireGuzzle(): void
|
||||||
{
|
{
|
||||||
if (!class_exists(Client::class)) {
|
if (!$this->guzzleIsInstalled()) {
|
||||||
throw SourceException::requireGuzzle();
|
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
|
* Retrieve the JSON response of the given URL
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user