當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Stmt::hasAttribute方法代碼示例

本文整理匯總了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);
     }
 }
開發者ID:GeeH,項目名稱:BetterReflection,代碼行數:36,代碼來源:ReflectionFunctionAbstract.php

示例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();
 }
開發者ID:ad3n,項目名稱:BetterReflection,代碼行數:12,代碼來源:ReflectionFunctionAbstract.php


注:本文中的PhpParser\Node\Stmt::hasAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。