本文整理汇总了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);
}
}
示例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);
}
示例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);
}