mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-10-22 17:05:40 +02:00
NEW: Adding Guzzle dependency.
This commit is contained in:
parent
f6652c2b37
commit
e323674adf
@ -16,7 +16,8 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"silverstripe/framework": "^4.0",
|
"silverstripe/framework": "^4.0",
|
||||||
"silverstripe/versioned": "^1.0"
|
"silverstripe/versioned": "^1.0",
|
||||||
|
"guzzlehttp/guzzle": "^6.3.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^5.7",
|
"phpunit/phpunit": "^5.7",
|
||||||
|
46
src/Traits/Fetcher.php
Normal file
46
src/Traits/Fetcher.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\EnvironmentCheck\Traits;
|
||||||
|
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple helper for fetching responses using Guzzle client.
|
||||||
|
*
|
||||||
|
* @package environmentcheck
|
||||||
|
*/
|
||||||
|
trait Fetcher
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Configuration for the Guzzle client
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $clientConfig = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges configuration arrays and returns the result
|
||||||
|
*
|
||||||
|
* @param array $extraConfig
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getClientConfig(array $extraConfig = []) : array
|
||||||
|
{
|
||||||
|
return array_merge($this->clientConfig, $extraConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch a response for a URL using Guzzle client.
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @param array|null $extraConfig Extra configuration
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
public function fetchResponse(string $url, ? array $extraConfig = []) : ? ResponseInterface
|
||||||
|
{
|
||||||
|
$config = $this->getClientConfig($extraConfig);
|
||||||
|
$client = new Client($config);
|
||||||
|
return $client->get($url);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user