public static function apply( string $text, $context, string $skip = '', ?callable $callback = null ): string {

    //
    $context = Storage::instance( $context );

    $output    = '';
    $delimiter = null;
    for( $i = 0, $length = strlen( $text ); $i < $length; ++$i ) {

      // detect skipped blocks (start and end)
      if( $delimiter == $text{$i} ) $delimiter = null;
      else if( !$delimiter && strpos( $skip, $text{$i} ) !== false ) $delimiter = $text{$i};

      // try to process the insertion
      if( !$delimiter && $text{$i} == '{' ) {

        $buffer = '';
        for( $j = $i + 1; $j < $length && $text{$j} != '}'; ++$j ) {
          $buffer .= $text{$j};
        }
        $i = $j;

        $output .= $callback ? $callback( $buffer, $context ) : $context[ $buffer ];
        continue;
      }

      $output .= $text{$i};
    }

    return $output;
  }
public static function apply( string $text, $context, string $skip = '', ?callable $callback = null ): string {

    //
    $context = Storage::instance( $context );

    $output    = '';
    $delimiter = null;
    for( $i = 0, $length = strlen( $text ); $i < $length; ++$i ) {

      // detect skipped blocks (start and end)
      if( $delimiter == $text{$i} ) $delimiter = null;
      else if( !$delimiter && strpos( $skip, $text{$i} ) !== false ) $delimiter = $text{$i};

      // try to process the insertion
      if( !$delimiter && $text{$i} == '{' ) {

        $buffer = '';
        for( $j = $i + 1; $j < $length && $text{$j} != '}'; ++$j ) {
          $buffer .= $text{$j};
        }
        $i = $j;

        $output .= $callback ? $callback( $buffer, $context ) : $context[ $buffer ];
        continue;
      }

      $output .= $text{$i};
    }

    return $output;
  }
public static function apply ( string $ text , $ context , string $ skip = '' , ? callable $ callback = null ) : string { // $ context = Storage :: instance ( $ context ) ; $ output = '' ; $ delimiter = null ; for ( $ i = 0 , $ length = strlen ( $ text ) ; $ i < $ length ; ++ $ i ) { // detect skipped blocks (start and end) if ( $ delimiter == $ text { $ i } ) $ delimiter = null ; else if ( ! $ delimiter && strpos ( $ skip , $ text { $ i } ) !== false ) $ delimiter = $ text { $ i } ; // try to process the insertion if ( ! $ delimiter && $ text { $ i } == '{' ) { $ buffer = '' ; for ( $ j = $ i + 1 ; $ j < $ length && $ text { $ j } != '}' ; ++ $ j ) { $ buffer .= $ text { $ j } ; } $ i = $ j ; $ output .= $ callback ? $ callback ( $ buffer , $ context ) : $ context [ $ buffer ] ; continue ; } $ output .= $ text { $ i } ; } return $ output ; }
Insert variables to the input from insertion array used the regexp constant of class

TODO implement condition and loop support

@param string                        $text     Input string to insert
@param array|object|StorageInterface $context  The insertion variables
@param string                        $skip     Opener (and closer) characters for blocks in the text that will not processed
@param callable|null                 $callback callback to process replaces

@return string
Insert variables to the input from insertion array used the regexp constant of class