/** * Return a static instance of PHTML. This works as a singleton and provides easy access to the output object * while not requiring that the class itself be a singleton which is undesirable. * * All classes that want to act as views for vicious should follow this convention. */ function phtml($template = null, $layout = null) { static $instance; if (!$instance) { $instance = new vicious\PHTML(); } if ($template !== null) { $instance->set_template($template); } if ($layout !== null) { $instance->set_layout($layout); } return $instance; }
public function testRenderTemplateWithLayout() { $p = new vicious\PHTML(); $p->title = "Test"; $p->template = 'for_layout'; $p->layout = 'layout'; ob_start(); $p->render(); $out = ob_get_clean(); $this->assertContains('<!DOCTYPE html>', $out); $this->assertContains('<h1>Test</h1>', $out); $this->assertContains('<title>Test</title>', $out); }