diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-10-22 10:49:34 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-10-22 10:49:45 +0200 |
commit | cc3fa38cee2e24dacb940ec5d7ca41e593aa824a (patch) | |
tree | 376eeb6910fc24d14f19992ab4a3d64aa1189448 /utility | |
parent | 720db05f884817ef3683acb697ab89b76a8e3f91 (diff) |
fix tests
Diffstat (limited to 'utility')
-rw-r--r-- | utility/proxyconfigparser.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/utility/proxyconfigparser.php b/utility/proxyconfigparser.php new file mode 100644 index 000000000..4710477e8 --- /dev/null +++ b/utility/proxyconfigparser.php @@ -0,0 +1,65 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Alessandro Cosentino 2012 + * @copyright Bernhard Posselt 2012, 2014 + */ + + +namespace OCA\News\Utility; + +use \OCP\IConfig; + + +class ProxyConfigParser { + + private $config; + + public function __construct(IConfig $config) { + $this->config = $config; + } + + + /** + * Parses the config and splits up the port + url + * @return array + */ + public function parse() { + $proxy = $this->config->getSystemValue('proxy'); + $userpasswd = $this->config->getSystemValue('proxyuserpwd'); + + $result = [ + 'host' => null, + 'port' => null, + 'user' => null, + 'password' => null + ]; + + // we need to filter out the port -.- + $url = new \Net_URL2($proxy); + $port = $url->getPort(); + + $url->setPort(false); + $host = $url->getUrl(); + + + $result['host'] = $host; + $result['port'] = $port; + + if ($userpasswd) { + $auth = explode(':', $userpasswd, 2); + $result['user'] = $auth[0]; + $result['password'] = $auth[1]; + } + + return $result; + } + + +}
\ No newline at end of file |