本文整理匯總了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);
}
}