本文整理汇总了PHP中PhpParser\Node::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::getName方法的具体用法?PHP Node::getName怎么用?PHP Node::getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpParser\Node
的用法示例。
在下文中一共展示了Node::getName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolveValue
protected function resolveValue(NodeInterface $nodeValue)
{
if ($nodeValue instanceof MagicConst) {
return $nodeValue->getName();
}
$subModules = $nodeValue->getSubNodeNames();
if (!is_array($subModules) || empty($subModules)) {
return;
}
$subModule = reset($subModules);
$value = $nodeValue->{$subModule};
if (is_object($value) && method_exists($value, 'toString')) {
$value = $value->toString();
} elseif (is_object($value) && property_exists($value, 'value')) {
$value = $value->value;
}
if (is_array($value)) {
$newValues = [];
foreach ($value as $key => $node) {
$newValues[$this->resolveValue($node->key)] = $this->resolveValue($node->value);
}
return $newValues;
}
if ($value === 'true') {
return true;
} elseif ($value === 'false') {
return false;
} elseif ($value === 'null') {
return;
}
return $value;
}
示例2: isMagicConst
/** Test the current PhpParser_Node node to see if it is a magic constant, and return the name if it is and null if it is not
*
* @param Node $node The sandboxed $node to test
*
* @return string|null Return string name of node, or null if it is not a magic constant
*/
protected function isMagicConst(Node $node)
{
return $node instanceof Node\Scalar\MagicConst ? $node->getName() : null;
}
示例3: getExpression
/**
* Returns the value from a node
*
* @param Node $node
* @return mixed
*/
private function getExpression(Node $node)
{
if ($node instanceof ConstFetch) {
$const = $node->name->parts[0];
if (isset($this->constMap[$const])) {
return $this->constMap[$const];
}
return $const;
}
if ($node instanceof ClassConstFetch) {
return $node->class->parts[0] . '::' . $node->name;
}
if ($node instanceof MagicConst) {
return $node->getName();
}
if ($node instanceof Array_) {
$prettyPrinter = new PrettyPrinter();
return $prettyPrinter->prettyPrintExpr($node);
}
}