ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Helper.php
Go to the documentation of this file.
1<?php
3
4class Helper
5{
10 public static function getElementHref(\DOMElement $element)
11 {
12 if ($element->hasAttribute('href')) {
13 return $element->getAttribute('href');
14 }
15 if ($element->hasAttributeNS('http://www.w3.org/1999/xlink', 'href')) {
16 return $element->getAttributeNS('http://www.w3.org/1999/xlink', 'href');
17 }
18 return null;
19 }
20
25 public static function extractIdReferenceFromHref($href)
26 {
27 if (!is_string($href) || strpos($href, '#') !== 0) {
28 return null;
29 }
30 return substr($href, 1);
31 }
32
38 public static function isElementContainedIn(\DOMElement $needle, \DOMElement $haystack)
39 {
40 if ($needle === $haystack) {
41 return true;
42 }
43 foreach ($haystack->childNodes as $childNode) {
44 if (!$childNode instanceof \DOMElement) {
45 continue;
46 }
47 if (self::isElementContainedIn($needle, $childNode)) {
48 return true;
49 }
50 }
51 return false;
52 }
53}
An exception for terminatinating execution or to throw for unit testing.
static extractIdReferenceFromHref($href)
Definition: Helper.php:25
static isElementContainedIn(\DOMElement $needle, \DOMElement $haystack)
Definition: Helper.php:38
static getElementHref(\DOMElement $element)
Definition: Helper.php:10