/** * {@inheritdoc} */ public function leaveNode(PHPParser_Node $node) { if (!isset($this->metaData[$node->getType()])) { return; } $this->checkSize($node); }
/** * Dumps a node or array. * * @param array|PHPParser_Node $node Node or array to dump * * @return string Dumped value */ public function dump($node) { if ($node instanceof PHPParser_Node) { $r = $node->getType() . '('; } elseif (is_array($node)) { $r = 'array('; } else { throw new InvalidArgumentException('Can only dump nodes and arrays.'); } foreach ($node as $key => $value) { $r .= "\n" . ' ' . $key . ': '; if (null === $value) { $r .= 'null'; } elseif (false === $value) { $r .= 'false'; } elseif (true === $value) { $r .= 'true'; } elseif (is_scalar($value)) { $r .= $value; } else { $r .= str_replace("\n", "\n" . ' ', $this->dump($value)); } } return $r . "\n" . ')'; }
/** * {@inheritDoc} */ public function leaveNode(\PHPParser_Node $node) { if ($node->getType() === 'Stmt_Class') { if ($this->newInterface) { $this->newContent[] = $this->buildNewInterface(); } $this->newInterface = false; } parent::leaveNode($node); }
protected function compileNode(\PHPParser_Node $node, Zval\Ptr $returnContext = null) { $nodeType = $node->getType(); if (isset($this->operators[$nodeType])) { call_user_func_array(array($this, 'compile' . $this->operators[$nodeType][0]), array_merge(array($node, $returnContext), array_slice($this->operators[$nodeType], 1))); return; } $methodName = 'compile_' . $nodeType; if (!method_exists($this, $methodName)) { var_dump($node); throw new CompileException($nodeType . ' not supported yet', $node->line); } call_user_func(array($this, $methodName), $node, $returnContext); }
/** * {@inheritdoc} */ public function leaveNode(PHPParser_Node $node) { return; switch ($node->getType()) { case 'Stmt_ClassMethod': case 'Expr_Closure': case 'Stmt_Function': case 'Stmt_If': case 'Stmt_Do': case 'Stmt_While': case 'Stmt_For': case 'Stmt_Foreach': break; } }
/** * {@inheritDoc} */ public function leaveNode(\PHPParser_Node $node) { switch ($node->getType()) { case 'Stmt_Class': case 'Stmt_Interface': case 'Stmt_Trait': $this->currentClass = false; break; case 'Stmt_ClassMethod': $this->currentMethod = false; break; case 'PhpFile': if ($this->currentPhpFile->isModified()) { return $this->currentPhpFile; } break; } }
public function leaveNode(PHPParser_Node $node) { if ($node instanceof PHPParser_Node_Expr_Array) { return new PHPParser_Node_Expr_AssignListInner($node->getSubNodes()); } elseif ($node instanceof PHPParser_Node_Expr_Variable || $node instanceof PHPParser_Node_Expr_ConstFetch) { return null; } elseif ($node instanceof PHPParser_Node_Name && $node->parts[0] === "null") { return new PHPParser_Node_Expr_Pass(array()); } elseif ($node instanceof PHPParser_Node_Expr_ArrayItem) { if ($node->key !== null) { throw new PHPParser_Error(self::keyFound, $node->getLine()); } if ($node->byRef !== false) { throw new PHPParser_Error(self::byRefFound, $node->getLine()); } } else { throw new PHPParser_Error(sprintf(self::unexpectedTokenFound, $node->getType()), $node->getLine()); } }
/** * Pretty prints a node. * * @param PHPParser_Node $node Node to be pretty printed * * @return string Pretty printed node */ protected function p(PHPParser_Node $node) { $type = $node->getType(); if (isset($this->precedanceMap[$type])) { $precedence = $this->precedanceMap[$type]; if ($precedence >= $this->precedenceStack[$this->precedenceStackPos]) { $this->precedenceStack[++$this->precedenceStackPos] = $precedence; $return = '(' . $this->{'p' . $type}($node) . ')'; --$this->precedenceStackPos; } else { $this->precedenceStack[++$this->precedenceStackPos] = $precedence; $return = $this->{'p' . $type}($node); --$this->precedenceStackPos; } return $return; } else { return $this->{'p' . $type}($node); } }
/** * {@inheritdoc} */ public function leaveNode(\PHPParser_Node $node) { switch ($node->getType()) { case 'Stmt_ClassMethod': $this->currentMethodRelevant = false; break; case 'Stmt_Class': // generate foreach ($this->factoryMethodStack as $name => $calling) { $factory = new \PHPParser_Node_Stmt_ClassMethod($name); $factory->type = \PHPParser_Node_Stmt_Class::MODIFIER_PROTECTED; $factory->params = $this->getProcessedArgument($calling->args); $class = $calling->getAttribute('classShortcut'); $factory->stmts = array(new \PHPParser_Node_Stmt_Return(new \PHPParser_Node_Expr_New(new \PHPParser_Node_Name($class), $factory->params))); $this->currentClassStmts[] = $factory; } break; } return parent::leaveNode($node); }
public function leaveNode(\PHPParser_Node $node) { switch ($node->getType()) { case 'Scalar_MagicConst_Line': return new NumberNode($node->getAttribute('startLine')); case 'Scalar_MagicConst_File': return new StringNode($this->location->file); case 'Scalar_MagicConst_Dir': return new StringNode($this->location->directory); case 'Scalar_MagicConst_Function': return new StringNode($this->location->function); case 'Scalar_MagicConst_Namespace': return new StringNode($this->location->namespace); case 'Scalar_MagicConst_Class': return new StringNode($this->location->class); case 'Scalar_MagicConst_Method': return new StringNode($this->location->method); case 'Scalar_MagicConst_Trait': return new StringNode($this->location->trait); } }
/** * {@inheritdoc} */ public function enterNode(PHPParser_Node $node) { switch ($node->getType()) { case 'Stmt_Class': $this->classNode = $node; break; case 'Stmt_Property': $this->checkPublicProperty($node); $this->checkProtectedProperty($node); break; case 'Stmt_ClassMethod': $this->checkGetter($node); $this->checkSetter($node); $this->checkAdder($node); $this->checkAnder($node); break; } }
/** * Prints an expression node with the least amount of parentheses necessary to preserve the meaning. * * @param PHPParser_Node $node Node to pretty print * @param int $parentPrecedence Precedence of the parent operator * @param int $parentAssociativity Associativity of parent operator * (-1 is left, 0 is nonassoc, 1 is right) * @param int $childPosition Position of the node relative to the operator * (-1 is left, 1 is right) * * @return string The pretty printed node */ protected function pPrec(PHPParser_Node $node, $parentPrecedence, $parentAssociativity, $childPosition) { $type = $node->getType(); if (isset($this->precedenceMap[$type])) { $childPrecedence = $this->precedenceMap[$type][0]; if ($childPrecedence > $parentPrecedence || $parentPrecedence == $childPrecedence && $parentAssociativity != $childPosition) { return '(' . $this->{'p' . $type}($node) . ')'; } } return $this->{'p' . $type}($node); }
/** * {@inheritdoc} */ public function leaveNode(PHPParser_Node $node) { switch ($node->getType()) { case 'Stmt_ClassMethod': case 'Expr_Closure': case 'Stmt_Function': array_pop($this->functionScopeStack); break; case 'Stmt_If': case 'Stmt_Do': case 'Stmt_While': case 'Stmt_For': case 'Stmt_Foreach': $tokenStack = end($this->functionScopeStack); $tokenStack->pop(); break; } }
/** Test the current PHPParser_Node node to see if it is a primitive, and return the name if it is and null if it is not * * @param \PHPParser_Node $node The sandboxed $node to test * * @return string|null Return string name of node, or null if it is not a primitive */ protected function is_primitive(\PHPParser_Node $node) { switch ($node->getType()) { case 'Expr_Cast_Array': case 'Expr_Array': return 'array'; case 'Expr_Cast_Bool': //booleans are treated as constants otherwise. . . return 'bool'; case 'Expr_Cast_String': case 'Scalar_String': case 'Scalar_Encapsed': return 'string'; case 'Expr_Cast_Double': case 'Scalar_DNumber': return 'float'; case 'Expr_Cast_Int': case 'Scalar_LNumber': return 'int'; case 'Expr_Cast_Object': return 'object'; } return null; }