refactor: Упрощение контроллера

This commit is contained in:
origami11@yandex.ru 2025-11-13 18:51:18 +03:00
parent b20ea0e7dc
commit 0473d410d1

View file

@ -47,16 +47,10 @@ class Action implements ActionInterface
public $part = null; public $part = null;
/** @var \ctiso\Registry Ссылка на настройки */ /** @var \ctiso\Registry Ссылка на настройки */
public $config; public $config;
/** @var \ctiso\Role\User Обьект пользователя */ /** @var \ctiso\Role\User Обьект пользователя */
public $user; public $user;
/** @var \ctiso\View\View Для Widgets */
public $view = null;
public array $childNodes = [];
public array $ctrlValues = [];
public array $childViews = [];
function __construct() { function __construct() {
$this->part = new Url(); $this->part = new Url();
@ -216,11 +210,7 @@ class Action implements ActionInterface
public function execute(HttpRequest $request) public function execute(HttpRequest $request)
{ {
$result = $this->preProcess($request); $result = $this->preProcess($request);
if (!empty($result)) { return $result;
$this->view = $result;
}
$text = $this->render();
return $text;
} }
/** /**
@ -352,78 +342,6 @@ class Action implements ActionInterface
return $result->export(); return $result->export();
} }
/**
* @param string $name
*/
public function setView($name): void
{
$this->view = $this->getView($name);
}
/**
* Установка заголовка для отображения
* @param string $title
*/
public function setTitle($title): void
{
$this->view->setTitle($title);
}
/**
* Добавление widget к отображению
* @param string $section
* @param View $node
*/
public function addChild($section, $node): void
{
$this->childNodes[$section] = $node;
}
/**
* Установка значения контроллера
* @param string $name
* @param mixed $value
*/
public function setValue($name, $value): void
{
$this->ctrlValues[$name] = $value;
}
/**
* Добавление дочернего отображения к текущему отображению
* @param string $section
* @param View $node
*/
public function addView($section, $node): void
{
$this->childViews[$section] = $node;
}
/**
* Генерация содержания
* Путаница c execute и render
* @return View|string
*/
public function render()
{
$view = $this->view;
if ($view instanceof View) {
$this->view->assignValues($this->ctrlValues);
/** @var ?Composite $node */
$node = null;
foreach ($this->childNodes as $name => $node) {
$node->make($this);
$this->view->setView($name, $node->view);
}
foreach ($this->childViews as $name => $node) {
$this->view->setView($name, $node);
}
}
return $this->view;
}
/** /**
* Установка идентификатора страницы * Установка идентификатора страницы
* @return int * @return int