WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

Pelago\Emogrifier

CssInliner::splitCssAndMediaQuery() private WC 1.0

Splits input CSS code into an array of parts for different media queries, in order. Each part is an array where:

  • key "css" will contain clean CSS code (for @media rules this will be the group rule body within "{...}")
  • key "media" will contain "@media " followed by the media query list, for all allowed media queries, or an empty string for CSS not within a media query

Example:

The CSS code

"@import "file.css"; h1 { color:red; } @media { h1 {}} @media tv { h1 {}}"

will be parsed into the following array:

0 => [

"css" => "h1 { color:red; }",
"media" => ""

],
1 => [

"css" => " h1 {}",
"media" => "@media "

]

Это метод класса: CssInliner{}

Хуков нет.

Возвращает

Строку[][].

Использование

// private - только в коде основоного (родительского) класса
$result = $this->splitCssAndMediaQuery( $css );
$css(строка) (обязательный)

Код CssInliner::splitCssAndMediaQuery() WC 4.5.2

woocommerce/vendor/pelago/emogrifier/src/Emogrifier/CssInliner.php
<?php
private function splitCssAndMediaQuery($css)
{
    $mediaTypesExpression = '';
    if (!empty($this->allowedMediaTypes)) {
        $mediaTypesExpression = '|' . \implode('|', \array_keys($this->allowedMediaTypes));
    }

    $mediaRuleBodyMatcher = '[^{]*+{(?:[^{}]*+{.*})?\\s*+}\\s*+';

    $cssSplitForAllowedMediaTypes = \preg_split(
        '#(@media\\s++(?:only\\s++)?+(?:(?=[{(])' . $mediaTypesExpression . ')' . $mediaRuleBodyMatcher
        . ')#misU',
        $css,
        -1,
        PREG_SPLIT_DELIM_CAPTURE
    );

    // filter the CSS outside/between allowed @media rules
    $cssCleaningMatchers = [
        'import/charset directives' => '/\\s*+@(?:import|charset)\\s[^;]++;/i',
        'remaining media enclosures' => '/\\s*+@media\\s' . $mediaRuleBodyMatcher . '/isU',
    ];

    $splitCss = [];
    foreach ($cssSplitForAllowedMediaTypes as $index => $cssPart) {
        $isMediaRule = $index % 2 !== 0;
        if ($isMediaRule) {
            \preg_match('/^([^{]*+){(.*)}[^}]*+$/s', $cssPart, $matches);
            $splitCss[] = [
                'css' => $matches[2],
                'media' => $matches[1],
            ];
        } else {
            $cleanedCss = \trim(\preg_replace($cssCleaningMatchers, '', $cssPart));
            if ($cleanedCss !== '') {
                $splitCss[] = [
                    'css' => $cleanedCss,
                    'media' => '',
                ];
            }
        }
    }
    return $splitCss;
}