From bc01761221384c0bbac0297d38e85bcaa6286a9a Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 28 Sep 2020 21:07:24 +0200 Subject: Fix repair step and test it Signed-off-by: Sean Molenaar --- lib/Config/DependencyException.php | 29 ----------- lib/Config/FetcherConfig.php | 104 ++++++++++--------------------------- lib/Config/LegacyConfig.php | 5 +- 3 files changed, 29 insertions(+), 109 deletions(-) delete mode 100644 lib/Config/DependencyException.php (limited to 'lib/Config') diff --git a/lib/Config/DependencyException.php b/lib/Config/DependencyException.php deleted file mode 100644 index 6f9d21be6..000000000 --- a/lib/Config/DependencyException.php +++ /dev/null @@ -1,29 +0,0 @@ - - * @author Bernhard Posselt - * @copyright 2012 Alessandro Cosentino - * @copyright 2012-2014 Bernhard Posselt - */ - -namespace OCA\News\Config; - -class DependencyException extends \Exception -{ - - - /** - * Constructor - * - * @param string $msg the error message - */ - public function __construct($msg) - { - parent::__construct($msg); - } -} 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); + } } diff --git a/lib/Config/LegacyConfig.php b/lib/Config/LegacyConfig.php index 71e19acfa..370638843 100644 --- a/lib/Config/LegacyConfig.php +++ b/lib/Config/LegacyConfig.php @@ -39,8 +39,7 @@ class LegacyConfig public function __construct( ?Folder $fileSystem, - LoggerInterface $logger, - $LoggerParameters + LoggerInterface $logger ) { $this->fileSystem = $fileSystem; $this->autoPurgeMinimumInterval = 60; @@ -51,7 +50,7 @@ class LegacyConfig $this->useCronUpdates = true; $this->logger = $logger; $this->exploreUrl = ''; - $this->loggerParams = $LoggerParameters; + $this->loggerParams = ['app' => Application::NAME]; $this->updateInterval = 3600; } -- cgit v1.2.3