Exemplo n.º 1
0
 /**
  * 
  * @return Token
  */
 public function findClosingToken(Token $startToken)
 {
     $source = $this->getSource();
     $blockOpener = $this->getBlockOpener();
     $blockCloser = $this->getBlockCloser();
     $opener = $source->findNextMatchingFrom($startToken->getPointer(), $blockOpener);
     $level = 0;
     $max = $source->getEndPointer();
     $openerPointer = $opener->getPointer();
     for ($currentPointer = $openerPointer; $currentPointer <= $max; $currentPointer++) {
         $currentToken = $source->getTokenAt($currentPointer);
         if ($currentToken->is($blockOpener)) {
             $level++;
             continue;
         }
         if ($currentToken->is($blockCloser)) {
             $level--;
             if ($level === 0) {
                 break;
             } else {
                 continue;
             }
         }
     }
     return $currentToken;
 }
Exemplo n.º 2
0
 /**
  * 
  * @param Token $startToken
  * @param Block $parentBlock
  * @return Block|null
  */
 public function makeBlock(Token $startToken, Block $parentBlock = null)
 {
     $tokenName = $startToken->getToken();
     if (!isset(static::$tokenHandlerCache[$tokenName])) {
         // attempt to register
         static::registerBlockHandlers([$startToken]);
     }
     // try again
     if (!empty(static::$tokenHandlerCache[$tokenName])) {
         $class = static::$tokenHandlerCache[$tokenName];
         return new $class($this, $startToken, $parentBlock);
     } else {
         return null;
     }
 }