19declare(strict_types=1);
42class Handler implements FileValidationHandlerInterface
50 protected FilePathFactoryInterface
$path;
57 FilePathFactoryInterface
$path,
64 ->withType(StatusType::SUCCESS)
65 ->withContent(
$import_status->content()->builder()->string()->withString(
'Validation SUCCESS'));
71 protected function checkIfFilesExist(array $file_handlers): ImportStatusHandlerCollectionInterface
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,
93 ): ImportStatusHandlerCollectionInterface {
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
107 ): ImportStatusHandlerCollectionInterface {
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
132 ): ImportStatusHandlerCollectionInterface {
134 $status_collection = $this->checkIfFilesExist([$xsd_file_handler]);
136 return $status_collection;
138 if (count($nodes) === 0) {
139 return $this->validateEmptyXML($xml_file_handler, $xsd_file_handler);
141 $old_value = libxml_use_internal_errors(
true);
142 $status_collection = $this->import_status->collection()->withNumberingEnabled(
true);
143 foreach ($nodes as $node) {
144 $doc =
new DOMDocument();
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())) {
154 }
catch (Exception
$e) {
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
174 ): ImportStatusHandlerCollectionInterface {
187 return $this->import_status->collection()->withNumberingEnabled(
true);
191 XMLFileHandlerInterface $xml_file_handler,
192 XSDFileHandlerInterface $xsd_file_handler
193 ): ImportStatusHandlerCollectionInterface {
194 return $this->validateXMLAtPath(
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
208 ): ImportStatusHandlerCollectionInterface {
209 return $this->validateXMLAtNodes(
212 $this->parser->DOM()->handler()
213 ->withFileHandler($xml_file_handler)
214 ->getNodeInfoAt($path_handler)
222 FileValidationSetCollectionInterface $sets
223 ): ImportStatusHandlerCollectionInterface {
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;
__construct(ilLogger $logger, ParserFactoryInterface $parser, ImportStatusFactoryInterface $import_status, FilePathFactoryInterface $path,)
FilePathFactoryInterface $path
ImportStatusFactoryInterface $import_status
validateSets(FileValidationSetCollectionInterface $sets)
ImportStatusHandlerInterface $success_status
createErrorMessage(string $msg, ?XMLFileHandlerInterface $xml_file_handler=null, ?XSDFileHandlerInterface $xsd_file_handler=null)
validateEmptyXML(XMLFileHandlerInterface $xml_file_handler, XSDFileHandlerInterface $xsd_file_handler)
collectErrors(?XMLFileHandlerInterface $xml_file_handler=null, ?XSDFileHandlerInterface $xsd_file_handler=null, array $errors=[])
validateXMLAtNodes(XMLFileHandlerInterface $xml_file_handler, XSDFileHandlerInterface $xsd_file_handler, XMLFileNodeInfoCollection $nodes)
checkIfFilesExist(array $file_handlers)
validateXMLFile(XMLFileHandlerInterface $xml_file_handler, XSDFileHandlerInterface $xsd_file_handler)
ParserFactoryInterface $parser
validateXMLAtPath(XMLFileHandlerInterface $xml_file_handler, XSDFileHandlerInterface $xsd_file_handler, FilePathHandlerInterface $path_handler)
Component logger with individual log levels by component id.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($err=$client->getError()) $namespace