ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
XPath.php
Go to the documentation of this file.
1<?php
3
4class XPath extends \DOMXPath
5{
7
12
13 public function __construct(\DOMDocument $doc)
14 {
15 parent::__construct($doc);
17 }
18
23 public function createNodeName($nodeName)
24 {
25 if (empty($this->defaultNamespaceURI)) {
26 return $nodeName;
27 }
28 return self::DEFAULT_NAMESPACE_PREFIX . ':' . $nodeName;
29 }
30
31 protected function handleDefaultNamespace()
32 {
33 $rootElements = $this->getRootElements();
34
35 if (count($rootElements) !== 1) {
36 throw new \LogicException(
37 sprintf('Got %d svg elements, expected exactly one', count($rootElements)),
38 1570870568
39 );
40 }
41 $this->defaultNamespaceURI = (string)$rootElements[0]->namespaceURI;
42
43 if ($this->defaultNamespaceURI !== '') {
44 $this->registerNamespace(self::DEFAULT_NAMESPACE_PREFIX, $this->defaultNamespaceURI);
45 }
46 }
47
51 protected function getRootElements()
52 {
53 $rootElements = [];
54 $elements = $this->document->getElementsByTagName('svg');
56 foreach ($elements as $element) {
57 if ($element->parentNode !== $this->document) {
58 continue;
59 }
60 $rootElements[] = $element;
61 }
62 return $rootElements;
63 }
64}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
__construct(\DOMDocument $doc)
Definition: XPath.php:13