Explodes shorthanded margin/padding properties for later combination

Paramètres

(string) val: Rule set:

1 call to CSSCompression_Combine_MarginPadding::expand()
CSSCompression_Combine_MarginPadding::combine dans advagg_css_compress/css-compressor-3.x/src/lib/Combine/MarginPadding.inc
Combines multiple directional properties of margin/padding into single definition.

Fichier

advagg_css_compress/css-compressor-3.x/src/lib/Combine/MarginPadding.inc, line 118

Classe

CSSCompression_Combine_MarginPadding
CSS Compressor [VERSION] [DATE] Corey Hart @ <a href="http://www.codenothing.com">http://www.codenothing.com</a>

Code

private function expand($val) {
    $pos = 0;
    while (preg_match($this->rmpbase, $val, $match, PREG_OFFSET_CAPTURE, $pos)) {
        $replace = '';
        $prop = $match[2][0];
        $value = preg_split($this->rspace, trim($match[3][0]));
        $positions = array(
            'top' => 0,
            'right' => 0,
            'bottom' => 0,
            'left' => 0,
        );
        // Skip uncombinables
        if ($this->Combine
            ->checkUncombinables($value)) {
            $pos = $match[0][1] + strlen($match[0][0]);
            continue;
        }
        // Each position needs a value
        switch (count($value)) {
            case 1:
                $positions['top'] = $positions['right'] = $positions['bottom'] = $positions['left'] = $value[0];
                break;
            case 2:
                $positions['top'] = $positions['bottom'] = $value[0];
                $positions['right'] = $positions['left'] = $value[1];
                break;
            case 3:
                $positions['top'] = $value[0];
                $positions['right'] = $positions['left'] = $value[1];
                $positions['bottom'] = $value[2];
                break;
            case 4:
                $positions['top'] = $value[0];
                $positions['right'] = $value[1];
                $positions['bottom'] = $value[2];
                $positions['left'] = $value[3];
                break;
            default:
                continue;
        }
        // Build the replacement
        foreach ($positions as $p => $v) {
            $replace .= "{$prop}-{$p}:{$v};";
        }
        $colon = strlen($match[1][0]);
        $val = substr_replace($val, $replace, $match[0][1] + $colon, strlen($match[0][0]) - $colon);
        $pos = $match[0][1] + strlen($replace) - $colon - 1;
    }
    return $val;
}