[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Selector 5 * 6 * @package Less 7 * @subpackage tree 8 */ 9 class Less_Tree_Selector extends Less_Tree{ 10 11 public $elements; 12 public $condition; 13 public $extendList = array(); 14 public $_css; 15 public $index; 16 public $evaldCondition = false; 17 public $type = 'Selector'; 18 public $currentFileInfo = array(); 19 public $isReferenced; 20 public $mediaEmpty; 21 22 public $elements_len = 0; 23 24 public $_oelements; 25 public $_oelements_len; 26 public $cacheable = true; 27 28 /** 29 * @param boolean $isReferenced 30 */ 31 public function __construct( $elements, $extendList = array() , $condition = null, $index=null, $currentFileInfo=null, $isReferenced=null ){ 32 33 $this->elements = $elements; 34 $this->elements_len = count($elements); 35 $this->extendList = $extendList; 36 $this->condition = $condition; 37 if( $currentFileInfo ){ 38 $this->currentFileInfo = $currentFileInfo; 39 } 40 $this->isReferenced = $isReferenced; 41 if( !$condition ){ 42 $this->evaldCondition = true; 43 } 44 45 $this->CacheElements(); 46 } 47 48 public function accept($visitor) { 49 $this->elements = $visitor->visitArray($this->elements); 50 $this->extendList = $visitor->visitArray($this->extendList); 51 if( $this->condition ){ 52 $this->condition = $visitor->visitObj($this->condition); 53 } 54 55 if( $visitor instanceof Less_Visitor_extendFinder ){ 56 $this->CacheElements(); 57 } 58 } 59 60 public function createDerived( $elements, $extendList = null, $evaldCondition = null ){ 61 $newSelector = new Less_Tree_Selector( $elements, ($extendList ? $extendList : $this->extendList), null, $this->index, $this->currentFileInfo, $this->isReferenced); 62 $newSelector->evaldCondition = $evaldCondition ? $evaldCondition : $this->evaldCondition; 63 return $newSelector; 64 } 65 66 67 public function match( $other ){ 68 69 if( !$other->_oelements || ($this->elements_len < $other->_oelements_len) ){ 70 return 0; 71 } 72 73 for( $i = 0; $i < $other->_oelements_len; $i++ ){ 74 if( $this->elements[$i]->value !== $other->_oelements[$i]) { 75 return 0; 76 } 77 } 78 79 return $other->_oelements_len; // return number of matched elements 80 } 81 82 83 public function CacheElements(){ 84 85 $this->_oelements = array(); 86 $css = ''; 87 88 foreach($this->elements as $v){ 89 90 $css .= $v->combinator; 91 if( !$v->value_is_object ){ 92 $css .= $v->value; 93 continue; 94 } 95 96 if( !property_exists($v->value,'value') || !is_string($v->value->value) ){ 97 $this->cacheable = false; 98 return; 99 } 100 $css .= $v->value->value; 101 } 102 103 $this->_oelements_len = preg_match_all('/[,&#\.\w-](?:[\w-]|(?:\\\\.))*/', $css, $matches); 104 if( $this->_oelements_len ){ 105 $this->_oelements = $matches[0]; 106 107 if( $this->_oelements[0] === '&' ){ 108 array_shift($this->_oelements); 109 $this->_oelements_len--; 110 } 111 } 112 } 113 114 public function isJustParentSelector(){ 115 return !$this->mediaEmpty && 116 count($this->elements) === 1 && 117 $this->elements[0]->value === '&' && 118 ($this->elements[0]->combinator === ' ' || $this->elements[0]->combinator === ''); 119 } 120 121 public function compile($env) { 122 123 $elements = array(); 124 foreach($this->elements as $el){ 125 $elements[] = $el->compile($env); 126 } 127 128 $extendList = array(); 129 foreach($this->extendList as $el){ 130 $extendList[] = $el->compile($el); 131 } 132 133 $evaldCondition = false; 134 if( $this->condition ){ 135 $evaldCondition = $this->condition->compile($env); 136 } 137 138 return $this->createDerived( $elements, $extendList, $evaldCondition ); 139 } 140 141 142 /** 143 * @see Less_Tree::genCSS 144 */ 145 public function genCSS( $output, $firstSelector = true ){ 146 147 if( !$firstSelector && $this->elements[0]->combinator === "" ){ 148 $output->add(' ', $this->currentFileInfo, $this->index); 149 } 150 151 foreach($this->elements as $element){ 152 $element->genCSS( $output ); 153 } 154 } 155 156 public function markReferenced(){ 157 $this->isReferenced = true; 158 } 159 160 public function getIsReferenced(){ 161 return !isset($this->currentFileInfo['reference']) || !$this->currentFileInfo['reference'] || $this->isReferenced; 162 } 163 164 public function getIsOutput(){ 165 return $this->evaldCondition; 166 } 167 168 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |