示例#1
0
 /**
  * @expectedException \Exception
  */
 public function testCompileException()
 {
     $file = 'foo';
     $c = new TemplateCompiler('r_');
     $c->compile($file);
 }
 /**
  * @param TemplateCompiler $compiler
  * @param mixed $arguments
  */
 public function templateMethodTest($compiler, $arguments)
 {
     $this->assertTrue($compiler instanceof TemplateCompiler);
     $compiler->setArguments($arguments);
     $this->viewMock->expects($this->any())->method('getShared')->will($this->returnValue([]));
     $this->assertSame("    <div>dummy template name</div>\n", $compiler->render());
     return $this->propertyToTest;
 }
示例#3
0
 /**
  * Output the template into the browser
  * Will also assign the labels and all user-defined constants.
  * If you want custom-headers, you should set them yourself, otherwise the content-type and charset will be set
  *
  * @param string $template      The path of the template to use.
  * @param bool   $customHeaders Deprecated variable.
  * @param bool   $parseCustom   Parse custom template.
  */
 public function display($template, $customHeaders = false, $parseCustom = false)
 {
     // do custom stuff
     if ($parseCustom) {
         new TemplateCustom($this);
     }
     // parse constants
     $this->parseConstants();
     // check debug
     $this->parseDebug();
     // parse the label
     $this->parseLabels();
     // parse date/time formats
     $this->parseDateTimeFormats();
     // parse vars
     $this->parseVars();
     // get template path
     $template = Theme::getPath($template);
     /*
      * Code below is exactly the same as from our parent (SpoonTemplate::display), except
      * for the compiler being used. We want our own compiler extension here.
      */
     // redefine
     $template = (string) $template;
     // validate name
     if (trim($template) == '' || !is_file($template)) {
         throw new \SpoonTemplateException('Please provide an existing template.');
     }
     // compiled name
     $compileName = $this->getCompileName((string) $template);
     // compiled if needed
     if ($this->forceCompile || !is_file($this->compileDirectory . '/' . $compileName)) {
         // create compiler
         $compiler = new TemplateCompiler((string) $template, $this->variables);
         // set some options
         $compiler->setCacheDirectory($this->cacheDirectory);
         $compiler->setCompileDirectory($this->compileDirectory);
         $compiler->setForceCompile($this->forceCompile);
         $compiler->setForms($this->forms);
         // compile & save
         $compiler->parseToFile();
     }
     // load template
     require $this->compileDirectory . '/' . $compileName;
 }
 public function testArguments()
 {
     $this->testInstance->setArguments(['a' => 5]);
     $this->testInstance->appendArguments(['b' => 6]);
     $this->assertSame(['a' => 5, 'b' => 6], $this->testInstance->getArguments());
 }
示例#5
0
 protected function composeTemplate($template)
 {
     return TemplateCompiler::composeTemplate($template);
 }