ProxyConfigParser::parse()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 19
nc 2
nop 0
1
<?php
2
/**
3
 * ownCloud - News
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Alessandro Cosentino <[email protected]>
9
 * @author Bernhard Posselt <[email protected]>
10
 * @copyright Alessandro Cosentino 2012
11
 * @copyright Bernhard Posselt 2012, 2014
12
 */
13
14
15
namespace OCA\News\Utility;
16
17
use \OCP\IConfig;
18
19
20
class ProxyConfigParser {
21
22
    private $config;
23
24
    public function __construct(IConfig $config) {
25
        $this->config = $config;
26
    }
27
28
29
    /**
30
     * Parses the config and splits up the port + url
31
     * @return array
32
     */
33
    public function parse() {
34
        $proxy = $this->config->getSystemValue('proxy');
35
        $userpasswd = $this->config->getSystemValue('proxyuserpwd');
36
37
        $result = [
38
            'host' => null,
39
            'port' => null,
40
            'user' => null,
41
            'password' => null
42
        ];
43
44
        // we need to filter out the port -.-
45
        $url = new \Net_URL2($proxy);
46
        $port = $url->getPort();
47
48
        $url->setPort(false);
49
        $host = $url->getUrl();
50
51
52
        $result['host'] = $host;
53
        $result['port'] = $port;
54
55
        if ($userpasswd) {
56
            $auth = explode(':', $userpasswd, 2);
57
            $result['user'] = $auth[0];
58
            $result['password'] = $auth[1];
59
        }
60
61
        return $result;
62
    }
63
64
65
}