fix: noverify + типы для правил провеки
This commit is contained in:
parent
9680409ba9
commit
90cbd3b2b6
10 changed files with 319 additions and 300 deletions
|
|
@ -95,7 +95,7 @@ class Component
|
||||||
|
|
||||||
public function getView($name)
|
public function getView($name)
|
||||||
{
|
{
|
||||||
if ($this->output == 'json') {
|
if ($this->output === 'json') {
|
||||||
return new FakeTemplate($name);
|
return new FakeTemplate($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,7 +126,7 @@ class Component
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl->stripComments(true);
|
$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('common', Path::join($this->config->get('system', 'web'), '../', 'common'));
|
||||||
$tpl->set('script', Path::join($this->config->get('system', 'web'), 'js'));
|
$tpl->set('script', Path::join($this->config->get('system', 'web'), 'js'));
|
||||||
|
|
@ -152,7 +152,7 @@ class Component
|
||||||
$registry = $this->config;
|
$registry = $this->config;
|
||||||
// Брать настройки из куков если есть
|
// Брать настройки из куков если есть
|
||||||
$template = ($this->template) ? $this->template : $this->getTemplateName($registry);
|
$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))) {
|
if(is_dir(Path::join($this->viewPath[$index], 'templates', $template))) {
|
||||||
return Path::join($this->viewPath[$index], 'templates', $template, $name);
|
return Path::join($this->viewPath[$index], 'templates', $template, $name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
342
src/Database.php
342
src/Database.php
|
|
@ -1,192 +1,202 @@
|
||||||
<?php
|
<?php
|
||||||
namespace {
|
namespace {
|
||||||
if(!function_exists('sqliteLower')){
|
if (!function_exists('sqliteLower')) {
|
||||||
function sqliteLower($str) {
|
function sqliteLower($str)
|
||||||
|
{
|
||||||
return mb_strtolower($str, 'UTF-8');
|
return mb_strtolower($str, 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ctiso {
|
namespace ctiso {
|
||||||
use PDO,
|
use PDO,
|
||||||
ctiso\Database\Statement,
|
ctiso\Database\Statement,
|
||||||
ctiso\Database\PDOStatement,
|
ctiso\Database\PDOStatement,
|
||||||
ctiso\Database\IdGenerator;
|
ctiso\Database\IdGenerator;
|
||||||
|
|
||||||
/**
|
|
||||||
* Класс оболочка для PDO для замены Creole
|
|
||||||
*/
|
|
||||||
class Database extends PDO
|
|
||||||
{
|
|
||||||
|
|
||||||
public $dsn;
|
|
||||||
public function __construct($dsn, $username = null, $password = null)
|
|
||||||
{
|
|
||||||
parent::__construct($dsn, $username, $password);
|
|
||||||
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
||||||
$this->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
|
||||||
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function prepare(string $sql, array $options = []): PDOStatement|false {
|
|
||||||
$result/*: PDOStatement*/ = parent::prepare($sql, $options);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDSN()
|
|
||||||
{
|
|
||||||
return $this->dsn;
|
|
||||||
}
|
|
||||||
public function isPostgres(){
|
|
||||||
return ($this->dsn["phptype"] == "pgsql");
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Создает соединение с базой данных
|
* Класс оболочка для PDO для замены Creole
|
||||||
*/
|
*/
|
||||||
static function getConnection(array $dsn)
|
class Database extends PDO
|
||||||
{
|
{
|
||||||
|
|
||||||
$connection = null;
|
public $dsn;
|
||||||
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
|
public function __construct($dsn, $username = null, $password = null)
|
||||||
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : "";
|
{
|
||||||
$connection/*: Database*/ = new self("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
|
parent::__construct($dsn, $username, $password);
|
||||||
if ($dsn['phptype'] == 'pgsql') {
|
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
$connection->query('SET client_encoding="UTF-8"');
|
$this->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||||
}
|
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]);
|
||||||
|
|
||||||
if (isset($dsn['schema'])) {
|
|
||||||
$connection->query('SET search_path TO ' . $dsn['schema']);
|
|
||||||
}
|
|
||||||
} elseif ($dsn['phptype'] == 'sqlite::memory') {
|
|
||||||
$connection = new self("{$dsn['phptype']}:");
|
|
||||||
$connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1);
|
|
||||||
} elseif ($dsn['phptype'] == 'sqlite') {
|
|
||||||
$connection/*: Database*/ = new self("{$dsn['phptype']}:{$dsn['database']}");
|
|
||||||
$connection->setAttribute(PDO::ATTR_TIMEOUT, 5);
|
|
||||||
$mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL';
|
|
||||||
$connection->query("PRAGMA journal_mode=$mode");
|
|
||||||
$connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1);
|
|
||||||
}
|
}
|
||||||
$connection->dsn = $dsn;
|
|
||||||
return $connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeQuery($query, $values=null): PDOStatement|bool
|
function prepare(string $sql, array $options = []): PDOStatement|false
|
||||||
{
|
{
|
||||||
$stmt = $this->prepare($query);
|
$result/*: PDOStatement*/ = parent::prepare($sql, $options);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
$stmt->execute($values);
|
public function getDSN()
|
||||||
$stmt->cache = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
{
|
||||||
return $stmt;
|
return $this->dsn;
|
||||||
}
|
}
|
||||||
|
public function isPostgres()
|
||||||
|
{
|
||||||
|
return ($this->dsn["phptype"] == "pgsql");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Создает соединение с базой данных
|
||||||
|
*/
|
||||||
|
static function getConnection(array $dsn)
|
||||||
|
{
|
||||||
|
|
||||||
public function prepareStatement($query)
|
$connection = null;
|
||||||
{
|
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
|
||||||
return new Statement($query, $this);
|
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : "";
|
||||||
}
|
$connection/*: Database*/ = new self("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
|
||||||
|
if ($dsn['phptype'] == 'pgsql') {
|
||||||
|
$connection->query('SET client_encoding="UTF-8"');
|
||||||
|
}
|
||||||
|
|
||||||
// Для совместимости со старым представлением баз данных CIS
|
if (isset($dsn['schema'])) {
|
||||||
/**
|
$connection->query('SET search_path TO ' . $dsn['schema']);
|
||||||
* Извлекает из базы все элементы по запросу
|
}
|
||||||
*/
|
} elseif ($dsn['phptype'] == 'sqlite::memory') {
|
||||||
public function fetchAllArray($query, $values = null)
|
$connection = new self("{$dsn['phptype']}:");
|
||||||
{
|
$connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1);
|
||||||
$sth = $this->prepare($query);
|
} elseif ($dsn['phptype'] == 'sqlite') {
|
||||||
$prep = $this->prepareValues($values);
|
$connection/*: Database*/ = new self("{$dsn['phptype']}:{$dsn['database']}");
|
||||||
$sth->execute($prep);
|
$connection->setAttribute(PDO::ATTR_TIMEOUT, 5);
|
||||||
return $sth->fetchAll(PDO::FETCH_ASSOC);
|
$mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL';
|
||||||
}
|
$connection->query("PRAGMA journal_mode=$mode");
|
||||||
|
$connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1);
|
||||||
|
}
|
||||||
|
$connection->dsn = $dsn;
|
||||||
|
return $connection;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public function executeQuery($query, $values = null): PDOStatement|bool
|
||||||
* Извлекает из базы первый элемент по запросу
|
{
|
||||||
*/
|
$stmt = $this->prepare($query);
|
||||||
public function fetchOneArray($query, $values = null)
|
|
||||||
{
|
|
||||||
$sth = $this->prepare($query);
|
|
||||||
$prep = $this->prepareValues($values);
|
|
||||||
$sth->execute($prep);
|
|
||||||
return $sth->fetch(PDO::FETCH_ASSOC);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function prepareValues($values)
|
$stmt->execute($values);
|
||||||
{
|
$stmt->cache = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
if (!$values) {
|
return $stmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareStatement($query)
|
||||||
|
{
|
||||||
|
return new Statement($query, $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Для совместимости со старым представлением баз данных CIS
|
||||||
|
/**
|
||||||
|
* Извлекает из базы все элементы по запросу
|
||||||
|
*/
|
||||||
|
public function fetchAllArray($query, $values = null)
|
||||||
|
{
|
||||||
|
$sth = $this->prepare($query);
|
||||||
|
$prep = $this->prepareValues($values);
|
||||||
|
$sth->execute($prep);
|
||||||
|
return $sth->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Извлекает из базы первый элемент по запросу
|
||||||
|
*/
|
||||||
|
public function fetchOneArray($query, $values = null)
|
||||||
|
{
|
||||||
|
$sth = $this->prepare($query);
|
||||||
|
$prep = $this->prepareValues($values);
|
||||||
|
$sth->execute($prep);
|
||||||
|
return $sth->fetch(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function prepareValues($values)
|
||||||
|
{
|
||||||
|
if (!$values) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$pg = $this->isPostgres();
|
||||||
|
$prep = [];
|
||||||
|
foreach ($values as $key => $value) {
|
||||||
|
$result = null;
|
||||||
|
if (is_bool($value)) {
|
||||||
|
if ($pg) {
|
||||||
|
$result = $value ? 'true' : 'false';
|
||||||
|
} else {
|
||||||
|
$result = $value ? 1 : 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = $value;
|
||||||
|
}
|
||||||
|
$prep[":" . $key] = $result;
|
||||||
|
}
|
||||||
|
return $prep;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Создает INSERT запрос
|
||||||
|
*/
|
||||||
|
function insertQuery($table, array $values, $return_id = false, $index = null)
|
||||||
|
{
|
||||||
|
$prep = $this->prepareValues($values);
|
||||||
|
|
||||||
|
$sql = "INSERT INTO $table (" . implode(",", array_keys($values))
|
||||||
|
. ") VALUES (" . implode(",", array_keys($prep)) . ")";
|
||||||
|
if ($return_id) {
|
||||||
|
if ($this->isPostgres()) {
|
||||||
|
$sql .= " RETURNING $index";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$stmt = $this->prepare($sql);
|
||||||
|
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
||||||
|
$stmt->execute($prep);
|
||||||
|
$result = $stmt->fetch();
|
||||||
|
if ($return_id) {
|
||||||
|
if ($this->isPostgres()) {
|
||||||
|
return $result[$index];
|
||||||
|
} else {
|
||||||
|
$result = $this->fetchOneArray("SELECT $index AS lastid FROM $table WHERE OID = last_insert_rowid()");
|
||||||
|
return $result['lastid'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Создает UPDATE запрос
|
||||||
|
*/
|
||||||
|
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";
|
||||||
|
|
||||||
|
$stmt = $this->prepare($sql);
|
||||||
|
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
||||||
|
$stmt->execute($prep);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIdGenerator()
|
||||||
|
{
|
||||||
|
return new IdGenerator($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Замечание: Только для Postgres SQL
|
||||||
|
* @param string $seq Имя последовательности для ключа таблицы
|
||||||
|
* @return int Идентефикатор следующей записи
|
||||||
|
*/
|
||||||
|
function getNextId($seq)
|
||||||
|
{
|
||||||
|
$result = $this->fetchOneArray("SELECT nextval('$seq')");
|
||||||
|
return $result['nextval'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function close()
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$pg = $this->isPostgres();
|
|
||||||
$prep = [];
|
|
||||||
foreach ($values as $key => $value) {
|
|
||||||
$result = null;
|
|
||||||
if(is_bool($value)) {
|
|
||||||
if ($pg) {
|
|
||||||
$result = $value ? 'true' : 'false';
|
|
||||||
} else {
|
|
||||||
$result = $value ? 1 : 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$result = $value;
|
|
||||||
}
|
|
||||||
$prep[":" . $key] = $result;
|
|
||||||
}
|
|
||||||
return $prep;
|
|
||||||
}
|
}
|
||||||
/**
|
}
|
||||||
* Создает INSERT запрос
|
|
||||||
*/
|
|
||||||
function insertQuery($table, array $values, $return_id = false, $index = null)
|
|
||||||
{
|
|
||||||
$prep = $this->prepareValues($values);
|
|
||||||
|
|
||||||
$sql = "INSERT INTO $table (" . implode(",", array_keys($values))
|
|
||||||
. ") VALUES (" . implode(",", array_keys($prep)). ")";
|
|
||||||
if ($return_id) {
|
|
||||||
if ($this->isPostgres()){
|
|
||||||
$sql .= " RETURNING $index";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$stmt = $this->prepare($sql);
|
|
||||||
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
|
||||||
$stmt->execute($prep);
|
|
||||||
$result = $stmt->fetch();
|
|
||||||
if ($return_id) {
|
|
||||||
if ($this->isPostgres()) {
|
|
||||||
return $result[$index];
|
|
||||||
} else {
|
|
||||||
$result = $this->fetchOneArray("SELECT $index AS lastid FROM $table WHERE OID = last_insert_rowid()");
|
|
||||||
return $result['lastid'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Создает UPDATE запрос
|
|
||||||
*/
|
|
||||||
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";
|
|
||||||
|
|
||||||
$stmt = $this->prepare($sql);
|
|
||||||
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
|
||||||
$stmt->execute($prep);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getIdGenerator() {
|
|
||||||
return new IdGenerator($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Замечание: Только для Postgres SQL
|
|
||||||
* @param string $seq Имя последовательности для ключа таблицы
|
|
||||||
* @return int Идентефикатор следующей записи
|
|
||||||
*/
|
|
||||||
function getNextId($seq) {
|
|
||||||
$result = $this->fetchOneArray("SELECT nextval('$seq')");
|
|
||||||
return $result['nextval'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function close() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class JsonInstall {
|
||||||
}
|
}
|
||||||
|
|
||||||
function missingTables($tables) {
|
function missingTables($tables) {
|
||||||
$actual_tables = $this->db_manager->GetAllTableNames();
|
$actual_tables = $this->db_manager->getAllTableNames();
|
||||||
$missingTables = [];
|
$missingTables = [];
|
||||||
foreach ($tables as $table) {
|
foreach ($tables as $table) {
|
||||||
if (!in_array($table, $actual_tables))
|
if (!in_array($table, $actual_tables))
|
||||||
|
|
@ -118,7 +118,7 @@ class JsonInstall {
|
||||||
|
|
||||||
//Выполнение действий
|
//Выполнение действий
|
||||||
foreach ($actions as $action) {
|
foreach ($actions as $action) {
|
||||||
$this->db_manager->ExecuteAction($action, $dbfill_file_path);
|
$this->db_manager->executeAction($action, $dbfill_file_path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo "Invalid dbfill.json";
|
echo "Invalid dbfill.json";
|
||||||
|
|
@ -133,13 +133,13 @@ class JsonInstall {
|
||||||
$pg = $this->db_manager->db->isPostgres();
|
$pg = $this->db_manager->db->isPostgres();
|
||||||
if ($pg) {
|
if ($pg) {
|
||||||
foreach ($this->serialColumns as $serialColumn) {
|
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) {
|
foreach ($initActions as $action) {
|
||||||
if ($action["type"] == "alterReference") {
|
if ($action["type"] == "alterReference") {
|
||||||
$this->db_manager->ExecuteAction($action);
|
$this->db_manager->executeAction($action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@ class Document {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Добавление стиля к документу
|
* Добавление стиля к документу
|
||||||
* @param $name string Имя стиля
|
* @param string $name string Имя стиля
|
||||||
* @param $values array Параметры стиля
|
* @param array $values array Параметры стиля
|
||||||
* @param $type Тип стиля
|
* @param string $type Тип стиля
|
||||||
*/
|
*/
|
||||||
function setStyle ($name, array $values, $type = 'Interior')
|
function setStyle ($name, array $values, $type = 'Interior')
|
||||||
{
|
{
|
||||||
|
|
@ -43,7 +43,6 @@ class Document {
|
||||||
if ($type == 'Borders') {
|
if ($type == 'Borders') {
|
||||||
$doc->startElement('Borders');
|
$doc->startElement('Borders');
|
||||||
foreach ($s as $border) {
|
foreach ($s as $border) {
|
||||||
$border/*: array*/ = $border;
|
|
||||||
$doc->startElement('Border');
|
$doc->startElement('Border');
|
||||||
foreach ($border as $key => $value) {
|
foreach ($border as $key => $value) {
|
||||||
$doc->writeAttribute('ss:' . $key, $value);
|
$doc->writeAttribute('ss:' . $key, $value);
|
||||||
|
|
|
||||||
|
|
@ -129,9 +129,9 @@ class Table
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Устанавливает стиль для клеток ряда
|
* Устанавливает стиль для клеток ряда
|
||||||
* @param $row integer Номер ряда
|
* @param int $row Номер ряда
|
||||||
* @param $y integer Номер столбца
|
* @param int $y Номер столбца
|
||||||
* @parma $name string Имя стиля
|
* @param string $name Имя стиля
|
||||||
*/
|
*/
|
||||||
function setCellStyle ($row, $y, $name)
|
function setCellStyle ($row, $y, $name)
|
||||||
{
|
{
|
||||||
|
|
@ -175,7 +175,7 @@ class Table
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Разделяет таблицу на две части по вертикали
|
* Разделяет таблицу на две части по вертикали
|
||||||
* @param $n integer Количество столбцов слева
|
* @param int $n Количество столбцов слева
|
||||||
*/
|
*/
|
||||||
function splitVertical($n) {
|
function splitVertical($n) {
|
||||||
$this->_splitVertical = $n;
|
$this->_splitVertical = $n;
|
||||||
|
|
@ -183,7 +183,7 @@ class Table
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Разделяет таблицу на две части по горизонтали
|
* Разделяет таблицу на две части по горизонтали
|
||||||
* @param $n integer Количество столбцов сверху
|
* @param int $n Количество столбцов сверху
|
||||||
*/
|
*/
|
||||||
function splitHorizontal($n) {
|
function splitHorizontal($n) {
|
||||||
$this->_splitHorizontal = $n;
|
$this->_splitHorizontal = $n;
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,12 @@ class Form extends View {
|
||||||
return '_form_edit';
|
return '_form_edit';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Добавление конструкторя для поля формы
|
||||||
|
* @param string $name Краткое название поля
|
||||||
|
* @param class-string<Field> $class
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function addFieldClass($name, $class)
|
public function addFieldClass($name, $class)
|
||||||
{
|
{
|
||||||
$this->constructor [$name] = $class;
|
$this->constructor [$name] = $class;
|
||||||
|
|
@ -80,6 +86,7 @@ class Form extends View {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Добавляет одно поле ввода на форму
|
* Добавляет одно поле ввода на форму
|
||||||
|
* @return Field
|
||||||
*/
|
*/
|
||||||
public function addField(array $init, $factory = null)
|
public function addField(array $init, $factory = null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
12
src/Path.php
12
src/Path.php
|
|
@ -24,7 +24,7 @@ class Path
|
||||||
if (isset($this->url['path'])) {
|
if (isset($this->url['path'])) {
|
||||||
$path = $this->url['path'];
|
$path = $this->url['path'];
|
||||||
// $path = preg_replace('/\/{2,}/', '/', $path);
|
// $path = preg_replace('/\/{2,}/', '/', $path);
|
||||||
$list = $this->listFromString($path);
|
$list = self::listFromString($path);
|
||||||
|
|
||||||
if (isset($this->url['scheme']) && !isset($this->url['host'])) {
|
if (isset($this->url['scheme']) && !isset($this->url['host'])) {
|
||||||
$this->absolute = false;
|
$this->absolute = false;
|
||||||
|
|
@ -32,7 +32,7 @@ class Path
|
||||||
$this->absolute = true;
|
$this->absolute = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->path = $this->optimize($list);
|
$this->path = self::optimize($list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ class Path
|
||||||
assert(is_string($fileName));
|
assert(is_string($fileName));
|
||||||
|
|
||||||
$path = pathinfo($fileName);
|
$path = pathinfo($fileName);
|
||||||
if ($path['dirname'] == ".") {
|
if ($path['dirname'] === ".") {
|
||||||
return $path['filename'];
|
return $path['filename'];
|
||||||
} else {
|
} else {
|
||||||
return self::join($path['dirname'], $path['filename']);
|
return self::join($path['dirname'], $path['filename']);
|
||||||
|
|
@ -142,14 +142,14 @@ class Path
|
||||||
foreach ($path as $n) {
|
foreach ($path as $n) {
|
||||||
switch ($n) {
|
switch ($n) {
|
||||||
// Может быть относительным или абсолютным путем
|
// Может быть относительным или абсолютным путем
|
||||||
case "": break;
|
case "": case ".": break;
|
||||||
case ".": break;
|
|
||||||
case "..":
|
case "..":
|
||||||
if (count($result) > 0 && $result[count($result) - 1] != '..') {
|
if (count($result) > 0 && $result[count($result) - 1] != '..') {
|
||||||
array_pop($result); break;
|
array_pop($result); break;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
array_push($result, $n);
|
$result[] = $n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,8 @@ class Email extends AbstractRule
|
||||||
|
|
||||||
public function isValid(Collection $container, $status = null)
|
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));
|
$emails = explode(",", $container->get($this->field));
|
||||||
foreach ($emails as $email) {
|
foreach ($emails as $email) {
|
||||||
// if (! preg_match("/^$user@($doIsValid|(\[($ipv4|$ipv6)\]))$/", $email)) return false;
|
|
||||||
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) return false;
|
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,24 +12,29 @@ use Exception,
|
||||||
|
|
||||||
class Validator
|
class Validator
|
||||||
{
|
{
|
||||||
protected $chain = array(); // Массив правил
|
protected $chain = []; // Массив правил
|
||||||
protected $errorMsg = array(); // Массив ошибок
|
protected $errorMsg = []; // Массив ошибок
|
||||||
protected $type = array(
|
|
||||||
'date' => 'ctiso\\Validator\\Rule\\Date',
|
/**
|
||||||
'email' => 'ctiso\\Validator\\Rule\\Email',
|
* Поля по умолчанию
|
||||||
'emaillist'=> 'ctiso\\Validator\\Rule\\EmailList',
|
* @var array<string, class-string<Rule\AbstractRule>>
|
||||||
'match' => 'ctiso\\Validator\\Rule\\MatchRule',
|
*/
|
||||||
'time' => 'ctiso\\Validator\\Rule\\Time',
|
protected $type = [
|
||||||
'alpha' => 'ctiso\\Validator\\Rule\\Alpha',
|
'date' => Rule\Date::class,
|
||||||
'require' => 'ctiso\\Validator\\Rule\\Notnull',
|
'email' => Rule\Email::class,
|
||||||
'numeric' => 'ctiso\\Validator\\Rule\\Numeric',
|
'emaillist'=> Rule\EmailList::class,
|
||||||
'unique' => 'ctiso\\Validator\\Rule\\Unique',
|
'match' => Rule\MatchRule::class,
|
||||||
'filename' => 'ctiso\\Validator\\Rule\\FileName',
|
'time' => Rule\Time::class,
|
||||||
'count' => 'ctiso\\Validator\\Rule\\Count',
|
'alpha' => Rule\Alpha::class,
|
||||||
'isfile' => 'ctiso\\Validator\\Rule\\IsFile',
|
'require' => Rule\Notnull::class,
|
||||||
'code' => 'ctiso\\Validator\\Rule\\Code',
|
'numeric' => Rule\Numeric::class,
|
||||||
'reg' => 'ctiso\\Validator\\Rule\\PregMatch',
|
'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 = []) {
|
function __construct($rules = []) {
|
||||||
$this->addRuleList($rules);
|
$this->addRuleList($rules);
|
||||||
|
|
@ -98,13 +103,17 @@ class Validator
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
$this->errorMsg = [];
|
||||||
|
}
|
||||||
|
|
||||||
public function validate(Collection $container, $rule = null, $status = null)
|
public function validate(Collection $container, $rule = null, $status = null)
|
||||||
{
|
{
|
||||||
$fields = [];
|
$fields = [];
|
||||||
if ($rule) {
|
if ($rule) {
|
||||||
$this->chain = $rule;
|
$this->chain = $rule;
|
||||||
}
|
}
|
||||||
$this->errorMsg = [];
|
// $this->errorMsg = [];
|
||||||
foreach ($this->chain as $rule) {
|
foreach ($this->chain as $rule) {
|
||||||
//echo $key;
|
//echo $key;
|
||||||
if (!in_array($rule->field, $fields) && !$this->skip($rule, $container) && !$rule->isValid($container, $status)) {
|
if (!in_array($rule->field, $fields) && !$this->skip($rule, $container) && !$rule->isValid($container, $status)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue