本文整理汇总了PHP中PhpParser\Node::getType方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::getType方法的具体用法?PHP Node::getType怎么用?PHP Node::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpParser\Node
的用法示例。
在下文中一共展示了Node::getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pushState
public function pushState($stateKey, Node $node)
{
if ($this->debug) {
printf("Stacking %s %s %s %d\n", $stateKey, $node->getType(), $node->name, count($this->stateStack));
}
$state = $this->getState($stateKey);
array_unshift($this->stateStack, ['node' => $node, 'state' => $state, 'key' => $state->getName(), 'nodeType' => $node->getType()]);
}
示例2: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(Node $node)
{
if (isset($this->mapping[$node->getType()])) {
// We have a mapping, so resolve the assign operation to
// Separate assign and operation nodes
$class = $this->mapping[$node->getType()];
return new Node\Expr\Assign($node->var, new $class($node->var, $node->expr));
}
}
示例3: getListPart
/**
* @param Node $stmts
* @return Node\Expr\List_
* @throws \Exception
*/
private function getListPart(Node $stmts)
{
if ($stmts->getType() === 'Expr_Assign' && $stmts->var->getType() === 'Expr_List') {
return $stmts->var;
} elseif ($stmts->getType() === 'Expr_List') {
return $stmts;
} else {
throw new \Exception("Unknown statement: " . $stmts->getType());
}
}
示例4: getUnexpectedThing
private function getUnexpectedThing(Node $node)
{
switch ($node->getType()) {
case 'Scalar_String':
case 'Scalar_LNumber':
case 'Scalar_DNumber':
return json_encode($node->value);
case 'Expr_ConstFetch':
return (string) $node->name;
default:
return $node->getType();
}
}
示例5: enterNode
public function enterNode(Node $node)
{
if ($node->getType() == 'Stmt_Use') {
foreach ($node->uses as $use) {
$this->uses[] = $use;
}
}
// echo $node->getType() . "\n";
if (isset($node->class) && $node->class) {
if ($node->class->getType() != 'Name_FullyQualified') {
$this->names[] = $node->class;
}
}
if (isset($node->extends) && $node->extends) {
if ($node->extends->getType() != 'Name_FullyQualified') {
$this->names[] = $node->extends;
}
}
if (isset($node->implements) && $node->implements) {
foreach ($node->implements as $implements) {
if ($implements->getType() != 'Name_FullyQualified') {
$this->names[] = $implements;
}
}
}
if (isset($node->params)) {
foreach ($node->params as $param) {
if ($param->type && !is_string($param->type)) {
if ($param->type->getType() != 'Name_FullyQualified') {
$this->names[] = $param->type;
}
}
}
}
}
示例6: leaveNode
public function leaveNode(Node $node)
{
$type = $node->getType();
if ($type == "Expr_BinaryOp_Concat") {
if ($node->right) {
//转为symbol
$right_symbol = SymbolUtils::getSymbolByNode($node->right);
$right_symbol != null && array_push($this->items, $right_symbol);
}
if ($node->left->getType() != "Expr_BinaryOp_Concat") {
$left_symbol = SymbolUtils::getSymbolByNode($node->left);
$left_symbol != null && array_push($this->items, $left_symbol);
}
} else {
if ($type == "Scalar_Encapsed") {
foreach ($node->parts as $item) {
if (!is_object($item)) {
$valueSymbol = new ValueSymbol();
$valueSymbol->setValue($item);
$valueSymbol != null && array_push($this->items, $valueSymbol);
} else {
$setItem = SymbolUtils::getSymbolByNode($item);
$setItem != null && array_push($this->items, $setItem);
}
}
}
}
}
示例7: leaveNode
public function leaveNode(Node $node)
{
if (!$node instanceof ConstFetch) {
$callback = [$this, 'rewrite' . ucfirst($node->getType())];
if (is_callable($callback)) {
call_user_func_array($callback, [$node]);
}
return;
}
if ($this->disable_const_rewrite_level > 0) {
return;
}
if (!$node->name instanceof Name) {
return;
}
if (!$node->name->isUnqualified()) {
return;
}
if (!ConstantPatcher::isBlacklisted((string) $node->name)) {
$replacement = new FullyQualified(array());
$replacement->set('\\__ConstProxy__::get(\'' . (string) $node->name . '\')');
$pos = $node->getAttribute('startTokenPos');
ConstantPatcher::$replacement[$pos] = '\\__ConstProxy__::get(\'' . (string) $node->name . '\')';
$node->name = $replacement;
}
}
示例8: enter
public final function enter(Node $node)
{
switch ($node->getType()) {
case 'Stmt_Namespace':
$this->namespace = $node->name;
$this->aliases = array();
// @todo : with multiple namespaces in one file : does this bug ?
// leave() shouldn't reset these values ?
break;
case 'Stmt_UseUse':
if (isset($this->aliases[$node->alias])) {
throw new \PhpParser\Error(sprintf('Cannot use "%s" as "%s" because the name is already in use', $node->name, $node->alias), $node->getLine());
}
$this->aliases[$node->alias] = $node->name;
break;
case 'Stmt_Class':
$this->context->pushState('class', $node);
$this->enterClassNode($node);
break;
case 'Stmt_Trait':
$this->context->pushState('trait', $node);
$this->enterTraitNode($node);
break;
case 'Stmt_Interface':
$this->context->pushState('interface', $node);
$this->enterInterfaceNode($node);
break;
}
}
示例9: enter
public function enter(\PhpParser\Node $node)
{
if ($node->getType() == 'Stmt_ClassMethod') {
// NS
$methodName = $node->name;
$currentFqcn = $this->getCurrentFqcn();
$declaringFqcn = $this->getReflectionContext()->getDeclaringClass($currentFqcn, $methodName);
// Vertices
$signatureIndex = $declaringFqcn . '::' . $methodName;
$classVertex = $this->findVertex('interface', $currentFqcn);
$signatureVertex = $this->findVertex('method', $signatureIndex);
// if current class == declaring class, we add the edge
if ($declaringFqcn == $currentFqcn) {
$this->getGraph()->addEdge($classVertex, $signatureVertex);
// I -> M
// and we link the signature to the params
foreach ($node->params as $idx => $param) {
// adding edge from signature to param :
$paramVertex = $this->findVertex('param', $signatureIndex . '/' . $idx);
// it is possible to not find the param because the signature
// is external to the source code :
if (!is_null($paramVertex)) {
$this->getGraph()->addEdge($signatureVertex, $paramVertex);
// M -> P
// now the type of the param :
$this->typeHintParam($param, $paramVertex);
}
}
}
}
}
示例10: create
/**
* @param Node $node
* @param $context
* @return AbstractTranspiler
* @throws NotImplementedException
*/
public static function create(Node $node, $context)
{
if ($context === null) {
throw new ContextNotProvidedException('You have to provide the context');
}
$type = $node->getType();
if (!array_key_exists($type, self::$transpilersMap)) {
print_R($type);
die;
throw new NotImplementedException("'" . $node->getType() . "' not implemented.");
}
$className = "\\Php2js\\Transpilers\\" . self::$transpilersMap[$type] . 'Transpiler';
$transpiler = new $className($node);
$transpiler->setContext($context);
return $transpiler;
}
示例11: isEqual
public static function isEqual(\PhpParser\Node $nodeA, \PhpParser\Node $nodeB)
{
if ($nodeA->getType() !== $nodeB->getType()) {
return false;
}
$subNodesA = $nodeA->getSubNodeNames();
$subNodesB = $nodeB->getSubNodeNames();
if ($subNodesA !== $subNodesB) {
return false;
}
foreach ($subNodesA as $key) {
$valueA = $nodeA->{$key};
$valueB = $nodeB->{$key};
$result = true;
if ($valueA instanceof \PhpParser\Node && $valueB instanceof \PhpParser\Node) {
$result = self::isEqual($valueA, $valueB);
} else {
$result = $valueA === $valueB;
}
if (!$result) {
return false;
}
}
return true;
}
示例12: enter
public final function enter(Node $node)
{
if ($node->getType() == 'Stmt_ClassMethod' && $node->isPublic()) {
$fqcn = $this->getCurrentFqcn();
$this->enterPublicMethod($fqcn, $node);
}
}
示例13: enterMethodCode
protected function enterMethodCode(Node $node)
{
switch ($node->getType()) {
case 'Expr_New':
$this->pushViolation($node, 'static factory (OCP violation)');
break;
}
}
示例14: enter
/**
* @inheritdoc
*/
public function enter(Node $node)
{
switch ($node->getType()) {
case 'PhpFile':
$this->context->pushState('file', $node);
break;
}
}
示例15: leaveNode
/**
* @inheritdoc
*/
public function leaveNode(Node $node)
{
switch ($node->getType()) {
case 'Stmt_Class':
$this->currentClass = null;
break;
case 'Stmt_ClassMethod':
$this->currentMethod = null;
break;
}
}