* http client factory added
This commit is contained in:
parent
d362088a9d
commit
06a3f22f59
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Zend\Cache\Storage\Adapter\Filesystem as FilesytemCache;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Http\Client;
|
||||
|
||||
/**
|
||||
@ -56,6 +58,19 @@ class ConfigProvider
|
||||
]);
|
||||
return $cache;
|
||||
},
|
||||
Client::class => function(ContainerInterface $container) {
|
||||
$configArray = $container->get('config');
|
||||
$config = new Config($configArray['app.config']);
|
||||
|
||||
$httpClient = new Client();
|
||||
$httpClient->setAdapter($curlAdapter = new Client\Adapter\Curl());
|
||||
$curlAdapter->setOptions(['timeout' => 300]);
|
||||
if($config->get('http.proxy.enabled', false)) {
|
||||
$curlAdapter
|
||||
->setCurlOption(CURLOPT_PROXYTYPE, $config->get('http.proxy.type'))
|
||||
->setCurlOption(CURLOPT_PROXY, $config->get('http.proxy.url'));
|
||||
}
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -11,15 +11,10 @@ class AvatarServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$router = $container->get(RouterInterface::class);
|
||||
$router = $container->get(RouterInterface::class);
|
||||
$httpClient = $container->get(Client::class);
|
||||
$cache = $container->get('service.avatarCache');
|
||||
$configArray = $container->get('config');
|
||||
$httpClient = new Client();
|
||||
$httpClient->getAdapter()->setOptions([
|
||||
'timeout' => 60,
|
||||
]);
|
||||
|
||||
$cache = $container->get('service.avatarCache');
|
||||
|
||||
$config = new Config($configArray['app.config']);
|
||||
return new AvatarService($httpClient, $config, $router, $cache);
|
||||
}
|
||||
|
||||
@ -11,15 +11,8 @@ class DataCollectorServiceFactory
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$configArray = $container->get('config');
|
||||
$httpClient = $container->get(Client::class);
|
||||
$config = new Config($configArray['app.config']);
|
||||
$httpClient = new Client();
|
||||
$httpClient->setAdapter($curlAdapter = new Client\Adapter\Curl());
|
||||
$curlAdapter->setOptions(['timeout' => 300]);
|
||||
if($config->get('http.proxy.enabled', false)) {
|
||||
$curlAdapter
|
||||
->setCurlOption(CURLOPT_PROXYTYPE, $config->get('http.proxy.type'))
|
||||
->setCurlOption(CURLOPT_PROXY, $config->get('http.proxy.url'));
|
||||
}
|
||||
$avatarService = $container->get(AvatarService::class);
|
||||
return new DataCollectorService($httpClient, $config, $avatarService);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user