4 * Extend Finder Visitor
9 class Less_Visitor_extendFinder extends Less_Visitor{
11 public $contexts = array();
12 public $allExtendsStack;
15 public function __construct(){
16 $this->contexts = array();
17 $this->allExtendsStack = array(array());
18 parent::__construct();
22 * @param Less_Tree_Ruleset $root
24 public function run($root){
25 $root = $this->visitObj($root);
26 $root->allExtends =& $this->allExtendsStack[0];
30 public function visitRule($ruleNode, &$visitDeeper ){
34 public function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ){
38 public function visitRuleset($rulesetNode){
40 if( $rulesetNode->root ){
44 $allSelectorsExtendList = array();
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;
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];
63 foreach($selector->extendList as $extend){
64 $this->allExtendsStackPush($rulesetNode, $selectorPath, $extend, $j);
66 foreach($allSelectorsExtendList as $extend){
67 $this->allExtendsStackPush($rulesetNode, $selectorPath, $extend, $j);
71 $this->contexts[] = $rulesetNode->selectors;
74 public function allExtendsStackPush($rulesetNode, $selectorPath, $extend, &$j){
75 $this->foundExtends = true;
76 $extend = clone $extend;
77 $extend->findSelfSelectors( $selectorPath );
78 $extend->ruleset = $rulesetNode;
80 $extend->firstExtendOnThisSelectorPath = true;
83 $end_key = count($this->allExtendsStack)-1;
84 $this->allExtendsStack[$end_key][] = $extend;
89 public function visitRulesetOut( $rulesetNode ){
90 if( !is_object($rulesetNode) || !$rulesetNode->root ){
91 array_pop($this->contexts);
95 public function visitMedia( $mediaNode ){
96 $mediaNode->allExtends = array();
97 $this->allExtendsStack[] =& $mediaNode->allExtends;
100 public function visitMediaOut(){
101 array_pop($this->allExtendsStack);
104 public function visitDirective( $directiveNode ){
105 $directiveNode->allExtends = array();
106 $this->allExtendsStack[] =& $directiveNode->allExtends;
109 public function visitDirectiveOut(){
110 array_pop($this->allExtendsStack);