diff --git a/src/CSSList/CSSBlockList.php b/src/CSSList/CSSBlockList.php index 8c58fbf9..4db38bfa 100644 --- a/src/CSSList/CSSBlockList.php +++ b/src/CSSList/CSSBlockList.php @@ -140,4 +140,27 @@ protected function allSelectors(array &$aResult, $sSpecificitySearch = null) } } } + + /** + * @param CSSList|Rule|RuleSet|Value $oElement + * @param array $aResult + * + * @return void + */ + protected function allFunctions($oElement, array &$aResult) + { + if ($oElement instanceof CSSBlockList) { + foreach ($oElement->getContents() as $oContent) { + $this->allFunctions($oContent, $aResult); + } + } elseif ($oElement instanceof RuleSet) { + foreach ($oElement->getRules() as $oRule) { + $this->allFunctions($oRule, $aResult); + } + } elseif ($oElement instanceof Rule) { + $this->allFunctions($oElement->getValue(), $aResult); + } elseif ($oElement instanceof CSSFunction) { + $aResult[] = $oElement; + } + } } diff --git a/src/CSSList/Document.php b/src/CSSList/Document.php index 822f3995..1ae31d01 100644 --- a/src/CSSList/Document.php +++ b/src/CSSList/Document.php @@ -109,6 +109,26 @@ public function getSelectorsBySpecificity($sSpecificitySearch = null) return $aResult; } + /** + * Returns all `CSSFunction` objects recursively found in the tree, no matter how deeply nested the rule sets are. + * + * @param CSSList|RuleSet|string $mElement + * the `CSSList` or `RuleSet` to start the search from (defaults to the whole document). + * If a string is given, it is used as rule name filter. + * + * @return array + */ + public function getAllFunctions($mElement = null) + { + if ($mElement === null) { + $mElement = $this; + } + /** @var array $aResult */ + $aResult = []; + $this->allFunctions($mElement, $aResult); + return $aResult; + } + /** * Expands all shorthand properties to their long value. *