View.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php declare(strict_types=1);
  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 https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
  10. */
  11. namespace PrivateBin;
  12. use Exception;
  13. /**
  14. * View
  15. *
  16. * Displays the templates
  17. */
  18. class View
  19. {
  20. /**
  21. * variables available in the template
  22. *
  23. * @access private
  24. * @var array
  25. */
  26. private $_variables = array();
  27. /**
  28. * assign variables to be used inside of the template
  29. *
  30. * @access public
  31. * @param string $name
  32. * @param mixed $value
  33. */
  34. public function assign($name, $value)
  35. {
  36. $this->_variables[$name] = $value;
  37. }
  38. /**
  39. * render a template
  40. *
  41. * @access public
  42. * @param string $template
  43. * @throws Exception
  44. */
  45. public function draw($template)
  46. {
  47. $file = substr($template, 0, 10) === 'bootstrap-' ? 'bootstrap' : $template;
  48. $path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $file . '.php';
  49. if (!file_exists($path)) {
  50. throw new Exception('Template ' . $template . ' not found!', 80);
  51. }
  52. extract($this->_variables);
  53. include $path;
  54. }
  55. }