closureUsedVariable() final public static method

final public static closureUsedVariable ( string $name, boolean $isReference = false ) : ClosureUsedVariableExpression
$name string
$isReference boolean
return ClosureUsedVariableExpression
コード例 #1
0
ファイル: InterpreterTest.php プロジェクト: timetoogo/pinq
 private function recompile(Parsing\IFunctionReflection $reflection, Parsing\IFunctionStructure $structure, &$closureExpression = null)
 {
     $signature = $reflection->getSignature();
     $usedVariables = array_map(function ($name) {
         return O\Expression::closureUsedVariable($name);
     }, $signature->getScopedVariableNames() ?: []);
     $closureExpression = O\Expression::closure($signature->returnsReference(), $reflection->getInnerReflection()->getClosureScopeClass() === null, $signature->getParameterExpressions(), $usedVariables, $structure->getBodyExpressions());
     return $closureExpression->evaluate($reflection->asEvaluationContext());
 }
コード例 #2
0
ファイル: AST.php プロジェクト: timetoogo/pinq
 private function parseClosureNode(Node\Expr\Closure $node)
 {
     $parameterExpressions = [];
     foreach ($node->params as $parameterNode) {
         $parameterExpressions[] = $this->parseParameterNode($parameterNode);
     }
     $usedVariables = [];
     foreach ($node->uses as $usedVariable) {
         $usedVariables[] = Expression::closureUsedVariable($usedVariable->var, $usedVariable->byRef);
     }
     $bodyExpressions = $this->parseNodes($node->stmts);
     return Expression::closure($node->byRef, $node->static, $parameterExpressions, $usedVariables, $bodyExpressions);
 }
コード例 #3
0
ファイル: MiscExpressionTest.php プロジェクト: timetoogo/pinq
 public function testNamedParameterExpressionAsVariableMethod()
 {
     $this->assertEquals(O\Expression::variable(O\Expression::value('foo')), O\Expression::parameter('foo')->asVariable());
     $this->assertEquals(O\Expression::variable(O\Expression::value('foobar')), O\Expression::closureUsedVariable('foobar')->asVariable());
 }
コード例 #4
0
ファイル: ExpressionTest.php プロジェクト: timetoogo/pinq
 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')]];
 }
コード例 #5
0
ファイル: ComplexParserTest.php プロジェクト: timetoogo/pinq
 /**
  * @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))]))]);
 }