We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /** |
||
| 6 | * (c) Kitodo. Key to digital objects e.V. <[email protected]> |
||
| 7 | * |
||
| 8 | * This file is part of the Kitodo and TYPO3 projects. |
||
| 9 | * |
||
| 10 | * @license GNU General Public License version 3 or later. |
||
| 11 | * For the full copyright and license information, please read the |
||
| 12 | * LICENSE.txt file that was distributed with this source code. |
||
| 13 | */ |
||
| 14 | |||
| 15 | namespace Kitodo\Dlf\Validation; |
||
| 16 | |||
| 17 | use DOMDocument; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The validator combines the configured schemes into one schema and validates the provided DOMDocument against this. |
||
| 21 | * |
||
| 22 | * @package TYPO3 |
||
| 23 | * @subpackage dlf |
||
| 24 | * |
||
| 25 | * @access public |
||
| 26 | */ |
||
| 27 | class XmlSchemesValidator extends AbstractDlfValidator |
||
| 28 | { |
||
| 29 | use LibXmlTrait; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 30 | |||
| 31 | private array $schemes; |
||
| 32 | |||
| 33 | public function __construct(array $configuration) |
||
| 34 | { |
||
| 35 | parent::__construct(DOMDocument::class); |
||
| 36 | $this->schemes = $configuration; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Combines the schemes to one schema and validates the DOMDocument against this. |
||
| 41 | * |
||
| 42 | * @param $value DOMDocument The value to validate |
||
| 43 | * @return bool True if is valid |
||
| 44 | */ |
||
| 45 | protected function isSchemeValid(DOMDocument $value): bool |
||
| 46 | { |
||
| 47 | $xsd = '<?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">'; |
||
| 48 | foreach ($this->schemes as $scheme) { |
||
| 49 | $xsd .= '<xs:import namespace="' . $scheme["namespace"] . '" schemaLocation="' . $scheme["schemaLocation"] . '"/>'; |
||
| 50 | } |
||
| 51 | $xsd .= '</xs:schema>'; |
||
| 52 | return $value->schemaValidateSource($xsd); |
||
| 53 | } |
||
| 54 | |||
| 55 | protected function isValid($value): void |
||
| 56 | { |
||
| 57 | $this->enableErrorBuffer(); |
||
| 58 | if (!$this->isSchemeValid($value)) { |
||
| 59 | $this->addErrorsOfBuffer(); |
||
| 60 | } |
||
| 61 | $this->disableErrorBuffer(); |
||
| 62 | } |
||
| 63 | } |
||
| 64 |