From 06a3f22f59822949193a792fa5a770623b24b1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Danyi?= Date: Mon, 14 Aug 2017 15:09:27 +0200 Subject: [PATCH] * http client factory added --- src/App/ConfigProvider.php | 15 +++++++++++++++ src/App/Service/AvatarServiceFactory.php | 11 +++-------- src/App/Service/DataCollectorServiceFactory.php | 9 +-------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/App/ConfigProvider.php b/src/App/ConfigProvider.php index 6ac37dd..e0c6252 100644 --- a/src/App/ConfigProvider.php +++ b/src/App/ConfigProvider.php @@ -1,8 +1,10 @@ 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')); + } + }, ], ]; } diff --git a/src/App/Service/AvatarServiceFactory.php b/src/App/Service/AvatarServiceFactory.php index 379861b..26501ce 100644 --- a/src/App/Service/AvatarServiceFactory.php +++ b/src/App/Service/AvatarServiceFactory.php @@ -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); } diff --git a/src/App/Service/DataCollectorServiceFactory.php b/src/App/Service/DataCollectorServiceFactory.php index b6fe16a..e274ea9 100644 --- a/src/App/Service/DataCollectorServiceFactory.php +++ b/src/App/Service/DataCollectorServiceFactory.php @@ -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); }