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\Namespaces;
 3: 
 4: use Pharborist\TokenNode;
 5: 
 6: /**
 7:  * Trait that gives a node an identifier in a namespace.
 8:  *
 9:  * Functions, constants, classes, interfaces, and traits all have an identifier.
10:  */
11: trait IdentifierNameTrait {
12:   /**
13:    * @var NameNode
14:    */
15:   protected $name;
16: 
17:   /**
18:    * @return NameNode
19:    */
20:   public function getName() {
21:     return $this->name;
22:   }
23: 
24:   /**
25:    * @return NamespaceNode
26:    */
27:   public function getNamespace() {
28:     return $this->name->getNamespace();
29:   }
30: 
31:   /**
32:    * Set the identifier name of this node.
33:    *
34:    * @param string $name
35:    *   New name.
36:    * @return $this
37:    */
38:   public function setName($name) {
39:     /** @var TokenNode $identifier */
40:     $identifier = $this->name->firstChild();
41:     $identifier->setText($name);
42:     return $this;
43:   }
44: 
45:   /**
46:    * Determine if this node belongs to namespace.
47:    *
48:    * @param string|NamespaceNode $ns
49:    *   Either the absolute namespace path or a NamespaceNode.
50:    *
51:    * @return boolean
52:    *   TRUE if the node belongs to the given namespace.
53:    */
54:   public function inNamespace($ns) {
55:     if (is_string($ns)) {
56:       $namespace_node = $this->name->getNamespace();
57:       $namespace = $namespace_node === NULL ? '' : $namespace_node->getName()->getAbsolutePath();
58:       return $ns === $namespace;
59:     }
60:     elseif ($ns instanceof NamespaceNode) {
61:       return $this->name->getNamespace() === $ns;
62:     }
63:     else {
64:       throw new \InvalidArgumentException();
65:     }
66:   }
67: }
68: 
Pharborist API documentation generated by ApiGen