Extend.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 must use a string (instead of int) so that array_merge()
  39. // preserves keys on arrays that use IDs in their keys.
  40. $this->object_id = 'id_' . $i++;
  41. $this->parent_ids = array(
  42. $this->object_id => true
  43. );
  44. }
  45. public function accept( $visitor ) {
  46. $this->selector = $visitor->visitObj( $this->selector );
  47. }
  48. public function compile( $env ) {
  49. Less_Parser::$has_extends = true;
  50. $this->selector = $this->selector->compile( $env );
  51. return $this;
  52. // return new Less_Tree_Extend( $this->selector->compile($env), $this->option, $this->index);
  53. }
  54. public function findSelfSelectors( $selectors ) {
  55. $selfElements = array();
  56. for ( $i = 0, $selectors_len = count( $selectors ); $i < $selectors_len; $i++ ) {
  57. $selectorElements = $selectors[$i]->elements;
  58. // duplicate the logic in genCSS function inside the selector node.
  59. // future TODO - move both logics into the selector joiner visitor
  60. if ( $i && $selectorElements && $selectorElements[0]->combinator === "" ) {
  61. $selectorElements[0]->combinator = ' ';
  62. }
  63. $selfElements = array_merge( $selfElements, $selectors[$i]->elements );
  64. }
  65. $this->selfSelectors = array( new Less_Tree_Selector( $selfElements ) );
  66. }
  67. }