Conditions | 5 |
Paths | 5 |
Total Lines | 28 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
21 | public function validate(Response $response) |
||
22 | { |
||
23 | if ($response->getContentType() !== 'text/xml') { |
||
24 | return; |
||
25 | } |
||
26 | |||
27 | $body = $response->getBody(); |
||
28 | if (preg_match('/<rss/', $body)) { |
||
29 | libxml_clear_errors(); |
||
30 | $dom = new \DOMDocument(); |
||
31 | @$dom->loadXML($body); |
||
32 | $lastError = libxml_get_last_error(); |
||
33 | if ($lastError) { |
||
34 | throw new ValidationFailedException( |
||
35 | 'The given xml file is not well formed (last error: ' . |
||
36 | str_replace("\n", '', $lastError->message) . ').'); |
||
37 | } |
||
38 | $valid = @$dom->schemaValidate($this->getSchema()); |
||
39 | if (!$valid) { |
||
40 | $lastError = libxml_get_last_error(); |
||
41 | $lastErrorMessage = str_replace("\n", '', $lastError->message); |
||
42 | throw new ValidationFailedException( |
||
43 | 'The given xml file did not Validate vs. ' . |
||
44 | $this->getSchema() . ' (last error: ' . |
||
45 | $lastErrorMessage . ').'); |
||
46 | } |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 |