From b20ea0e7dc1f61cc3fc3fb0be3cbddb135551816 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Wed, 12 Nov 2025 19:41:24 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=94=D0=BE=D0=BF.=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 30 +-------------------------- src/Session.php | 3 ++- src/Settings.php | 4 ++-- src/Tools/SQLStatementExtractor.php | 6 +++--- src/Validator/Rule/PregMatch.php | 2 +- src/View/Composite.php | 5 +++-- src/View/FakeTemplate.php | 32 +++++++++++++++++++++++++++++ src/View/Plain.php | 2 +- 8 files changed, 45 insertions(+), 39 deletions(-) create mode 100644 src/View/FakeTemplate.php diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 6cdb811..18d1320 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -16,35 +16,7 @@ use ctiso\Controller\SiteInterface; use ctiso\Database\PDOStatement; use PHPTAL; use PHPTAL_PreFilter_Normalize; - -class FakeTemplate { - /** @var array */ - public $_data = []; - /** @var string */ - public $_name = ''; - - /** - * @param string $name - */ - function __construct($name) { - $this->_name = $name; - } - - /** - * @param string $key - * @param mixed $value - */ - function __set($key, $value): void { - $this->_data[$key] = $value; - } - - /** - * @return string - */ - function execute() { - return json_encode($this->_data); - } -} +use ctiso\View\FakeTemplate; /** * Класс компонента diff --git a/src/Session.php b/src/Session.php index 028e190..bf17b0c 100644 --- a/src/Session.php +++ b/src/Session.php @@ -15,7 +15,8 @@ class Session function set(string|array $key, mixed $value): void { if (is_array($key)) { - $_SESSION[strtolower(get_class($key[0]))][$key[1]] = $value; + $className = get_class($key[0]); + $_SESSION[strtolower($className)][$key[1]] = $value; } else { $_SESSION[$key] = $value; } diff --git a/src/Settings.php b/src/Settings.php index e678ea5..d6958c3 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -184,7 +184,7 @@ class Settings /** * Запись настроек в файл (Может переименовать в store) * - * @param File $file + * @param string $file * @return void */ public function write($file = null) @@ -199,7 +199,7 @@ class Settings $result = var_export($this->data, true); $result = ""; } - file_put_contents (($file) ? $file : $this->file, $result); + file_put_contents(($file) ? $file : $this->file, $result); } /** diff --git a/src/Tools/SQLStatementExtractor.php b/src/Tools/SQLStatementExtractor.php index c022ed8..5041e69 100644 --- a/src/Tools/SQLStatementExtractor.php +++ b/src/Tools/SQLStatementExtractor.php @@ -66,8 +66,8 @@ class SQLStatementExtractor /** * Extract SQL statements from array of lines. * - * @param list $lines Lines of the read-in file. - * @return list + * @param string[] $lines Lines of the read-in file. + * @return string[] SQL statements */ protected static function extractStatements($lines) { @@ -177,6 +177,6 @@ class SQLStatementExtractor protected static function getLines(string $buffer): array { $lines = preg_split("/\r?\n|\r/", $buffer); - return $lines; + return $lines === false ? [] : $lines; } } diff --git a/src/Validator/Rule/PregMatch.php b/src/Validator/Rule/PregMatch.php index 6b7f75c..71e4252 100644 --- a/src/Validator/Rule/PregMatch.php +++ b/src/Validator/Rule/PregMatch.php @@ -15,6 +15,6 @@ class PregMatch extends AbstractRule public function isValid(Collection $container, $status = null): bool { - return preg_match($this->pattern, $container->get($this->field)); + return preg_match($this->pattern, $container->get($this->field)) !== false; } } diff --git a/src/View/Composite.php b/src/View/Composite.php index 531f470..edfaafb 100644 --- a/src/View/Composite.php +++ b/src/View/Composite.php @@ -1,8 +1,9 @@ _name = $name; + } + + /** + * @param string $key + * @param mixed $value + */ + function __set($key, $value): void { + $this->_data[$key] = $value; + } + + /** + * @return string + */ + function execute() { + return json_encode($this->_data); + } +} diff --git a/src/View/Plain.php b/src/View/Plain.php index f6fc13e..f070d3d 100644 --- a/src/View/Plain.php +++ b/src/View/Plain.php @@ -71,6 +71,6 @@ class Plain extends \stdClass include ($document); $content = ob_get_contents (); ob_clean (); - return $content; + return $content === false ? '' : $content; } }