本文整理汇总了PHP中PhpParser\Node\Stmt::hasAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Stmt::hasAttribute方法的具体用法?PHP Stmt::hasAttribute怎么用?PHP Stmt::hasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpParser\Node\Stmt
的用法示例。
在下文中一共展示了Stmt::hasAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateFunctionAbstract
/**
* Populate the common elements of the function abstract
*
* @param MethodOrFunctionNode $node
* @param LocatedSource $locatedSource
* @param NamespaceNode|null $declaringNamespace
*/
protected function populateFunctionAbstract(MethodOrFunctionNode $node, LocatedSource $locatedSource, NamespaceNode $declaringNamespace = null)
{
$this->node = $node;
$this->name = $node->name;
$this->locatedSource = $locatedSource;
$this->declaringNamespace = $declaringNamespace;
if ($node->hasAttribute('comments')) {
/* @var \PhpParser\Comment\Doc $comment */
$comment = $node->getAttribute('comments')[0];
$this->docBlock = $comment->getReformattedText();
}
// We must determine if params are optional or not ahead of time, but
// we must do it in reverse...
$overallOptionalFlag = true;
$lastParamIndex = count($node->params) - 1;
for ($i = $lastParamIndex; $i >= 0; $i--) {
$hasDefault = $node->params[$i]->default !== null;
// When we find the first parameter that does not have a default,
// flip the flag as all params for this are no longer optional
// EVEN if they have a default value
if (!$hasDefault) {
$overallOptionalFlag = false;
}
$node->params[$i]->isOptional = $overallOptionalFlag;
}
foreach ($node->params as $paramIndex => $paramNode) {
$this->parameters[] = ReflectionParameter::createFromNode($paramNode, $this, $paramIndex);
}
}
示例2: getDocComment
/**
* @return string
*/
public function getDocComment()
{
if (!$this->node->hasAttribute('comments')) {
return '';
}
/* @var \PhpParser\Comment\Doc $comment */
$comment = $this->node->getAttribute('comments')[0];
return $comment->getReformattedText();
}