csscomb::parse_properties PHP Method

parse_properties() public method

Парсит CSS-декларации из строки
public parse_properties ( $css = '' )
    function parse_properties($css = '')
    {
        if ($this->mode === 'css-file') {
            // отделяем фигурную скобку
            $matches = null;
            preg_match('@

                ^
                (.*?)
                (
                    \\s*?
                    }
                )

            @ismx', $css, $matches);
            $all = null;
            preg_match_all('@
                ^
                (
                    \\s*
                    /\\*.*\\*/
                )
                ;
                (
                    \\s*
                    }
                )
            @ismx', $css, $all);
            if (count($all[0]) > 0 and $all[0][0] !== null and $all[0][0] === $css) {
                // Если в этом участке кода ничего нет кроме одиногоко /* ... */ и закрывающей }
                $all[0][0] = '';
                return $all[1][0] . $all[2][0];
            }
            if (sizeof($matches) > 0 and strlen($matches[1]) > 0) {
                // если есть и свойства и скобка и хотя бы одно :
                $properties = $matches[1];
                $brace = $matches[2];
                if (is_array($this->sort_order[0])) {
                    // Если порядок сортировки разбит на группы свойств
                    /**
                     * Если CSS-свойства уже были разделены на группы пустой 
                     * строкой, то нужно поудалять это разделение, чтобы сделать 
                     * новое.
                     */
                    $properties = preg_replace('/
                        \\r?\\n
                        \\ *?
                        \\r?\\n
                        /ismx', "\n", $properties);
                }
                /* отделяем первый комментарий, который находится на той же строке, где и была скобка */
                $matches = null;
                $first_spaces = $first_comment = '';
                preg_match('@

                    ^
                    (.*?)
                    (inlinecomment\\d*__)
                    (.*)
                    $

                    @ismx', $properties, $matches);
                if (count($matches) === 5 and strlen($matches[1]) === 0) {
                    $first_spaces = $matches[2];
                    $first_comment = $matches[3];
                    $properties = $matches[4];
                }
                $matches = null;
                preg_match_all('@

                    \\s*
                    (
                        .[^:]*
                        [:>]
                        .[^;]*
                        ;
                        (               # На этой же строке (после ;) может быть комментарий. Он тоже пригодится.
                            inlinecomment\\d*__
                        )
                        ?
                        (\\s{0,1}/\\*\\*/)?

                    )

                    @ismx', $properties, $matches);
                $props = $matches[0];
                $props = $this->resort_properties($props);
                $props = $first_spaces . $first_comment . implode($props) . $brace;
            } else {
                $props = $css;
            }
        }
        if ($this->mode === 'properties' or $this->mode === 'style-attribute') {
            preg_match_all('@

                    \\s*
                    (
                        .[^:]*          # все что угодно, но не :
                        :
                        .[^;]*          # все что угодно, но не ;
                        ;
                        (               # На этой же строке (после ;) может быть комментарий. Он тоже пригодится.
                            inlinecomment\\d*__
                        )
                        *?
                    )

                    @ismx', $css, $matches);
            $props = $matches[0];
            if (sizeof($props) > 0) {
                // если есть и свойства и скобка и хотя бы одно :
                $props = $this->resort_properties($props);
                $props = implode($props);
            } else {
                $props = $css;
            }
        }
        return $props;
    }