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.

62 lines
1.7 KiB

  1. <?php
  2. /**
  3. * Родительский класс для всех декораторов. Содержит основной функционал.
  4. *
  5. * @copyright netmonsters.ru
  6. * @link
  7. * @package Majestic
  8. * @subpackage Decorator
  9. * @since
  10. * @version SVN: $Id$
  11. * @filesource $URL$
  12. */
  13. abstract class Decorator
  14. {
  15. protected $layout = false;
  16. protected $action = false;
  17. protected $action_name = 'Action';
  18. protected $templater = false;
  19. function __construct()
  20. {
  21. if (!$this->layout) {
  22. throw new MJException('$layout not set in '.get_class($this));
  23. }
  24. $this->templater = Load::templater();
  25. }
  26. /**
  27. * Основной метод вывода
  28. *
  29. */
  30. function display(Action $action)
  31. {
  32. $this->action = $action;
  33. $this->templater->assign($this->action_name, $this->action->display(), $this->layout);
  34. $this->exec();
  35. $this->templater->setPath(WRAPPERS_TPL_PATH);
  36. return $this->templater->fetch($this->layout);
  37. }
  38. /**
  39. * Добавить данные на вывод
  40. *
  41. * @param string $var_name - имя переменной, в которую будет осуществлен вывод
  42. * @param Action $action - действие
  43. * @param Decorator $decorator - декоратор, в котором должно выполнится действие.
  44. */
  45. function addOutput($var_name, Action $action, Decorator $decorator = null)
  46. {
  47. $this->templater->assign($var_name, $decorator ? $decorator->display($action) : $action->display(), $this->layout);
  48. }
  49. /**
  50. * Основной метод для дочерних декораторов
  51. *
  52. */
  53. abstract function exec();
  54. }
  55. ?>