Skip to content

Commit 22826b2

Browse files
committed
Add prepend and replace methods
1 parent 1c471f9 commit 22826b2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/Sabberworm/CSS/CSSList/CSSList.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function getLineNo() {
3131
return $this->iLineNo;
3232
}
3333

34+
public function prepend($oItem) {
35+
array_unshift($this->aContents, $oItem);
36+
}
37+
3438
public function append($oItem) {
3539
$this->aContents[] = $oItem;
3640
}
@@ -48,6 +52,19 @@ public function remove($oItemToRemove) {
4852
return false;
4953
}
5054

55+
/**
56+
* Replaces an item from the CSS list.
57+
* @param RuleSet|Import|Charset|CSSList $oItemToRemove May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset or another CSSList (most likely a MediaQuery)
58+
*/
59+
public function replace($oOldItem, $oNewItem) {
60+
$iKey = array_search($oOldItem, $this->aContents, true);
61+
if ($iKey !== false) {
62+
array_splice($this->aContents, $iKey, 1, $oNewItem);
63+
return true;
64+
}
65+
return false;
66+
}
67+
5168
/**
5269
* Set the contents.
5370
* @param array $aContents Objects to set as content.

0 commit comments

Comments
 (0)