Skip to content

Commit ea58a33

Browse files
committed
RuleSet::addRule() insert position support.
2 parents 0643a61 + d0c0a47 commit ea58a33

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
@@ -29,12 +29,22 @@ public function getLineNo() {
2929
return $this->iLineNo;
3030
}
3131

32-
public function addRule(Rule $oRule) {
32+
public function addRule(Rule $oRule, Rule $oSibling = null, /* boolean */ $bPrepend = false) {
3333
$sRule = $oRule->getRule();
3434
if(!isset($this->aRules[$sRule])) {
3535
$this->aRules[$sRule] = array();
3636
}
37-
$this->aRules[$sRule][] = $oRule;
37+
38+
$iPosition = $bPrepend ? 0 : count($this->aRules[$sRule]);
39+
40+
if ($oSibling !== null) {
41+
$iSiblingPos = array_search($oSibling, $this->aRules[$sRule], true);
42+
if ($iSiblingPos !== false) {
43+
$iPosition = $bPrepend ? $iSiblingPos : $iSiblingPos + 1;
44+
}
45+
}
46+
47+
array_splice($this->aRules[$sRule], $iPosition, 0, array($oRule));
3848
}
3949

4050
/**

0 commit comments

Comments
 (0)