Visitor.php 876 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Visitor
  4. *
  5. * @package Less
  6. * @subpackage visitor
  7. */
  8. class Less_Visitor {
  9. protected $methods = array();
  10. protected $_visitFnCache = array();
  11. public function __construct() {
  12. $this->_visitFnCache = get_class_methods( get_class( $this ) );
  13. $this->_visitFnCache = array_flip( $this->_visitFnCache );
  14. }
  15. public function visitObj( $node ) {
  16. $funcName = 'visit'.$node->type;
  17. if ( isset( $this->_visitFnCache[$funcName] ) ) {
  18. $visitDeeper = true;
  19. $this->$funcName( $node, $visitDeeper );
  20. if ( $visitDeeper ) {
  21. $node->accept( $this );
  22. }
  23. $funcName = $funcName . "Out";
  24. if ( isset( $this->_visitFnCache[$funcName] ) ) {
  25. $this->$funcName( $node );
  26. }
  27. } else {
  28. $node->accept( $this );
  29. }
  30. return $node;
  31. }
  32. public function visitArray( $nodes ) {
  33. array_map( array( $this,'visitObj' ), $nodes );
  34. return $nodes;
  35. }
  36. }