Пример #1
0
 public function test_methodChaining()
 {
     $templateFile = __DIR__ . '/files/templates/main.tmpl';
     $x = new Template($templateFile);
     $y = new Template($templateFile);
     $varList = array('file1' => "first", 'file2' => "second");
     $varList2 = array('ar1' => "var one", 'ar2' => "the second");
     $y->addVarList($varList);
     $y->addVar('var1', 'test');
     $y->addVarListWithPrefix($varList2, 'v');
     $y->addVar('var1', "use this");
     $normalRender = $y->render();
     $this->assertNotEquals(file_get_contents($templateFile), $normalRender);
     $chainRender = $x->addVarList($varList)->addVar('var1', 'test')->addVarListWithPrefix($varList2, 'v')->addVar('var1', "use this")->render();
     $this->assertNotEquals(file_get_contents($templateFile), $chainRender);
     $this->assertEquals($normalRender, $chainRender);
 }
Пример #2
0
 public function setBlockRow($handle, $removeDefs = true)
 {
     $name = $handle;
     $rowPlaceholder = $name;
     $reg = "/<!-- BEGIN {$handle} -->(.+){0,}<!-- END {$handle} -->/sU";
     $m = array();
     preg_match_all($reg, $this->_contents, $m);
     if (!is_array($m) || !isset($m[0][0]) || !is_string($m[0][0])) {
         throw new \Exception("could not find block row '" . $handle . "' in template '" . $this->name . ", filename=(" . $this->_origin . ")");
     } else {
         if ($removeDefs) {
             $openHandle = "<!-- BEGIN {$handle} -->";
             $endHandle = "<!-- END {$handle} -->";
             $m[0][0] = str_replace($openHandle, "", $m[0][0]);
             $m[0][0] = str_replace($endHandle, "", $m[0][0]);
         }
         $this->_contents = preg_replace($reg, "{" . $rowPlaceholder . "}", $this->_contents);
     }
     $blockRow = new Template(null, $rowPlaceholder);
     $blockRow->setContents($m[0][0]);
     $this->_blockRows[$handle] = $blockRow;
     return $blockRow;
 }