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


PHP Expr::getAttribute方法代碼示例

本文整理匯總了PHP中PhpParser\Node\Expr::getAttribute方法的典型用法代碼示例。如果您正苦於以下問題:PHP Expr::getAttribute方法的具體用法?PHP Expr::getAttribute怎麽用?PHP Expr::getAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PhpParser\Node\Expr的用法示例。


在下文中一共展示了Expr::getAttribute方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: resolve

 /**
  * @param Expr $expr
  *
  * @return array Returns an array of types, or an empty array if the expression doesn't return a value
  */
 public static function resolve(Expr $expr)
 {
     if (!$expr->getAttribute("scope") or !$expr->getAttribute("scopeInner")) {
         throw new \InvalidArgumentException("Expr must have its scope and scopeInner resolved");
     }
     switch (get_class($expr)) {
         default:
             return BasicExpressionReturnTypeResolver::resolve($expr);
     }
 }
開發者ID:sekjun9878,項目名稱:elphp,代碼行數:15,代碼來源:SmartExpressionReturnTypeResolver.php

示例2: setVariableDefaultValue

        /**
         * @param AbstractVariableObject     $variable
         * @param \PhpParser\Node\Expr       $default
         * @return string
         */
        private function setVariableDefaultValue(AbstractVariableObject $variable, \PhpParser\Node\Expr $default = NULL) {
            if ($default === NULL) {
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\String) {
                $variable->setDefault($default->getAttribute('originalValue'));
                if ($variable->getType() == '{unknown}') {
                    $variable->setType('string');
                }
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\LNumber ||
                $default instanceof \PhpParser\Node\Expr\UnaryMinus ||
                $default instanceof \PhpParser\Node\Expr\UnaryPlus) {
                $variable->setDefault($default->getAttribute('originalValue'));
                if ($variable->getType() == '{unknown}') {
                    $variable->setType('integer');
                }
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\DNumber) {
                $variable->setDefault($default->getAttribute('originalValue'));
                if ($variable->getType() == '{unknown}') {
                    $variable->setType('float');
                }
                return;
            }
            if ($default instanceof \PhpParser\Node\Expr\Array_) {
                //var_dump($default);
                //$parameter->setDefault(join('\\', $default->items));
                if ($variable->getType() == '{unknown}') {
                    $variable->setType('array');
                }
                return;
            }
            if ($default instanceof \PhpParser\Node\Expr\ClassConstFetch) {
                $variable->setDefault(join('\\', $default->class->parts) . '::' . $default->name);
                return;
            }
            if ($default instanceof \PhpParser\Node\Expr\ConstFetch) {
                $variable->setDefault(join('\\', $default->name->parts));
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Trait_) {
                $variable->setName('__TRAIT__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Class_) {
                $variable->setDefault('__CLASS__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Method) {
                $variable->setName('__METHOD__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Dir) {
                $variable->setName('__DIR__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\File) {
                $variable->setName('__FILE__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Function_) {
                $variable->setName('__FUNC__');
                return;
            }
            if ($default instanceof \PhpParser\Node\Scalar\MagicConst\Line) {
                $variable->setName('__LINE__');
                return;
            }

            $type = get_class($default);
            $line = $default->startLine;
            $file = $this->result->getFileName();
            throw new ParseErrorException("Unexpected expression type '$type' for default value in line $line of file '$file'", ParseErrorException::UnexpectedExpr);
        }
開發者ID:rxz135cc,項目名稱:yii2webApp,代碼行數:82,代碼來源:UnitCollectingVisitor.php

示例3: resolveExpressionValue

 private function resolveExpressionValue(\PhpParser\Node\Expr $expr)
 {
     if ($expr instanceof \PhpParser\Node\Scalar\String_) {
         return array('type' => 'string', 'value' => $expr->getAttribute('originalValue'));
     }
     if ($expr instanceof \PhpParser\Node\Scalar\LNumber || $expr instanceof \PhpParser\Node\Expr\UnaryMinus || $expr instanceof \PhpParser\Node\Expr\UnaryPlus) {
         return array('type' => 'integer', 'value' => $expr->getAttribute('originalValue'));
     }
     if ($expr instanceof \PhpParser\Node\Scalar\DNumber) {
         return array('type' => 'float', 'value' => $expr->getAttribute('originalValue'));
     }
     if ($expr instanceof \PhpParser\Node\Expr\Array_) {
         return array('type' => 'array', 'value' => '');
     }
     if ($expr instanceof \PhpParser\Node\Expr\ClassConstFetch) {
         return array('type' => '{unknown}', 'value' => '', 'constant' => join('\\', $expr->class->parts) . '::' . $expr->name);
     }
     if ($expr instanceof \PhpParser\Node\Expr\ConstFetch) {
         $reference = join('\\', $expr->name->parts);
         if (in_array(strtolower($reference), array('true', 'false'))) {
             return array('type' => 'boolean', 'value' => $reference);
         }
         return array('type' => '{unknown}', 'value' => '', 'constant' => join('\\', $expr->name->parts));
     }
     if ($expr instanceof \PhpParser\Node\Scalar\MagicConst\Line) {
         return array('type' => 'integer', 'value' => '', 'constant' => $expr->getName());
     }
     if ($expr instanceof \PhpParser\Node\Scalar\MagicConst) {
         return array('type' => 'string', 'value' => '', 'constant' => $expr->getName());
     }
     $type = get_class($expr);
     $line = $expr->getLine();
     $file = $this->result->getFileName();
     throw new ParseErrorException("Unexpected expression type '{$type}' for value in line {$line} of file '{$file}'", ParseErrorException::UnexpectedExpr);
 }
開發者ID:theseer,項目名稱:phpdox,代碼行數:35,代碼來源:UnitCollectingVisitor.php


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