chore: Аннотации к типам

This commit is contained in:
origami11@yandex.ru 2025-10-23 15:54:14 +03:00
parent 530a3b931d
commit 730a608f9b
27 changed files with 491 additions and 134 deletions

View file

@ -38,13 +38,18 @@ class FakeTemplate {
*/
class Component
{
/** @var string[] */
public $viewPath = [];
/** @var string[] */
public $webPath = [];
/** @var ?string */
public $template = null;
public string $templatePath;
/** @var string */
public $component_id;
/** @var string */
public $component_title;
public $COMPONENTS_WEB;
@ -53,9 +58,12 @@ class Component
public Database $db;
public Collection $parameter;
/** @var string */
public $output = 'html';
/** @var string */
public $module;
/** @var string */
public $item_module;
/**
@ -66,12 +74,22 @@ class Component
function before() {
}
/**
* @param string $match
* @return string
*/
static function replaceContent($match) {
return \ctiso\Tales::phptal_component(htmlspecialchars_decode($match[3]));
}
/**
* @param string $text
* @return string
*/
static function applyComponents($text) {
return preg_replace_callback('/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u', 'ctiso\\Controller\\Component::replaceContent', $text);
$callback = fn($x) => self::replaceContent($x);
return preg_replace_callback('/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u',
$callback, $text);
}
function execute(HttpRequest $request, $has_id = true) {
@ -101,13 +119,18 @@ class Component
? $_COOKIE['with_template'] : ($_registry ? $_registry->get('site', 'template') : 'modern');
}
/**
* Получить шаблон
* @param string $name
* @return PHPTAL|FakeTemplate
*/
public function getView($name)
{
if ($this->output === 'json') {
return new FakeTemplate($name);
}
/* @var Registry $config */
/** @var Registry $config */
$config = $this->config;
$default = $config->get('site', 'template');
$template = ($this->template) ? $this->template : $this->getTemplateName($config);
@ -152,10 +175,19 @@ class Component
return $tpl;
}
/**
* Возвращает путь к шаблону по умолчанию
* @return string
*/
function _getDefaultPath() {
return $this->viewPath[count($this->viewPath) - 1];
}
/**
* Возвращает путь к шаблону
* @param string $name
* @return string
*/
public function getTemplatePath($name) {
$registry = $this->config;
// Брать настройки из куков если есть
@ -169,6 +201,10 @@ class Component
return Path::join($this->viewPath[count($this->viewPath) - 1], 'templates', 'modern', $name);
}
/**
* Возвращает путь к шаблонам
* @return string
*/
public function getTemplateWebPath()
{
return Path::join($this->webPath[count($this->webPath) - 1], 'templates', 'modern');
@ -201,6 +237,11 @@ class Component
return $result;
}
/**
* @param array $list
* @param bool $selected
* @return array
*/
public function optionsPair(array $list, $selected = false) {
$result = [];
foreach ($list as $key => $value) {
@ -371,12 +412,16 @@ class Component
return $component;
}
/**
* @return ?array{name: string, url: string}
*/
function getEditUrl() {
return null;
}
/**
* @param ComponentRequest $request
* @return array
*/
function raw_query($request)
{
@ -403,6 +448,8 @@ class Component
/**
* @param ComponentRequest $request
* @param array $list
* @return string
*/
function query($request, $list)
{
@ -416,7 +463,12 @@ class Component
return '?' . http_build_query($arr);
}
function addRequireJsPath($name, $path, $shim = null) {
/**
* @param string $name
* @param string $path
* @param array $shim
*/
function addRequireJsPath($name, $path, $shim = null): void {
$this->site->addRequireJsPath($name, $path, $shim);
}