eZ\Publish\Core\FieldType\RichText\Validator::validate PHP Метод

validate() публичный Метод

Handles ISO Schematron (as XSLT stylesheet), XSD and RELAX NG schemas.
public validate ( DOMDocument $document ) : string[]
$document DOMDocument
Результат string[] An array of validation errors
    public function validate(DOMDocument $document)
    {
        $this->startRecordingErrors();
        $additionalErrors = array();
        foreach ($this->schemas as $schema) {
            $errors = $this->validateBySchema($document, $schema);
            if (!empty($errors)) {
                $additionalErrors = array_merge($additionalErrors, $errors);
            }
        }
        $errors = $this->collectErrors();
        if (isset($additionalErrors)) {
            $errors = array_merge($errors, $additionalErrors);
        }
        return $errors;
    }

Usage Example

 function convert($xmlString)
 {
     $inputDocument = $this->createDocument($xmlString);
     $this->removeComments($inputDocument);
     $convertedDocument = $this->converter->convert($inputDocument);
     // Needed by some disabled output escaping (eg. legacy ezxml paragraph <line/> elements)
     $convertedDocumentNormalized = new DOMDocument();
     $convertedDocumentNormalized->loadXML($convertedDocument->saveXML());
     $errors = $this->validator->validate($convertedDocument);
     $result = $convertedDocumentNormalized->saveXML();
     if (!empty($errors)) {
         $this->logger->error("Validation errors when converting xmlstring", ['result' => $result, 'errors' => $errors, 'xmlString' => $xmlString]);
     }
     return $result;
 }