1 | <?php |
||
15 | class HttpGetRequest |
||
16 | { |
||
17 | public $origin |
||
|
|||
18 | , $scheme = 'http' |
||
19 | , $host = 'example.com' |
||
20 | , $port = 80 |
||
21 | , $path = '/' |
||
22 | |||
23 | , $special = null |
||
24 | |||
25 | , $query = array() |
||
26 | , $headers = array() |
||
27 | |||
28 | , $curlOpts = array() |
||
29 | |||
30 | , $username = null |
||
31 | , $password = null |
||
32 | |||
33 | , $maybePublic = true |
||
34 | , $verbose = false |
||
35 | ; |
||
36 | |||
37 | /** |
||
38 | * normalize url and authentication info |
||
39 | * @param string $origin domain text |
||
40 | * @param string $url |
||
41 | * @param IO/IOInterface $io |
||
42 | */ |
||
43 | 6 | public function __construct($origin, $url, IO\IOInterface $io) |
|
62 | |||
63 | 6 | public function importURL($url) |
|
64 | { |
||
65 | 6 | $struct = parse_url($url); |
|
66 | 6 | if (! $struct) { |
|
67 | throw new \InvalidArgumentException("$url is not valid URL"); |
||
68 | } |
||
69 | |||
70 | 6 | $this->scheme = self::setOr($struct, 'scheme', $this->scheme); |
|
71 | 6 | $this->host = self::setOr($struct, 'host', $this->host); |
|
72 | 6 | $this->port = self::setOr($struct, 'port', null); |
|
73 | 6 | $this->path = self::setOr($struct, 'path', ''); |
|
74 | 6 | $this->username = self::setOr($struct, 'user', null); |
|
75 | 6 | $this->password = self::setOr($struct, 'pass', null); |
|
76 | |||
77 | 6 | if (! empty($struct['query'])) { |
|
78 | 1 | parse_str($struct['query'], $this->query); |
|
79 | } |
||
80 | 6 | } |
|
81 | |||
82 | // utility for __construct |
||
83 | 6 | private static function setOr(array $struct, $key, $default=null) |
|
91 | |||
92 | 1 | public function getCurlOpts() |
|
115 | |||
116 | 2 | public function getURL() |
|
137 | |||
138 | /** |
||
139 | * special domain special flag |
||
140 | * @param array $map |
||
141 | */ |
||
142 | 1 | public function setSpecial(array $map) |
|
151 | |||
152 | 1 | public static function genUA() |
|
168 | } |
||
169 |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.