Skip to content

Instantly share code, notes, and snippets.

@G4MR
Last active December 15, 2015 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save G4MR/bc05b925956bd0dcb95c to your computer and use it in GitHub Desktop.
Save G4MR/bc05b925956bd0dcb95c to your computer and use it in GitHub Desktop.
<?php
class View
{
private $data = [];
public function __construct($renderer, $template)
{
$this->renderer = $renderer;
$this->template = $template;
}
public static function make($template)
{
$container = Container::getInstance();
return new View($container->get('renderer'), $template);
}
public function setRenderer($renderer)
{
$this->renderer = $renderer;
}
public function __get($value)
{
return $this->data[$value] ?? null; //can't wait for php7
}
public function __set($variable, $value)
{
$this->data[$variable] = $value;
}
public function render($return = true)
{
if($return === true) {
return $this->renderer->render($this->template, $this->data);
}
echo $this->renderer->render($this->template, $this->data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment