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