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

Breadcrumb

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

function CommentsRegistry::onTokenConsumed

Listener called every time a token is consumed and when the scanner reaches the end of the source

Parameters

Token|null $token Consumed token or null if the end has: been reached

Return value

void

File

vendor/mck89/peast/lib/Peast/Syntax/CommentsRegistry.php, line 110

Class

CommentsRegistry
Comments registry class. Internal class used to manage comments

Namespace

Peast\Syntax

Code

public function onTokenConsumed($token = null) {
    
    //Check if it's a comment
    if ($token && $token->type === Token::TYPE_COMMENT) {
        
        //If there is not an open comments buffer, create it
        if (!$this->buffer) {
            $this->buffer = array(
                "prev" => $this->lastTokenIndex,
                "next" => null,
                "comments" => array(),
            );
        }
        
        //Add the comment token to the buffer
        $this->buffer["comments"][] = $token;
    }
    else {
        if ($token) {
            $loc = $token->location;
            
            //Store the token end position
            $this->lastTokenIndex = $loc->end
                ->getIndex();
            if ($this->buffer) {
                
                //Fill the "next" key on the comments buffer with the token
                
                //start position
                $this->buffer["next"] = $loc->start
                    ->getIndex();
            }
        }
        
        //If there is an open comment buffer, close it and move it to the
        
        //registry
        if ($buffer = $this->buffer) {
            
            //Use the location as key to add the group of comments to the
            
            //registry, in this way if comments are reprocessed they won't
            
            //be duplicated
            $key = implode("-", array(
                $buffer["prev"] !== null ? $buffer["prev"] : "",
                $buffer["next"] !== null ? $buffer["next"] : "",
            ));
            $this->registry[$key] = $this->buffer;
            $this->buffer = null;
        }
    }
}

API Navigation

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