Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet

DeclarationBlock::expandBorderShorthandpublicWC 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 border declarations (e.g. border: 1px red;).

Additional splitting happens in expandDimensionsShorthand.

Multiple borders are not yet supported as of 3.

Method of the class: DeclarationBlock{}

No Hooks.

Returns

null. Nothing (null).

Usage

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

Changelog

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

DeclarationBlock::expandBorderShorthand() code WC 10.5.0

public function expandBorderShorthand()
{
    $aBorderRules = [
        'border',
        'border-left',
        'border-right',
        'border-top',
        'border-bottom',
    ];
    $aBorderSizes = [
        'thin',
        'medium',
        'thick',
    ];
    $aRules = $this->getRulesAssoc();
    foreach ($aBorderRules as $sBorderRule) {
        if (!isset($aRules[$sBorderRule])) {
            continue;
        }
        $oRule = $aRules[$sBorderRule];
        $mRuleValue = $oRule->getValue();
        $aValues = [];
        if (!$mRuleValue instanceof RuleValueList) {
            $aValues[] = $mRuleValue;
        } else {
            $aValues = $mRuleValue->getListComponents();
        }
        foreach ($aValues as $mValue) {
            if ($mValue instanceof Value) {
                $mNewValue = clone $mValue;
            } else {
                $mNewValue = $mValue;
            }
            if ($mValue instanceof Size) {
                $sNewRuleName = $sBorderRule . "-width";
            } elseif ($mValue instanceof Color) {
                $sNewRuleName = $sBorderRule . "-color";
            } else {
                if (in_array($mValue, $aBorderSizes)) {
                    $sNewRuleName = $sBorderRule . "-width";
                } else {
                    $sNewRuleName = $sBorderRule . "-style";
                }
            }
            $oNewRule = new Rule($sNewRuleName, $oRule->getLineNo(), $oRule->getColNo());
            $oNewRule->setIsImportant($oRule->getIsImportant());
            $oNewRule->addValue([$mNewValue]);
            $this->addRule($oNewRule);
        }
        $this->removeRule($sBorderRule);
    }
}