1: <?php
2:
3: class CssProperties {
4:
5: 6: 7: 8:
9: private $properties;
10:
11: 12: 13: 14:
15: public function __construct($properties) {
16: $this->properties = $properties;
17: }
18:
19: 20: 21: 22: 23:
24: public function build($selectors, $pseudoClass = false) {
25: $b = $this->_selectors($selectors, $pseudoClass) . " {\n";
26: foreach ($this->properties as $name => $value) {
27: $b .= $this->_buildProperty($name, $value);
28: }
29: $b .= "}\n";
30:
31: return $b;
32: }
33:
34: 35: 36: 37: 38:
39: public function add(CssProperties $otherProperties) {
40: return new CssProperties(
41: array_merge(
42: $this->properties
43: , $otherProperties->properties
44: )
45: );
46: }
47:
48: private function _selectors($selectors, $pseudoClass) {
49: if (!is_array($selectors)) {
50: $selectors = explode(',', $selectors);
51: }
52:
53: $b = array();
54: foreach ($selectors as $selector) {
55: $s = trim($selector);
56: if ($pseudoClass) {
57: $s .= ':' . $pseudoClass;
58: }
59: $b[] = $s;
60: }
61: return implode(', ', $b);
62: }
63:
64: 65: 66: 67: 68: 69:
70: private function _buildProperty($name, $value) {
71: $value = ArrayUtil::arraylize($value);
72:
73: $b = '';
74: foreach ($value as $v) {
75: $b .= "\t$name: $v;\n";
76: }
77: return $b;
78: }
79:
80: }