Merge branch 'noglob' into php8

This commit is contained in:
origami11@yandex.ru 2024-01-09 12:03:17 +03:00
commit 3a2b273adc
9 changed files with 76 additions and 42 deletions

View file

@ -78,10 +78,11 @@ class Front extends Action
$module->front = $this; $module->front = $this;
// Ведение лога // Ведение лога
$logger = new ActionLogger($module, $logPath, $this->user); $logger = new ActionLogger($module, $logPath, $this->user);
$logger->before = $this->loadSettings(Path::join($modPath, 'filter', 'logger.php')); $filename = Path::join($modPath, 'filters', 'logger.json');
$logger->before = $this->loadSettings($filename);
// Управление доступом // Управление доступом
$module->access = new ActionAccess($logger, $this->user); $module->access = new ActionAccess($logger, $this->user);
$module->access->access = $this->loadSettings(Path::join($modPath, 'filter', 'access.php')); $module->access->access = $this->loadSettings(Path::join($modPath, 'filters', 'access.json'));
$module->setUp(); $module->setUp();

View file

@ -28,14 +28,14 @@ class Installer
return $setup; return $setup;
} }
function getUninstallFile($name){ function getUninstallFile($name) {
return Path::join(call_user_func($this->installPath, $name), "sql", "uninstall.json"); return Path::join(call_user_func($this->installPath, $name), "sql", "uninstall.json");
} }
// Проверка версии обновления // Проверка версии обновления
function isChanged($name) // Информация о модулях function isChanged($name) // Информация о модулях
{ {
$item = $this->_registry->get('system', $name); $item = $this->_registry->get($name);
if ($item) { if ($item) {
$setup = $this->getSetupFile($name); $setup = $this->getSetupFile($name);
if (file_exists($setup) && (filemtime($setup) > $item['time'])) { if (file_exists($setup) && (filemtime($setup) > $item['time'])) {
@ -78,10 +78,11 @@ class Installer
if (file_exists($setup) && ($this->isChanged($name) || $force)) { if (file_exists($setup) && ($this->isChanged($name) || $force)) {
$registry = $this->_registry; $registry = $this->_registry;
$settings = new Settings($setup); $settings = new Settings($setup);
$settings->read(); $settings->read();
$item = $registry->get('system', $name); $item = $registry->get($name);
$version_new = $settings->get('version'); $version_new = $settings->get('version');
if ($item) { if ($item) {
@ -106,7 +107,7 @@ class Installer
'version' => $version_new, 'version' => $version_new,
'time' => filemtime($setup) 'time' => filemtime($setup)
]); ]);
$registry->writeKey([$name], $settings->get('settings')); // $registry->writeKey([$name], $settings->export());
$registry->write(); $registry->write();
} }

View file

@ -63,8 +63,10 @@ class JsonInstall {
$table_name = $action["table_name"]; $table_name = $action["table_name"];
if (isset($refs[$table_name])) { if (isset($refs[$table_name])) {
foreach ($refs[$table_name] as $value) { foreach ($refs[$table_name] as $value) {
$action['fields'][$value['column']]['references'] = $action['fields'][$value['column']]['references'] = [
$value['refTable']."(".$value['refColumn'].")"; "refTable" => $value['refTable'],
'refColumn' => $value['refColumn']
];
} }
} }

View file

@ -145,7 +145,7 @@ class Manager
$constraint = isset($data['constraint']) ? " ".$data['constraint'] : ""; $constraint = isset($data['constraint']) ? " ".$data['constraint'] : "";
$references = ""; $references = "";
if (isset($data['references'])) { if (isset($data['references'])) {
$references = " REFERENCES ".$data['references']; $references = " REFERENCES " . $data['references']['refTable'] . '(' .$data['references']['refColumn'] . ')';
} }
if (isset($data["not_null"]) && $data["not_null"]) { if (isset($data["not_null"]) && $data["not_null"]) {
$constraint .=" NOT NULL"; $constraint .=" NOT NULL";

View file

@ -202,7 +202,7 @@ class Login extends Filter
$module = $request->get('module'); $module = $request->get('module');
$action = $request->get('action'); $action = $request->get('action');
$moduleDir = explode('_',$module)[0]; $moduleDir = explode('\\',$module)[0];
$file = Path::join($this->config->get('system', 'path'), 'modules', $moduleDir, 'filters', 'white.json'); $file = Path::join($this->config->get('system', 'path'), 'modules', $moduleDir, 'filters', 'white.json');
if (file_exists($file)) { if (file_exists($file)) {
$whiteList = json_decode(file_get_contents($file), true); $whiteList = json_decode(file_get_contents($file), true);

View file

@ -59,7 +59,7 @@ class Tales {
/** /**
* Функция подключения компонента * Функция подключения компонента
*/ */
static function phptal_component ($expression) { static function phptal_component($expression) {
$begin = floatval(microtime(true)); $begin = floatval(microtime(true));
$component/*: Component*/ = null; $component/*: Component*/ = null;

View file

@ -0,0 +1,21 @@
<?php
/**
*/
namespace ctiso\Validator\Rule;
use ctiso\Validator\Rule\AbstractRule,
ctiso\Collection;
class PregMatch extends AbstractRule
{
public $pattern;
public function getErrorMsg()
{
return "Поле в неправильном формате";
}
public function isValid(Collection $container, $status = null)
{
return preg_match($this->pattern,$container->get($this->field));
}
}

View file

@ -14,20 +14,7 @@ class Validator
{ {
protected $chain = array(); // Массив правил protected $chain = array(); // Массив правил
protected $errorMsg = array(); // Массив ошибок protected $errorMsg = array(); // Массив ошибок
protected $type = array(
function __construct($rules = array()) {
$this->addRuleList($rules);
}
/**
* Добавление списка правил в специальном формате
* array(array('name' => fieldname, 'validate' => ruletext), ...)
* fieldname - Имя переменой для проверки
* ruletext - Описание правила см. формат правила ниже
*/
public function addRuleList(array $input)
{
$type = array(
'date' => 'ctiso\\Validator\\Rule\\Date', 'date' => 'ctiso\\Validator\\Rule\\Date',
'email' => 'ctiso\\Validator\\Rule\\Email', 'email' => 'ctiso\\Validator\\Rule\\Email',
'emaillist'=> 'ctiso\\Validator\\Rule\\EmailList', 'emaillist'=> 'ctiso\\Validator\\Rule\\EmailList',
@ -40,9 +27,26 @@ class Validator
'filename' => 'ctiso\\Validator\\Rule\\FileName', 'filename' => 'ctiso\\Validator\\Rule\\FileName',
'count' => 'ctiso\\Validator\\Rule\\Count', 'count' => 'ctiso\\Validator\\Rule\\Count',
'isfile' => 'ctiso\\Validator\\Rule\\IsFile', 'isfile' => 'ctiso\\Validator\\Rule\\IsFile',
'code' => 'ctiso\\Validator\\Rule\\Code' 'code' => 'ctiso\\Validator\\Rule\\Code',
'reg' => 'ctiso\\Validator\\Rule\\PregMatch',
); );
function __construct($rules = array()) {
$this->addRuleList($rules);
}
function addRuleType($name, $className) {
$this->type[$name] = $className;
}
/**
* Добавление списка правил в специальном формате
* array(array('name' => fieldname, 'validate' => ruletext), ...)
* fieldname - Имя переменой для проверки
* ruletext - Описание правила см. формат правила ниже
*/
public function addRuleList(array $input)
{
// Разбор правила проверки // Разбор правила проверки
// Формат правила 'rule1|rule2,param1=value1|rule3,param1=value1,param2=value2' // Формат правила 'rule1|rule2,param1=value1|rule3,param1=value1,param2=value2'
foreach ($input as $value) { foreach ($input as $value) {
@ -55,8 +59,8 @@ class Validator
$rule_param = explode(",", $rule); $rule_param = explode(",", $rule);
$name = array_shift($rule_param); $name = array_shift($rule_param);
if (isset($type[$name])) { if (isset($this->type[$name])) {
$constructor = $type[$name]; $constructor = $this->type[$name];
$ruleObj = new $constructor($value['name'], false); // Нужны шаблонные сообщения для правил $ruleObj = new $constructor($value['name'], false); // Нужны шаблонные сообщения для правил
if (isset($value['context'])) { if (isset($value['context'])) {
$ruleObj->setContext($value['context']); $ruleObj->setContext($value['context']);
@ -74,7 +78,7 @@ class Validator
} }
} }
public function addRule($rule/*: any*/) { public function addRule($rule/*:z any*/) {
if (is_array($rule)) { if (is_array($rule)) {
$this->chain = array_merge($this->chain, $rule); $this->chain = array_merge($this->chain, $rule);
} else { } else {
@ -82,7 +86,7 @@ class Validator
} }
} }
public function skip($rule/*: AbstractRule*/, $container/*: Collection*/) // -> Rule_Abstract public function skip($rule/*z: AbstractRule*/, $container/*: Collection*/) // -> Rule_Abstract
{ {
if ($rule->skipEmpty()) { if ($rule->skipEmpty()) {
$data = $container->get($rule->field); $data = $container->get($rule->field);

View file

@ -17,6 +17,7 @@ class View
public $active_module; public $active_module;
public $module_action; public $module_action;
public $prefix;
public $suggestions; //подсказки public $suggestions; //подсказки
@ -59,7 +60,7 @@ class View
*/ */
public function addScript($name) public function addScript($name)
{ {
$output = $this->resolveName($this->alias, $name); $output = $this->resolveName($this->alias, $name . '?' . http_build_query($this->prefix));
$this->_script [] = $output; $this->_script [] = $output;
} }
@ -77,6 +78,10 @@ class View
} }
} }
public function setPrefix($name, $val) {
$this->prefix[$name] = $val;
}
/** /**
* Добавляет стили к текущему шаблону * Добавляет стили к текущему шаблону
* *
@ -84,7 +89,7 @@ class View
*/ */
public function addStyleSheet($name) public function addStyleSheet($name)
{ {
$output = $this->resolveName($this->alias, $name); $output = $this->resolveName($this->alias, $name . '?' . http_build_query($this->prefix));
$this->_stylesheet [] = $output; $this->_stylesheet [] = $output;
} }