You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.5 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage View
  7. * @since 2010-02-25
  8. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. class PHPView implements iView
  12. {
  13. protected $path = '';
  14. protected $variables = array();
  15. protected $extension = '.phtml';
  16. protected $template = '';
  17. public function __construct($path)
  18. {
  19. $this->setPath($path);
  20. }
  21. public function getPath()
  22. {
  23. return $this->path;
  24. }
  25. public function setPath($path)
  26. {
  27. $this->path = $path;
  28. }
  29. /**
  30. * @param ViewAction $object
  31. */
  32. public function assignObject($object)
  33. {
  34. foreach (get_object_vars($object) as $name => $value) {
  35. $this->assign($name, $value);
  36. }
  37. }
  38. public function assign($name, $value = null)
  39. {
  40. $this->variables[$name] = $value;
  41. }
  42. public function fetch($template)
  43. {
  44. $this->template = $this->getTemplatePath($template);
  45. unset($template);
  46. extract($this->variables);
  47. ob_start();
  48. if (!(include($this->template)) == 'OK') {
  49. ob_clean();
  50. throw new Exception('Template "' . $this->template .'" not found.');
  51. }
  52. return ob_get_clean();
  53. }
  54. public function escape($var)
  55. {
  56. return htmlentities($var, ENT_QUOTES, 'UTF-8');
  57. }
  58. protected function getTemplatePath($template)
  59. {
  60. return $this->path . $template . $this->extension;
  61. }
  62. }