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