Last active
December 15, 2015 11:43
-
-
Save G4MR/bc05b925956bd0dcb95c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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