38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Service;
|
||
|
|
|
||
|
|
use Interop\Container\ContainerInterface;
|
||
|
|
use Zend\Config\Config;
|
||
|
|
use Zend\Http\Client;
|
||
|
|
|
||
|
|
class HttpClientFactory
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @param ContainerInterface $container
|
||
|
|
* @return Client
|
||
|
|
*/
|
||
|
|
public function __invoke(ContainerInterface $container): Client
|
||
|
|
{
|
||
|
|
$configArray = $container->get('config');
|
||
|
|
$config = new Config($configArray['app.config']);
|
||
|
|
|
||
|
|
$httpClient = new Client();
|
||
|
|
$httpClient->setAdapter($curlAdapter = new Client\Adapter\Curl());
|
||
|
|
$curlAdapter->setOptions([
|
||
|
|
'timeout' => 300,
|
||
|
|
]);
|
||
|
|
$curlAdapter
|
||
|
|
->setCurlOption(CURLOPT_SSL_VERIFYPEER, false)
|
||
|
|
->setCurlOption(CURLOPT_SSL_VERIFYHOST, false);
|
||
|
|
if ($config->get('http.proxy.enabled', false)) {
|
||
|
|
$curlAdapter
|
||
|
|
->setCurlOption(CURLOPT_PROXYTYPE, $config->get('http.proxy.type'))
|
||
|
|
->setCurlOption(CURLOPT_PROXY, $config->get('http.proxy.url'));
|
||
|
|
}
|
||
|
|
return $httpClient;
|
||
|
|
}
|
||
|
|
}
|