1: <?php
2: namespace Pharborist;
3:
4: use Pharborist\Namespaces\UseDeclarationNode;
5:
6: 7: 8:
9: class StatementBlockNode extends ParentNode {
10: protected function _getStatements() {
11: $matches = [];
12: $child = $this->head;
13: while ($child) {
14: if ($child instanceof StatementNode) {
15: $matches[] = $child;
16: }
17: elseif ($child instanceof StatementBlockNode) {
18: $matches = array_merge($matches, $child->_getStatements());
19: }
20: $child = $child->next;
21: }
22: return $matches;
23: }
24:
25: 26: 27:
28: public function getStatements() {
29: return new NodeCollection($this->_getStatements(), FALSE);
30: }
31:
32: 33: 34: 35: 36: 37:
38: public function getUseDeclarations() {
39: $declarations = new NodeCollection();
40:
41: $use_blocks = $this->children(Filter::isInstanceOf('\Pharborist\Namespaces\UseDeclarationBlockNode'));
42: foreach ($use_blocks as $use_block) {
43: foreach ($use_block->getDeclarationStatements() as $use_statement) {
44: $declarations->add($use_statement->getDeclarations());
45: }
46: }
47: return $declarations;
48: }
49:
50: 51: 52: 53: 54: 55:
56: public function getClassAliases() {
57: $mappings = array();
58: foreach ($this->getUseDeclarations() as $use_declaration) {
59: if ($use_declaration->isClass()) {
60: $mappings[$use_declaration->getBoundedName()] = $use_declaration->getName()->getAbsolutePath();
61: }
62: }
63: return $mappings;
64: }
65: }
66: