|
2 | 2 |
|
3 | 3 | namespace Sabberworm\CSS\CSSList; |
4 | 4 |
|
| 5 | +use Sabberworm\CSS\CSSElement; |
5 | 6 | use Sabberworm\CSS\Property\Selector; |
6 | 7 | use Sabberworm\CSS\Rule\Rule; |
7 | 8 | use Sabberworm\CSS\RuleSet\DeclarationBlock; |
@@ -59,7 +60,53 @@ protected function allRuleSets(array &$aResult) |
59 | 60 | } |
60 | 61 |
|
61 | 62 | /** |
62 | | - * @param CSSList|Rule|RuleSet|Value $oElement |
| 63 | + * Returns all `Value` objects found recursively in `Rule`s in the tree. |
| 64 | + * |
| 65 | + * @param CSSElement|string|null $element |
| 66 | + * This is the `CSSList` or `RuleSet` to start the search from (defaults to the whole document). |
| 67 | + * If a string is given, it is used as a rule name filter. |
| 68 | + * Passing a string for this parameter is deprecated in version 8.9.0, and will not work from v9.0; |
| 69 | + * use the following parameter to pass a rule name filter instead. |
| 70 | + * @param string|bool|null $ruleSearchPatternOrSearchInFunctionArguments |
| 71 | + * This allows filtering rules by property name |
| 72 | + * (e.g. if "color" is passed, only `Value`s from `color` properties will be returned, |
| 73 | + * or if "font-" is provided, `Value`s from all font rules, like `font-size`, and including `font` itself, |
| 74 | + * will be returned). |
| 75 | + * If a Boolean is provided, it is treated as the `$searchInFunctionArguments` argument. |
| 76 | + * Passing a Boolean for this parameter is deprecated in version 8.9.0, and will not work from v9.0; |
| 77 | + * use the `$searchInFunctionArguments` parameter instead. |
| 78 | + * @param bool $searchInFunctionArguments whether to also return Value objects used as Function arguments. |
| 79 | + * |
| 80 | + * @return array<int, Value> |
| 81 | + * |
| 82 | + * @see RuleSet->getRules() |
| 83 | + */ |
| 84 | + public function getAllValues( |
| 85 | + $element = null, |
| 86 | + $ruleSearchPatternOrSearchInFunctionArguments = null, |
| 87 | + $searchInFunctionArguments = false |
| 88 | + ) { |
| 89 | + if (\is_bool($ruleSearchPatternOrSearchInFunctionArguments)) { |
| 90 | + $searchInFunctionArguments = $ruleSearchPatternOrSearchInFunctionArguments; |
| 91 | + $searchString = null; |
| 92 | + } else { |
| 93 | + $searchString = $ruleSearchPatternOrSearchInFunctionArguments; |
| 94 | + } |
| 95 | + |
| 96 | + if ($element === null) { |
| 97 | + $element = $this; |
| 98 | + } elseif (\is_string($element)) { |
| 99 | + $searchString = $element; |
| 100 | + $element = $this; |
| 101 | + } |
| 102 | + |
| 103 | + $result = []; |
| 104 | + $this->allValues($element, $result, $searchString, $searchInFunctionArguments); |
| 105 | + return $result; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * @param CSSElement|string $oElement |
63 | 110 | * @param array<int, Value> $aResult |
64 | 111 | * @param string|null $sSearchString |
65 | 112 | * @param bool $bSearchInFunctionArguments |
|
0 commit comments