19 declare(strict_types=1);
42 class Handler implements FileValidationHandlerInterface
50 protected FilePathFactoryInterface
$path;
55 ParserFactoryInterface $parser,
56 ImportStatusFactoryInterface $import_status,
57 FilePathFactoryInterface $path,
63 $this->success_status = $import_status->handler()
64 ->withType(StatusType::SUCCESS)
65 ->withContent($import_status->content()->builder()->string()->withString(
'Validation SUCCESS'));
73 $status_collection = $this->import_status->collection()->withNumberingEnabled(
true);
74 foreach ($file_handlers as $file_handler) {
75 if ($file_handler->fileExists()) {
78 $status_collection->withAddedStatus($this->import_status->handler()
80 ->withContent($this->import_status->content()->builder()->string()
81 ->withString(
'File does not exist: ' . $file_handler->getFilePath())));
83 return $status_collection;
90 ?XMLFileHandlerInterface $xml_file_handler =
null,
91 ?XSDFileHandlerInterface $xsd_file_handler =
null,
94 $status_collection = $this->import_status->collection();
95 foreach ($errors as
$error) {
96 $status_collection = $status_collection->getMergedCollectionWith(
100 return $status_collection;
105 ?XMLFileHandlerInterface $xml_file_handler =
null,
106 ?XSDFileHandlerInterface $xsd_file_handler =
null 108 $status_collection = $this->import_status->collection();
109 $xml_str = is_null($xml_file_handler)
111 :
"<br>XML-File: " . $xml_file_handler->getSubPathToDirBeginningAtPathEnd(self::TMP_DIR_NAME)->getFilePath();
112 $xsd_str = is_null($xsd_file_handler)
114 :
"<br>XSD-File: " . $xsd_file_handler->getSubPathToDirBeginningAtPathEnd(self::XML_DIR_NAME)->getFilePath();
115 $content = $this->import_status->content()->builder()->string()->withString(
119 .
"<br>ERROR Message: " . $msg
121 $status_collection = $status_collection->withAddedStatus(
124 return $status_collection;
129 XMLFileHandlerInterface $xml_file_handler,
130 XSDFileHandlerInterface $xsd_file_handler,
131 XMLFileNodeInfoCollection $nodes
136 return $status_collection;
138 if (count($nodes) === 0) {
141 $old_value = libxml_use_internal_errors(
true);
142 $status_collection = $this->import_status->collection()->withNumberingEnabled(
true);
143 foreach ($nodes as $node) {
145 $doc->loadXML($node->getXML(), LIBXML_NOBLANKS);
146 $doc->normalizeDocument();
147 foreach ($xml_file_handler->getNamespaces() as
$namespace) {
151 if ($doc->schemaValidate($xsd_file_handler->getFilePath())) {
157 $errors = libxml_get_errors();
158 libxml_clear_errors();
159 $status_collection = $status_collection->getMergedCollectionWith($this->
collectErrors(
165 libxml_use_internal_errors($old_value);
168 : $this->import_status->collection()->withAddedStatus($this->success_status);
172 XMLFileHandlerInterface $xml_file_handler,
173 XSDFileHandlerInterface $xsd_file_handler
187 return $this->import_status->collection()->withNumberingEnabled(
true);
191 XMLFileHandlerInterface $xml_file_handler,
192 XSDFileHandlerInterface $xsd_file_handler
197 $this->path->handler()->withNode($this->path->node()->anyElement())->withStartAtRoot(
true)
205 XMLFileHandlerInterface $xml_file_handler,
206 XSDFileHandlerInterface $xsd_file_handler,
207 FilePathHandlerInterface $path_handler
212 $this->parser->DOM()->handler()
213 ->withFileHandler($xml_file_handler)
214 ->getNodeInfoAt($path_handler)
222 FileValidationSetCollectionInterface $sets
224 $status_collection = $this->import_status->collection();
225 foreach ($sets as $set) {
226 $status_collection = $status_collection->getMergedCollectionWith($this->
validateXMLAtPath(
227 $set->getXMLFileHandler(),
228 $set->getXSDFileHandler(),
229 $set->getFilePathHandler()
232 return $status_collection;
if($err=$client->getError()) $namespace
collectErrors(?XMLFileHandlerInterface $xml_file_handler=null, ?XSDFileHandlerInterface $xsd_file_handler=null, array $errors=[])
validateXMLAtNodes(XMLFileHandlerInterface $xml_file_handler, XSDFileHandlerInterface $xsd_file_handler, XMLFileNodeInfoCollection $nodes)
__construct(ilLogger $logger, ParserFactoryInterface $parser, ImportStatusFactoryInterface $import_status, FilePathFactoryInterface $path,)
ParserFactoryInterface $parser
createErrorMessage(string $msg, ?XMLFileHandlerInterface $xml_file_handler=null, ?XSDFileHandlerInterface $xsd_file_handler=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
validateSets(FileValidationSetCollectionInterface $sets)
validateEmptyXML(XMLFileHandlerInterface $xml_file_handler, XSDFileHandlerInterface $xsd_file_handler)
checkIfFilesExist(array $file_handlers)
validateXMLAtPath(XMLFileHandlerInterface $xml_file_handler, XSDFileHandlerInterface $xsd_file_handler, FilePathHandlerInterface $path_handler)
validateXMLFile(XMLFileHandlerInterface $xml_file_handler, XSDFileHandlerInterface $xsd_file_handler)
ImportStatusFactoryInterface $import_status
FilePathFactoryInterface $path
ImportStatusHandlerInterface $success_status