Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/CSSList/CSSBlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,27 @@ protected function allSelectors(array &$aResult, $sSpecificitySearch = null)
}
}
}

/**
* @param CSSList|Rule|RuleSet|Value $oElement
* @param array<int, CSSFunction> $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;
}
}
}
20 changes: 20 additions & 0 deletions src/CSSList/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, CSSFunction>
*/
public function getAllFunctions($mElement = null)
{
if ($mElement === null) {
$mElement = $this;
}
/** @var array<int, Value> $aResult */
$aResult = [];
$this->allFunctions($mElement, $aResult);
return $aResult;
}

/**
* Expands all shorthand properties to their long value.
*
Expand Down
Loading