diff --git a/src/Collection.php b/src/Collection.php index 430cc69..cf8b814 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -58,23 +58,12 @@ class Collection implements \ArrayAccess /** * @param string $key - * @param int $default + * @param int $default * @return int */ - public function getInt(string $key, int $default = 0): int + public function getInt($key, $default = 0) { - $value = $this->get($key); - - // Фильтруем как целое число - if (is_numeric($value)) { - // Приводим к int, но сначала проверим, что не float с дробной частью - $floatVal = (float)$value; - if (is_finite($floatVal) && floor($floatVal) === $floatVal) { - return (int)$floatVal; - } - } - - return $default; + return (int)$this->get($key, $default); } /** @@ -84,59 +73,15 @@ class Collection implements \ArrayAccess */ public function getString(string $key, string $default = ''): string { - $value = $this->get($key); - - if (is_string($value)) { - return $value; - } - - if (is_numeric($value)) { - return (string)$value; - } - - return $default; + return (string)$this->get($key, $default); } - /** - * Получает булево значение - * Поддерживает: 1, '1', 'true', 'on', 'yes' → true - * Иначе → false - */ - public function getBool(string $key, bool $default = false): bool - { - $value = $this->get($key); - - if (is_bool($value)) { - return $value; - } - - if (is_string($value)) { - $value = strtolower(trim($value)); - return in_array($value, ['1', 'true', 'on', 'yes'], true); - } - - if (is_numeric($value)) { - return (bool)$value; - } - - return $default; - } - - function getArray(string $key, array $default = []): array { - $result = $this->get($key); - if (is_array($result)) { - return $result; - } - return $default; - } - - /** * @param string $key * @param int $default * @return int */ - public function getNat(string $key, int $default = 1): int + public function getNat($key, $default = 1) { $result = (int)$this->get($key, $default); return (($result > 0) ? $result : $default); diff --git a/src/Connection/HttpResponse.php b/src/Connection/HttpResponse.php index fad35ab..9f0fe69 100644 --- a/src/Connection/HttpResponse.php +++ b/src/Connection/HttpResponse.php @@ -47,12 +47,12 @@ class HttpResponse if (isset($this->param['Transfer-Encoding']) && $this->param['Transfer-Encoding'] == 'chunked') { //$this->data = substr($this->response, $this->offset); - $index = (int)hexdec($this->getLine()); + $index = hexdec($this->getLine()); $chunk = []; while ($index > 0) { $chunk [] = substr($this->response, $this->offset, $index); $this->offset += $index; - $index = (int)hexdec($this->getLine()); + $index = hexdec($this->getLine()); } $this->data = implode("", $chunk); diff --git a/src/Controller/Action.php b/src/Controller/Action.php index 84cf844..13b7ba8 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -111,7 +111,7 @@ class Action implements ActionInterface * @param int $size * @return string Путь к иконке */ - function findIcon($icon, $size) { + function findIcon($icon, $size): string { $webPath = $this->config->get('site', 'web'); return Path::join($webPath, 'icons', $size . 'x' . $size, $icon . '.png'); } @@ -119,8 +119,8 @@ class Action implements ActionInterface /** * Создает представление * @param string $name - * @param class-string $viewClass - * @return Composite + * @param class-string $viewClass + * @return View */ public function getView($name, $viewClass = Composite::class) { @@ -143,7 +143,7 @@ class Action implements ActionInterface /** @var \ctiso\View\Composite */ $tpl = new $viewClass($template); - $tpl->config = $this->config; + $tpl->set('config', $this->config); $stylePath = Path::join($webPath, "assets", "css"); $iconsPath = Path::join($webPath, 'icons'); @@ -231,7 +231,7 @@ class Action implements ActionInterface /** * Страница по умолчанию * @param HttpRequest $request - * @return string|false + * @return View|string */ public function actionIndex(HttpRequest $request) { return ""; diff --git a/src/Controller/ActionInterface.php b/src/Controller/ActionInterface.php index 4c8dbf6..ddb2ff6 100644 --- a/src/Controller/ActionInterface.php +++ b/src/Controller/ActionInterface.php @@ -2,6 +2,7 @@ namespace ctiso\Controller; +use ctiso\View\Template; use ctiso\Database; use ctiso\HttpRequest; @@ -10,14 +11,14 @@ interface ActionInterface { * Действие может вернуть Шаблон или строку * * @param HttpRequest $request - * @return \ctiso\View\View|string|false + * @return Template|string|false */ function execute(HttpRequest $request); function getConnection(): Database; /** * @param string $name - * @param class-string<\ctiso\View\View> $class - * @return \ctiso\View\View + * @param class-string