| Conditions | 6 |
| Paths | 8 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | public function validate($value, Constraint $constraint) |
||
| 19 | { |
||
| 20 | $match = false; |
||
| 21 | if (strpos($value, '/') === 0) { |
||
| 22 | $context = $this->router->getContext(); |
||
| 23 | $baseUrl = $context->getScheme().'://'.$context->getHost().$context->getBaseUrl(); |
||
| 24 | $value = $baseUrl.$value; |
||
| 25 | } |
||
| 26 | |||
| 27 | $handle = curl_init($value); |
||
| 28 | curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); |
||
| 29 | curl_exec($handle); |
||
| 30 | $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); |
||
| 31 | |||
| 32 | // $httpCode >= 200 && $httpCode < 300 for all http request accepted |
||
| 33 | // $httpCode === 401 for page with authentification required |
||
| 34 | if ($httpCode >= 200 && $httpCode < 300 || $httpCode === 401) { |
||
| 35 | $match = true; |
||
| 36 | } |
||
| 37 | |||
| 38 | if ($match === false) { |
||
| 39 | $this->context->buildViolation($constraint->message) |
||
| 40 | ->setParameter('%string%', $value) |
||
| 41 | ->addViolation(); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 |