Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define('DR', realpath(dirname(__FILE__)).DS);
- class View
- {
- # view file path
- private $file;
- # view local variables
- private $data = array();
- # view rendered content
- private $content;
- # view global variables
- private static $_data = array();
- private function __construct($name)
- {
- $name = str_replace(array('/', '//', '\\'), DIRECTORY_SEPARATOR, $name);
- $file = DR.'views'.DS.$name.EXT;
- if (file_exists($file))
- {
- $this->file = $file;
- }
- return true;
- }
- public static function factory($name = '')
- {
- if (empty($name))
- {
- return false;
- }
- return new view($name);
- }
- public function __set($key = '', $value = null)
- {
- if (empty($key))
- {
- return false;
- }
- $this->data[$key] = $value;
- return true;
- }
- public function __get($key = '')
- {
- if (empty($key))
- {
- return false;
- }
- if (array_key_exists($key, $this->data))
- {
- return $this->data[$key];
- }
- else
- {
- return false;
- }
- }
- public function bind($key = '', $value = null)
- {
- if (empty($key))
- {
- return false;
- }
- view::$_data[$key] = $value;
- return true;
- }
- public function render()
- {
- if (!empty(view::$_data))
- {
- extract(view::$_data);
- }
- extract($this->data);
- ob_start();
- include($this->file);
- $this->content = ob_get_contents();
- ob_end_clean();
- return (string) $this->content;
- }
- public function __toString()
- {
- return $this->render();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement