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;
24 use DOMNode;
25 use DOMXPath;
26 use ilLogger;
27 use ILIAS\Export\ImportHandler\I\File\Path\ilHandlerInterface as ilFilePathHandlerInterface;
28 use ILIAS\Export\ImportHandler\I\File\XML\ilHandlerInterface as ilXMLFileHandlerInterface;
29 use ILIAS\Export\ImportHandler\I\File\XML\Node\Info\ilCollectionInterface as ilXMLFileNodeInfoCollectionInterface;
30 use ILIAS\Export\ImportHandler\I\File\XML\Node\Info\ilFactoryInterface as ilXMLFileNodeInfoFactoryInterface;
31 use ILIAS\Export\ImportHandler\I\Parser\DOM\ilHandlerInterface as ilDOMParserHandlerInterface;
33 
34 class ilHandler implements ilDOMParserHandlerInterface
35 {
36  protected ilXMLFileHandlerInterface $xml_file_handler;
37  protected ilXMLFileNodeInfoFactoryInterface $info;
38  protected ilLogger $logger;
39  protected DOMDocument $dom_doc;
40 
41  public function __construct(
42  ilLogger $logger,
43  ilXMLFileNodeInfoFactoryInterface $info,
44  ) {
45  $this->logger = $logger;
46  $this->info = $info;
47  }
48 
52  public function withFileHandler(ilXMLFileHandlerInterface $file_handler): ilDOMParserHandlerInterface
53  {
54  $clone = clone $this;
55  $clone->xml_file_handler = $file_handler;
56  $clone->dom_doc = $file_handler->loadDomDocument();
57  return $clone;
58  }
59 
60  public function getNodeInfoAt(ilFilePathHandlerInterface $path): ilXMLFileNodeInfoCollectionInterface
61  {
62  $dom_xpath = new DOMXPath($this->dom_doc);
63  foreach ($this->xml_file_handler->getNamespaces() as $namespace) {
64  $dom_xpath->registerNamespace($namespace->getPrefix(), $namespace->getNamespace());
65  }
66  $nodes = $dom_xpath->query($path->toString());
67  $node_info_collection = $this->info->collection();
69  foreach ($nodes as $node) {
70  $node_info = $this->info->DOM()->withDOMNode($node);
71  $node_info_collection = $node_info_collection->withElement($node_info);
72  }
73  return $node_info_collection;
74  }
75 }
if($err=$client->getError()) $namespace
$path
Definition: ltiservices.php:32
ilXMLFileNodeInfoFactoryInterface $info
withFileHandler(ilXMLFileHandlerInterface $file_handler)
getNodeInfoAt(ilParserPathHandlerInterface $path)
__construct(ilLogger $logger, ilXMLFileNodeInfoFactoryInterface $info,)