fix: noverify + типы для правил провеки

This commit is contained in:
origami11@yandex.ru 2025-01-21 19:33:33 +03:00
parent 9680409ba9
commit 90cbd3b2b6
10 changed files with 319 additions and 300 deletions

View file

@ -95,7 +95,7 @@ class Component
public function getView($name)
{
if ($this->output == 'json') {
if ($this->output === 'json') {
return new FakeTemplate($name);
}
@ -126,7 +126,7 @@ class Component
}
$tpl->stripComments(true);
$tpl->addPreFilter(new PHPTAL_PreFilter_Normalize());
$tpl->addPreFilter(new \PHPTAL_PreFilter_Normalize());
$tpl->set('common', Path::join($this->config->get('system', 'web'), '../', 'common'));
$tpl->set('script', Path::join($this->config->get('system', 'web'), 'js'));
@ -152,7 +152,7 @@ class Component
$registry = $this->config;
// Брать настройки из куков если есть
$template = ($this->template) ? $this->template : $this->getTemplateName($registry);
foreach ($this->viewPath as $index => $viewPath) {
foreach ($this->viewPath as $index => $_) {
if(is_dir(Path::join($this->viewPath[$index], 'templates', $template))) {
return Path::join($this->viewPath[$index], 'templates', $template, $name);
}

View file

@ -1,7 +1,8 @@
<?php
namespace {
if (!function_exists('sqliteLower')) {
function sqliteLower($str) {
function sqliteLower($str)
{
return mb_strtolower($str, 'UTF-8');
}
}
@ -28,7 +29,8 @@ class Database extends PDO
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]);
}
function prepare(string $sql, array $options = []): PDOStatement|false {
function prepare(string $sql, array $options = []): PDOStatement|false
{
$result/*: PDOStatement*/ = parent::prepare($sql, $options);
return $result;
}
@ -37,7 +39,8 @@ class Database extends PDO
{
return $this->dsn;
}
public function isPostgres(){
public function isPostgres()
{
return ($this->dsn["phptype"] == "pgsql");
}
/**
@ -164,15 +167,19 @@ class Database extends PDO
function updateQuery($table, array $values, $cond)
{
$prep = $this->prepareValues($values);
$sql = "UPDATE $table SET " . implode(",",
array_map(function($k,$v){return $k."=".$v;}, array_keys($values), array_keys($prep))) . " WHERE $cond";
$sql = "UPDATE $table SET " . implode(
",",
array_map(function ($k, $v) {
return $k . "=" . $v; }, array_keys($values), array_keys($prep))
) . " WHERE $cond";
$stmt = $this->prepare($sql);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute($prep);
}
function getIdGenerator() {
function getIdGenerator()
{
return new IdGenerator($this);
}
@ -181,12 +188,15 @@ class Database extends PDO
* @param string $seq Имя последовательности для ключа таблицы
* @return int Идентефикатор следующей записи
*/
function getNextId($seq) {
function getNextId($seq)
{
$result = $this->fetchOneArray("SELECT nextval('$seq')");
return $result['nextval'];
}
function close() {
function close()
{
return null;
}
}}
}
}

View file

@ -33,7 +33,7 @@ class JsonInstall {
}
function missingTables($tables) {
$actual_tables = $this->db_manager->GetAllTableNames();
$actual_tables = $this->db_manager->getAllTableNames();
$missingTables = [];
foreach ($tables as $table) {
if (!in_array($table, $actual_tables))
@ -118,7 +118,7 @@ class JsonInstall {
//Выполнение действий
foreach ($actions as $action) {
$this->db_manager->ExecuteAction($action, $dbfill_file_path);
$this->db_manager->executeAction($action, $dbfill_file_path);
}
} else {
echo "Invalid dbfill.json";
@ -133,13 +133,13 @@ class JsonInstall {
$pg = $this->db_manager->db->isPostgres();
if ($pg) {
foreach ($this->serialColumns as $serialColumn) {
$this->db_manager->UpdateSerial($serialColumn["table"], $serialColumn["column"]);
$this->db_manager->updateSerial($serialColumn["table"], $serialColumn["column"]);
}
foreach ($initActions as $action) {
if ($action["type"] == "alterReference") {
$this->db_manager->ExecuteAction($action);
$this->db_manager->executeAction($action);
}
}
}

View file

@ -18,9 +18,9 @@ class Document {
/**
* Добавление стиля к документу
* @param $name string Имя стиля
* @param $values array Параметры стиля
* @param $type Тип стиля
* @param string $name string Имя стиля
* @param array $values array Параметры стиля
* @param string $type Тип стиля
*/
function setStyle ($name, array $values, $type = 'Interior')
{
@ -43,7 +43,6 @@ class Document {
if ($type == 'Borders') {
$doc->startElement('Borders');
foreach ($s as $border) {
$border/*: array*/ = $border;
$doc->startElement('Border');
foreach ($border as $key => $value) {
$doc->writeAttribute('ss:' . $key, $value);

View file

@ -129,9 +129,9 @@ class Table
/**
* Устанавливает стиль для клеток ряда
* @param $row integer Номер ряда
* @param $y integer Номер столбца
* @parma $name string Имя стиля
* @param int $row Номер ряда
* @param int $y Номер столбца
* @param string $name Имя стиля
*/
function setCellStyle ($row, $y, $name)
{
@ -175,7 +175,7 @@ class Table
/**
* Разделяет таблицу на две части по вертикали
* @param $n integer Количество столбцов слева
* @param int $n Количество столбцов слева
*/
function splitVertical($n) {
$this->_splitVertical = $n;
@ -183,7 +183,7 @@ class Table
/**
* Разделяет таблицу на две части по горизонтали
* @param $n integer Количество столбцов сверху
* @param int $n Количество столбцов сверху
*/
function splitHorizontal($n) {
$this->_splitHorizontal = $n;

View file

@ -73,6 +73,12 @@ class Form extends View {
return '_form_edit';
}
/**
* Добавление конструкторя для поля формы
* @param string $name Краткое название поля
* @param class-string<Field> $class
* @return void
*/
public function addFieldClass($name, $class)
{
$this->constructor [$name] = $class;
@ -80,6 +86,7 @@ class Form extends View {
/**
* Добавляет одно поле ввода на форму
* @return Field
*/
public function addField(array $init, $factory = null)
{

View file

@ -24,7 +24,7 @@ class Path
if (isset($this->url['path'])) {
$path = $this->url['path'];
// $path = preg_replace('/\/{2,}/', '/', $path);
$list = $this->listFromString($path);
$list = self::listFromString($path);
if (isset($this->url['scheme']) && !isset($this->url['host'])) {
$this->absolute = false;
@ -32,7 +32,7 @@ class Path
$this->absolute = true;
}
$this->path = $this->optimize($list);
$this->path = self::optimize($list);
}
}
@ -94,7 +94,7 @@ class Path
assert(is_string($fileName));
$path = pathinfo($fileName);
if ($path['dirname'] == ".") {
if ($path['dirname'] === ".") {
return $path['filename'];
} else {
return self::join($path['dirname'], $path['filename']);
@ -142,14 +142,14 @@ class Path
foreach ($path as $n) {
switch ($n) {
// Может быть относительным или абсолютным путем
case "": break;
case ".": break;
case "": case ".": break;
case "..":
if (count($result) > 0 && $result[count($result) - 1] != '..') {
array_pop($result); break;
}
break;
default:
array_push($result, $n);
$result[] = $n;
}
}
return $result;

View file

@ -16,14 +16,8 @@ class Email extends AbstractRule
public function isValid(Collection $container, $status = null)
{
$user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\|\{\}~\']+';
$doIsValid = '(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]\.?)+';
$ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}';
$ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}';
$emails = explode(",", $container->get($this->field));
foreach ($emails as $email) {
// if (! preg_match("/^$user@($doIsValid|(\[($ipv4|$ipv6)\]))$/", $email)) return false;
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) return false;
}

View file

@ -12,24 +12,29 @@ use Exception,
class Validator
{
protected $chain = array(); // Массив правил
protected $errorMsg = array(); // Массив ошибок
protected $type = array(
'date' => 'ctiso\\Validator\\Rule\\Date',
'email' => 'ctiso\\Validator\\Rule\\Email',
'emaillist'=> 'ctiso\\Validator\\Rule\\EmailList',
'match' => 'ctiso\\Validator\\Rule\\MatchRule',
'time' => 'ctiso\\Validator\\Rule\\Time',
'alpha' => 'ctiso\\Validator\\Rule\\Alpha',
'require' => 'ctiso\\Validator\\Rule\\Notnull',
'numeric' => 'ctiso\\Validator\\Rule\\Numeric',
'unique' => 'ctiso\\Validator\\Rule\\Unique',
'filename' => 'ctiso\\Validator\\Rule\\FileName',
'count' => 'ctiso\\Validator\\Rule\\Count',
'isfile' => 'ctiso\\Validator\\Rule\\IsFile',
'code' => 'ctiso\\Validator\\Rule\\Code',
'reg' => 'ctiso\\Validator\\Rule\\PregMatch',
);
protected $chain = []; // Массив правил
protected $errorMsg = []; // Массив ошибок
/**
* Поля по умолчанию
* @var array<string, class-string<Rule\AbstractRule>>
*/
protected $type = [
'date' => Rule\Date::class,
'email' => Rule\Email::class,
'emaillist'=> Rule\EmailList::class,
'match' => Rule\MatchRule::class,
'time' => Rule\Time::class,
'alpha' => Rule\Alpha::class,
'require' => Rule\Notnull::class,
'numeric' => Rule\Numeric::class,
'unique' => Rule\Unique::class,
'filename' => Rule\FileName::class,
'count' => Rule\Count::class,
'isfile' => Rule\IsFile::class,
'code' => Rule\Code::class,
'reg' => Rule\PregMatch::class,
];
function __construct($rules = []) {
$this->addRuleList($rules);
@ -98,13 +103,17 @@ class Validator
return false;
}
function reset() {
$this->errorMsg = [];
}
public function validate(Collection $container, $rule = null, $status = null)
{
$fields = [];
if ($rule) {
$this->chain = $rule;
}
$this->errorMsg = [];
// $this->errorMsg = [];
foreach ($this->chain as $rule) {
//echo $key;
if (!in_array($rule->field, $fields) && !$this->skip($rule, $container) && !$rule->isValid($container, $status)) {