core added

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@2 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
akulikov
2008-12-02 08:59:06 +00:00
parent 763f0d5676
commit 62eef89248
12 changed files with 912 additions and 0 deletions

55
core/Decorator.class.php Normal file
View File

@ -0,0 +1,55 @@
<?php
/**
* Родительский класс для всех декораторов. Содержит основной функционал.
*
*/
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();
}
?>