From 8786e845680ba4a6011aff3ab6d4944778a36ce4 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Mon, 1 Dec 2025 19:44:22 +0300 Subject: [PATCH] =?UTF-8?q?chore:=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BA=20=D1=82=D0=B8=D0=BF=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Connection/HttpRequest.php | 6 +++++- src/Controller/Action.php | 34 ++++-------------------------- src/Controller/ActionInterface.php | 4 +++- src/Filter/Login.php | 5 ++++- src/Form/Form.php | 6 +++++- src/Layout/Manager.php | 4 ++-- src/Path.php | 6 +++--- src/Process.php | 6 +++++- src/Tools/Drawing.php | 3 +++ src/Tools/Image.php | 5 ++--- src/View/Top.php | 5 +++-- src/View/View.php | 4 ++-- 12 files changed, 41 insertions(+), 47 deletions(-) diff --git a/src/Connection/HttpRequest.php b/src/Connection/HttpRequest.php index 5c71f1d..368feda 100644 --- a/src/Connection/HttpRequest.php +++ b/src/Connection/HttpRequest.php @@ -73,7 +73,11 @@ class HttpRequest public function setUrl($url): void { $this->url = $url; - $this->host = parse_url($this->url, PHP_URL_HOST); + $host = parse_url($this->url, PHP_URL_HOST); + if (!$host) { + throw new \RuntimeException("Не удалось получить хост"); + } + $this->host = $host; } public function getUrl(): string diff --git a/src/Controller/Action.php b/src/Controller/Action.php index 8c57a29..e26b41e 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -41,8 +41,8 @@ class Action implements ActionInterface /** @var ?\ctiso\Filter\ActionLogger Обьект для ведения лога */ public $logger = null; /** @var Factory Обьект для создания моделей */ - private $factory = null; // Ссылка на обьект создания модели - private array $helpers = []; // Помошники для действий + private $factory = null; + /** @var ?Url Параметры для ссылки */ public $part = null; @@ -99,7 +99,6 @@ class Action implements ActionInterface * @param string $name */ public function addSuggest(View $view, $name): void { - $suggest = []; $file = Path::join($this->modulePath, 'help', $name . '.suggest'); if (file_exists($file)) { $view->suggestions = include($file); @@ -131,7 +130,8 @@ class Action implements ActionInterface $webPath = $this->config->get('system', 'web'); $list = [ - Path::join($this->modulePath, 'templates', $this->viewPathPrefix) => Path::join($webPath, "modules", $this->name, 'templates', $this->viewPathPrefix), + Path::join($this->modulePath, 'templates', $this->viewPathPrefix) + => Path::join($webPath, "modules", $this->name, 'templates', $this->viewPathPrefix), Path::join($basePath, "templates") => Path::join($webPath, "templates") ]; @@ -286,32 +286,6 @@ class Action implements ActionInterface return $this->nUrl($name, array_merge(['mode' => 'ajax'], $param)); } - /** - * Добавление помошника контроллера - * @param class-string $class - */ - public function addHelper($class): void - { - $this->helpers [] = $class; - } - - /** - * Вызов помошников контроллера - * @param HttpRequest $request - * @return mixed - */ - public function callHelpers(HttpRequest $request) - { - $action = self::ACTION_PREFIX . $request->getAction(); - foreach ($this->helpers as $helper) { - if (method_exists($helper, $action)) { - return call_user_func([$helper, $action], $request, $this); - } else { - return $helper->actionIndex($request, $this); // Вместо return response ??? - } - } - } - /** * Загрузка файла класса * @deprecated Веместо его нужно использовать автозагрузку diff --git a/src/Controller/ActionInterface.php b/src/Controller/ActionInterface.php index 97d3251..4c8dbf6 100644 --- a/src/Controller/ActionInterface.php +++ b/src/Controller/ActionInterface.php @@ -7,8 +7,10 @@ use ctiso\HttpRequest; interface ActionInterface { /** + * Действие может вернуть Шаблон или строку + * * @param HttpRequest $request - * @return mixed + * @return \ctiso\View\View|string|false */ function execute(HttpRequest $request); function getConnection(): Database; diff --git a/src/Filter/Login.php b/src/Filter/Login.php index f2d0c4f..d5195cb 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -63,6 +63,9 @@ class Login extends Filter $db = Database::getConnection($dsn); $user = $db->fetchOneArray("SELECT * FROM users WHERE login = :login", ['login' => $login]); + if ($user === false) { + return false; + } $userPassword = $user['password']; } /*else if (time() - $result->getInt('lastupdate') > 60*60*24*60) { // Проверить давность пароля, 60 дней @@ -184,7 +187,7 @@ class Login extends Filter } } else if (isset($_SERVER['HTTP_REFERER'])) { $arr = []; - parse_str(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY) ?? '', $arr); + parse_str(parse_url($_SERVER['HTTP_REFERER'] ?? '', PHP_URL_QUERY) ?? '', $arr); if (isset($arr['back_page']) && $request->get('mode') != 'ajax') { $request->redirect($arr['back_page']); } diff --git a/src/Form/Form.php b/src/Form/Form.php index 7bfde94..a425af1 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -188,7 +188,11 @@ class Form { { foreach ($schema as $key => $conv) { list($value, $type) = $conv; - $this->field [$key]->setValue(call_user_func([\ctiso\Primitive::class, 'from_' . $type], $data->$value)); + $convertFn = [\ctiso\Primitive::class, 'from_' . $type]; + if (!is_callable($convertFn)) { + throw new \Exception('Не найден метод преобразования ' . $type); + } + $this->field[$key]->setValue(call_user_func($convertFn, $data->$value)); } } diff --git a/src/Layout/Manager.php b/src/Layout/Manager.php index c256afb..45098d6 100644 --- a/src/Layout/Manager.php +++ b/src/Layout/Manager.php @@ -39,7 +39,7 @@ class Manager extends Filter /** * @param HttpRequest $request - * @param array $get + * @param array|true $get * @return bool */ public function checkGet($request, $get) @@ -85,7 +85,7 @@ class Manager extends Filter $layout = $condition[1]; $view = $layout->execute($request); if (is_object($view)) { - return $view->render(); + return $view->execute(); } else { return $view; } diff --git a/src/Path.php b/src/Path.php index 8754f7f..b9b386a 100644 --- a/src/Path.php +++ b/src/Path.php @@ -120,9 +120,9 @@ class Path * Преобразует строку пути в массив * * @param string $path Путь - * @return array + * @return list|false */ - public static function listFromString(string $path): array + public static function listFromString(string $path): array|false { $list = preg_split('#\\\\|/#s', $path); return $list; @@ -182,7 +182,7 @@ class Path . $path['host'] . (isset($path['port']) ? ':' . $path['port'] : '')) : '') . $slash - . $path['path'] + . ($path['path'] ?? '') . (isset($path['query']) ? '?' . $path['query'] : '') . (isset($path['fragment']) ? '#' . $path['fragment'] : ''); } diff --git a/src/Process.php b/src/Process.php index fd319f9..e0c9473 100644 --- a/src/Process.php +++ b/src/Process.php @@ -33,7 +33,11 @@ function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") function process_exists($pid) { if (PHP_OS == 'WINNT') { - $processes = explode("\n", shell_exec("tasklist.exe /NH /FO CSV")); + $content = shell_exec("tasklist.exe /NH /FO CSV"); + if (!$content) { + return false; + } + $processes = explode("\n", $content); foreach ($processes as $process) { if ($process != "") { $csv = str_getcsv($process); diff --git a/src/Tools/Drawing.php b/src/Tools/Drawing.php index 9758044..d950481 100644 --- a/src/Tools/Drawing.php +++ b/src/Tools/Drawing.php @@ -81,6 +81,9 @@ class Drawing for ($i = 0; $i < $count; $i++) { $item = $words[$i]; $dimensions = imagettfbbox($size, $angle, $font, $current_line . ($first_word ? '' : ' ') . $item); + if ($dimensions === false) { + continue; + } $line_width = $dimensions[2] - $dimensions[0]; $line_height = $dimensions[1] - $dimensions[7]; diff --git a/src/Tools/Image.php b/src/Tools/Image.php index ee04dcb..dd3ebd4 100644 --- a/src/Tools/Image.php +++ b/src/Tools/Image.php @@ -30,9 +30,8 @@ class Image if ($percent > 1 && !$force) { $percent = 1; } - $new_width = $width * $percent; - $new_height = $height * $percent; - + $new_width = max(1, (int)($width * $percent)); + $new_height = max(1, (int)($height * $percent)); $image_p = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); diff --git a/src/View/Top.php b/src/View/Top.php index 0a34cb1..2a7d7fe 100644 --- a/src/View/Top.php +++ b/src/View/Top.php @@ -45,7 +45,8 @@ class Top extends Composite * * @return string */ - public function render() + #[\Override] + public function execute(): string { $this->doTree('alias'); @@ -107,7 +108,7 @@ class Top extends Composite $this->set('title', $this->getTitle()); $this->set('jspath', $this->config->get('system', 'web')); // - return $this->execute(); // execute+phptal ?? + return parent::execute(); // execute+phptal ?? } /** diff --git a/src/View/View.php b/src/View/View.php index c4d4106..7d7776e 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -219,9 +219,9 @@ class View extends \stdClass } /** - * @return View|string|false + * Шаблон всегда возвращает строку */ - function execute() { + function execute(): string { return ''; } }