chore: Проверки к типам

This commit is contained in:
origami11@yandex.ru 2025-12-01 19:44:22 +03:00
parent 5d3fae4249
commit 8786e84568
12 changed files with 41 additions and 47 deletions

View file

@ -73,7 +73,11 @@ class HttpRequest
public function setUrl($url): void public function setUrl($url): void
{ {
$this->url = $url; $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 public function getUrl(): string

View file

@ -41,8 +41,8 @@ class Action implements ActionInterface
/** @var ?\ctiso\Filter\ActionLogger Обьект для ведения лога */ /** @var ?\ctiso\Filter\ActionLogger Обьект для ведения лога */
public $logger = null; public $logger = null;
/** @var Factory Обьект для создания моделей */ /** @var Factory Обьект для создания моделей */
private $factory = null; // Ссылка на обьект создания модели private $factory = null;
private array $helpers = []; // Помошники для действий
/** @var ?Url Параметры для ссылки */ /** @var ?Url Параметры для ссылки */
public $part = null; public $part = null;
@ -99,7 +99,6 @@ class Action implements ActionInterface
* @param string $name * @param string $name
*/ */
public function addSuggest(View $view, $name): void { public function addSuggest(View $view, $name): void {
$suggest = [];
$file = Path::join($this->modulePath, 'help', $name . '.suggest'); $file = Path::join($this->modulePath, 'help', $name . '.suggest');
if (file_exists($file)) { if (file_exists($file)) {
$view->suggestions = include($file); $view->suggestions = include($file);
@ -131,7 +130,8 @@ class Action implements ActionInterface
$webPath = $this->config->get('system', 'web'); $webPath = $this->config->get('system', 'web');
$list = [ $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") 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)); 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 Веместо его нужно использовать автозагрузку * @deprecated Веместо его нужно использовать автозагрузку

View file

@ -7,8 +7,10 @@ use ctiso\HttpRequest;
interface ActionInterface { interface ActionInterface {
/** /**
* Действие может вернуть Шаблон или строку
*
* @param HttpRequest $request * @param HttpRequest $request
* @return mixed * @return \ctiso\View\View|string|false
*/ */
function execute(HttpRequest $request); function execute(HttpRequest $request);
function getConnection(): Database; function getConnection(): Database;

View file

@ -63,6 +63,9 @@ class Login extends Filter
$db = Database::getConnection($dsn); $db = Database::getConnection($dsn);
$user = $db->fetchOneArray("SELECT * FROM users WHERE login = :login", ['login' => $login]); $user = $db->fetchOneArray("SELECT * FROM users WHERE login = :login", ['login' => $login]);
if ($user === false) {
return false;
}
$userPassword = $user['password']; $userPassword = $user['password'];
} /*else if (time() - $result->getInt('lastupdate') > 60*60*24*60) { } /*else if (time() - $result->getInt('lastupdate') > 60*60*24*60) {
// Проверить давность пароля, 60 дней // Проверить давность пароля, 60 дней
@ -184,7 +187,7 @@ class Login extends Filter
} }
} else if (isset($_SERVER['HTTP_REFERER'])) { } else if (isset($_SERVER['HTTP_REFERER'])) {
$arr = []; $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') { if (isset($arr['back_page']) && $request->get('mode') != 'ajax') {
$request->redirect($arr['back_page']); $request->redirect($arr['back_page']);
} }

View file

@ -188,7 +188,11 @@ class Form {
{ {
foreach ($schema as $key => $conv) { foreach ($schema as $key => $conv) {
list($value, $type) = $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));
} }
} }

View file

@ -39,7 +39,7 @@ class Manager extends Filter
/** /**
* @param HttpRequest $request * @param HttpRequest $request
* @param array $get * @param array|true $get
* @return bool * @return bool
*/ */
public function checkGet($request, $get) public function checkGet($request, $get)
@ -85,7 +85,7 @@ class Manager extends Filter
$layout = $condition[1]; $layout = $condition[1];
$view = $layout->execute($request); $view = $layout->execute($request);
if (is_object($view)) { if (is_object($view)) {
return $view->render(); return $view->execute();
} else { } else {
return $view; return $view;
} }

View file

@ -120,9 +120,9 @@ class Path
* Преобразует строку пути в массив * Преобразует строку пути в массив
* *
* @param string $path Путь * @param string $path Путь
* @return array<string> * @return list<string>|false
*/ */
public static function listFromString(string $path): array public static function listFromString(string $path): array|false
{ {
$list = preg_split('#\\\\|/#s', $path); $list = preg_split('#\\\\|/#s', $path);
return $list; return $list;
@ -182,7 +182,7 @@ class Path
. $path['host'] . $path['host']
. (isset($path['port']) ? ':' . $path['port'] : '')) : '') . (isset($path['port']) ? ':' . $path['port'] : '')) : '')
. $slash . $slash
. $path['path'] . ($path['path'] ?? '')
. (isset($path['query']) ? '?' . $path['query'] : '') . (isset($path['query']) ? '?' . $path['query'] : '')
. (isset($path['fragment']) ? '#' . $path['fragment'] : ''); . (isset($path['fragment']) ? '#' . $path['fragment'] : '');
} }

View file

@ -33,7 +33,11 @@ function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\")
function process_exists($pid) function process_exists($pid)
{ {
if (PHP_OS == 'WINNT') { 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) { foreach ($processes as $process) {
if ($process != "") { if ($process != "") {
$csv = str_getcsv($process); $csv = str_getcsv($process);

View file

@ -81,6 +81,9 @@ class Drawing
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$item = $words[$i]; $item = $words[$i];
$dimensions = imagettfbbox($size, $angle, $font, $current_line . ($first_word ? '' : ' ') . $item); $dimensions = imagettfbbox($size, $angle, $font, $current_line . ($first_word ? '' : ' ') . $item);
if ($dimensions === false) {
continue;
}
$line_width = $dimensions[2] - $dimensions[0]; $line_width = $dimensions[2] - $dimensions[0];
$line_height = $dimensions[1] - $dimensions[7]; $line_height = $dimensions[1] - $dimensions[7];

View file

@ -30,9 +30,8 @@ class Image
if ($percent > 1 && !$force) { if ($percent > 1 && !$force) {
$percent = 1; $percent = 1;
} }
$new_width = $width * $percent; $new_width = max(1, (int)($width * $percent));
$new_height = $height * $percent; $new_height = max(1, (int)($height * $percent));
$image_p = imagecreatetruecolor($new_width, $new_height); $image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

View file

@ -45,7 +45,8 @@ class Top extends Composite
* *
* @return string * @return string
*/ */
public function render() #[\Override]
public function execute(): string
{ {
$this->doTree('alias'); $this->doTree('alias');
@ -107,7 +108,7 @@ class Top extends Composite
$this->set('title', $this->getTitle()); $this->set('title', $this->getTitle());
$this->set('jspath', $this->config->get('system', 'web')); $this->set('jspath', $this->config->get('system', 'web'));
// //
return $this->execute(); // execute+phptal ?? return parent::execute(); // execute+phptal ??
} }
/** /**

View file

@ -219,9 +219,9 @@ class View extends \stdClass
} }
/** /**
* @return View|string|false * Шаблон всегда возвращает строку
*/ */
function execute() { function execute(): string {
return ''; return '';
} }
} }