ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use DOMDocument;
25 use ILIAS\Export\ImportHandler\I\File\Namespace\ilFactoryInterface as ilFileNamespaceFactoryInterface;
26 use ILIAS\Export\ImportHandler\I\File\Namespace\ilHandlerInterface as ilFileNamespaceHandlerInterface;
27 use ILIAS\Export\ImportHandler\I\File\XML\ilHandlerInterface as ilXMLFileHandlerInterface;
29 use ILIAS\Export\ImportStatus\I\ilFactoryInterface as ilImportStatusFactoryInterface;
31 use SplFileInfo;
32 
33 class ilHandler extends ilFileHandler implements ilXMLFileHandlerInterface
34 {
35  protected ilImportStatusFactoryInterface $status;
36 
37  public function __construct(
38  ilFileNamespaceFactoryInterface $namespace,
39  ilImportStatusFactoryInterface $status
40  ) {
41  parent::__construct($namespace);
42  $this->status = $status;
43  }
44 
45  public function withFileInfo(SplFileInfo $file_info): ilHandler
46  {
47  $clone = clone $this;
48  $clone->xml_file_info = $file_info;
49  return $clone;
50  }
51 
52  public function withAdditionalNamespace(ilFileNamespaceHandlerInterface $namespace_handler): ilHandler
53  {
54  $clone = clone $this;
55  $clone->namespaces = $clone->namespaces->withElement($namespace_handler);
56  return $clone;
57  }
58 
62  public function loadDomDocument(): DOMDocument
63  {
64  $old_val = libxml_use_internal_errors(true);
65  $doc = new DOMDocument();
66  $doc->load($this->getFilePath());
67  $status_collection = $this->status->collection();
68  $errors = libxml_get_errors();
69  libxml_clear_errors();
70  foreach ($errors as $error) {
71  $status_collection = $status_collection->withAddedStatus(
72  $this->status->handler()->withType(StatusType::FAILED)->withContent(
73  $this->status->content()->builder()->string()->withString(
74  "Error loading dom document:" .
75  "<br> XML: " . $this->getSubPathToDirBeginningAtPathEnd('temp')->getFilePath() .
76  "<br>ERROR: " . $error->message
77  )
78  )
79  );
80  }
81  if ($status_collection->hasStatusType(StatusType::FAILED)) {
82  $exception = $this->status->exception($status_collection->toString(StatusType::FAILED));
83  $exception->setStatuses($status_collection);
84  throw $exception;
85  }
86  libxml_use_internal_errors($old_val);
87  return $doc;
88  }
89 }
ilFileNamespaceFactoryInterface $namespace
__construct(ilFileNamespaceFactoryInterface $namespace, ilImportStatusFactoryInterface $status)
__construct(VocabulariesInterface $vocabularies)
ilImportStatusFactoryInterface $status
ilErrorHandling $error
Definition: class.ilias.php:55
withAdditionalNamespace(ilFileNamespaceHandlerInterface $namespace_handler)