feat: Удаление магических методов в шаблонах

This commit is contained in:
origami11@yandex.ru 2025-12-02 19:43:10 +03:00
parent 18cc1cad01
commit 61b5bc1c0f
13 changed files with 148 additions and 111 deletions

View file

@ -8,15 +8,17 @@ use ctiso\Arr;
use ctiso\Path;
use ctiso\File;
use ctiso\Form\Form;
use ctiso\View\Composite;
use ctiso\View\View;
use ctiso\Database;
use ctiso\Collection;
use ctiso\Registry;
use ctiso\Controller\SiteInterface;
use ctiso\Database\PDOStatement;
use ctiso\View\Json;
use PHPTAL;
use PHPTAL_PreFilter_Normalize;
use ctiso\View\FakeTemplate;
use ctiso\View\Template;
use ctiso\View\TalView;
/**
* Класс компонента
@ -117,12 +119,12 @@ class Component
/**
* Получить шаблон
* @param string $name
* @return PHPTAL|FakeTemplate
* @return Template
*/
public function getView($name)
{
if ($this->output === 'json') {
return new FakeTemplate($name);
return new Json($name);
}
/** @var Registry $config */
@ -136,8 +138,7 @@ class Component
// Загружать шаблон по умолчанию если не найден текущий
$dir = Path::join($this->viewPath[$index], 'templates', $template);
if(is_dir($dir)) {
$tpl = new PHPTAL(Path::join($this->viewPath[$index], 'templates', $template, $name));
$tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION);
$tpl = new TalView(Path::join($this->viewPath[$index], 'templates', $template, $name));
$selected = $index;
break;
}
@ -146,13 +147,11 @@ class Component
if ($selected === null) {
// Последний вариант viewPath, путь к папке компонента
$selected = count($this->viewPath) - 1;
$tpl = new PHPTAL(Path::join($this->viewPath[$selected], 'templates', 'modern', $name));
$tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION);
$tpl = new TalView(Path::join($this->viewPath[$selected], 'templates', 'modern', $name));
$template = 'modern';
}
$tpl->stripComments(true);
$tpl->addPreFilter(new \PHPTAL_PreFilter_Normalize());
// $tpl->addPreFilter(new \PHPTAL_PreFilter_Normalize());
$tpl->set('common', Path::join($this->config->get('system', 'web'), '../', 'common'));
$tpl->set('script', Path::join($this->config->get('system', 'web'), 'js'));
@ -280,19 +279,19 @@ class Component
/**
* Генерация интерфейса для выбора галлереи фотографии
* @param Composite $view
* @param View $view
* @param ?\ctiso\Form\OptionsFactory $options
*/
public function setParameters(Composite $view, $options = null): void
public function setParameters(View $view, $options = null): void
{
$form = new Form();
$settings = $this->getInfo();
$form->addFieldList($settings['parameter'], $options);
$view->form = $form;
$view->component = $settings['component'];
$view->component_title = $settings['title'];
$view->set('form', $form);
$view->set('component', $settings['component']);
$view->set('component_title', $settings['title']);
}
/**