Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ParserAbstract.php

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

... See full list

File

vendor/mck89/peast/lib/Peast/Syntax/ParserAbstract.php, line 192

Class

ParserAbstract
Base class for parsers.

Namespace

Peast\Syntax

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal