function ParserAbstract::isolateContext
Calls a method with an isolated parser context, applying the given flags, but restoring their values after the execution.
Parameters
array|null $flags Key/value array of changes to apply to the: context flags. If it's null or the first element of the array is null the context will be reset before applying new values.
string $fn Method to call:
array|null $args Method arguments:
Return value
mixed
37 calls to ParserAbstract::isolateContext()
- Parser::parseArgumentList in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses an arguments list
- Parser::parseArrayLiteral in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses an array literal
- Parser::parseBindingElement in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a binding element
- Parser::parseCaseClause in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a case in a switch statement
- Parser::parseClassStaticBlock in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a field definition
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ ParserAbstract.php, line 192
Class
- ParserAbstract
- Base class for parsers.
Namespace
Peast\SyntaxCode
protected function isolateContext($flags, $fn, $args = null) {
//Store the current context
$oldContext = clone $this->context;
//If flag argument is null reset the context
if ($flags === null) {
$this->initContext();
}
else {
//Apply new values to the flags
foreach ($flags as $k => $v) {
// If null reset the context
if ($v === null) {
$this->initContext();
}
else {
$this->context->{$k} = $v;
}
}
}
//Call the method with the given arguments
$ret = $args ? call_user_func_array(array(
$this,
$fn,
), $args) : $this->{$fn}();
//Restore previous context
$this->context = $oldContext;
return $ret;
}