sabberworm / PHP-CSS-Parser

A Parser for CSS Files written in PHP. Allows extraction of CSS files into a data structure, manipulation of said structure and output as (optimized) CSS

Home Page:http://www.sabberworm.com/blog/2010/6/10/php-css-parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ordering of properties after expanding shorthands is wrong

Idrinth opened this issue · comments

.some-rule{
	padding:5px;
	padding-top: 20px
}

leads to

array(5) {
  [0]=>
  string(18) "padding-top: 20px;"
  [1]=>
  string(17) "padding-top: 5px;"
  [2]=>
  string(19) "padding-right: 5px;"
  [3]=>
  string(20) "padding-bottom: 5px;"
  [4]=>
  string(18) "padding-left: 5px;"
}

Giving padding-top a 5px instead of the expected 20px when getting rules as assoc. Most likely related to that creating shorthands leads to the original input instead of merging the padding rules.

looks like that can be fixed with some tiny changes - if I find the time tonight I'll add a pull request:

In addRule

		if ($oSibling !== null) {
			$iSiblingPos = array_search($oSibling, $this->aRules[$sRule], true);
			if ($iSiblingPos !== false) {
				$iPosition = $iSiblingPos;
            } elseif ($sRule !== $oSibling->getRule()) {
                $ruleKeys = array_keys($this->aRules);
                $pos = array_search($oSibling->getRule(), $ruleKeys, true);
                if ($pos !== false && $pos < array_search($oRule->getRule(), $ruleKeys, true)) {
                    $iPosition = 0;
                }
            }
		}

And then passing in the original Rule as a sibling.

Seems the master is changed a lot in comparison to the latest release - not yet sure how to do this now.