本文整理汇总了PHP中PhpParser\Node::hasAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::hasAttribute方法的具体用法?PHP Node::hasAttribute怎么用?PHP Node::hasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpParser\Node
的用法示例。
在下文中一共展示了Node::hasAttribute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enterNode
/**
* Check all nodes
*
* @param Node $node
* @return void
**/
public function enterNode(Node $node)
{
// Skip nodes without comments.
if (!$node->hasAttribute("comments")) {
return;
}
// Check if annotations should be preserved. Only nodes with actual
// doc comment blocks are processed.
$comments = [];
if ($this->preserveAnnotations) {
$docComment = $node->getDocComment();
if ($docComment) {
$text = $docComment->getText();
// Check if it is a doc comment.
if (strpos($text, "/**") !== false) {
$text = $this->stripComment($text);
if ($text) {
$comments = [new Comment($text)];
}
}
}
}
// Remove (or set) comments.
$node->setAttribute("comments", $comments);
return $node;
}
示例2: enterNode
/**
* Called when entering a node.
*
* Return value semantics:
* * null: $node stays as-is
* * otherwise: $node is set to the return value
*
* @param Node $node Node
*
* @return null|Node Node
*/
public function enterNode(Node $node)
{
if (isset($node->returnType)) {
var_dump($node->returnType);
die;
} elseif ($node instanceof Node\Param) {
if ($node->hasAttribute("generic_name")) {
$type = $node->getAttribute("generic_name");
if (isset($this->genericTypes[$type])) {
$node->type = new Node\Name\FullyQualified($this->genericTypes[$type]);
} else {
throw new \LogicException("Bad generic found");
}
} elseif ($node->type instanceof Node\Name && $node->type->hasAttribute("generics") && $node->type->getAttribute("generics")) {
$type = $node->getAttribute("original_type")->parts;
foreach ($node->type->getAttribute("generics") as $generic) {
if (isset($this->genericTypes[$generic])) {
$value = str_replace("\\", Engine::NS_TOKEN, $this->genericTypes[$generic]);
$type[] = Engine::CLASS_TOKEN . $value . Engine::CLASS_TOKEN;
} else {
throw new \LogicException("Bad generic found");
}
}
$node->type = new Node\Name\FullyQualified($type);
} elseif ((string) $node->name == "item") {
var_dump($node);
die;
}
}
}
示例3: leaveNode
public function leaveNode(Node $node)
{
if ($node->hasAttribute(NameResolver::TAG_NAMES_ATTRIBUTE)) {
$tags = $node->getAttribute(NameResolver::TAG_NAMES_ATTRIBUTE);
foreach ($tags as $tagName) {
$name = new Node\Name($tagName);
$name->setAttribute('isComment', true);
$this->collect($name, $node);
}
}
}
示例4: leaveNode
public function leaveNode(Node $node)
{
if (!$node->hasAttribute('oldEnabledRules')) {
return;
}
// Restore rules as they were before this node
$this->enabledRules = $node->getAttribute('oldEnabledRules');
}
示例5: detectNowDoc
/**
* @param \PhpParser\Node $node
*/
private function detectNowDoc(Node $node)
{
if ($node->hasAttribute('isNowDoc') && $node instanceof Node\Scalar\String_) {
$this->getResult()->addRequirement(Reason::NOWDOC_LITERAL, $node->getLine());
}
}
示例6: dumpPosition
protected function dumpPosition(Node $node)
{
if (!$node->hasAttribute('startLine') || !$node->hasAttribute('endLine')) {
return null;
}
$start = $node->getAttribute('startLine');
$end = $node->getAttribute('endLine');
if ($node->hasAttribute('startFilePos') && $node->hasAttribute('endFilePos') && null !== $this->code) {
$start .= ':' . $this->toColumn($this->code, $node->getAttribute('startFilePos'));
$end .= ':' . $this->toColumn($this->code, $node->getAttribute('endFilePos'));
}
return "[{$start} - {$end}]";
}
示例7: detectShortEchoSyntax
private function detectShortEchoSyntax(Node $node)
{
if ($node instanceof Node\Stmt\Echo_ && $node->hasAttribute('isShortEchoTag')) {
$this->getResult()->addRequirement(Reason::SHORT_ECHO_TAG, $node->getLine());
}
}
示例8: removeGenerics
protected function removeGenerics(Node $node)
{
if (!$node->hasAttribute('generics') || !$node->getAttribute('generics')) {
return;
}
foreach ($node->getAttribute('generics') as $type) {
unset($this->currentGenerics[$type]);
}
}