final public static field ( |
||
$value | ||
$name | ||
리턴 |
public function parseExpressionNode(Node\Expr $node) { switch (true) { case $mappedNode = $this->parseOperatorNode($node): return $mappedNode; case $node instanceof Node\Scalar && ($mappedNode = $this->parseScalarNode($node)): return $mappedNode; case $node instanceof Node\Expr\Variable: return Expression::variable($this->parseNameNode($node->name)); case $node instanceof Node\Expr\Array_: return $this->parseArrayNode($node); case $node instanceof Node\Expr\FuncCall: return $this->parseFunctionCallNode($node); case $node instanceof Node\Expr\New_: return Expression::newExpression($this->parseNameNode($node->class), $this->parseNodes($node->args)); case $node instanceof Node\Expr\MethodCall: return Expression::methodCall($this->parseNode($node->var), $this->parseNameNode($node->name), $this->parseNodes($node->args)); case $node instanceof Node\Expr\PropertyFetch: return Expression::field($this->parseNode($node->var), $this->parseNameNode($node->name)); case $node instanceof Node\Expr\ArrayDimFetch: return Expression::index($this->parseNode($node->var), $node->dim === null ? null : $this->parseNode($node->dim)); case $node instanceof Node\Expr\ConstFetch: return Expression::constant($this->parseAbsoluteName($node->name)); case $node instanceof Node\Expr\ClassConstFetch: return Expression::classConstant($this->parseNameNode($node->class), $node->name); case $node instanceof Node\Expr\StaticCall: return Expression::staticMethodCall($this->parseNameNode($node->class), $this->parseNameNode($node->name), $this->parseNodes($node->args)); case $node instanceof Node\Expr\StaticPropertyFetch: return Expression::staticField($this->parseNameNode($node->class), $this->parseNameNode($node->name)); case $node instanceof Node\Expr\Ternary: return $this->parseTernaryNode($node); case $node instanceof Node\Expr\Closure: return $this->parseClosureNode($node); case $node instanceof Node\Expr\Empty_: return Expression::emptyExpression($this->parseNode($node->expr)); case $node instanceof Node\Expr\Isset_: return Expression::issetExpression($this->parseNodes($node->vars)); default: throw new ASTException('Cannot parse AST with unknown expression node: %s', get_class($node)); } }
public function expressions() { return [[O\Expression::arrayExpression([])], [O\Expression::arrayItem(null, O\Expression::value(0), false)], [O\Expression::assign(O\Expression::value(0), O\Operators\Assignment::EQUAL, O\Expression::value(0))], [O\Expression::binaryOperation(O\Expression::value(0), O\Operators\Binary::ADDITION, O\Expression::value(0))], [O\Expression::unaryOperation(O\Operators\Unary::PLUS, O\Expression::value(0))], [O\Expression::cast(O\Operators\Cast::STRING, O\Expression::value(0))], [O\Expression::closure(false, false, [], [], [])], [O\Expression::closureUsedVariable('var')], [O\Expression::emptyExpression(O\Expression::value(0))], [O\Expression::field(O\Expression::value(0), O\Expression::value(0))], [O\Expression::functionCall(O\Expression::value(0))], [O\Expression::index(O\Expression::value(0), O\Expression::value(0))], [O\Expression::invocation(O\Expression::value(0))], [O\Expression::issetExpression([O\Expression::value(0)])], [O\Expression::unsetExpression([O\Expression::value(0)])], [O\Expression::methodCall(O\Expression::value(0), O\Expression::value(0))], [O\Expression::newExpression(O\Expression::value(0))], [O\Expression::parameter('')], [O\Expression::argument(O\Expression::value(0))], [O\Expression::returnExpression()], [O\Expression::staticMethodCall(O\Expression::value(0), O\Expression::value(0))], [O\Expression::staticField(O\Expression::value(0), O\Expression::value(0))], [O\Expression::ternary(O\Expression::value(0), null, O\Expression::value(0))], [O\Expression::throwExpression(O\Expression::value(0))], [O\Expression::value(0)], [O\Expression::variable(O\Expression::value(0))], [O\Expression::constant('foo')], [O\Expression::classConstant(O\Expression::value(0), 'foo')]]; }
/** * @dataProvider parsers */ public function testNestedClosures() { $function = function () { return static function &($foo) use($foo, &$bar) { $foo->bar += 5; }; }; $this->assertParsedAs($function, [O\Expression::returnExpression(O\Expression::closure(true, true, [O\Expression::parameter('foo')], [O\Expression::closureUsedVariable('foo'), O\Expression::closureUsedVariable('bar', true)], [O\Expression::assign(O\Expression::field(self::variable('foo'), O\Expression::value('bar')), O\Operators\Assignment::ADDITION, O\Expression::value(5))]))]); }
/** * @dataProvider parsers */ public function testField() { $this->assertParsedAs(function () { $i->field; }, [O\Expression::field(O\Expression::variable(O\Expression::value('i')), O\Expression::value('field'))]); }
/** * @expectedException \Pinq\Analysis\TypeException */ public function testFieldsAreCaseSensitive() { $class = $this->typeSystem->getObjectType('DateInterval'); $class->getField(O\Expression::field(O\Expression::value(''), O\Expression::value('T'))); }