| 1 |
<?php |
| 2 |
/** |
| 3 |
* @private |
| 4 |
*/ |
| 5 |
class Less_Tree_Extend extends Less_Tree { |
| 6 |
|
| 7 |
/** @var Less_Tree_Selector */ |
| 8 |
public $selector; |
| 9 |
/** @var string */ |
| 10 |
public $option; |
| 11 |
/** @var int */ |
| 12 |
public $index; |
| 13 |
/** @var Less_Tree_Selector[] */ |
| 14 |
public $selfSelectors = []; |
| 15 |
/** @var bool */ |
| 16 |
public $allowBefore; |
| 17 |
/** @var bool */ |
| 18 |
public $allowAfter; |
| 19 |
/** @var bool */ |
| 20 |
public $firstExtendOnThisSelectorPath; |
| 21 |
/** @var Less_Tree_Ruleset|null */ |
| 22 |
public $ruleset; |
| 23 |
/** @var string */ |
| 24 |
public $object_id; |
| 25 |
/** @var array<string,true> */ |
| 26 |
public $parent_ids = []; |
| 27 |
|
| 28 |
/** |
| 29 |
* @param Less_Tree_Selector $selector |
| 30 |
* @param string $option |
| 31 |
* @param int $index |
| 32 |
*/ |
| 33 |
public function __construct( $selector, $option, $index ) { |
| 34 |
static $i = 0; |
| 35 |
$this->selector = $selector; |
| 36 |
$this->option = $option; |
| 37 |
$this->index = $index; |
| 38 |
|
| 39 |
switch ( $option ) { |
| 40 |
case "all": |
| 41 |
$this->allowBefore = true; |
| 42 |
$this->allowAfter = true; |
| 43 |
break; |
| 44 |
default: |
| 45 |
$this->allowBefore = false; |
| 46 |
$this->allowAfter = false; |
| 47 |
break; |
| 48 |
} |
| 49 |
|
| 50 |
// This must use a string (instead of int) so that array_merge() |
| 51 |
// preserves keys on arrays that use IDs in their keys. |
| 52 |
$this->object_id = 'id_' . $i++; |
| 53 |
|
| 54 |
$this->parent_ids = [ |
| 55 |
$this->object_id => true |
| 56 |
]; |
| 57 |
} |
| 58 |
|
| 59 |
public function accept( $visitor ) { |
| 60 |
$this->selector = $visitor->visitObj( $this->selector ); |
| 61 |
} |
| 62 |
|
| 63 |
public function compile( $env ) { |
| 64 |
Less_Parser::$has_extends = true; |
| 65 |
$this->selector = $this->selector->compile( $env ); |
| 66 |
return $this; |
| 67 |
// return new self( $this->selector->compile($env), $this->option, $this->index); |
| 68 |
} |
| 69 |
|
| 70 |
public function clone() { |
| 71 |
return new self( $this->selector, $this->option, $this->index ); |
| 72 |
} |
| 73 |
|
| 74 |
public function findSelfSelectors( $selectors ) { |
| 75 |
$selfElements = []; |
| 76 |
|
| 77 |
for ( $i = 0, $selectors_len = count( $selectors ); $i < $selectors_len; $i++ ) { |
| 78 |
$selectorElements = $selectors[$i]->elements; |
| 79 |
// duplicate the logic in genCSS function inside the selector node. |
| 80 |
// future TODO - move both logics into the selector joiner visitor |
| 81 |
if ( $i && $selectorElements && $selectorElements[0]->combinator === "" ) { |
| 82 |
$selectorElements[0]->combinator = ' '; |
| 83 |
} |
| 84 |
$selfElements = array_merge( $selfElements, $selectors[$i]->elements ); |
| 85 |
} |
| 86 |
|
| 87 |
$this->selfSelectors = [ new Less_Tree_Selector( $selfElements ) ]; |
| 88 |
} |
| 89 |
|
| 90 |
} |