private function CSSCompression_Combine_MarginPadding::storage in Advanced CSS/JS Aggregation 7
Same name and namespace in other branches
- 6 advagg_css_compress/css-compressor-3.x/src/lib/Combine/MarginPadding.inc \CSSCompression_Combine_MarginPadding::storage()
Build the storage object for iteration
Parameters
(string) val: Rule Set:
1 call to CSSCompression_Combine_MarginPadding::storage()
- CSSCompression_Combine_MarginPadding::combine in advagg_css_compress/
css-compressor-3.x/ src/ lib/ Combine/ MarginPadding.inc - Combines multiple directional properties of margin/padding into single definition.
File
- advagg_css_compress/
css-compressor-3.x/ src/ lib/ Combine/ MarginPadding.inc, line 69
Class
- CSSCompression_Combine_MarginPadding
- CSS Compressor [VERSION] [DATE] Corey Hart @ http://www.codenothing.com
Code
private function storage($val) {
$storage = array();
$pos = 0;
// Find all possible occurences of margin/padding and mark their directional value
while (preg_match($this->rmp, $val, $match, PREG_OFFSET_CAPTURE, $pos)) {
if (!isset($storage[$match[2][0]])) {
$storage[$match[2][0]] = array(
$match[3][0] => $match[4][0],
);
}
// Override double written properties
$storage[$match[2][0]][$match[3][0]] = $match[4][0];
$pos = $match[0][1] + strlen($match[0][0]) - 1;
}
// Go through each tag for possible combination
foreach ($storage as $tag => $arr) {
// Only combine if all 4 definitions are found
if (count($arr) == 4 && !$this->Combine
->checkUncombinables($arr)) {
// All 4 are the same
if ($arr['top'] == $arr['bottom'] && $arr['left'] == $arr['right'] && $arr['top'] == $arr['left']) {
$storage[$tag] = "{$tag}:" . $arr['top'] . ';';
}
else {
if ($arr['top'] == $arr['bottom'] && $arr['left'] == $arr['right']) {
$storage[$tag] = "{$tag}:" . $arr['top'] . ' ' . $arr['left'] . ';';
}
else {
if ($arr['right'] == $arr['left']) {
$storage[$tag] = "{$tag}:" . $arr['top'] . ' ' . $arr['right'] . ' ' . $arr['bottom'] . ';';
}
else {
$storage[$tag] = "{$tag}:" . $arr['top'] . ' ' . $arr['right'] . ' ' . $arr['bottom'] . ' ' . $arr['left'] . ';';
}
}
}
}
else {
unset($storage[$tag]);
}
}
return $storage;
}