Automattic\WooCommerce\Vendor\Sabberworm\CSS\RuleSet
DeclarationBlock::createDimensionsShorthand
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.
Looks for long format CSS dimensional properties (margin, padding, border-color, border-style and border-width) and converts them into shorthand CSS properties.
Method of the class: DeclarationBlock{}
No Hooks.
Returns
null. Nothing (null).
Usage
$DeclarationBlock = new DeclarationBlock(); $DeclarationBlock->createDimensionsShorthand();
Changelog
| Deprecated | Since 8.7.0 | , will be removed without substitution in version 9.0 in #511 |
DeclarationBlock::createDimensionsShorthand() DeclarationBlock::createDimensionsShorthand code WC 10.5.0
public function createDimensionsShorthand()
{
$aPositions = ['top', 'right', 'bottom', 'left'];
$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) {
$aFoldable = [];
foreach ($aRules as $sRuleName => $oRule) {
foreach ($aPositions as $sPosition) {
if ($sRuleName == sprintf($sExpanded, $sPosition)) {
$aFoldable[$sRuleName] = $oRule;
}
}
}
// All four dimensions must be present
if (count($aFoldable) == 4) {
$aValues = [];
foreach ($aPositions as $sPosition) {
$oRule = $aRules[sprintf($sExpanded, $sPosition)];
$mRuleValue = $oRule->getValue();
$aRuleValues = [];
if (!$mRuleValue instanceof RuleValueList) {
$aRuleValues[] = $mRuleValue;
} else {
$aRuleValues = $mRuleValue->getListComponents();
}
$aValues[$sPosition] = $aRuleValues;
}
$oNewRule = new Rule($sProperty, $oRule->getLineNo(), $oRule->getColNo());
if ((string)$aValues['left'][0] == (string)$aValues['right'][0]) {
if ((string)$aValues['top'][0] == (string)$aValues['bottom'][0]) {
if ((string)$aValues['top'][0] == (string)$aValues['left'][0]) {
// All 4 sides are equal
$oNewRule->addValue($aValues['top']);
} else {
// Top and bottom are equal, left and right are equal
$oNewRule->addValue($aValues['top']);
$oNewRule->addValue($aValues['left']);
}
} else {
// Only left and right are equal
$oNewRule->addValue($aValues['top']);
$oNewRule->addValue($aValues['left']);
$oNewRule->addValue($aValues['bottom']);
}
} else {
// No sides are equal
$oNewRule->addValue($aValues['top']);
$oNewRule->addValue($aValues['left']);
$oNewRule->addValue($aValues['bottom']);
$oNewRule->addValue($aValues['right']);
}
$this->addRule($oNewRule);
foreach ($aPositions as $sPosition) {
$this->removeRule(sprintf($sExpanded, $sPosition));
}
}
}
}