Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet

DeclarationBlock::expandDimensionsShorthandpublicWC 1.0

Deprecated since since 8.7.0, will be removed without substitution in version 9.0 in #511. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.

Splits shorthand dimensional declarations (e.g. margin: 0px auto;) into their constituent parts.

Handles margin, padding, border-color, border-style and border-width.

Method of the class: DeclarationBlock{}

No Hooks.

Returns

null. Nothing (null).

Usage

$DeclarationBlock = new DeclarationBlock();
$DeclarationBlock->expandDimensionsShorthand();

Changelog

Deprecated Since 8.7.0 , will be removed without substitution in version 9.0 in #511

DeclarationBlock::expandDimensionsShorthand() code WC 10.8.1

public function expandDimensionsShorthand()
{
    $aExpansions = [
        'margin' => 'margin-%s',
        'padding' => 'padding-%s',
        'border-color' => 'border-%s-color',
        'border-style' => 'border-%s-style',
        'border-width' => 'border-%s-width',
    ];
    $aRules = $this->getRulesAssoc();
    foreach ($aExpansions as $sProperty => $sExpanded) {
        if (!isset($aRules[$sProperty])) {
            continue;
        }
        $oRule = $aRules[$sProperty];
        $mRuleValue = $oRule->getValue();
        $aValues = [];
        if (!$mRuleValue instanceof RuleValueList) {
            $aValues[] = $mRuleValue;
        } else {
            $aValues = $mRuleValue->getListComponents();
        }
        $top = $right = $bottom = $left = null;
        switch (count($aValues)) {
            case 1:
                $top = $right = $bottom = $left = $aValues[0];
                break;
            case 2:
                $top = $bottom = $aValues[0];
                $left = $right = $aValues[1];
                break;
            case 3:
                $top = $aValues[0];
                $left = $right = $aValues[1];
                $bottom = $aValues[2];
                break;
            case 4:
                $top = $aValues[0];
                $right = $aValues[1];
                $bottom = $aValues[2];
                $left = $aValues[3];
                break;
        }
        foreach (['top', 'right', 'bottom', 'left'] as $sPosition) {
            $oNewRule = new Rule(sprintf($sExpanded, $sPosition), $oRule->getLineNo(), $oRule->getColNo());
            $oNewRule->setIsImportant($oRule->getIsImportant());
            $oNewRule->addValue(${$sPosition});
            $this->addRule($oNewRule);
        }
        $this->removeRule($sProperty);
    }
}