Skip to content

Commit

Permalink
Merge pull request #5 from moknomo/patch-1
Browse files Browse the repository at this point in the history
rm deprecated addIndentation
  • Loading branch information
dpolac authored Jun 6, 2018
2 parents 703d444 + 5a45e31 commit b052a2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions NodeExpression/Lambda.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,54 @@ protected function compileWithArguments(
{
$compiler->raw("\n");
$compiler->indent();
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("function() use(&\$context) {\n");
$compiler->indent();

// copy of arguments and __ from context
foreach ($arguments as $arg) {
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("if (isset(\$context['$arg'])) \$outer$arg = \$context['$arg'];\n");
}
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("if (isset(\$context['__'])) \$outer__ = \$context['__'];\n");

// adding closure's arguments to context
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("\$context['__'] = func_get_args();\n");
foreach ($arguments as $i => $arg) {
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("if (func_num_args()>$i) \$context['$arg'] = func_get_arg($i);\n");
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("else unset(\$context['$arg']);\n");
}

// getting call result
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("\$result = ");
$compiler->subcompile($this->getNode($expressionNode));
$compiler->raw(";\n");

// recreating original context
foreach ($arguments as $arg) {
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("if (isset(\$outer$arg)) \$context['$arg'] = \$outer$arg ;\n");
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("else unset(\$context['$arg']);\n");
}
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("if (isset(\$outer__)) \$context['__'] = \$outer__ ;\n");
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("else unset(\$context['__']);\n");

// return statement
$compiler->addIndentation();
$compiler->write('');
$compiler->raw("return \$result;\n");
$compiler->outdent();
$compiler->addIndentation();
$compiler->write('');

$compiler->raw("}\n");
$compiler->outdent();
$compiler->addIndentation();
$compiler->write('');
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
"require": {
"php": "^5.4 || ^7.0",
"twig/twig": "^1.0",
"twig/twig": "^1.0 || ^2.0",
"dpolac/dictionary": "^1.0"
},
"require-dev": {
Expand Down

0 comments on commit b052a2f

Please sign in to comment.