<?php
namespace wcf\util;
+use wcf\system\exception\SystemException;
/**
* Provides helper methods to work with PHP's DOM implementation.
return null;
}
+ /**
+ * Returns a non-live collection of elements.
+ *
+ * @param (\DOMDocument|\DOMElement) $context context element
+ * @param string $tagName tag name
+ * @return \DOMElement[] list of elements
+ * @throws SystemException
+ */
+ public static function getElements($context, $tagName) {
+ if (!($context instanceof \DOMDocument) && !($context instanceof \DOMElement)) {
+ throw new SystemException("Expected context to be either of type \\DOMDocument or \\DOMElement.");
+ }
+
+ $elements = [];
+ foreach ($context->getElementsByTagName($tagName) as $element) {
+ $elements[] = $element;
+ }
+
+ return $elements;
+ }
+
/**
* Returns the immediate parent element before provided ancestor element. Returns null if
* the ancestor element is the direct parent of provided node.