Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet
RuleSet::getRules
Returns all rules matching the given rule name
Method of the class: RuleSet{}
No Hooks.
Returns
Array
Usage
$RuleSet = new RuleSet(); $RuleSet->getRules( $mRule );
- $mRule(Rule|string|null)
- Pattern to search for. If null, returns all rules. If the pattern ends with a dash, all rules starting with the pattern are returned as well as one matching the pattern with the dash excluded. Passing a
Rulefor this parameter is deprecated in version 8.9.0, and will not work from v9.0. CallgetRules($rule->getRule())instead.
Default:null
RuleSet::getRules() RuleSet::getRules code WC 10.4.3
public function getRules($mRule = null)
{
if ($mRule instanceof Rule) {
$mRule = $mRule->getRule();
}
/** @var array<int, Rule> $aResult */
$aResult = [];
foreach ($this->aRules as $sName => $aRules) {
// Either no search rule is given or the search rule matches the found rule exactly
// or the search rule ends in “-” and the found rule starts with the search rule.
if (
!$mRule || $sName === $mRule
|| (
strrpos($mRule, '-') === strlen($mRule) - strlen('-')
&& (strpos($sName, $mRule) === 0 || $sName === substr($mRule, 0, -1))
)
) {
$aResult = array_merge($aResult, $aRules);
}
}
usort($aResult, function (Rule $first, Rule $second) {
if ($first->getLineNo() === $second->getLineNo()) {
return $first->getColNo() - $second->getColNo();
}
return $first->getLineNo() - $second->getLineNo();
});
return $aResult;
}