Conditions | 8 |
Paths | 8 |
Total Lines | 25 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
28 | public static function parseUrl($url) |
||
29 | { |
||
30 | $info = parse_url($url); |
||
31 | if (!$info || empty($info['scheme'])) { |
||
32 | throw new InvalidUrl('The string must be a valid URL'); |
||
33 | } |
||
34 | |||
35 | if (empty($info['scheme']) || !in_array($info['scheme'], array('http', 'https'))) { |
||
36 | throw new InvalidUrl('Scheme must be one of http or https'); |
||
37 | } |
||
38 | |||
39 | if (empty($info['port'])) { |
||
40 | // Порт не указан |
||
41 | $port = $info['scheme'] == 'https' ? 443 : 80; |
||
42 | } else { |
||
43 | $port = intval($info['port']); |
||
44 | } |
||
45 | |||
46 | return array( |
||
47 | 'scheme' => $info['scheme'], |
||
48 | 'host' => $info['host'], |
||
49 | 'port' => $port, |
||
50 | 'path' => !empty($info['path']) ? trim($info['path'], '/') : '', |
||
51 | ); |
||
52 | } |
||
53 | } |
||
54 |