private static function validateXmlDom(DOMDocument $dom, $schemaOrCallable): void
    {
        $internalErrors = \libxml_use_internal_errors(true);
        \libxml_clear_errors();

        $exception = null;

        if (\is_callable($schemaOrCallable)) {
            try {
                /** @var callable $schemaOrCallable */
                $valid = $schemaOrCallable($dom, $internalErrors);
            } catch (Throwable $exception) {
                $valid = false;
            }
        } elseif (\is_string($schemaOrCallable) && \is_file($schemaOrCallable)) {
            $valid = @$dom->schemaValidateSource(\file_get_contents($schemaOrCallable));
        } else {
            \libxml_use_internal_errors($internalErrors);

            throw new InvalidArgumentException('The schemaOrCallable argument has to be a valid path to XSD file or callable.');
        }

        if (! $valid) {
            $errors = self::getErrorsAsString(self::getXmlErrors($internalErrors));

            if ($errors === '') {
                $errors = 'The XML file is not valid.';
            }

            throw new InvalidArgumentException($errors, 0, $exception);
        }
    }
private static function validateXmlDom(DOMDocument $dom, $schemaOrCallable): void
    {
        $internalErrors = \libxml_use_internal_errors(true);
        \libxml_clear_errors();

        $exception = null;

        if (\is_callable($schemaOrCallable)) {
            try {
                /** @var callable $schemaOrCallable */
                $valid = $schemaOrCallable($dom, $internalErrors);
            } catch (Throwable $exception) {
                $valid = false;
            }
        } elseif (\is_string($schemaOrCallable) && \is_file($schemaOrCallable)) {
            $valid = @$dom->schemaValidateSource(\file_get_contents($schemaOrCallable));
        } else {
            \libxml_use_internal_errors($internalErrors);

            throw new InvalidArgumentException('The schemaOrCallable argument has to be a valid path to XSD file or callable.');
        }

        if (! $valid) {
            $errors = self::getErrorsAsString(self::getXmlErrors($internalErrors));

            if ($errors === '') {
                $errors = 'The XML file is not valid.';
            }

            throw new InvalidArgumentException($errors, 0, $exception);
        }
    }
private static function validateXmlDom ( DOMDocument $ dom , $ schemaOrCallable ) : void { $ internalErrors = \ libxml_use_internal_errors ( true ) ; \ libxml_clear_errors ( ) ; $ exception = null ; if ( \ is_callable ( $ schemaOrCallable ) ) { try { /** @var callable $schemaOrCallable */ $ valid = $ schemaOrCallable ( $ dom , $ internalErrors ) ; } catch ( Throwable $ exception ) { $ valid = false ; } } elseif ( \ is_string ( $ schemaOrCallable ) && \ is_file ( $ schemaOrCallable ) ) { $ valid = @ $ dom -> schemaValidateSource ( \ file_get_contents ( $ schemaOrCallable ) ) ; } else { \ libxml_use_internal_errors ( $ internalErrors ) ; throw new InvalidArgumentException ( 'The schemaOrCallable argument has to be a valid path to XSD file or callable.' ) ; } if ( ! $ valid ) { $ errors = self :: getErrorsAsString ( self :: getXmlErrors ( $ internalErrors ) ) ; if ( $ errors === '' ) { $ errors = 'The XML file is not valid.' ; } throw new InvalidArgumentException ( $ errors , 0 , $ exception ) ; } }
Validates DOMDocument against a file or callback.

@param \DOMDocument    $dom
@param callable|string $schemaOrCallable

@throws \Viserio\Component\Contract\Parser\Exception\InvalidArgumentException

@return void
Validates DOMDocument against a file or callback .