Extend.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Extend
  4. *
  5. * @package Less
  6. * @subpackage tree
  7. */
  8. class Less_Tree_Extend extends Less_Tree{
  9. public $selector;
  10. public $option;
  11. public $index;
  12. public $selfSelectors = array();
  13. public $allowBefore;
  14. public $allowAfter;
  15. public $firstExtendOnThisSelectorPath;
  16. public $type = 'Extend';
  17. public $ruleset;
  18. public $object_id;
  19. public $parent_ids = array();
  20. /**
  21. * @param integer $index
  22. */
  23. public function __construct($selector, $option, $index){
  24. static $i = 0;
  25. $this->selector = $selector;
  26. $this->option = $option;
  27. $this->index = $index;
  28. switch($option){
  29. case "all":
  30. $this->allowBefore = true;
  31. $this->allowAfter = true;
  32. break;
  33. default:
  34. $this->allowBefore = false;
  35. $this->allowAfter = false;
  36. break;
  37. }
  38. $this->object_id = $i++;
  39. $this->parent_ids = array($this->object_id);
  40. }
  41. public function accept( $visitor ){
  42. $this->selector = $visitor->visitObj( $this->selector );
  43. }
  44. public function compile( $env ){
  45. Less_Parser::$has_extends = true;
  46. $this->selector = $this->selector->compile($env);
  47. return $this;
  48. //return new Less_Tree_Extend( $this->selector->compile($env), $this->option, $this->index);
  49. }
  50. public function findSelfSelectors( $selectors ){
  51. $selfElements = array();
  52. for( $i = 0, $selectors_len = count($selectors); $i < $selectors_len; $i++ ){
  53. $selectorElements = $selectors[$i]->elements;
  54. // duplicate the logic in genCSS function inside the selector node.
  55. // future TODO - move both logics into the selector joiner visitor
  56. if( $i && $selectorElements && $selectorElements[0]->combinator === "") {
  57. $selectorElements[0]->combinator = ' ';
  58. }
  59. $selfElements = array_merge( $selfElements, $selectors[$i]->elements );
  60. }
  61. $this->selfSelectors = array(new Less_Tree_Selector($selfElements));
  62. }
  63. }