first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_XML_Config_Validate {
/**
* @var \LibXMLError[]
*/
private $errors = [];
private $path_to_xsd;
function __construct( $path_to_xsd = null ) {
$this->path_to_xsd = $path_to_xsd ? realpath( $path_to_xsd ) : null;
}
/**
* @return \LibXMLError[]
*/
public function get_errors() {
return $this->errors;
}
/**
* @param string $file_full_path
*
* @return bool
*/
function from_file( $file_full_path ) {
$this->errors = array();
$xml = file_get_contents( $file_full_path );
return $this->from_string( $xml );
}
/**
* @param string $xml
*
* @return bool
*/
function from_string( $xml ) {
if ( '' === preg_replace( '/(\W)+/', '', $xml ) ) {
return false;
}
$this->errors = array();
libxml_use_internal_errors( true );
$xml_object = $this->get_xml( $xml );
if ( $this->path_to_xsd && ! $xml_object->schemaValidate( $this->path_to_xsd ) ) {
$this->errors = libxml_get_errors();
}
libxml_clear_errors();
return count($this->errors) === 0;
}
/**
* @param string $content The string representation of the XML file
*
* @return DOMDocument
*/
private function get_xml( $content ) {
$xml = new DOMDocument();
$xml->loadXML( $content );
return $xml;
}
}