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.

72 lines
1.5 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage Layout
  7. * @since 2010-02-25
  8. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. abstract class Layout
  12. {
  13. protected $template;
  14. /**
  15. * @var PHPView
  16. */
  17. protected $view;
  18. public function __construct()
  19. {
  20. $this->view = FrontController::getInstance()->getView();
  21. }
  22. /**
  23. * @param string $name
  24. * @param Action $action
  25. */
  26. protected function assign($name, $action)
  27. {
  28. $this->view->assign($name, $action->fetch());
  29. }
  30. /**
  31. * @param string $name
  32. * @param Action $action
  33. */
  34. protected function append($name, $action)
  35. {
  36. $this->view->append($name, $action->fetch());
  37. }
  38. /**
  39. * @param string $name
  40. * @param Action $action
  41. */
  42. protected function prepend($name, $action)
  43. {
  44. $this->view->prepend($name, $action->fetch());
  45. }
  46. abstract protected function execute();
  47. /**
  48. * @param Action $action
  49. */
  50. public function fetch($action)
  51. {
  52. $this->view->assign('content', $action->fetch());
  53. $this->execute();
  54. return $this->view->fetch($this->getTemplate());
  55. }
  56. protected function getTemplate()
  57. {
  58. $template = ($this->template) ? $this->template : substr(get_class($this), 0, -6/*strlen('Layout')*/);
  59. return '/layouts/' . $template;
  60. }
  61. }