NodeVisitor.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace PhpParser;
  3. interface NodeVisitor
  4. {
  5. /**
  6. * Called once before traversal.
  7. *
  8. * Return value semantics:
  9. * * null: $nodes stays as-is
  10. * * otherwise: $nodes is set to the return value
  11. *
  12. * @param Node[] $nodes Array of nodes
  13. *
  14. * @return null|Node[] Array of nodes
  15. */
  16. public function beforeTraverse(array $nodes);
  17. /**
  18. * Called when entering a node.
  19. *
  20. * Return value semantics:
  21. * * null
  22. * => $node stays as-is
  23. * * NodeTraverser::DONT_TRAVERSE_CHILDREN
  24. * => Children of $node are not traversed. $node stays as-is
  25. * * NodeTraverser::STOP_TRAVERSAL
  26. * => Traversal is aborted. $node stays as-is
  27. * * otherwise
  28. * => $node is set to the return value
  29. *
  30. * @param Node $node Node
  31. *
  32. * @return null|int|Node Node
  33. */
  34. public function enterNode(Node $node);
  35. /**
  36. * Called when leaving a node.
  37. *
  38. * Return value semantics:
  39. * * null
  40. * => $node stays as-is
  41. * * NodeTraverser::REMOVE_NODE
  42. * => $node is removed from the parent array
  43. * * NodeTraverser::STOP_TRAVERSAL
  44. * => Traversal is aborted. $node stays as-is
  45. * * array (of Nodes)
  46. * => The return value is merged into the parent array (at the position of the $node)
  47. * * otherwise
  48. * => $node is set to the return value
  49. *
  50. * @param Node $node Node
  51. *
  52. * @return null|false|int|Node|Node[] Node
  53. */
  54. public function leaveNode(Node $node);
  55. /**
  56. * Called once after traversal.
  57. *
  58. * Return value semantics:
  59. * * null: $nodes stays as-is
  60. * * otherwise: $nodes is set to the return value
  61. *
  62. * @param Node[] $nodes Array of nodes
  63. *
  64. * @return null|Node[] Array of nodes
  65. */
  66. public function afterTraverse(array $nodes);
  67. }