View.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 0.22
  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. * @return void
  35. */
  36. public function assign($name, $value)
  37. {
  38. $this->_variables[$name] = $value;
  39. }
  40. /**
  41. * render a template
  42. *
  43. * @access public
  44. * @param string $template
  45. * @throws Exception
  46. * @return void
  47. */
  48. public function draw($template)
  49. {
  50. $path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $template . '.php';
  51. if (!file_exists($path)) {
  52. throw new Exception('Template ' . $template . ' not found!', 80);
  53. }
  54. extract($this->_variables);
  55. include $path;
  56. }
  57. }