chore: Проверки для типов
This commit is contained in:
parent
6fdc3eb46b
commit
5d3fae4249
15 changed files with 125 additions and 42 deletions
|
|
@ -205,7 +205,7 @@ class Action implements ActionInterface
|
|||
/**
|
||||
* Выполнение действия
|
||||
* @param HttpRequest $request
|
||||
* @return View|string
|
||||
* @return View|string|false
|
||||
*/
|
||||
public function execute(HttpRequest $request)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -96,11 +96,12 @@ class Component
|
|||
}
|
||||
|
||||
$this->before();
|
||||
if (method_exists($this, $action)) {
|
||||
return call_user_func([$this, $action], $crequest);
|
||||
} else {
|
||||
return $this->actionIndex($crequest);
|
||||
$actionMethod = [$this, $action];
|
||||
if (is_callable($actionMethod)) {
|
||||
return call_user_func($actionMethod, $crequest);
|
||||
}
|
||||
|
||||
return $this->actionIndex($crequest);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ namespace ctiso {
|
|||
* Извлекает из базы все элементы по запросу (Для совместимости со старым представлением баз данных CIS)
|
||||
* @param string $query - запрос
|
||||
* @param ?array<string, mixed> $values - значения
|
||||
* @return list<array<string, mixed>>
|
||||
* @return array<array<string, mixed>>
|
||||
*/
|
||||
public function fetchAllArray($query, $values = null)
|
||||
{
|
||||
|
|
@ -212,6 +212,9 @@ namespace ctiso {
|
|||
return $result[$index];
|
||||
} else {
|
||||
$result = $this->fetchOneArray("SELECT $index AS lastid FROM $table WHERE OID = last_insert_rowid()");
|
||||
if ($result === false) {
|
||||
throw new \RuntimeException("Ошибка получения идентификатора");
|
||||
}
|
||||
return $result['lastid'];
|
||||
}
|
||||
}
|
||||
|
|
@ -255,6 +258,9 @@ namespace ctiso {
|
|||
function getNextId($seq)
|
||||
{
|
||||
$result = $this->fetchOneArray("SELECT nextval('$seq')");
|
||||
if ($result === false) {
|
||||
throw new \RuntimeException("Ошибка получения следующего идентификатора");
|
||||
}
|
||||
return $result['nextval'];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,27 +8,67 @@ use ctiso\Path;
|
|||
use Exception;
|
||||
|
||||
/**
|
||||
* @phpstan-type Action array{
|
||||
* type:string,
|
||||
* @phpstan-type DropAction array{
|
||||
* type:"dropTable",
|
||||
* table_name:string
|
||||
* }
|
||||
*
|
||||
* @phpstan-type CreateAction array{
|
||||
* type:"createTable",
|
||||
* table_name:string,
|
||||
* table:string,
|
||||
* fields:array<mixed>,
|
||||
* field: ColumnProps,
|
||||
* constraints:?array<mixed>,
|
||||
* references:?array<mixed>,
|
||||
* fields:array<mixed>,
|
||||
* }
|
||||
*
|
||||
* @phpstan-type AddColumnAction array{
|
||||
* type:"addColumn",
|
||||
* table_name:string,
|
||||
* column_name:string,
|
||||
* field:ColumnProps
|
||||
* }
|
||||
*
|
||||
* @phpstan-type AlterReferenceAction array{
|
||||
* type:"alterReference",
|
||||
* table:string,
|
||||
* column:string,
|
||||
* refTable:string,
|
||||
* refColumn:string
|
||||
* }
|
||||
*
|
||||
* @phpstan-type RenameColumnAction array{
|
||||
* type:"renameColumn",
|
||||
* table:string,
|
||||
* old_name:string,
|
||||
* new_name:string
|
||||
* }
|
||||
*
|
||||
* @phpstan-type ExecuteFileAction array{
|
||||
* type:"executeFile",
|
||||
* source:string,
|
||||
* pgsql?:string,
|
||||
* old_name?:string,
|
||||
* new_name?:string,
|
||||
* column?:string,
|
||||
* column_name?:string,
|
||||
* refTable?:string,
|
||||
* refColumn?:string,
|
||||
* values:array<mixed>,
|
||||
* pgsql:?string
|
||||
* }
|
||||
*
|
||||
* @phpstan-type CreateViewAction array{
|
||||
* type:"createView",
|
||||
* view:string,
|
||||
* select:string
|
||||
* }
|
||||
*
|
||||
* @phpstan-type InsertAction array{
|
||||
* type:"insert",
|
||||
* table_name:string,
|
||||
* values:array<mixed>
|
||||
* }
|
||||
*
|
||||
* @phpstan-type Action DropAction
|
||||
* | CreateAction
|
||||
* | AddColumnAction
|
||||
* | AlterReferenceAction
|
||||
* | RenameColumnAction
|
||||
* | ExecuteFileAction
|
||||
* | CreateViewAction
|
||||
* | InsertAction
|
||||
*
|
||||
* @phpstan-type ColumnProps array{
|
||||
* name:string,
|
||||
* type:string,
|
||||
|
|
@ -266,7 +306,7 @@ class Manager
|
|||
* @example createTableQuery('users',['id'=>['type'=>'integer','constraint'=>'PRIMARY KEY']])
|
||||
* @param string $table
|
||||
* @param array $fields
|
||||
* @param array|string|null $constraints
|
||||
* @param array{fields: array<string>, type: string}|string|null $constraints
|
||||
*/
|
||||
public function createTableQuery($table, $fields, $constraints): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -111,8 +111,11 @@ class Mail
|
|||
if (file_exists($filename)) {
|
||||
$file = fopen($filename, "rb");
|
||||
if (is_resource($file)) {
|
||||
$data = fread($file, filesize($filename));
|
||||
$this->attachment[] = ($name) ? [$data, $name] : [$data, basename($filename)];
|
||||
$size = filesize($filename);
|
||||
if ($size !== false && $size > 0) {
|
||||
$data = fread($file, $size);
|
||||
$this->attachment[] = ($name) ? [$data, $name] : [$data, basename($filename)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class Primitive {
|
|||
|
||||
if ($month != 0 && $day != 0 && $year != 0) {
|
||||
if (checkdate($month, $day, $year)) {
|
||||
return mktime(0, 0, 0, $month, $day, $year);
|
||||
return mktime(0, 0, 0, $month, $day, $year) ?: 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ class Primitive {
|
|||
$tmp = [];
|
||||
if (preg_match('/(\d+)-(\d+)-(\d+)T(\d+):(\d+)Z/', $value, $tmp)) {
|
||||
if (checkdate((int)$tmp[2], (int)$tmp[3], (int)$tmp[1])) {
|
||||
$result = mktime((int)$tmp[4], (int)$tmp[5], 0, (int)$tmp[2], (int)$tmp[3], (int)$tmp[1]);
|
||||
$result = mktime((int)$tmp[4], (int)$tmp[5], 0, (int)$tmp[2], (int)$tmp[3], (int)$tmp[1]) ?: 0;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class User implements UserInterface
|
|||
* @param PDOStatement $result
|
||||
* @return PDOStatement|bool
|
||||
*/
|
||||
function setSID(string $random, $result)
|
||||
function setSID(string $random, $result)
|
||||
{
|
||||
return $this->db->executeQuery("UPDATE users SET sid = :sid, trie_count = 0 WHERE id_user = :user", [
|
||||
'user' => $result->getInt('id_user'),
|
||||
|
|
@ -115,6 +115,9 @@ class User implements UserInterface
|
|||
|
||||
function updateTries(string $login): void {
|
||||
$user = $this->db->fetchOneArray("SELECT id_user, trie_count FROM users WHERE login = :login", ['login' => $login]);
|
||||
if ($user === false) {
|
||||
return;
|
||||
}
|
||||
$this->db->executeQuery(
|
||||
"UPDATE users SET trie_time = :cur_time, trie_count = :count WHERE id_user = :id_user",
|
||||
['cur_time' => time(), 'count' => $user['trie_count']+1, 'id_user' => $user['id_user']]
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ class Session
|
|||
{
|
||||
if (is_array($key)) {
|
||||
$className = get_class($key[0]);
|
||||
/*if ($className === false) {
|
||||
throw new \RuntimeException("Invalid class name " . $className);
|
||||
}*/
|
||||
$_SESSION[strtolower($className)][$key[1]] = $value;
|
||||
} else {
|
||||
$_SESSION[$key] = $value;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,11 @@ class Setup
|
|||
public function __construct($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->node = simplexml_load_file($file);
|
||||
$node = simplexml_load_file($file);
|
||||
if ($node === false) {
|
||||
throw new \RuntimeException("Can't load file $file");
|
||||
}
|
||||
$this->node = $node;
|
||||
|
||||
$this->target = '';
|
||||
$this->source = '';
|
||||
|
|
@ -127,7 +131,7 @@ class Setup
|
|||
|
||||
/**
|
||||
* Заменяет переменные на их значения в строке
|
||||
* @param list<string> $match массив совпадения
|
||||
* @param array<string> $match массив совпадения
|
||||
* @return string
|
||||
*/
|
||||
function replaceVariable(array $match)
|
||||
|
|
@ -147,7 +151,7 @@ class Setup
|
|||
{
|
||||
$result = [];
|
||||
foreach ($attributes as $key => $value) {
|
||||
$result[$key] = preg_replace_callback("/\\\${(\w+)}/", [$this, 'replaceVariable'], $value);
|
||||
$result[$key] = preg_replace_callback("/\\\${(\w+)}/", $this->replaceVariable(...), $value);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ class Drawing
|
|||
$temp_x = $x;
|
||||
for ($i = 0; $i < mb_strlen($text); $i++) {
|
||||
$bbox = imagettftext($image, $size, $angle, $temp_x, $y, $color, $font, $text[$i]);
|
||||
$temp_x += $spacing + ($bbox[2] - $bbox[0]);
|
||||
$temp_x += $spacing + ($bbox !== false ? ($bbox[2] - $bbox[0]) : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,11 @@ class Image
|
|||
{
|
||||
$width = imagesx($image);
|
||||
$height = imagesy($image);
|
||||
|
||||
$percent = min($prewidth / $width, $preheight / $height);
|
||||
if ($percent > 1 && !$force) $percent = 1;
|
||||
if ($percent > 1 && !$force) {
|
||||
$percent = 1;
|
||||
}
|
||||
$new_width = $width * $percent;
|
||||
$new_height = $height * $percent;
|
||||
|
||||
|
|
|
|||
|
|
@ -89,8 +89,8 @@ class TemplateImage
|
|||
|
||||
/**
|
||||
* Создает пустое изображение
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
* @param int<1, max> $width
|
||||
* @param int<1, max> $height
|
||||
*/
|
||||
function setEmptyImage($width, $height): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use ctiso\Validator\Rule\AbstractRule,
|
|||
|
||||
class Time extends AbstractRule
|
||||
{
|
||||
/** @var non-empty-string */
|
||||
private string $split = ":";
|
||||
|
||||
public function getErrorMsg(): string
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ use Exception;
|
|||
|
||||
class View extends \stdClass
|
||||
{
|
||||
protected array $_section = []; // Вложенные шаблоны
|
||||
// Блоки
|
||||
/** @var string[] $_stylesheet */
|
||||
protected array $_stylesheet = []; // Массив стилей текущего шаблона
|
||||
/** @var string[] $_script */
|
||||
protected array $_script = []; // Массив скриптов текущего шаблона
|
||||
/** @var array<View|string> Вложенные шаблоны */
|
||||
protected array $_section = [];
|
||||
|
||||
/** @var string[] $_stylesheet Массив стилей текущего шаблона */
|
||||
protected array $_stylesheet = [];
|
||||
/** @var string[] $_script Массив скриптов текущего шаблона */
|
||||
protected array $_script = [];
|
||||
/** @var string[] $_scriptstring */
|
||||
public array $_scriptstring = [];
|
||||
/** @var string[] $_startup */
|
||||
|
|
@ -46,7 +47,7 @@ class View extends \stdClass
|
|||
*/
|
||||
public function setView($section, $view): void
|
||||
{
|
||||
$this->_section [$section] = $view;
|
||||
$this->_section[$section] = $view;
|
||||
if (is_object($view)) {
|
||||
$view->parent_view = $this;
|
||||
}
|
||||
|
|
@ -122,6 +123,14 @@ class View extends \stdClass
|
|||
return $result;
|
||||
}
|
||||
|
||||
/*
|
||||
function getTitleArray(): array {
|
||||
return array_reduce($this->_section, fn ($result, $item) =>
|
||||
is_object($item) ? array_merge($result, $item->getTitleArray()) : $result, []);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*abstract*/ public function set(string $key, mixed $value): void
|
||||
{
|
||||
}
|
||||
|
|
@ -208,4 +217,11 @@ class View extends \stdClass
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return View|string|false
|
||||
*/
|
||||
function execute() {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,15 @@ class ZipFile extends ZipArchive
|
|||
|
||||
// Read all Files in Dir
|
||||
$dir = opendir($location);
|
||||
if (!$dir) {
|
||||
throw new \RuntimeException("Enable to open dir '$dir'");
|
||||
}
|
||||
while (($file = readdir($dir)) !== false)
|
||||
{
|
||||
if (in_array($file, $this->ignore)) continue;
|
||||
// Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
|
||||
$call = (is_dir($location . $file)) ? 'addDir' : 'addFile';
|
||||
call_user_func([$this, $call], $location . $file, $name . $file);
|
||||
$call = (is_dir($location . $file)) ? $this->addDir(...) : $this->addFile(...);
|
||||
call_user_func($call, $location . $file, $name . $file);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue