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\Objects;
  3: 
  4: use Pharborist\CommaListNode;
  5: use Pharborist\Functions\CallNode;
  6: use Pharborist\Namespaces\NameNode;
  7: use Pharborist\Node;
  8: use Pharborist\Token;
  9: use Pharborist\TokenNode;
 10: use Pharborist\Variables\VariableExpressionNode;
 11: 
 12: /**
 13:  * An object method call, e.g. `$object->method()`
 14:  */
 15: class ObjectMethodCallNode extends CallNode implements VariableExpressionNode {
 16:   /**
 17:    * @var Node
 18:    */
 19:   protected $object;
 20: 
 21:   /**
 22:    * @var TokenNode
 23:    */
 24:   protected $operator;
 25: 
 26:   /**
 27:    * @var Node
 28:    */
 29:   protected $methodName;
 30: 
 31:   /**
 32:    * @return Node
 33:    */
 34:   public function getObject() {
 35:     return $this->object;
 36:   }
 37: 
 38:   /**
 39:    * The object operator '->' token (T_OBJECT_OPERATOR).
 40:    *
 41:    * @return TokenNode
 42:    */
 43:   public function getOperator() {
 44:     return $this->operator;
 45:   }
 46: 
 47:   /**
 48:    * @return Node
 49:    */
 50:   public function getMethodName() {
 51:     return $this->methodName;
 52:   }
 53: 
 54:   /**
 55:    * @param string|Node $method_name
 56:    * @return $this
 57:    */
 58:   public function setMethodName($method_name) {
 59:     if (is_string($method_name)) {
 60:       $method_name = Token::identifier($method_name);
 61:     }
 62:     $this->methodName->replaceWith($method_name);
 63:     $this->methodName = $method_name;
 64:     return $this;
 65:   }
 66: 
 67:   /**
 68:    * Creates a method call on an object with an empty argument list.
 69:    *
 70:    * @param Node $object
 71:    *  The expression that is an object.
 72:    * @param string $method_name
 73:    *  The name of the called method.
 74:    *
 75:    * @return static
 76:    */
 77:   public static function create(Node $object, $method_name) {
 78:     /** @var ObjectMethodCallNode $node */
 79:     $node = new static();
 80:     $node->addChild($object, 'object');
 81:     $node->addChild(Token::objectOperator(), 'operator');
 82:     $node->addChild(Token::identifier($method_name), 'methodName');
 83:     $node->addChild(Token::openParen(), 'openParen');
 84:     $node->addChild(new CommaListNode(), 'arguments');
 85:     $node->addChild(Token::closeParen(), 'closeParen');
 86:     return $node;
 87:   }
 88: 
 89:   /**
 90:    * If this is a chained method call (e.g., foo()->bar()->baz()), returns
 91:    * the previous call in the chain.
 92:    *
 93:    * @return \Pharborist\Functions\CallNode|NULL
 94:    *   The previous call in the chain or NULL if there is none.
 95:    */
 96:   public function getPreviousCall() {
 97:     if ($this->object instanceof CallNode) {
 98:       return $this->object;
 99:     }
100:     else {
101:       return NULL;
102:     }
103:   }
104: }
105: 
Pharborist API documentation generated by ApiGen