| 148 |
lars |
1 |
<?php declare(strict_types=1);
|
|
|
2 |
/*
|
|
|
3 |
* This file is part of PHPUnit.
|
|
|
4 |
*
|
|
|
5 |
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
namespace PHPUnit\Util\Xml;
|
|
|
11 |
|
|
|
12 |
use function file_get_contents;
|
|
|
13 |
use function libxml_clear_errors;
|
|
|
14 |
use function libxml_get_errors;
|
|
|
15 |
use function libxml_use_internal_errors;
|
|
|
16 |
use DOMDocument;
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* @internal This class is not covered by the backward compatibility promise for PHPUnit
|
|
|
20 |
*/
|
|
|
21 |
final class Validator
|
|
|
22 |
{
|
|
|
23 |
public function validate(DOMDocument $document, string $xsdFilename): ValidationResult
|
|
|
24 |
{
|
|
|
25 |
$originalErrorHandling = libxml_use_internal_errors(true);
|
|
|
26 |
|
|
|
27 |
$document->schemaValidateSource(file_get_contents($xsdFilename));
|
|
|
28 |
|
|
|
29 |
$errors = libxml_get_errors();
|
|
|
30 |
libxml_clear_errors();
|
|
|
31 |
libxml_use_internal_errors($originalErrorHandling);
|
|
|
32 |
|
|
|
33 |
return ValidationResult::fromArray($errors);
|
|
|
34 |
}
|
|
|
35 |
}
|