diff options
Diffstat (limited to 'lib/Config/FetcherConfig.php')
-rw-r--r-- | lib/Config/FetcherConfig.php | 104 |
1 files changed, 27 insertions, 77 deletions
diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php index 1e9b7941e..4966f5b40 100644 --- a/lib/Config/FetcherConfig.php +++ b/lib/Config/FetcherConfig.php @@ -60,71 +60,11 @@ class FetcherConfig 'text/xml;q=0.4, */*;q=0.2'; /** - * Configure a guzzle client - * - * @return ClientInterface Legacy client to guzzle. - */ - public function getClient() - { - if (!class_exists('GuzzleHttp\Collection')) { - return new FeedIoClient($this->getConfig()); - } - - return new LegacyGuzzleClient($this->getOldConfig()); - } - /** - * Get configuration for modern guzzle. - * @return Client Guzzle client. - */ - private function getConfig() - { - $config = [ - 'timeout' => $this->client_timeout, - 'headers' => ['User-Agent' => static::DEFAULT_USER_AGENT, 'Accept' => static::DEFAULT_ACCEPT], - ]; - - if (!empty($this->proxy)) { - $config['proxy'] = $this->proxy; - } - if (!empty($this->redirects)) { - $config['redirect.max'] = $this->redirects; - } - - return new Client($config); - } - - /** - * Get configuration for old guzzle. - * @return Client Guzzle client. - */ - private function getOldConfig() - { - $config = [ - 'request.options' => [ - 'timeout' => $this->client_timeout, - 'headers' => ['User-Agent' => static::DEFAULT_USER_AGENT], - ], - ]; - - if (!empty($this->proxy)) { - $config['request.options']['proxy'] = $this->proxy; - } - - if (!empty($this->redirects)) { - $config['request.options']['redirect.max'] = $this->redirects; - } - - return new Client($config); - } - - /** - * Set settings for config. - * - * @param IConfig $config The shared configuration + * FetcherConfig constructor. * - * @return self + * @param IConfig $config */ - public function setConfig(IConfig $config) + public function __construct(IConfig $config) { $this->client_timeout = $config->getAppValue( Application::NAME, @@ -137,27 +77,14 @@ class FetcherConfig Application::DEFAULT_SETTINGS['maxRedirects'] ); - return $this; - } - - /** - * Set the proxy - * - * @param IConfig $config Nextcloud config. - * - * @return self - */ - public function setProxy(IConfig $config) - { $proxy = $config->getSystemValue('proxy', null); - $creds = $config->getSystemValue('proxyuserpwd', null); - if (is_null($proxy)) { return $this; } $url = new \Net_URL2($proxy); + $creds = $config->getSystemValue('proxyuserpwd', null); if ($creds) { $auth = explode(':', $creds, 2); $url->setUserinfo($auth[0], $auth[1]); @@ -167,4 +94,27 @@ class FetcherConfig return $this; } + + /** + * Configure a guzzle client + * + * @return ClientInterface Legacy client to guzzle. + */ + public function getClient() + { + $config = [ + 'timeout' => $this->client_timeout, + 'headers' => ['User-Agent' => static::DEFAULT_USER_AGENT, 'Accept' => static::DEFAULT_ACCEPT], + ]; + + if (!empty($this->proxy)) { + $config['proxy'] = $this->proxy; + } + if (!empty($this->redirects)) { + $config['redirect.max'] = $this->redirects; + } + + $client = new Client($config); + return new FeedIoClient($client); + } } |