template.class.php 645 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. class Template {
  3. public $name;
  4. public function __construct($name){
  5. $this->name = $name;
  6. }
  7. public function __get($name){
  8. switch($name){
  9. case 'path':
  10. return realpath(dirname(__FILE__)).'/../templates/'.$this->name.'.php';
  11. break;
  12. }
  13. }
  14. public function __invoke($context){
  15. ob_start();
  16. $GLOBALS['context'] = $context;
  17. if(file_exists($this->path) && is_file($this->path)){
  18. include($this->path);
  19. }
  20. $ret = ob_get_contents();
  21. ob_end_clean();
  22. return $ret;
  23. }
  24. public function __toString(){
  25. return $this(array());
  26. }
  27. public function run($context){
  28. return $this($context);
  29. }
  30. }
  31. ?>