Example #1
0
 /**
  * Test the "for" block where the source variable isn't found
  *
  * @expectedException \Exception
  */
 public function testForBlockWithBadReplace()
 {
     // Use the tokenizer to build the tokens
     $t = new Tokenizer();
     $document = 'this is a {% for item in badvar %} bad varname {% endfor %} here';
     $tokens = $t->execute($document);
     $data = [];
     $block = new BlockFor($data, $tokens[0], new Document($document));
     $result = $block->execute();
 }
Example #2
0
 /**
  * Execute the token/data parsing
  *
  * @param array $data Data to populate into the structure
  * @return \SalesforceEng\Breakout\Document instance
  */
 public function execute(array $data)
 {
     $document = $this->document;
     while ($this->container->valid()) {
         $current = $this->container->current();
         $this->container->next();
         if (is_array($current)) {
             $tokenType = $current[0]->getToken();
             switch ($tokenType) {
                 case 'if':
                     $ifBlock = new Block\BlockIf($data, $current, $document);
                     $document = $ifBlock->execute();
                     break;
                 case 'for':
                     $forBlock = new Block\BlockFor($data, $current, $document);
                     $document = $forBlock->execute();
                     break;
                 case 'raw':
                     $rawBlock = new Block\BlockRaw($data, $current, $document);
                     $document = $rawBlock->execute();
             }
         } else {
             $document = $this->handleVariable($data, $current, $document);
         }
     }
     return $document;
 }