Skip to content

Commit 2d2545a

Browse files
authored
Merge pull request #149 from raxbg/prepend_replace
Add prepend and replace methods
2 parents 19dbbd8 + 22826b2 commit 2d2545a

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
@@ -176,6 +176,10 @@ public function getLineNo() {
176176
return $this->iLineNo;
177177
}
178178

179+
public function prepend($oItem) {
180+
array_unshift($this->aContents, $oItem);
181+
}
182+
179183
public function append($oItem) {
180184
$this->aContents[] = $oItem;
181185
}
@@ -193,6 +197,19 @@ public function remove($oItemToRemove) {
193197
return false;
194198
}
195199

200+
/**
201+
* Replaces an item from the CSS list.
202+
* @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)
203+
*/
204+
public function replace($oOldItem, $oNewItem) {
205+
$iKey = array_search($oOldItem, $this->aContents, true);
206+
if ($iKey !== false) {
207+
array_splice($this->aContents, $iKey, 1, $oNewItem);
208+
return true;
209+
}
210+
return false;
211+
}
212+
196213
/**
197214
* Set the contents.
198215
* @param array $aContents Objects to set as content.

0 commit comments

Comments
 (0)