chore: Проверки к типам
This commit is contained in:
parent
5d3fae4249
commit
8786e84568
12 changed files with 41 additions and 47 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 Веместо его нужно использовать автозагрузку
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,9 +120,9 @@ class 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);
|
||||
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'] : '');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 ??
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -219,9 +219,9 @@ class View extends \stdClass
|
|||
}
|
||||
|
||||
/**
|
||||
* @return View|string|false
|
||||
* Шаблон всегда возвращает строку
|
||||
*/
|
||||
function execute() {
|
||||
function execute(): string {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue