silverstripe /
silverstripe-environmentcheck
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SilverStripe\EnvironmentCheck\Services; |
||
| 4 | |||
| 5 | use GuzzleHttp\Client as GuzzleClient; |
||
| 6 | use SilverStripe\Core\Injector\Factory; |
||
| 7 | use SilverStripe\Core\Config\Configurable; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Factory class for creating HTTP client which are injected into some env check classes. Inject via YAML, |
||
| 11 | * arguments for Guzzle client can be supplied using "constructor" property or set as default_config. |
||
| 12 | * |
||
| 13 | * @see SilverStripe\EnvironmentCheck\Traits\Fetcher |
||
| 14 | */ |
||
| 15 | class ClientFactory implements Factory |
||
| 16 | { |
||
| 17 | use Configurable; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Default config for Guzzle client. |
||
| 21 | * |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | private static $default_config = []; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 25 | |||
| 26 | /** |
||
| 27 | * Wrapper to create a Guzzle client. |
||
| 28 | * |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | public function create($service, array $params = []) |
||
| 32 | { |
||
| 33 | return new GuzzleClient($this->getConfig($params)); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Merge config provided from yaml with default config |
||
| 38 | * |
||
| 39 | * @param array $overrides |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | public function getConfig(array $overrides) |
||
| 43 | { |
||
| 44 | return array_merge( |
||
| 45 | $this->config()->get('default_config'), |
||
| 46 | $overrides |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | } |
||
| 50 |