You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This allows for constructs like these
* {
color: red;
color: rgba(255, 0, 0, 0.9);
width: 250%;
width: -moz-device-width; //I don’t think there is a vendor-property like this but you get the point.
height: 3px !important;
height: 9px;
}
ClosesMyIntervals#30 (for its most relevant change).
The API had to be changed to accommodate this feature. RuleSet’s `getRules` method now returns indexed arrays. To get the old behaviour, use `getRulesAssoc`.
`removeRule` changed as well but only for the case of passing a Rule instance directly. To get the old behaviour back in case you wanted it, use `removeRule($oRuleInstance->getRule())`.
Copy file name to clipboardExpand all lines: lib/Sabberworm/CSS/RuleSet/RuleSet.php
+47-26Lines changed: 47 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -17,56 +17,77 @@ public function __construct() {
17
17
}
18
18
19
19
publicfunctionaddRule(Rule$oRule) {
20
-
$this->aRules[$oRule->getRule()] = $oRule;
20
+
$sRule = $oRule->getRule();
21
+
if(!isset($this->aRules[$sRule])) {
22
+
$this->aRules[$sRule] = array();
23
+
}
24
+
$this->aRules[$sRule][] = $oRule;
21
25
}
22
26
23
27
/**
24
-
* Returns all rules matching the given pattern
28
+
* Returns all rules matching the given rule name
25
29
* @param (null|string|Rule) $mRule 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 Rule behaves like calling getRules($mRule->getRule()).
26
30
* @example $oRuleSet->getRules('font-') //returns an array of all rules either beginning with font- or matching font.
27
31
* @example $oRuleSet->getRules('font') //returns array('font' => $oRule) or array().
28
32
*/
29
33
publicfunctiongetRules($mRule = null) {
30
-
if ($mRule === null) {
31
-
return$this->aRules;
32
-
}
33
-
$aResult = array();
34
34
if ($mRuleinstanceof Rule) {
35
35
$mRule = $mRule->getRule();
36
36
}
37
-
if (strrpos($mRule, '-') === strlen($mRule) - strlen('-')) {
38
-
$sStart = substr($mRule, 0, -1);
39
-
foreach ($this->aRulesas$oRule) {
40
-
if ($oRule->getRule() === $sStart || strpos($oRule->getRule(), $mRule) === 0) {
// 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.
* Returns all rules matching the given pattern and returns them in an associative array with the rule’s name as keys. This method exists mainly for backwards-compatibility and is really only partially useful.
49
+
* @param (string) $mRule 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 Rule behaves like calling getRules($mRule->getRule()).
50
+
* Note: This method loses some information: Calling this (with an argument of 'background-') on a declaration block like { background-color: green; background-color; rgba(0, 127, 0, 0.7); } will only yield an associative array containing the rgba-valued rule while @link{getRules()} would yield an indexed array containing both.
51
+
*/
52
+
publicfunctiongetRulesAssoc($mRule = null) {
53
+
$aResult = array();
54
+
foreach($this->getRules($mRule) as$oRule) {
55
+
$aResult[$oRule->getRule()] = $oRule;
46
56
}
47
57
return$aResult;
48
58
}
49
59
60
+
/**
61
+
* Remove a rule from this RuleSet. This accepts all the possible values that @link{getRules()} accepts. If given a Rule, it will only remove this particular rule (by identity). If given a name, it will remove all rules by that name. Note: this is previous from pre-v.2.0 behaviour of PHP-CSS-Parser, where passing a Rule instance would remove all rules with the same name. To get the old behvaiour, use removeRule($oRule->getRule()).
62
+
* @param (null|string|Rule) $mRule pattern to remove. If $mRule is null, all rules are removed. If the pattern ends in a dash, all rules starting with the pattern are removed as well as one matching the pattern with the dash excluded. Passing a Rule behaves matches by identity.
63
+
*/
50
64
publicfunctionremoveRule($mRule) {
51
-
if ($mRuleinstanceof Rule) {
52
-
$mRule = $mRule->getRule();
53
-
}
54
-
if (strrpos($mRule, '-') === strlen($mRule) - strlen('-')) {
55
-
$sStart = substr($mRule, 0, -1);
56
-
foreach ($this->aRulesas$oRule) {
57
-
if ($oRule->getRule() === $sStart || strpos($oRule->getRule(), $mRule) === 0) {
// 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 or equals it (without the trailing dash).
0 commit comments