|
15 | 15 | */
|
16 | 16 | abstract class CSSList {
|
17 | 17 |
|
18 |
| - private $aContents; |
| 18 | + private $aContents; |
19 | 19 |
|
20 |
| - public function __construct() { |
21 |
| - $this->aContents = array(); |
22 |
| - } |
| 20 | + public function __construct() { |
| 21 | + $this->aContents = array(); |
| 22 | + } |
23 | 23 |
|
24 |
| - public function append($oItem) { |
25 |
| - $this->aContents[] = $oItem; |
26 |
| - } |
| 24 | + public function append($oItem) { |
| 25 | + $this->aContents[] = $oItem; |
| 26 | + } |
27 | 27 |
|
28 |
| - /** |
29 |
| - * Removes an item from the CSS list. |
30 |
| - * @param RuleSet|Import|Charset|CSSList $oItemToRemove May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset or another CSSList (most likely a MediaQuery) |
31 |
| - */ |
32 |
| - public function remove($oItemToRemove) { |
33 |
| - $iKey = array_search($oItemToRemove, $this->aContents, true); |
34 |
| - if ($iKey !== false) { |
35 |
| - unset($this->aContents[$iKey]); |
36 |
| - } |
37 |
| - } |
| 28 | + /** |
| 29 | + * Removes an item from the CSS list. |
| 30 | + * @param RuleSet|Import|Charset|CSSList $oItemToRemove May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset or another CSSList (most likely a MediaQuery) |
| 31 | + */ |
| 32 | + public function remove($oItemToRemove) { |
| 33 | + $iKey = array_search($oItemToRemove, $this->aContents, true); |
| 34 | + if ($iKey !== false) { |
| 35 | + unset($this->aContents[$iKey]); |
| 36 | + } |
| 37 | + } |
38 | 38 |
|
39 |
| - public function removeDeclarationBlockBySelector($mSelector, $bRemoveAll = false) { |
40 |
| - if ($mSelector instanceof DeclarationBlock) { |
41 |
| - $mSelector = $mSelector->getSelectors(); |
42 |
| - } |
43 |
| - if (!is_array($mSelector)) { |
44 |
| - $mSelector = explode(',', $mSelector); |
45 |
| - } |
46 |
| - foreach ($mSelector as $iKey => &$mSel) { |
47 |
| - if (!($mSel instanceof Selector)) { |
48 |
| - $mSel = new Selector($mSel); |
49 |
| - } |
50 |
| - } |
51 |
| - foreach ($this->aContents as $iKey => $mItem) { |
52 |
| - if (!($mItem instanceof DeclarationBlock)) { |
53 |
| - continue; |
54 |
| - } |
55 |
| - if ($mItem->getSelectors() == $mSelector) { |
56 |
| - unset($this->aContents[$iKey]); |
57 |
| - if (!$bRemoveAll) { |
58 |
| - return; |
59 |
| - } |
60 |
| - } |
61 |
| - } |
62 |
| - } |
| 39 | + public function removeDeclarationBlockBySelector($mSelector, $bRemoveAll = false) { |
| 40 | + if ($mSelector instanceof DeclarationBlock) { |
| 41 | + $mSelector = $mSelector->getSelectors(); |
| 42 | + } |
| 43 | + if (!is_array($mSelector)) { |
| 44 | + $mSelector = explode(',', $mSelector); |
| 45 | + } |
| 46 | + foreach ($mSelector as $iKey => &$mSel) { |
| 47 | + if (!($mSel instanceof Selector)) { |
| 48 | + $mSel = new Selector($mSel); |
| 49 | + } |
| 50 | + } |
| 51 | + foreach ($this->aContents as $iKey => $mItem) { |
| 52 | + if (!($mItem instanceof DeclarationBlock)) { |
| 53 | + continue; |
| 54 | + } |
| 55 | + if ($mItem->getSelectors() == $mSelector) { |
| 56 | + unset($this->aContents[$iKey]); |
| 57 | + if (!$bRemoveAll) { |
| 58 | + return; |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + } |
63 | 63 |
|
64 |
| - public function __toString() { |
65 |
| - $sResult = ''; |
66 |
| - foreach ($this->aContents as $oContent) { |
67 |
| - $sResult .= $oContent->__toString(); |
68 |
| - } |
69 |
| - return $sResult; |
70 |
| - } |
| 64 | + public function __toString() { |
| 65 | + $sResult = ''; |
| 66 | + foreach ($this->aContents as $oContent) { |
| 67 | + $sResult .= $oContent->__toString(); |
| 68 | + } |
| 69 | + return $sResult; |
| 70 | + } |
71 | 71 |
|
72 |
| - public function getContents() { |
73 |
| - return $this->aContents; |
74 |
| - } |
| 72 | + public function getContents() { |
| 73 | + return $this->aContents; |
| 74 | + } |
75 | 75 |
|
76 |
| - protected function allDeclarationBlocks(&$aResult) { |
77 |
| - foreach ($this->aContents as $mContent) { |
78 |
| - if ($mContent instanceof DeclarationBlock) { |
79 |
| - $aResult[] = $mContent; |
80 |
| - } else if ($mContent instanceof CSSList) { |
81 |
| - $mContent->allDeclarationBlocks($aResult); |
82 |
| - } |
83 |
| - } |
84 |
| - } |
| 76 | + protected function allDeclarationBlocks(&$aResult) { |
| 77 | + foreach ($this->aContents as $mContent) { |
| 78 | + if ($mContent instanceof DeclarationBlock) { |
| 79 | + $aResult[] = $mContent; |
| 80 | + } else if ($mContent instanceof CSSList) { |
| 81 | + $mContent->allDeclarationBlocks($aResult); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
85 | 85 |
|
86 |
| - protected function allRuleSets(&$aResult) { |
87 |
| - foreach ($this->aContents as $mContent) { |
88 |
| - if ($mContent instanceof RuleSet) { |
89 |
| - $aResult[] = $mContent; |
90 |
| - } else if ($mContent instanceof CSSList) { |
91 |
| - $mContent->allRuleSets($aResult); |
92 |
| - } |
93 |
| - } |
94 |
| - } |
| 86 | + protected function allRuleSets(&$aResult) { |
| 87 | + foreach ($this->aContents as $mContent) { |
| 88 | + if ($mContent instanceof RuleSet) { |
| 89 | + $aResult[] = $mContent; |
| 90 | + } else if ($mContent instanceof CSSList) { |
| 91 | + $mContent->allRuleSets($aResult); |
| 92 | + } |
| 93 | + } |
| 94 | + } |
95 | 95 |
|
96 |
| - protected function allValues($oElement, &$aResult, $sSearchString = null, $bSearchInFunctionArguments = false) { |
97 |
| - if ($oElement instanceof CSSList) { |
98 |
| - foreach ($oElement->getContents() as $oContent) { |
99 |
| - $this->allValues($oContent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
100 |
| - } |
101 |
| - } else if ($oElement instanceof RuleSet) { |
102 |
| - foreach ($oElement->getRules($sSearchString) as $oRule) { |
103 |
| - $this->allValues($oRule, $aResult, $sSearchString, $bSearchInFunctionArguments); |
104 |
| - } |
105 |
| - } else if ($oElement instanceof Rule) { |
106 |
| - $this->allValues($oElement->getValue(), $aResult, $sSearchString, $bSearchInFunctionArguments); |
107 |
| - } else if ($oElement instanceof ValueList) { |
108 |
| - if ($bSearchInFunctionArguments || !($oElement instanceof CSSFunction)) { |
109 |
| - foreach ($oElement->getListComponents() as $mComponent) { |
110 |
| - $this->allValues($mComponent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
111 |
| - } |
112 |
| - } |
113 |
| - } else { |
114 |
| - //Non-List Value or String (CSS identifier) |
115 |
| - $aResult[] = $oElement; |
116 |
| - } |
117 |
| - } |
| 96 | + protected function allValues($oElement, &$aResult, $sSearchString = null, $bSearchInFunctionArguments = false) { |
| 97 | + if ($oElement instanceof CSSList) { |
| 98 | + foreach ($oElement->getContents() as $oContent) { |
| 99 | + $this->allValues($oContent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
| 100 | + } |
| 101 | + } else if ($oElement instanceof RuleSet) { |
| 102 | + foreach ($oElement->getRules($sSearchString) as $oRule) { |
| 103 | + $this->allValues($oRule, $aResult, $sSearchString, $bSearchInFunctionArguments); |
| 104 | + } |
| 105 | + } else if ($oElement instanceof Rule) { |
| 106 | + $this->allValues($oElement->getValue(), $aResult, $sSearchString, $bSearchInFunctionArguments); |
| 107 | + } else if ($oElement instanceof ValueList) { |
| 108 | + if ($bSearchInFunctionArguments || !($oElement instanceof CSSFunction)) { |
| 109 | + foreach ($oElement->getListComponents() as $mComponent) { |
| 110 | + $this->allValues($mComponent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
| 111 | + } |
| 112 | + } |
| 113 | + } else { |
| 114 | + //Non-List Value or String (CSS identifier) |
| 115 | + $aResult[] = $oElement; |
| 116 | + } |
| 117 | + } |
118 | 118 |
|
119 |
| - protected function allSelectors(&$aResult, $sSpecificitySearch = null) { |
120 |
| - foreach ($this->getAllDeclarationBlocks() as $oBlock) { |
121 |
| - foreach ($oBlock->getSelectors() as $oSelector) { |
122 |
| - if ($sSpecificitySearch === null) { |
123 |
| - $aResult[] = $oSelector; |
124 |
| - } else { |
125 |
| - $sComparison = "\$bRes = {$oSelector->getSpecificity()} $sSpecificitySearch;"; |
126 |
| - eval($sComparison); |
127 |
| - if ($bRes) { |
128 |
| - $aResult[] = $oSelector; |
129 |
| - } |
130 |
| - } |
131 |
| - } |
132 |
| - } |
133 |
| - } |
| 119 | + protected function allSelectors(&$aResult, $sSpecificitySearch = null) { |
| 120 | + foreach ($this->getAllDeclarationBlocks() as $oBlock) { |
| 121 | + foreach ($oBlock->getSelectors() as $oSelector) { |
| 122 | + if ($sSpecificitySearch === null) { |
| 123 | + $aResult[] = $oSelector; |
| 124 | + } else { |
| 125 | + $sComparison = "\$bRes = {$oSelector->getSpecificity()} $sSpecificitySearch;"; |
| 126 | + eval($sComparison); |
| 127 | + if ($bRes) { |
| 128 | + $aResult[] = $oSelector; |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + } |
134 | 134 |
|
135 | 135 | }
|
0 commit comments