From 22826b249c0cb98f9a62f361eb8faf3f28d8d2f3 Mon Sep 17 00:00:00 2001 From: raxbg Date: Fri, 5 Oct 2018 16:41:05 +0300 Subject: [PATCH] Add prepend and replace methods --- lib/Sabberworm/CSS/CSSList/CSSList.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Sabberworm/CSS/CSSList/CSSList.php b/lib/Sabberworm/CSS/CSSList/CSSList.php index bc90460b..84113058 100644 --- a/lib/Sabberworm/CSS/CSSList/CSSList.php +++ b/lib/Sabberworm/CSS/CSSList/CSSList.php @@ -31,6 +31,10 @@ public function getLineNo() { return $this->iLineNo; } + public function prepend($oItem) { + array_unshift($this->aContents, $oItem); + } + public function append($oItem) { $this->aContents[] = $oItem; } @@ -48,6 +52,19 @@ public function remove($oItemToRemove) { return false; } + /** + * Replaces an item from the CSS list. + * @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) + */ + public function replace($oOldItem, $oNewItem) { + $iKey = array_search($oOldItem, $this->aContents, true); + if ($iKey !== false) { + array_splice($this->aContents, $iKey, 1, $oNewItem); + return true; + } + return false; + } + /** * Set the contents. * @param array $aContents Objects to set as content.