|
13 | 13 | * A CSSBlockList is a CSSList whose DeclarationBlocks are guaranteed to contain valid declaration blocks or at-rules.
|
14 | 14 | * Most CSSLists conform to this category but some at-rules (such as @keyframes) do not.
|
15 | 15 | */
|
16 |
| -abstract class CSSBlockList extends CSSList { |
17 |
| - public function __construct($iLineNo = 0) { |
18 |
| - parent::__construct($iLineNo); |
19 |
| - } |
| 16 | +abstract class CSSBlockList extends CSSList |
| 17 | +{ |
| 18 | + public function __construct($iLineNo = 0) |
| 19 | + { |
| 20 | + parent::__construct($iLineNo); |
| 21 | + } |
20 | 22 |
|
21 |
| - protected function allDeclarationBlocks(&$aResult) { |
22 |
| - foreach ($this->aContents as $mContent) { |
23 |
| - if ($mContent instanceof DeclarationBlock) { |
24 |
| - $aResult[] = $mContent; |
25 |
| - } else if ($mContent instanceof CSSBlockList) { |
26 |
| - $mContent->allDeclarationBlocks($aResult); |
27 |
| - } |
28 |
| - } |
29 |
| - } |
| 23 | + protected function allDeclarationBlocks(&$aResult) |
| 24 | + { |
| 25 | + foreach ($this->aContents as $mContent) { |
| 26 | + if ($mContent instanceof DeclarationBlock) { |
| 27 | + $aResult[] = $mContent; |
| 28 | + } elseif ($mContent instanceof CSSBlockList) { |
| 29 | + $mContent->allDeclarationBlocks($aResult); |
| 30 | + } |
| 31 | + } |
| 32 | + } |
30 | 33 |
|
31 |
| - protected function allRuleSets(&$aResult) { |
32 |
| - foreach ($this->aContents as $mContent) { |
33 |
| - if ($mContent instanceof RuleSet) { |
34 |
| - $aResult[] = $mContent; |
35 |
| - } else if ($mContent instanceof CSSBlockList) { |
36 |
| - $mContent->allRuleSets($aResult); |
37 |
| - } |
38 |
| - } |
39 |
| - } |
| 34 | + protected function allRuleSets(&$aResult) |
| 35 | + { |
| 36 | + foreach ($this->aContents as $mContent) { |
| 37 | + if ($mContent instanceof RuleSet) { |
| 38 | + $aResult[] = $mContent; |
| 39 | + } elseif ($mContent instanceof CSSBlockList) { |
| 40 | + $mContent->allRuleSets($aResult); |
| 41 | + } |
| 42 | + } |
| 43 | + } |
40 | 44 |
|
41 |
| - protected function allValues($oElement, &$aResult, $sSearchString = null, $bSearchInFunctionArguments = false) { |
42 |
| - if ($oElement instanceof CSSBlockList) { |
43 |
| - foreach ($oElement->getContents() as $oContent) { |
44 |
| - $this->allValues($oContent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
45 |
| - } |
46 |
| - } else if ($oElement instanceof RuleSet) { |
47 |
| - foreach ($oElement->getRules($sSearchString) as $oRule) { |
48 |
| - $this->allValues($oRule, $aResult, $sSearchString, $bSearchInFunctionArguments); |
49 |
| - } |
50 |
| - } else if ($oElement instanceof Rule) { |
51 |
| - $this->allValues($oElement->getValue(), $aResult, $sSearchString, $bSearchInFunctionArguments); |
52 |
| - } else if ($oElement instanceof ValueList) { |
53 |
| - if ($bSearchInFunctionArguments || !($oElement instanceof CSSFunction)) { |
54 |
| - foreach ($oElement->getListComponents() as $mComponent) { |
55 |
| - $this->allValues($mComponent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
56 |
| - } |
57 |
| - } |
58 |
| - } else { |
59 |
| - //Non-List Value or CSSString (CSS identifier) |
60 |
| - $aResult[] = $oElement; |
61 |
| - } |
62 |
| - } |
63 |
| - |
64 |
| - protected function allSelectors(&$aResult, $sSpecificitySearch = null) { |
65 |
| - $aDeclarationBlocks = array(); |
66 |
| - $this->allDeclarationBlocks($aDeclarationBlocks); |
67 |
| - foreach ($aDeclarationBlocks as $oBlock) { |
68 |
| - foreach ($oBlock->getSelectors() as $oSelector) { |
69 |
| - if ($sSpecificitySearch === null) { |
70 |
| - $aResult[] = $oSelector; |
71 |
| - } else { |
72 |
| - $sComparator = '==='; |
73 |
| - $aSpecificitySearch = explode(' ', $sSpecificitySearch); |
74 |
| - $iTargetSpecificity = $aSpecificitySearch[0]; |
75 |
| - if(count($aSpecificitySearch) > 1) { |
76 |
| - $sComparator = $aSpecificitySearch[0]; |
77 |
| - $iTargetSpecificity = $aSpecificitySearch[1]; |
78 |
| - } |
79 |
| - $iTargetSpecificity = (int)$iTargetSpecificity; |
80 |
| - $iSelectorSpecificity = $oSelector->getSpecificity(); |
81 |
| - $bMatches = false; |
82 |
| - switch($sComparator) { |
83 |
| - case '<=': |
84 |
| - $bMatches = $iSelectorSpecificity <= $iTargetSpecificity; |
85 |
| - break; |
86 |
| - case '<': |
87 |
| - $bMatches = $iSelectorSpecificity < $iTargetSpecificity; |
88 |
| - break; |
89 |
| - case '>=': |
90 |
| - $bMatches = $iSelectorSpecificity >= $iTargetSpecificity; |
91 |
| - break; |
92 |
| - case '>': |
93 |
| - $bMatches = $iSelectorSpecificity > $iTargetSpecificity; |
94 |
| - break; |
95 |
| - default: |
96 |
| - $bMatches = $iSelectorSpecificity === $iTargetSpecificity; |
97 |
| - break; |
98 |
| - } |
99 |
| - if ($bMatches) { |
100 |
| - $aResult[] = $oSelector; |
101 |
| - } |
102 |
| - } |
103 |
| - } |
104 |
| - } |
105 |
| - } |
| 45 | + protected function allValues($oElement, &$aResult, $sSearchString = null, $bSearchInFunctionArguments = false) |
| 46 | + { |
| 47 | + if ($oElement instanceof CSSBlockList) { |
| 48 | + foreach ($oElement->getContents() as $oContent) { |
| 49 | + $this->allValues($oContent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
| 50 | + } |
| 51 | + } elseif ($oElement instanceof RuleSet) { |
| 52 | + foreach ($oElement->getRules($sSearchString) as $oRule) { |
| 53 | + $this->allValues($oRule, $aResult, $sSearchString, $bSearchInFunctionArguments); |
| 54 | + } |
| 55 | + } elseif ($oElement instanceof Rule) { |
| 56 | + $this->allValues($oElement->getValue(), $aResult, $sSearchString, $bSearchInFunctionArguments); |
| 57 | + } elseif ($oElement instanceof ValueList) { |
| 58 | + if ($bSearchInFunctionArguments || !($oElement instanceof CSSFunction)) { |
| 59 | + foreach ($oElement->getListComponents() as $mComponent) { |
| 60 | + $this->allValues($mComponent, $aResult, $sSearchString, $bSearchInFunctionArguments); |
| 61 | + } |
| 62 | + } |
| 63 | + } else { |
| 64 | + //Non-List Value or CSSString (CSS identifier) |
| 65 | + $aResult[] = $oElement; |
| 66 | + } |
| 67 | + } |
106 | 68 |
|
| 69 | + protected function allSelectors(&$aResult, $sSpecificitySearch = null) |
| 70 | + { |
| 71 | + $aDeclarationBlocks = array(); |
| 72 | + $this->allDeclarationBlocks($aDeclarationBlocks); |
| 73 | + foreach ($aDeclarationBlocks as $oBlock) { |
| 74 | + foreach ($oBlock->getSelectors() as $oSelector) { |
| 75 | + if ($sSpecificitySearch === null) { |
| 76 | + $aResult[] = $oSelector; |
| 77 | + } else { |
| 78 | + $sComparator = '==='; |
| 79 | + $aSpecificitySearch = explode(' ', $sSpecificitySearch); |
| 80 | + $iTargetSpecificity = $aSpecificitySearch[0]; |
| 81 | + if (count($aSpecificitySearch) > 1) { |
| 82 | + $sComparator = $aSpecificitySearch[0]; |
| 83 | + $iTargetSpecificity = $aSpecificitySearch[1]; |
| 84 | + } |
| 85 | + $iTargetSpecificity = (int)$iTargetSpecificity; |
| 86 | + $iSelectorSpecificity = $oSelector->getSpecificity(); |
| 87 | + $bMatches = false; |
| 88 | + switch ($sComparator) { |
| 89 | + case '<=': |
| 90 | + $bMatches = $iSelectorSpecificity <= $iTargetSpecificity; |
| 91 | + break; |
| 92 | + case '<': |
| 93 | + $bMatches = $iSelectorSpecificity < $iTargetSpecificity; |
| 94 | + break; |
| 95 | + case '>=': |
| 96 | + $bMatches = $iSelectorSpecificity >= $iTargetSpecificity; |
| 97 | + break; |
| 98 | + case '>': |
| 99 | + $bMatches = $iSelectorSpecificity > $iTargetSpecificity; |
| 100 | + break; |
| 101 | + default: |
| 102 | + $bMatches = $iSelectorSpecificity === $iTargetSpecificity; |
| 103 | + break; |
| 104 | + } |
| 105 | + if ($bMatches) { |
| 106 | + $aResult[] = $oSelector; |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + } |
107 | 112 | }
|
0 commit comments