Skip to content

Commit d0c0a47

Browse files
committed
RuleSet::addRule() insert position support.
1 parent 3ff5d66 commit d0c0a47

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/Sabberworm/CSS/RuleSet/RuleSet.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,22 @@ public function __construct() {
1717
$this->aRules = array();
1818
}
1919

20-
public function addRule(Rule $oRule) {
20+
public function addRule(Rule $oRule, Rule $oSibling = null, /* boolean */ $bPrepend = false) {
2121
$sRule = $oRule->getRule();
2222
if(!isset($this->aRules[$sRule])) {
2323
$this->aRules[$sRule] = array();
2424
}
25-
$this->aRules[$sRule][] = $oRule;
25+
26+
$iPosition = $bPrepend ? 0 : count($this->aRules[$sRule]);
27+
28+
if ($oSibling !== null) {
29+
$iSiblingPos = array_search($oSibling, $this->aRules[$sRule], true);
30+
if ($iSiblingPos !== false) {
31+
$iPosition = $bPrepend ? $iSiblingPos : $iSiblingPos + 1;
32+
}
33+
}
34+
35+
array_splice($this->aRules[$sRule], $iPosition, 0, array($oRule));
2636
}
2737

2838
/**

0 commit comments

Comments
 (0)