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.8 KiB

<?php
/**
* Родительский класс для всех декораторов. Содержит основной функционал.
*
* @copyright NetMonsters <team@netmonsters.ru>
* @link
* @package Majestic
* @subpackage Decorator
* @since
* @version SVN: $Id$
* @filesource $URL$
*/
abstract class Decorator
{
protected $layout = false;
protected $action = false;
protected $action_name = 'Action';
protected $templater = false;
function __construct()
{
if (!$this->layout) {
throw new MJException('$layout not set in '.get_class($this));
}
$this->templater = Load::templater();
}
/**
* Основной метод вывода
*
*/
function display(Action $action)
{
$this->action = $action;
$this->templater->assign($this->action_name, $this->action->display(), $this->layout);
$this->exec();
$this->templater->setPath(WRAPPERS_TPL_PATH);
return $this->templater->fetch($this->layout);
}
/**
* Добавить данные на вывод
*
* @param string $var_name - имя переменной, в которую будет осуществлен вывод
* @param Action $action - действие
* @param Decorator $decorator - декоратор, в котором должно выполнится действие.
*/
function addOutput($var_name, Action $action, Decorator $decorator = null)
{
$this->templater->assign($var_name, $decorator ? $decorator->display($action) : $action->display(), $this->layout);
}
/**
* Основной метод для дочерних декораторов
*
*/
abstract function exec();
}
?>