1 | <?php |
||
28 | class Url |
||
29 | { |
||
30 | /** |
||
31 | * scheme - http |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $scheme; |
||
35 | |||
36 | /** |
||
37 | * host - example.com |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $host; |
||
41 | |||
42 | /** |
||
43 | * port - 80, 443... |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $port; |
||
47 | |||
48 | /** |
||
49 | * user - credential if authentication used |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $user; |
||
53 | |||
54 | /** |
||
55 | * pass - credential if authentication used |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $pass; |
||
59 | |||
60 | /** |
||
61 | * path - /my-page.html |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $path; |
||
65 | |||
66 | /** |
||
67 | * query - ?xx=yy&zz=aa |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $query; |
||
71 | |||
72 | /** |
||
73 | * fragment - #anchor |
||
74 | * @var string |
||
75 | */ |
||
76 | protected $fragment; |
||
77 | |||
78 | /** |
||
79 | * Standard ports for specific schemes |
||
80 | * @var array |
||
81 | */ |
||
82 | private static $defaultPorts = [ |
||
83 | 'http' => 80, |
||
84 | 'https' => 443, |
||
85 | 'ftp' => 21, |
||
86 | 'ssh' => 22 |
||
87 | ]; |
||
88 | |||
89 | /** |
||
90 | * @param string $url |
||
91 | */ |
||
92 | 47 | public function __construct($url) |
|
110 | |||
111 | /** |
||
112 | * Check if the given string is an URL or not |
||
113 | * @param string $url |
||
114 | * @return boolean |
||
115 | */ |
||
116 | 46 | public static function isValid($url) |
|
120 | |||
121 | /** |
||
122 | * Check if the current URL use Basic Auth or not |
||
123 | * @return boolean |
||
124 | */ |
||
125 | 1 | public function hasAuth() |
|
129 | |||
130 | /** |
||
131 | * Rebuilt the URL with all known parts |
||
132 | * @return string |
||
133 | */ |
||
134 | 25 | public function toString() |
|
159 | |||
160 | /** |
||
161 | * Encapsulate all setters / getters and method calls |
||
162 | * @param string $name |
||
163 | * @param array $arguments |
||
164 | * @return mixed |
||
165 | * @throws \BadMethodCallException |
||
166 | */ |
||
167 | 43 | public function __call($name, array $arguments) |
|
183 | |||
184 | /** |
||
185 | * Transform to string with dynamic cast |
||
186 | * @return String |
||
187 | */ |
||
188 | 14 | public function __toString() |
|
196 | |||
197 | /** |
||
198 | * Fill a property with the given value |
||
199 | * @param string $name |
||
200 | * @param mixed $value |
||
201 | * @throws \InvalidArgumentException |
||
202 | */ |
||
203 | 43 | protected function populate($name, $value) |
|
230 | |||
231 | /** |
||
232 | * Property name to retrieve from the current object |
||
233 | * This function is defined only for the special port case |
||
234 | * @param string $name |
||
235 | * @return mixed |
||
236 | */ |
||
237 | 15 | protected function retrieve($name) |
|
249 | } |
||
250 |