]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/oyejorge/less.php/lib/Less/Visitor/extendFinder.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / oyejorge / less.php / lib / Less / Visitor / extendFinder.php
1 <?php
2
3 /**
4  * Extend Finder Visitor
5  *
6  * @package Less
7  * @subpackage visitor
8  */
9 class Less_Visitor_extendFinder extends Less_Visitor{
10
11         public $contexts = array();
12         public $allExtendsStack;
13         public $foundExtends;
14
15         public function __construct(){
16                 $this->contexts = array();
17                 $this->allExtendsStack = array(array());
18                 parent::__construct();
19         }
20
21         /**
22          * @param Less_Tree_Ruleset $root
23          */
24     public function run($root){
25                 $root = $this->visitObj($root);
26                 $root->allExtends =& $this->allExtendsStack[0];
27                 return $root;
28         }
29
30     public function visitRule($ruleNode, &$visitDeeper ){
31                 $visitDeeper = false;
32         }
33
34     public function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){
35                 $visitDeeper = false;
36         }
37
38     public function visitRuleset($rulesetNode){
39
40                 if( $rulesetNode->root ){
41                         return;
42                 }
43
44                 $allSelectorsExtendList = array();
45
46                 // get &:extend(.a); rules which apply to all selectors in this ruleset
47                 if( $rulesetNode->rules ){
48                         foreach($rulesetNode->rules as $rule){
49                                 if( $rule instanceof Less_Tree_Extend ){
50                                         $allSelectorsExtendList[] = $rule;
51                                         $rulesetNode->extendOnEveryPath = true;
52                                 }
53                         }
54                 }
55
56
57                 // now find every selector and apply the extends that apply to all extends
58                 // and the ones which apply to an individual extend
59                 foreach($rulesetNode->paths as $selectorPath){
60                         $selector = end($selectorPath); //$selectorPath[ count($selectorPath)-1];
61
62                         $j = 0;
63                         foreach($selector->extendList as $extend){
64                                 $this->allExtendsStackPush($rulesetNode, $selectorPath, $extend, $j);
65                         }
66                         foreach($allSelectorsExtendList as $extend){
67                                 $this->allExtendsStackPush($rulesetNode, $selectorPath, $extend, $j);
68                         }
69                 }
70
71                 $this->contexts[] = $rulesetNode->selectors;
72         }
73
74     public function allExtendsStackPush($rulesetNode, $selectorPath, $extend, &$j){
75                 $this->foundExtends = true;
76                 $extend = clone $extend;
77                 $extend->findSelfSelectors( $selectorPath );
78                 $extend->ruleset = $rulesetNode;
79                 if( $j === 0 ){
80                         $extend->firstExtendOnThisSelectorPath = true;
81                 }
82
83                 $end_key = count($this->allExtendsStack)-1;
84                 $this->allExtendsStack[$end_key][] = $extend;
85                 $j++;
86         }
87
88
89     public function visitRulesetOut( $rulesetNode ){
90                 if( !is_object($rulesetNode) || !$rulesetNode->root ){
91                         array_pop($this->contexts);
92                 }
93         }
94
95     public function visitMedia( $mediaNode ){
96                 $mediaNode->allExtends = array();
97                 $this->allExtendsStack[] =& $mediaNode->allExtends;
98         }
99
100     public function visitMediaOut(){
101                 array_pop($this->allExtendsStack);
102         }
103
104     public function visitDirective( $directiveNode ){
105                 $directiveNode->allExtends = array();
106                 $this->allExtendsStack[] =& $directiveNode->allExtends;
107         }
108
109     public function visitDirectiveOut(){
110                 array_pop($this->allExtendsStack);
111         }
112 }
113
114