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