Conditions | 6 |
Paths | 6 |
Total Lines | 25 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
23 | public function check($url) |
||
24 | { |
||
25 | if (strpos($url, '/') === 0) { |
||
26 | $context = $this->router->getContext(); |
||
27 | $baseUrl = $context->getScheme().'://'.$context->getHost().$context->getBaseUrl(); |
||
28 | $url = $baseUrl.$url; |
||
29 | } |
||
30 | |||
31 | $handle = curl_init($url); |
||
32 | curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); |
||
33 | curl_setopt($handle, CURLOPT_HEADER, true); |
||
34 | curl_setopt($handle, CURLOPT_NOBODY, true); |
||
35 | curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 2); |
||
36 | curl_exec($handle); |
||
37 | $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); |
||
38 | |||
39 | // $httpCode (success) >= 200 && $httpCode (redirect) < 310 for all http request accepted |
||
40 | if ($httpCode >= 200 && $httpCode < 310) { |
||
41 | return self::URL_VALID; |
||
42 | } elseif ($httpCode === 404 || $httpCode === 0) { |
||
43 | return self::URL_NOT_FOUND; |
||
44 | } |
||
45 | |||
46 | return self::URL_PROBLEM; |
||
47 | } |
||
48 | } |
||
49 |