Overview

Namespaces

  • Pharborist
    • Constants
    • ControlStructures
    • Exceptions
    • Functions
    • Generators
    • Namespaces
    • Objects
    • Operators
    • Types
    • Variables

Classes

  • Pharborist\Variables\CompoundVariableNode
  • Pharborist\Variables\GlobalStatementNode
  • Pharborist\Variables\ReferenceVariableNode
  • Pharborist\Variables\StaticVariableNode
  • Pharborist\Variables\StaticVariableStatementNode
  • Pharborist\Variables\VariableNode
  • Pharborist\Variables\VariableVariableNode

Interfaces

  • Pharborist\Variables\VariableExpressionNode
  • Overview
  • Namespace
  • Class
 1: <?php
 2: namespace Pharborist;
 3: 
 4: use Pharborist\Namespaces\NamespaceNode;
 5: 
 6: /**
 7:  * The root node of any Pharborist syntax tree.
 8:  */
 9: class RootNode extends StatementBlockNode {
10:   /**
11:    * Creates a new, blank PHP source file.
12:    *
13:    * @param string|NULL $ns
14:    *  If provided, the new document will have this namespace added to it.
15:    *
16:    * @return static
17:    */
18:   public static function create($ns = NULL) {
19:     $node = new RootNode();
20:     $node->addChild(Token::openTag());
21:     if (is_string($ns) && $ns) {
22:       NamespaceNode::create($ns)->appendTo($node)->after(Token::newline());
23:     }
24:     return $node;
25:   }
26: 
27:   /**
28:    * Returns if this document contains a particular namespace.
29:    *
30:    * @param string $ns
31:    *  The name of the namespace to look for.
32:    *
33:    * @return boolean
34:    */
35:   public function hasNamespace($ns) {
36:     return in_array($ns, $this->getNamespaceNames());
37:   }
38: 
39:   /**
40:    * Returns every namespace in this document.
41:    *
42:    * @return \Pharborist\NodeCollection
43:    */
44:   public function getNamespaces() {
45:     return $this->children(Filter::isInstanceOf('\Pharborist\Namespaces\NamespaceNode'));
46:   }
47: 
48:   /**
49:    * Returns a particular namespace, if it exists.
50:    *
51:    * @param string $ns
52:    *  The name of the namespace to look for.
53:    *
54:    * @return \Pharborist\Namespaces\NamespaceNode|NULL
55:    */
56:   public function getNamespace($ns) {
57:     $namespaces = $this
58:       ->getNamespaces()
59:       ->filter(function(NamespaceNode $node) use ($ns) {
60:         return $node->getName()->getPath() === $ns;
61:       });
62: 
63:     return $namespaces->isEmpty() ? NULL : $namespaces[0];
64:   }
65: 
66:   /**
67:    * Returns the name of every namespace in this document.
68:    *
69:    * @param boolean $absolute
70:    *
71:    * @return string[]
72:    */
73:   public function getNamespaceNames($absolute = FALSE) {
74:     $iterator = function(NamespaceNode $ns) use ($absolute) {
75:       $name = $ns->getName();
76:       return $absolute ? $name->getAbsolutePath() : $name->getPath();
77:     };
78:     return array_map($iterator, $this->getNamespaces()->toArray());
79:   }
80: }
81: 
Pharborist API documentation generated by ApiGen