1
0

View.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * PrivateBin
  4. *
  5. * a zero-knowledge paste bin
  6. *
  7. * @link https://github.com/PrivateBin/PrivateBin
  8. * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
  9. * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
  10. * @version 1.1
  11. */
  12. namespace PrivateBin;
  13. use Exception;
  14. /**
  15. * View
  16. *
  17. * Displays the templates
  18. */
  19. class View
  20. {
  21. /**
  22. * variables available in the template
  23. *
  24. * @access private
  25. * @var array
  26. */
  27. private $_variables = array();
  28. /**
  29. * assign variables to be used inside of the template
  30. *
  31. * @access public
  32. * @param string $name
  33. * @param mixed $value
  34. */
  35. public function assign($name, $value)
  36. {
  37. $this->_variables[$name] = $value;
  38. }
  39. /**
  40. * render a template
  41. *
  42. * @access public
  43. * @param string $template
  44. * @throws Exception
  45. */
  46. public function draw($template)
  47. {
  48. $file = substr($template, 0, 9) === 'bootstrap' ? 'bootstrap' : $template;
  49. $path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $file . '.php';
  50. if (!file_exists($path)) {
  51. throw new Exception('Template ' . $template . ' not found!', 80);
  52. }
  53. extract($this->_variables);
  54. include $path;
  55. }
  56. }