From 5474090f852f484b5ab8d15da950055a1ac5def5 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Fri, 23 May 2025 13:35:46 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=98=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 98 +++++++++++++++++++++----------- src/Controller/SiteInterface.php | 11 +++- src/Form/Form.php | 12 ++-- src/Form/OptionsFactory.php | 7 +++ src/Form/Select.php | 6 +- 5 files changed, 90 insertions(+), 44 deletions(-) create mode 100644 src/Form/OptionsFactory.php diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 6beb987..993521b 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -1,20 +1,20 @@ get('site', 'template') : 'modern'); } @@ -184,7 +188,12 @@ class Component return $model; } - public function options($key, $val, $res/*: PDOStatement*/) { + /** + * @param string $key + * @param string $val + * @param $res + */ + public function options(string $key, string $val, $res) { $result = []; while($res->next()) { $result[] = ['value' => $res->getString($key), 'name' => $res->getString($val)]; @@ -192,7 +201,7 @@ class Component return $result; } - public function optionsPair($list, $selected = false) { + public function optionsPair(array $list, $selected = false) { $result = []; foreach ($list as $key => $value) { $result [] = ['value' => $key, 'name' => $value, 'selected' => $key == $selected]; @@ -200,7 +209,13 @@ class Component return $result; } - function findFile($pathList, $name) { + /** + * Найти файл по пути + * @param string[] $pathList + * @param string $name + * @return string|null + */ + function findFile(array $pathList, string $name) { foreach($pathList as $item) { $filename = Path::join($item, $name); if (file_exists($filename)) { @@ -223,6 +238,8 @@ class Component /** * Генерация интерфейса для выбора галлереи фотографии + * @param Composite $view + * @param \ctiso\Form\OptionsFactory $options */ public function setParameters(Composite $view, $options = null) { @@ -245,10 +262,12 @@ class Component /** * Обьеденить с ComponentFactory + * @param string $expression + * @param SiteInterface $site + * @return Component */ - static function loadComponent($expression, $site/*: SiteInterface*/) + static function loadComponent(string $expression, $site) { - $expression = htmlspecialchars_decode($expression); $offset = strpos($expression, '?'); $url = parse_url($expression); @@ -261,16 +280,18 @@ class Component parse_str($query, $arguments); } $name = $path; - $config = $site->config; + $config = $site->getConfig(); $filename = ucfirst($name); $path = Path::join ($config->get('site', 'components'), $name, $filename . '.php'); $className = implode("\\", ['Components', ucfirst($name), $filename]); - $component/*: Component*/ = null; + /** + * @var ?Component $component + */ + $component = null; if (file_exists($path)) { - // require_once ($path); $component = new $className(); $component->viewPath = [$config->get('site', 'components') . '/' . $name . '/']; @@ -279,7 +300,7 @@ class Component } else { $component = new $className(); - $template = $component->getTemplateName($site->config); + $template = $component->getTemplateName($site->getConfig()); $component->viewPath = [ // Сначало ищем локально @@ -308,7 +329,7 @@ class Component $db = $site->getDatabase(); $component->db = $db; - $component->config = $site->config; + $component->config = $site->getConfig(); $component->site = $site; $stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?"); @@ -344,7 +365,7 @@ class Component $editor = $component->getEditUrl(); if ($editor) { - $site->componentsConfig[] = $editor; + $site->addComponentConfig($editor); } return $component; @@ -354,12 +375,15 @@ class Component return null; } - function raw_query($request/*: ComponentRequest*/) + /** + * @param ComponentRequest $request + */ + function raw_query($request) { $arr = $request->r->export('get'); $param = []; - $parameter/*: Collection*/ = $this->parameter; + $parameter = $this->parameter; foreach($parameter->export() as $key => $value) { $param[$key] = $value; } @@ -377,7 +401,10 @@ class Component } - function query($request/*: ComponentRequest*/, $list) + /** + * @param ComponentRequest $request + */ + function query($request, $list) { $arr = $request->r->export('get'); @@ -393,6 +420,9 @@ class Component $this->site->addRequireJsPath($name, $path, $shim); } - function actionIndex($request/*: ComponentRequest*/) { + /** + * @param ComponentRequest $request + */ + function actionIndex($request) { } } diff --git a/src/Controller/SiteInterface.php b/src/Controller/SiteInterface.php index 1125601..e5abe67 100644 --- a/src/Controller/SiteInterface.php +++ b/src/Controller/SiteInterface.php @@ -4,9 +4,14 @@ namespace ctiso\Controller; interface SiteInterface { function getResource(); - function loadComponent($expression); function getDatabase(); function getConfig(); - function setComponentConfig($config); - function addRequireJsPath($name, $path, $schim = null); + function getTheme(); + function addComponentConfig($config); + function addRequireJsPath(string $name, string $path, ?array $shim = null); + function addStyleSheet(string $url); + + function loadComponent(string $expression); + function findTemplate(string $name); + function replaceImg(string $src, int $width, int $height); } diff --git a/src/Form/Form.php b/src/Form/Form.php index b634115..30450d8 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -16,8 +16,8 @@ use ctiso\Form\Field, * Форма для ввода */ class Form { - public $field = array(); //Поля формы - public $fieldsets = array(); //Группы полей (fieldset). Некоторые поля могут не принадлежать никаким группам + public $field = []; //Поля формы + public $fieldsets = []; //Группы полей (fieldset). Некоторые поля могут не принадлежать никаким группам public $action = ""; public $method = 'post'; @@ -26,9 +26,9 @@ class Form { protected $replace; protected $before; - public $_title = array(); - public $alias = array(); - private $constructor = array(); + public $_title = []; + public $alias = []; + private $constructor = []; /** * Строим форму по ее структуре. Каждому типу соответствует определенный класс. @@ -183,7 +183,7 @@ class Form { { $this->field[$name]->setValue($value); } - + function execute() { return $this; diff --git a/src/Form/OptionsFactory.php b/src/Form/OptionsFactory.php new file mode 100644 index 0000000..8921b56 --- /dev/null +++ b/src/Form/OptionsFactory.php @@ -0,0 +1,7 @@ +