1: <?php
2: namespace Pharborist;
3:
4: /**
5: * Public API for Node.
6: *
7: * This interface is used by tagging interfaces such as ExpressionNode to
8: * indicate they support the Node API.
9: */
10: interface NodeInterface {
11: /**
12: * Get the source position of the node.
13: * @return SourcePosition
14: */
15: public function getSourcePosition();
16:
17: /**
18: * Convert the node into PHP source code.
19: * @return string
20: */
21: public function getText();
22:
23: /**
24: * Get the parent node.
25: * @param callable $callback An optional callback to filter by.
26: * @return ParentNode
27: */
28: public function parent(callable $callback = NULL);
29:
30: /**
31: * Get the ancestors of this node.
32: * @param callable $callback An optional callback to filter by.
33: * @return NodeCollection
34: */
35: public function parents(callable $callback = NULL);
36:
37: /**
38: * Get ancestors up to the node matched by callback.
39: * @param callable $callback Callback to test for match.
40: * @param bool $inclusive TRUE to include the node matched by callback.
41: * @return NodeCollection
42: */
43: public function parentsUntil(callable $callback, $inclusive = FALSE);
44:
45: /**
46: * Get the first node matched by the callback by testing this node and
47: * traversing up through its ancestors in the tree.
48: * @param callable $callback Callback to test for match.
49: * @return Node
50: */
51: public function closest(callable $callback);
52:
53: /**
54: * Get the last node matched by the callback by testing this node and
55: * traversing up through its ancestors in the tree.
56: * @param callable $callback Callback to test for match.
57: * @return Node
58: */
59: public function furthest(callable $callback);
60:
61: /**
62: * Get the position of the element relative to its sibling elements.
63: * @return int
64: */
65: public function index();
66:
67: /**
68: * Get the previous sibling.
69: * @param callable $callback An optional callback to filter by.
70: * @return Node
71: */
72: public function previous(callable $callback = NULL);
73:
74: /**
75: * Get the previous siblings of this node.
76: * @param callable $callback An optional callback to filter by.
77: * @return NodeCollection
78: */
79: public function previousAll(callable $callback = NULL);
80:
81: /**
82: * Get all the preceding siblings up to but not including the match.
83: * @param callable $callback Callback to test for match.
84: * @param bool $inclusive TRUE to include the node matched by callback.
85: * @return NodeCollection
86: */
87: public function previousUntil(callable $callback, $inclusive = FALSE);
88:
89: /**
90: * Get the next immediate sibling.
91: * @param callable $callback An optional callback to filter by.
92: * @return Node
93: */
94: public function next(callable $callback = NULL);
95:
96: /**
97: * Get all the following siblings.
98: * @param callable $callback An optional callback to filter by.
99: * @return NodeCollection
100: */
101: public function nextAll(callable $callback = NULL);
102:
103: /**
104: * Get all the following siblings up to but not including the match.
105: * @param callable $callback Callback to test for match.
106: * @param bool $inclusive TRUE to include the node matched by callback.
107: * @return NodeCollection
108: */
109: public function nextUntil(callable $callback, $inclusive = FALSE);
110:
111: /**
112: * Get the siblings.
113: * @param callable $callback An optional callback to filter by.
114: * @return NodeCollection
115: */
116: public function siblings(callable $callback = NULL);
117:
118: /**
119: * Insert this node before targets.
120: * @param Node|Node[]|NodeCollection $targets Nodes to insert before.
121: * @return $this
122: */
123: public function insertBefore($targets);
124:
125: /**
126: * Insert nodes before this node.
127: * @param Node|Node[]|NodeCollection $nodes Nodes to insert.
128: * @return $this
129: */
130: public function before($nodes);
131:
132: /**
133: * Insert this node after targets.
134: * @param Node|Node[]|NodeCollection $targets Nodes to insert after.
135: * @return $this
136: */
137: public function insertAfter($targets);
138:
139: /**
140: * Insert nodes after this node.
141: * @param Node|Node[]|NodeCollection $nodes Nodes to insert.
142: * @return $this
143: */
144: public function after($nodes);
145:
146: /**
147: * Remove this node from its parent.
148: * @return $this
149: */
150: public function remove();
151:
152: /**
153: * Replace this node with another node.
154: * @param Node|Node[]|NodeCollection|callable $node Replacement node.
155: * @return $this
156: */
157: public function replaceWith($node);
158:
159: /**
160: * Swap this node with another.
161: * @param Node $node Node to swap with.
162: * @return $this
163: */
164: public function swapWith(Node $node);
165:
166: /**
167: * Replace nodes with this node.
168: * @param Node|Node[]|NodeCollection $targets Nodes to replace.
169: * @return $this
170: */
171: public function replaceAll($targets);
172:
173: /**
174: * Prepend this node to target.
175: * @param ParentNode|ParentNode[]|NodeCollection $targets Targets to prepend to.
176: * @return $this
177: */
178: public function prependTo($targets);
179:
180: /**
181: * Append this node to target.
182: * @param ParentNode|ParentNode[]|NodeCollection $targets Targets to append to.
183: * @return $this
184: */
185: public function appendTo($targets);
186:
187: /**
188: * Returns the root node if this node belongs to one.
189: *
190: * @return RootNode|NULL
191: */
192: public function getRoot();
193:
194: /**
195: * Returns TRUE if this node belongs to a root node.
196: */
197: public function hasRoot();
198: }
199: