chore: Аннотации к типам
This commit is contained in:
parent
e2ba6bd46e
commit
e5713e9015
28 changed files with 305 additions and 110 deletions
|
|
@ -4,16 +4,23 @@
|
|||
* Класс оболочка для PDOStatement для замены Creole
|
||||
*/
|
||||
namespace ctiso\Database;
|
||||
use PDO,
|
||||
ctiso\Database;
|
||||
|
||||
use PDO;
|
||||
use ctiso\Database;
|
||||
|
||||
class Statement
|
||||
{
|
||||
/** @var ?int */
|
||||
protected $limit = null;
|
||||
/** @var ?int */
|
||||
protected $offset = null;
|
||||
/** @var never */
|
||||
protected $statement = null;
|
||||
protected $binds = array();
|
||||
/** @var array{int|string, mixed, int}[] */
|
||||
protected $binds = [];
|
||||
/** @var Database */
|
||||
protected $conn;
|
||||
/** @var string */
|
||||
protected $query;
|
||||
|
||||
/**
|
||||
|
|
@ -37,14 +44,23 @@ class Statement
|
|||
$this->binds [] = [$n, $value, PDO::PARAM_LOB];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $limit
|
||||
*/
|
||||
function setLimit($limit) {
|
||||
$this->limit = $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $offset
|
||||
*/
|
||||
function setOffset($offset) {
|
||||
$this->offset = $offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?PDOStatement
|
||||
*/
|
||||
function executeQuery() {
|
||||
if ($this->limit) {
|
||||
$this->query .= " LIMIT {$this->limit} OFFSET {$this->offset}";
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class TableCell
|
|||
class TableRow
|
||||
{
|
||||
public $style = false;
|
||||
public $cells = array();
|
||||
public $cells = [];
|
||||
public $height = false;
|
||||
|
||||
function setCell($y, $value)
|
||||
|
|
@ -48,7 +48,7 @@ class Table
|
|||
static $index;
|
||||
private $name;
|
||||
private $style;
|
||||
protected $rows = array();
|
||||
protected $rows = [];
|
||||
|
||||
protected $_splitVertical = false;
|
||||
protected $_splitHorizontal = false;
|
||||
|
|
@ -106,9 +106,9 @@ class Table
|
|||
* @param int $row Номер ряда
|
||||
* @param string $name Имя стиля
|
||||
*/
|
||||
function setRowStyle ($row, $name)
|
||||
function setRowStyle(int $row, $name)
|
||||
{
|
||||
assert(is_numeric($row) && $row > 0);
|
||||
assert($row > 0);
|
||||
|
||||
$this->rows[$row]->style = $name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,19 @@ namespace ctiso\Filter;
|
|||
class Authorization {
|
||||
const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#';
|
||||
const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign';
|
||||
/** @var string */
|
||||
public $group;
|
||||
|
||||
/**
|
||||
* @param string $group
|
||||
*/
|
||||
function __construct($group) {
|
||||
$this->group = $group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group
|
||||
*/
|
||||
static function isLogged($group = 'access') {
|
||||
// echo session_status();
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
|
|
@ -29,6 +36,10 @@ class Authorization {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param string $group
|
||||
*/
|
||||
static function enter($id, $group = 'access') {
|
||||
// $db->executeQuery("UPDATE visitor SET sid = '' WHERE id_visitor = " . $result->getInt('id_user'));
|
||||
// session_register("access");
|
||||
|
|
@ -40,7 +51,7 @@ class Authorization {
|
|||
$_SESSION ["time"] = time();
|
||||
}
|
||||
|
||||
static function getRawSign()
|
||||
static function getRawSign(): string
|
||||
{
|
||||
$rawSign = self::SESSION_BROWSER_SIGN_SECRET;
|
||||
$signParts = ['HTTP_USER_AGENT'];
|
||||
|
|
@ -52,13 +63,12 @@ class Authorization {
|
|||
return $rawSign;
|
||||
}
|
||||
|
||||
static function getBrowserSign()
|
||||
static function getBrowserSign(): string
|
||||
{
|
||||
|
||||
return md5(self::getRawSign());
|
||||
}
|
||||
|
||||
function logout() {
|
||||
function logout(): void {
|
||||
session_destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ use ctiso\Form\Field;
|
|||
|
||||
class CheckBox extends Field
|
||||
{
|
||||
/** @var bool */
|
||||
public $checked = false;
|
||||
function setValue($value)
|
||||
function setValue($value): void
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->checked = $value;
|
||||
|
|
|
|||
|
|
@ -6,22 +6,31 @@ namespace ctiso\Form;
|
|||
|
||||
class Field
|
||||
{
|
||||
/** @var bool */
|
||||
public $hidden = false;
|
||||
/** @var string */
|
||||
public $name;
|
||||
/** @var string */
|
||||
public $label; // Метка поля
|
||||
|
||||
public $value; // Значение поля
|
||||
/** @var string */
|
||||
public $type = ""; // Каждому типу элемента соответствует макрос TAL
|
||||
/** @var ?string */
|
||||
public $error_msg = null;
|
||||
public $default = null;
|
||||
public $error = false;
|
||||
public $require = false;
|
||||
public $hint = null;
|
||||
/** @var ?int */
|
||||
public $maxlength = null;
|
||||
public $fieldset = null;
|
||||
// Блоки (Убрать в отдельный класс!!!)
|
||||
public $_title = array();
|
||||
public $_title = [];
|
||||
/** @var string */
|
||||
public $description = "";
|
||||
public $alias = array();
|
||||
/** @var array */
|
||||
public $alias = [];
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
public function __construct ($input = [], $factory = null)
|
||||
|
|
@ -44,12 +53,12 @@ class Field
|
|||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
function setValue($value)
|
||||
function setValue($value): void
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
function getId()
|
||||
function getId(): string
|
||||
{
|
||||
return $this->name . '_label';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,18 +16,26 @@ use ctiso\Form\Field,
|
|||
* Форма для ввода
|
||||
*/
|
||||
class Form {
|
||||
/** @var array */
|
||||
public $field = []; //Поля формы
|
||||
/** @var array */
|
||||
public $fieldsets = []; //Группы полей (fieldset). Некоторые поля могут не принадлежать никаким группам
|
||||
|
||||
/** @var string */
|
||||
public $action = "";
|
||||
/** @var string */
|
||||
public $method = 'post';
|
||||
/** @var string */
|
||||
public $header;
|
||||
|
||||
protected $replace;
|
||||
protected $before;
|
||||
|
||||
/** @var array */
|
||||
public $_title = [];
|
||||
/** @var array */
|
||||
public $alias = [];
|
||||
/** @var class-string<Field>[] */
|
||||
private $constructor = [];
|
||||
|
||||
/**
|
||||
|
|
@ -119,7 +127,6 @@ class Form {
|
|||
/**
|
||||
* Добавление массива fieldset на форму
|
||||
*/
|
||||
|
||||
public function addFieldSetList(array $list)
|
||||
{
|
||||
foreach ($list as $fieldset) {
|
||||
|
|
@ -150,6 +157,11 @@ class Form {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Устанавливает ошибку для поля
|
||||
* @param string $name
|
||||
* @param string $message
|
||||
*/
|
||||
function setFieldError($name, $message)
|
||||
{
|
||||
$this->field[$name]->error = true;
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@ namespace ctiso\Form;
|
|||
use ctiso\Form\Input;
|
||||
|
||||
class Hidden extends Input {
|
||||
/** @var bool */
|
||||
public $hidden = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use ctiso\Form\Select;
|
|||
|
||||
class QuestionType extends Select
|
||||
{
|
||||
function setValue($value)
|
||||
function setValue($value): void
|
||||
{
|
||||
// Установить selected у options
|
||||
$this->value = $value;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use ctiso\Form\Select;
|
|||
|
||||
class SelectMany extends Select
|
||||
{
|
||||
function setValue($value)
|
||||
function setValue(mixed $value): void
|
||||
{
|
||||
// Установить selected у options
|
||||
if (!is_array($value)) { $value = [$value]; }
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use ctiso\Form\Select;
|
|||
|
||||
class SelectOne extends Select
|
||||
{
|
||||
function setValue($value)
|
||||
function setValue($value): void
|
||||
{
|
||||
// Установить selected у options
|
||||
$this->value = $value;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace ctiso\Form;
|
|||
use ctiso\Form\Field;
|
||||
|
||||
class TextArea extends Field {
|
||||
function setValue($value)
|
||||
function setValue($value): void
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,15 @@ namespace ctiso\Form;
|
|||
|
||||
class ViewState // extends Collection
|
||||
{
|
||||
private $values = array();
|
||||
/** @var array */
|
||||
private $values = [];
|
||||
|
||||
function set($name, $value)
|
||||
/**
|
||||
* Устанавливает значение
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
function set($name, $value): void
|
||||
{
|
||||
$this->values[$name] = $value;
|
||||
}
|
||||
|
|
@ -28,7 +34,7 @@ class ViewState // extends Collection
|
|||
return $result;
|
||||
}
|
||||
|
||||
function saveState()
|
||||
function saveState(): string
|
||||
{
|
||||
return base64_encode(serialize($this->values));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,10 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Функциональное программирование в PHP
|
||||
* package functional
|
||||
*/
|
||||
namespace ctiso;
|
||||
|
||||
/**
|
||||
* Эмуляция каррированой функции
|
||||
*/
|
||||
namespace ctiso;
|
||||
|
||||
class right {
|
||||
protected $params;
|
||||
protected $fn;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\Model;
|
||||
use ctiso\Registry,
|
||||
ctiso\Database,
|
||||
ctiso\Role\User;
|
||||
|
||||
use ctiso\Registry;
|
||||
use ctiso\Database;
|
||||
use ctiso\Role\User;
|
||||
|
||||
class Factory
|
||||
{
|
||||
|
|
|
|||
40
src/Path.php
40
src/Path.php
|
|
@ -160,6 +160,10 @@ class Path
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Преобразует путь в строку
|
||||
* @param array{ host?: string, path?: string, query?: string, fragment?: string, scheme?: string, user?: string, pass?: string, port?: int} $path Путь
|
||||
*/
|
||||
public static function makeUrl($path): string
|
||||
{
|
||||
$slash = (isset($path['host']) && (strlen($path['path']) > 0) && ($path['path'][0] != '/')) ? '/' : '';
|
||||
|
|
@ -231,7 +235,12 @@ class Path
|
|||
return $path->__toString();
|
||||
}
|
||||
|
||||
// Вычисляет относительный путь в виде строки
|
||||
/**
|
||||
* Вычисляет относительный путь в виде строки
|
||||
* @param string $rpath Путь относительно которого вычисляется относительный путь
|
||||
* @param string $lpath Путь к которому вычисляется относительный путь
|
||||
* @return string Относительный путь
|
||||
*/
|
||||
static function relative($rpath, $lpath) {
|
||||
// Нужно проверять диск!!
|
||||
$self = new Path($rpath);
|
||||
|
|
@ -259,6 +268,7 @@ class Path
|
|||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function append($path)
|
||||
{
|
||||
|
|
@ -300,12 +310,12 @@ class Path
|
|||
}
|
||||
|
||||
// Проверка структуры имени файла
|
||||
static function checkName(string $name, string $extension)
|
||||
static function checkName(string $name, string $extension): bool
|
||||
{
|
||||
return (strlen(pathinfo($name, PATHINFO_FILENAME)) > 0) && (pathinfo($name, PATHINFO_EXTENSION) == $extension);
|
||||
}
|
||||
|
||||
static function isCharName(string $char)
|
||||
static function isCharName(string $char): bool
|
||||
{
|
||||
$ch = ord($char);
|
||||
return ((($ch >= ord('a')) && ($ch <= ord('z'))) || (strpos('-._', $char) !== false) || (($ch >= ord('0')) && ($ch <= ord('9'))));
|
||||
|
|
@ -354,10 +364,10 @@ class Path
|
|||
/**
|
||||
* Список файлов в директории
|
||||
*
|
||||
* @param ?array $allow массив расширений для файлов
|
||||
* @param array $ignore массив имен пааок которые не нужно обрабатывать
|
||||
* @param ?string[] $allow массив расширений для файлов
|
||||
* @param string[] $ignore массив имен пааок которые не нужно обрабатывать
|
||||
*
|
||||
* @returnarray
|
||||
* @return string[]
|
||||
*/
|
||||
public function getContent(?array $allow = null, array $ignore = [])
|
||||
{
|
||||
|
|
@ -368,10 +378,10 @@ class Path
|
|||
/**
|
||||
* Обьединяет строки в путь соединяя необходимым разделителем
|
||||
*
|
||||
* @param ?array $allow массив расширений разрешеных для файлов
|
||||
* @param array $ignore массив имен пааок которые не нужно обрабатывать
|
||||
* @param ?string[] $allow массив расширений разрешеных для файлов
|
||||
* @param string[] $ignore массив имен папок которые не нужно обрабатывать
|
||||
*
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
function getContentRec(?array $allow = null, array $ignore = [])
|
||||
{
|
||||
|
|
@ -381,7 +391,15 @@ class Path
|
|||
return $result;
|
||||
}
|
||||
|
||||
// Использовать SPL ???
|
||||
/**
|
||||
* Список файлов в директории
|
||||
*
|
||||
* @param string $base Базовый путь
|
||||
* @param ?string[] $allow массив расширений для файлов
|
||||
* @param string[] $ignore массив имен папок которые не нужно обрабатывать
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected static function fileList(string $base, ?array &$allow, array &$ignore): array
|
||||
{
|
||||
if ($base == '') $base = '.';
|
||||
|
|
@ -407,7 +425,7 @@ class Path
|
|||
return $result;
|
||||
}
|
||||
|
||||
protected static function fileListAll(array &$result, string $base, ?array &$allow, array &$ignore)
|
||||
protected static function fileListAll(array &$result, string $base, ?array &$allow, array &$ignore): void
|
||||
{
|
||||
$files = self::fileList($base, $allow, $ignore);
|
||||
foreach ($files as $name) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
/**
|
||||
* Преобразование типов !!! Пересмотреть использование классов!!
|
||||
* Класс преобразования типа значения поля класса в тип поля таблицы
|
||||
* @package system
|
||||
*/
|
||||
|
||||
namespace ctiso;
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ use ctiso\File,
|
|||
Exception;
|
||||
|
||||
class Registry {
|
||||
public array $namespace = [];
|
||||
public $data;
|
||||
private array $namespace = [];
|
||||
|
||||
function importFile(string $namespace, ?string $filePath = null) {
|
||||
$data = json_decode(File::getContents($filePath), true);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\Role;
|
||||
use ctiso\Database,
|
||||
ctiso\Database\Statement;
|
||||
|
||||
use ctiso\Database;
|
||||
use ctiso\Database\Statement;
|
||||
use ctiso\Database\PDOStatement;
|
||||
|
||||
// Класс должен быть в библиотеке приложения
|
||||
class User implements UserInterface
|
||||
|
|
@ -11,8 +13,10 @@ class User implements UserInterface
|
|||
|
||||
public string $fullname;
|
||||
public string $name;
|
||||
/** @var string */
|
||||
public $access;
|
||||
public string $password;
|
||||
/** @var int */
|
||||
public $id;
|
||||
public Database $db;
|
||||
public array $groups;
|
||||
|
|
@ -34,8 +38,7 @@ class User implements UserInterface
|
|||
return \ctiso\Filter\Authorization::isLogged();
|
||||
}
|
||||
|
||||
|
||||
public function getUserByQuery(Statement $stmt)
|
||||
public function getUserByQuery(Statement $stmt): ?PDOStatement
|
||||
{
|
||||
$result = $stmt->executeQuery();
|
||||
if ($result->next()) {
|
||||
|
|
@ -56,7 +59,7 @@ class User implements UserInterface
|
|||
return $result->get('password');
|
||||
}
|
||||
|
||||
public function getUserByLogin(string $login)
|
||||
public function getUserByLogin(string $login): ?PDOStatement
|
||||
{
|
||||
$stmt = $this->db->prepareStatement("SELECT * FROM users WHERE login = ?");
|
||||
$stmt->setString(1, $login);
|
||||
|
|
@ -69,7 +72,7 @@ class User implements UserInterface
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function getUserById(int $id)
|
||||
public function getUserById(int $id): ?PDOStatement
|
||||
{
|
||||
$stmt = $this->db->prepareStatement("SELECT * FROM users WHERE id_user = ?");
|
||||
$stmt->setInt(1, $_SESSION ['access']);
|
||||
|
|
|
|||
|
|
@ -199,10 +199,20 @@ class Settings
|
|||
file_put_contents (($file) ? $file : $this->file, $result);
|
||||
}
|
||||
|
||||
public function set($key, $value) {
|
||||
/**
|
||||
* Установка значения ключа
|
||||
* @param string $key Ключ
|
||||
* @param mixed $value Значение
|
||||
*/
|
||||
public function set($key, $value): void {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение значения ключа
|
||||
* @param string $key Ключ
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
return isset($this->data[$key]) && $this->data[$key] != '' ? $this->data[$key] : $default;
|
||||
|
|
@ -218,6 +228,7 @@ class Settings
|
|||
|
||||
/**
|
||||
* Список модулей/ключей
|
||||
* @return array
|
||||
*/
|
||||
public function getKeys()
|
||||
{
|
||||
|
|
@ -226,6 +237,8 @@ class Settings
|
|||
|
||||
/**
|
||||
* Проверка наличия ключа
|
||||
* @param string $name Ключ
|
||||
* @return bool
|
||||
*/
|
||||
public function hasKey($name)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,11 +13,18 @@ use ctiso\Path;
|
|||
use SimpleXMLElement;
|
||||
|
||||
class FakeZipArchive {
|
||||
/** @var string */
|
||||
public $base;
|
||||
function open($path) {
|
||||
|
||||
function open(string $path) {
|
||||
$this->base = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает содержимое файла
|
||||
* @param string $file
|
||||
* @return string
|
||||
*/
|
||||
function getFromName($file) {
|
||||
return file_get_contents(Path::join($this->base, $file));
|
||||
}
|
||||
|
|
@ -25,16 +32,25 @@ class FakeZipArchive {
|
|||
|
||||
class Setup
|
||||
{
|
||||
protected $actions = array();
|
||||
public $context = array();
|
||||
/** @var array */
|
||||
protected $actions = [];
|
||||
/** @var array */
|
||||
public $context = [];
|
||||
/** @var string */
|
||||
protected $file;
|
||||
/** @var string */
|
||||
protected $action;
|
||||
/** @var SimpleXMLElement */
|
||||
protected $node;
|
||||
protected $stack = array();
|
||||
/** @var array */
|
||||
protected $stack = [];
|
||||
|
||||
/** @var FakeZipArchive */
|
||||
public $zip;
|
||||
|
||||
/** @var string */
|
||||
public $target;
|
||||
/** @var string */
|
||||
public $source;
|
||||
|
||||
public function __construct($file)
|
||||
|
|
@ -58,14 +74,18 @@ class Setup
|
|||
|
||||
/**
|
||||
* Регистрация новых действия для установки
|
||||
* @param string $name
|
||||
* @param callable $action
|
||||
*/
|
||||
public function registerAction(string $name, $action)
|
||||
public function registerAction(string $name, $action): void
|
||||
{
|
||||
$this->actions[$name] = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка переменных для шаблона
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function set(string $name, $value)
|
||||
{
|
||||
|
|
@ -188,7 +208,7 @@ class Setup
|
|||
$setup->executeActions();
|
||||
}
|
||||
|
||||
function targetPath($s) {
|
||||
function targetPath(string $s): string {
|
||||
return $this->target . '/' . $s;
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +218,7 @@ class Setup
|
|||
*
|
||||
* @param array{dst:string} $attributes
|
||||
*/
|
||||
public function makeDirectory(array $attributes)
|
||||
public function makeDirectory(array $attributes): void
|
||||
{
|
||||
$path = $this->targetPath($attributes['dst']);
|
||||
if (!file_exists($path)) {
|
||||
|
|
@ -206,7 +226,7 @@ class Setup
|
|||
}
|
||||
}
|
||||
|
||||
function testWhen(array $attributes)
|
||||
function testWhen(array $attributes): void
|
||||
{
|
||||
if (!isset($attributes['test']) || $attributes['test'] == $this->action) {
|
||||
$this->executeActions($this->action);
|
||||
|
|
@ -218,7 +238,7 @@ class Setup
|
|||
* @param Database $conn
|
||||
* @param string $file
|
||||
*/
|
||||
function batchSQLZip($conn, $file)
|
||||
function batchSQLZip($conn, $file): void
|
||||
{
|
||||
$stmtList = SQLStatementExtractor::extract($this->zip->getFromName($file));
|
||||
foreach ($stmtList as $stmt) {
|
||||
|
|
@ -231,7 +251,7 @@ class Setup
|
|||
* @param Database $conn
|
||||
* @param string $file
|
||||
*/
|
||||
static function batchSQL($conn, $file)
|
||||
static function batchSQL($conn, $file): void
|
||||
{
|
||||
$stmtList = SQLStatementExtractor::extractFile($file);
|
||||
foreach ($stmtList as $stmt) {
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ use PHPTAL_Php_TalesInternal,
|
|||
|
||||
class Tales_DateTime implements PHPTAL_Tales
|
||||
{
|
||||
static public function date(string $expression, $nothrow = false): string
|
||||
static public function date(string $expression, bool $nothrow = false): string
|
||||
{
|
||||
return "ctiso\\Tales::phptal_date(".PHPTAL_Php_TalesInternal::path($expression).")";
|
||||
}
|
||||
|
||||
static public function time(string $expression, $nothrow = false): string
|
||||
static public function time(string $expression, bool $nothrow = false): string
|
||||
{
|
||||
return "ctiso\\Tales::phptal_time(".PHPTAL_Php_TalesInternal::path($expression).")";
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ class Tales_DateTime implements PHPTAL_Tales
|
|||
|
||||
class Tales_Component implements PHPTAL_Tales
|
||||
{
|
||||
static public function component(string $expression, $nothrow = false): string
|
||||
static public function component(string $expression, bool $nothrow = false): string
|
||||
{
|
||||
$s = PHPTAL_Php_TalesInternal::string($expression);
|
||||
return "ctiso\\Tales::phptal_component(" . $s . ")";
|
||||
|
|
@ -35,7 +35,7 @@ class Tales_Component implements PHPTAL_Tales
|
|||
|
||||
class Tales_Assets implements PHPTAL_Tales
|
||||
{
|
||||
static public function assets(string $expression, $nothrow = false): string
|
||||
static public function assets(string $expression, bool $nothrow = false): string
|
||||
{
|
||||
$s = PHPTAL_Php_TalesInternal::string($expression);
|
||||
return "ctiso\\Tales::phptal_asset(" . $s . ")";
|
||||
|
|
|
|||
|
|
@ -12,7 +12,15 @@ class Drawing
|
|||
const ALIGN_CENTER = "center";
|
||||
const ALIGN_RIGHT = "right";
|
||||
|
||||
static function drawrectnagle(GdImage &$image, int $left, int $top, int $width, int $height, array $rgb): void
|
||||
/**
|
||||
* @param GdImage $image
|
||||
* @param int $left
|
||||
* @param int $top
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
* @param array $rgb
|
||||
*/
|
||||
static function drawRectangle(GdImage &$image, int $left, int $top, int $width, int $height, array $rgb): void
|
||||
{
|
||||
$color = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
|
||||
$right = $left + $width;
|
||||
|
|
@ -25,6 +33,19 @@ class Drawing
|
|||
|
||||
/**
|
||||
* http://ru2.php.net/imagettftext
|
||||
*
|
||||
* @param GdImage $image
|
||||
* @param int $size
|
||||
* @param float $angle
|
||||
* @param int $left
|
||||
* @param int $top
|
||||
* @param int $color
|
||||
* @param string $font
|
||||
* @param string $text
|
||||
* @param int $max_width
|
||||
* @param int $max_height
|
||||
* @param string $align
|
||||
* @param string $valign
|
||||
*/
|
||||
static function imagettftextbox(
|
||||
GdImage &$image,
|
||||
|
|
@ -115,7 +136,6 @@ class Drawing
|
|||
return $largest_line_height * count($lines);
|
||||
}
|
||||
|
||||
|
||||
function imagettftextSp(GdImage $image, float $size, float $angle, int $x, int $y, int $color, string $font, string $text, int $spacing = 0)
|
||||
{
|
||||
if ($spacing == 0) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use GdImage;
|
|||
class Image
|
||||
{
|
||||
/**
|
||||
* @param $uri
|
||||
* @param string $uri
|
||||
* @return GdImage|false
|
||||
*/
|
||||
static function load($uri): GdImage|false
|
||||
|
|
|
|||
|
|
@ -2,10 +2,16 @@
|
|||
|
||||
namespace ctiso\Tools;
|
||||
|
||||
class StringUtil {
|
||||
class StringUtil
|
||||
{
|
||||
|
||||
// from creole
|
||||
static function strToArray(string $str): array {
|
||||
/**
|
||||
* Преобразует строку в массив
|
||||
* @param string $str
|
||||
* @return array
|
||||
*/
|
||||
static function strToArray(string $str): array
|
||||
{
|
||||
$str = substr($str, 1, -1); // remove { }
|
||||
$res = [];
|
||||
|
||||
|
|
@ -39,8 +45,13 @@ class StringUtil {
|
|||
return $res;
|
||||
}
|
||||
|
||||
//Нормализация строк на русском
|
||||
static function normalizeRussian(string $str): string {
|
||||
/**
|
||||
* Нормализация строк на русском
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
static function normalizeRussian(string $str): string
|
||||
{
|
||||
$result = preg_replace('/\s+/', ' ', $str);
|
||||
if (is_string($result)) {
|
||||
$result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям
|
||||
|
|
@ -50,8 +61,14 @@ class StringUtil {
|
|||
return $result;
|
||||
}
|
||||
|
||||
//Проверка равенства двух строк на русском языке.
|
||||
static function equalRussianCheck($str1,$str2): bool {
|
||||
/**
|
||||
* Проверка равенства двух строк на русском языке.
|
||||
* @param string $str1
|
||||
* @param string $str2
|
||||
* @return bool
|
||||
*/
|
||||
static function equalRussianCheck($str1, $str2): bool
|
||||
{
|
||||
return self::normalizeRussian($str1) == self::normalizeRussian($str2);
|
||||
}
|
||||
|
||||
|
|
@ -61,8 +78,13 @@ class StringUtil {
|
|||
* output: true
|
||||
* input: $str="foo" $variants="foo1|foo2|foo3"
|
||||
* output: false
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $variants
|
||||
* @return bool
|
||||
*/
|
||||
static function compare_string_to_variants($str, string $variants){
|
||||
static function compare_string_to_variants($str, string $variants)
|
||||
{
|
||||
$variants_array = explode('|', $variants);
|
||||
$founded = false;
|
||||
foreach ($variants_array as $variant) {
|
||||
|
|
@ -71,11 +93,25 @@ class StringUtil {
|
|||
return $founded;
|
||||
}
|
||||
|
||||
static function mb_str_split(string $str): array|false {
|
||||
/**
|
||||
* Разбивает строку на массив символов
|
||||
* @param string $str
|
||||
* @return array|false
|
||||
*/
|
||||
static function mb_str_split(string $str): array|false
|
||||
{
|
||||
return preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
|
||||
static function mb_strtr($str, $from, $to) {
|
||||
/**
|
||||
* Заменяет символы в строке на символы из другой строки
|
||||
* @param string $str
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return string
|
||||
*/
|
||||
static function mb_strtr($str, $from, $to)
|
||||
{
|
||||
return str_replace(self::mb_str_split($from), self::mb_str_split($to), $str);
|
||||
}
|
||||
|
||||
|
|
@ -95,17 +131,37 @@ class StringUtil {
|
|||
"%" => '_',
|
||||
"#" => '_',
|
||||
"*" => '_',
|
||||
"ж"=>"zh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh",
|
||||
"щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya",
|
||||
"Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH",
|
||||
"Щ"=>"SHCH","Ь"=>"", "Ю"=>"YU", "Я"=>"YA",
|
||||
"Й"=>"i", "й"=>"ie", "ё"=>"Ye",
|
||||
"ж" => "zh",
|
||||
"ц" => "ts",
|
||||
"ч" => "ch",
|
||||
"ш" => "sh",
|
||||
"щ" => "shch",
|
||||
"ь" => "",
|
||||
"ю" => "yu",
|
||||
"я" => "ya",
|
||||
"Ж" => "ZH",
|
||||
"Ц" => "TS",
|
||||
"Ч" => "CH",
|
||||
"Ш" => "SH",
|
||||
"Щ" => "SHCH",
|
||||
"Ь" => "",
|
||||
"Ю" => "YU",
|
||||
"Я" => "YA",
|
||||
"Й" => "i",
|
||||
"й" => "ie",
|
||||
"ё" => "Ye",
|
||||
"№" => "N"
|
||||
]);
|
||||
return strtolower($st);
|
||||
}
|
||||
|
||||
static function validate_encoded_string(string $st): int|false {
|
||||
/**
|
||||
* Проверяет, является ли строка кодированной
|
||||
* @param string $st
|
||||
* @return int|false
|
||||
*/
|
||||
static function validate_encoded_string(string $st): int|false
|
||||
{
|
||||
$enc_st = self::encodestring($st);
|
||||
return preg_match('/^[\w_-]+(\.[\w_-]+)?$/', $enc_st);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,13 @@ use Exception,
|
|||
ctiso\Validator\Rule\AbstractRule,
|
||||
ctiso\Collection;
|
||||
|
||||
/**
|
||||
* @phpstan-type Rule array{
|
||||
* validate:string, // Описание правила см. формат правила ниже
|
||||
* name:string, // Имя переменой для проверки
|
||||
* context?:object
|
||||
* }
|
||||
*/
|
||||
class Validator
|
||||
{
|
||||
/** @var AbstractRule[] */
|
||||
|
|
@ -36,6 +43,9 @@ class Validator
|
|||
'reg' => Rule\PregMatch::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param Rule[] $rules
|
||||
*/
|
||||
function __construct($rules = []) {
|
||||
$this->addRuleList($rules);
|
||||
}
|
||||
|
|
@ -51,9 +61,7 @@ class Validator
|
|||
|
||||
/**
|
||||
* Добавление списка правил в специальном формате
|
||||
* array(array('name' => fieldname, 'validate' => ruletext), ...)
|
||||
* fieldname - Имя переменой для проверки
|
||||
* ruletext - Описание правила см. формат правила ниже
|
||||
* @param Rule[] $input
|
||||
*/
|
||||
public function addRuleList(array $input): void
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace ctiso\View;
|
||||
use ctiso\View\View,
|
||||
PHPTAL;
|
||||
use PHPTAL_TranslationService;
|
||||
|
||||
class Composite extends View
|
||||
{
|
||||
|
|
@ -39,7 +40,7 @@ class Composite extends View
|
|||
return $this->tal->execute();
|
||||
}
|
||||
|
||||
function setTranslator($t): void {
|
||||
function setTranslator(PHPTAL_TranslationService $t): void {
|
||||
$this->tal->setTranslator($t);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,13 @@ class Top extends Composite
|
|||
{
|
||||
/**
|
||||
* Общая строка заголовка
|
||||
* @var int
|
||||
*/
|
||||
public $mid = 0;
|
||||
public $require = array();
|
||||
public $deps = array();
|
||||
/** @var array */
|
||||
public $require = [];
|
||||
/** @var array */
|
||||
public $deps = [];
|
||||
|
||||
/**
|
||||
* Заголовок страницы
|
||||
|
|
|
|||
|
|
@ -22,10 +22,14 @@ class View extends \stdClass
|
|||
|
||||
public ?string $active_module = null;
|
||||
public string $module_action;
|
||||
|
||||
/** @var string[] */
|
||||
public array $prefix;
|
||||
|
||||
/** @var string[] */
|
||||
public array $suggestions = []; //подсказки
|
||||
|
||||
/** @var string[] $alias */
|
||||
public array $alias = [];
|
||||
public $codeGenerator = null;
|
||||
public $parent_view = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue