/** * Render a template * * $data cannot contain template as a key * * throws RuntimeException if $templatePath . $template does not exist * * @param \ResponseInterface $response * @param $template * @param array $data * * @return ResponseInterface * * @throws \InvalidArgumentException * @throws \RuntimeException */ public function render(ResponseInterface $response, $template, array $data = []) { if (isset($data['template'])) { throw new \InvalidArgumentException("Duplicate template key found"); } if (!is_file($this->templatePath . $template)) { throw new \RuntimeException("View cannot render `{$template}` because the template does not exist"); } $template = \PHPTAL::create($this->templatePath . $template); foreach ($data as $key => $value) { $template->{$key} = $value; } $response->getBody()->write($template->execute()); return $response; }
function testCreateWithFileMethod() { $obj = PHPTAL::create('input/phptal.01.html'); $this->assertInstanceOf('PHPTAL', $obj); $obj->getCodePath(); }