fix: Определения типов
This commit is contained in:
parent
9f6fd74b17
commit
dd74a97894
28 changed files with 334 additions and 249 deletions
|
|
@ -41,7 +41,7 @@ class Collection implements \ArrayAccess
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($key/*: string*/, $value/*: any*/)
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class Action
|
|||
public Database $db;
|
||||
|
||||
// Фильтры
|
||||
/** @var ?ActionAccess */
|
||||
public $access = null; // Обьект хранит параметры доступа
|
||||
public $logger = null; // Обьект для ведения лога
|
||||
|
||||
|
|
@ -42,8 +43,10 @@ class Action
|
|||
private $helpers = array(); // Помошники для действий
|
||||
public $part = null; // Параметры для ссылки
|
||||
|
||||
public $config/*: Registry*/; // Ссылка на настройки
|
||||
public $user/*: User*/; // Обьект пользователя
|
||||
/** @var \ctiso\Registry */
|
||||
public $config; // Ссылка на настройки
|
||||
/** @var \ctiso\Role\User */
|
||||
public $user; // Обьект пользователя
|
||||
|
||||
// Для Widgets
|
||||
public $view = null;
|
||||
|
|
@ -214,7 +217,7 @@ class Action
|
|||
*/
|
||||
public function nUrl($actionName, array $param = [])
|
||||
{
|
||||
$access/*: ActionAccess*/ = $this->access;
|
||||
$access = $this->access;
|
||||
$url = new Url();
|
||||
|
||||
//print_r([$name, $param]);
|
||||
|
|
@ -337,7 +340,8 @@ class Action
|
|||
if ($view instanceof View) {
|
||||
$this->view->assignValues($this->ctrlValues);
|
||||
|
||||
$node/*: Composite*/ = null;
|
||||
/** @var ?Composite $node */
|
||||
$node = null;
|
||||
foreach ($this->childNodes as $name => $node) {
|
||||
$node->make($this);
|
||||
$this->view->setView($name, $node->view);
|
||||
|
|
@ -376,7 +380,7 @@ class Action
|
|||
$this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction());
|
||||
}
|
||||
|
||||
function redirect($action/*: string*/) {
|
||||
function redirect(string $action) {
|
||||
header('location: ' . $action);
|
||||
exit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,10 @@ class Request {
|
|||
public $r;
|
||||
public $id;
|
||||
|
||||
function __construct($request/*: HttpRequest*/, $id) {
|
||||
/**
|
||||
* @param HttpRequest $request
|
||||
*/
|
||||
function __construct($request, $id) {
|
||||
$this->r = $request;
|
||||
$this->id = $id;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,12 @@ class Service
|
|||
{
|
||||
public $viewPath = [];
|
||||
public $webPath = [];
|
||||
public $config/*: Registry*/;
|
||||
/** @var Registry */
|
||||
public $config;
|
||||
public $template;
|
||||
public $templatePath;
|
||||
public $COMPONENTS_WEB;
|
||||
|
||||
|
||||
public $db;
|
||||
|
||||
public function getTemplatePath($name)
|
||||
|
|
@ -53,7 +54,12 @@ class Service
|
|||
return $model;
|
||||
}
|
||||
|
||||
public function options($key, $val, $res/*: PDOStatement*/) {
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $val
|
||||
* @param PDOStatement $res
|
||||
*/
|
||||
public function options($key, $val, $res) {
|
||||
$result = [];
|
||||
while($res->next()) {
|
||||
$result[] = ['value' => $res->getInt($key), 'name' => $res->getString($val)];
|
||||
|
|
@ -68,7 +74,7 @@ class Service
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
function getInfo() {
|
||||
$filename = Path::join($this->viewPath[0], 'install.json');
|
||||
if (file_exists($filename)) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ namespace ctiso {
|
|||
|
||||
function prepare(string $sql, array $options = []): PDOStatement|false
|
||||
{
|
||||
$result/*: PDOStatement*/ = parent::prepare($sql, $options);
|
||||
/** @var PDOStatement $result */
|
||||
$result = parent::prepare($sql, $options);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
@ -49,10 +50,11 @@ namespace ctiso {
|
|||
static function getConnection(array $dsn)
|
||||
{
|
||||
|
||||
/** @var ?Database */
|
||||
$connection = null;
|
||||
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
|
||||
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : "";
|
||||
$connection/*: Database*/ = new self("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
|
||||
$connection = 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"');
|
||||
}
|
||||
|
|
@ -64,9 +66,9 @@ namespace ctiso {
|
|||
$connection = new self("{$dsn['phptype']}:");
|
||||
$connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1);
|
||||
} elseif ($dsn['phptype'] == 'sqlite') {
|
||||
$connection/*: Database*/ = new self("{$dsn['phptype']}:{$dsn['database']}");
|
||||
$connection = new self("{$dsn['phptype']}:{$dsn['database']}");
|
||||
$connection->setAttribute(PDO::ATTR_TIMEOUT, 5);
|
||||
$mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL';
|
||||
$mode = defined('SQLITE_JOURNAL_MODE') ? \SQLITE_JOURNAL_MODE : 'WAL';
|
||||
$connection->query("PRAGMA journal_mode=$mode");
|
||||
$connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ class JsonInstall {
|
|||
return $missingTables;
|
||||
}
|
||||
|
||||
//Создать таблицы
|
||||
function initDataBase($initActions/*: array*/, $dbinit_path) {
|
||||
// Создать таблицы
|
||||
function initDataBase(array $initActions, $dbinit_path) {
|
||||
$pg = $this->db_manager->db->isPostgres();
|
||||
if (!$pg) {
|
||||
$refs = [];
|
||||
|
|
|
|||
|
|
@ -9,14 +9,15 @@ use Exception;
|
|||
|
||||
class Manager
|
||||
{
|
||||
public $db/*: Database*/;
|
||||
/** @var Database */
|
||||
public $db;
|
||||
|
||||
public function __construct(Database $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function executeAction($action/*: array*/, $db_file = "")
|
||||
public function executeAction(array $action, $db_file = "")
|
||||
{
|
||||
switch($action["type"]) {
|
||||
case "dropTable":
|
||||
|
|
@ -117,7 +118,7 @@ class Manager
|
|||
return;
|
||||
}
|
||||
|
||||
$data/*: array*/ = $this->dumpTable($table);
|
||||
$data = $this->dumpTable($table);
|
||||
|
||||
$this->db->query("ALTER TABLE ".$table." RENAME TO ".$tmp_table.";");
|
||||
$table_info[$new_name] = $table_info[$old_name];
|
||||
|
|
@ -169,7 +170,7 @@ class Manager
|
|||
$this->db->query($q);
|
||||
}
|
||||
|
||||
public function getConstraintDef($c/*: array*/)
|
||||
public function getConstraintDef(array $c)
|
||||
{
|
||||
if ($c['type'] == 'unique') {
|
||||
return "UNIQUE(" . implode(", ", $c['fields']) . ")";
|
||||
|
|
@ -209,7 +210,7 @@ class Manager
|
|||
foreach ($table_fields as $name => $value) {
|
||||
$type = strtolower($value['type']);
|
||||
if ($type == "boolean") {
|
||||
foreach ($data as &$row) {
|
||||
foreach ($data as &$row) {
|
||||
if (isset($row[$name])) {
|
||||
$row[$name] = boolval($row[$name]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,11 @@ class Statement
|
|||
protected $conn;
|
||||
protected $query;
|
||||
|
||||
function __construct($query, $conn/*: Database*/) {
|
||||
/**
|
||||
* @param string $query
|
||||
* @param Database $conn
|
||||
*/
|
||||
function __construct($query, $conn) {
|
||||
$this->query = $query;
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
|
@ -45,7 +49,7 @@ class Statement
|
|||
if ($this->limit) {
|
||||
$this->query .= " LIMIT {$this->limit} OFFSET {$this->offset}";
|
||||
}
|
||||
$stmt/*: PDOStatement*/ = $this->conn->prepare($this->query);
|
||||
$stmt = $this->conn->prepare($this->query);
|
||||
foreach ($this->binds as $bind) {
|
||||
list($n, $value, $type) = $bind;
|
||||
$stmt->bindValue($n, $value, (int) $type);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ class StatementIterator implements \Iterator
|
|||
private $pos = 0;
|
||||
private $row_count;
|
||||
|
||||
public function __construct($rs/*: PDOStatement*/) {
|
||||
/**
|
||||
* @param PDOStatement $rs
|
||||
*/
|
||||
public function __construct($rs) {
|
||||
$this->result = $rs;
|
||||
$this->row_count = $rs->getRecordCount();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,25 +61,26 @@ class Table
|
|||
/**
|
||||
* Записать значение в клетку с заданными координатами
|
||||
*/
|
||||
function setCell($x, $y, $value)
|
||||
function setCell(int $x, int $y, $value)
|
||||
{
|
||||
assert(is_numeric($x) && $x > 0);
|
||||
assert(is_numeric($y) && $y > 0);
|
||||
assert($x > 0);
|
||||
assert($y > 0);
|
||||
|
||||
if(! isset($this->rows[$x])) {
|
||||
$this->rows[$x] = new TableRow();
|
||||
}
|
||||
$row/*: TableRow*/ = $this->rows[$x];
|
||||
/** @var TableRow $row */
|
||||
$row = $this->rows[$x];
|
||||
$row->setCell($y, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Заполняет ряд начиная с указанного столбца значениями из массива
|
||||
*/
|
||||
function setRow($row, $index, array $data)
|
||||
function setRow(int $row, int $index, array $data)
|
||||
{
|
||||
assert(is_numeric($index) && $index > 0);
|
||||
assert(is_numeric($row) && $row > 0);
|
||||
assert($index > 0);
|
||||
assert($row > 0);
|
||||
|
||||
reset($data);
|
||||
for ($i = $index; $i < $index + count($data); $i++) {
|
||||
|
|
@ -90,20 +91,20 @@ class Table
|
|||
|
||||
/**
|
||||
* Устанавливает высоту ряда
|
||||
* @param $row integer Номер ряда
|
||||
* @parma $value real Высота ряда
|
||||
* @param int $row Номер ряда
|
||||
* @param number $value Высота ряда
|
||||
*/
|
||||
function setRowHeight ($row, $value)
|
||||
function setRowHeight (int $row, $value)
|
||||
{
|
||||
assert(is_numeric($row) && $row > 0);
|
||||
assert($row > 0);
|
||||
|
||||
$this->rows[$row]->height = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Устанавливает стиль ряда
|
||||
* @param $row integer Номер ряда
|
||||
* @parma $name string Имя стиля
|
||||
* @param int $row Номер ряда
|
||||
* @param string $name Имя стиля
|
||||
*/
|
||||
function setRowStyle ($row, $name)
|
||||
{
|
||||
|
|
@ -118,12 +119,13 @@ class Table
|
|||
* @param $cell Номер столбца
|
||||
* @param $merge Количество клеток для обьединения
|
||||
*/
|
||||
function setCellMerge($x, $cell, $merge)
|
||||
function setCellMerge(int $x, int $cell, $merge)
|
||||
{
|
||||
assert(is_numeric($x) && $x > 0);
|
||||
assert(is_numeric($cell) && $cell > 0);
|
||||
assert($x > 0);
|
||||
assert($cell > 0);
|
||||
|
||||
$row/*: TableRow*/ = $this->rows[$x];
|
||||
/** @var TableRow $row */
|
||||
$row = $this->rows[$x];
|
||||
$row->cells[$cell]->merge = $merge;
|
||||
}
|
||||
|
||||
|
|
@ -135,14 +137,15 @@ class Table
|
|||
*/
|
||||
function setCellStyle ($row, $y, $name)
|
||||
{
|
||||
if (isset($this->rows[$row]))
|
||||
if (isset($this->rows[$row])) {
|
||||
$this->rows[$row]->setCellStyle($y, $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет строку к таблице
|
||||
*/
|
||||
function addRow($index = 1, array $data = [""])
|
||||
function addRow(int $index = 1, array $data = [""])
|
||||
{
|
||||
assert(is_numeric($index) && $index > 0);
|
||||
$offset = $this->getRows() + 1;
|
||||
|
|
@ -158,7 +161,7 @@ class Table
|
|||
*/
|
||||
function getRows()
|
||||
{
|
||||
$keys/*: array*/ = array_keys($this->rows);
|
||||
$keys = array_keys($this->rows);
|
||||
return max($keys);
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +172,7 @@ class Table
|
|||
*/
|
||||
function getRowCells(TableRow $row)
|
||||
{
|
||||
$keys/*: array*/ = array_keys($row->cells);
|
||||
$keys = array_keys($row->cells);
|
||||
return max($keys);
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +210,7 @@ class Table
|
|||
/**
|
||||
* Генерация клетки таблицы (Переработать)
|
||||
*/
|
||||
function createCell (TableCell $ncell, XMLWriter $doc, $j, $value/*: any*/, $setIndex) {
|
||||
function createCell (TableCell $ncell, XMLWriter $doc, $j, mixed $value, $setIndex) {
|
||||
$doc->startElement("Cell");
|
||||
|
||||
if ($ncell->style) {
|
||||
|
|
@ -266,8 +269,8 @@ class Table
|
|||
if ($this->rows[$i]->height) {
|
||||
$doc->writeAttribute('ss:Height', $this->rows[$i]->height);
|
||||
}
|
||||
|
||||
$nrow/*: TableRow*/ = $this->rows[$i];
|
||||
/** @var TableRow $nrow */
|
||||
$nrow = $this->rows[$i];
|
||||
// Флаг индикатор подстановки номера столбца
|
||||
$setIndex = false;
|
||||
for ($j = 1; $j <= $columns; $j++) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Фильтр действий
|
||||
* Фильтр действий
|
||||
*/
|
||||
namespace ctiso\Filter;
|
||||
use ctiso\Filter\UserAccess,
|
||||
|
|
@ -12,9 +12,13 @@ class ActionAccess
|
|||
{
|
||||
public $access = array();
|
||||
public $processor;
|
||||
public $user/*: User*/;
|
||||
/** @var User */
|
||||
public $user;
|
||||
|
||||
function __construct($processor/*: Filter*/, $user) {
|
||||
/**
|
||||
* @param Filter $processor
|
||||
*/
|
||||
function __construct($processor, $user) {
|
||||
$this->processor = $processor;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,19 @@ use ctiso\Role\UserInterface,
|
|||
|
||||
/* Переделать формат Логов на список json */
|
||||
class ActionLogger
|
||||
{
|
||||
{
|
||||
public $before = array();
|
||||
public $file;
|
||||
public $user;
|
||||
public $action;
|
||||
public $processor;
|
||||
|
||||
function __construct($processor/*: Filter*/, $logPath, $user/*: UserInterface*/) {
|
||||
/**
|
||||
* @param $processor Filter
|
||||
* @param $logPath string
|
||||
* @param $user UserInterface
|
||||
*/
|
||||
function __construct($processor, $logPath, $user) {
|
||||
$this->processor = $processor;
|
||||
$this->user = $user;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,12 +10,17 @@ use ctiso\Controller\Action,
|
|||
|
||||
class Filter
|
||||
{
|
||||
/** @var Action */
|
||||
public $processor;
|
||||
public function __construct($processor/*: Action*/)
|
||||
|
||||
/**
|
||||
* @param Action $processor
|
||||
*/
|
||||
public function __construct($processor)
|
||||
{
|
||||
$this->processor = $processor;
|
||||
}
|
||||
|
||||
|
||||
public function execute(HttpRequest $request)
|
||||
{
|
||||
return $this->processor->execute($request);
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ class Field
|
|||
public $label; // Метка поля
|
||||
public $value; // Значение поля
|
||||
public $type = ""; // Каждому типу элемента соответствует макрос TAL
|
||||
public $error_msg = null;
|
||||
public $default = null;
|
||||
public $error = false;
|
||||
public $error_msg = null;
|
||||
public $default = null;
|
||||
public $error = false;
|
||||
public $require = false;
|
||||
public $hint = null;
|
||||
public $maxlength = null;
|
||||
|
|
@ -22,10 +22,10 @@ class Field
|
|||
public $_title = array();
|
||||
public $description = "";
|
||||
public $alias = array();
|
||||
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
public function __construct ($input = [], $factory = null)
|
||||
{
|
||||
{
|
||||
$this->default = null;
|
||||
if (isset($input['validate'])) {
|
||||
$this->require = strpos($input['validate'], 'require') !== false;
|
||||
|
|
@ -41,7 +41,10 @@ class Field
|
|||
}
|
||||
}
|
||||
|
||||
function setValue($value/*: any*/)
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,25 +11,25 @@
|
|||
namespace ctiso;
|
||||
|
||||
class right {
|
||||
protected $params;
|
||||
protected $params;
|
||||
protected $fn;
|
||||
|
||||
|
||||
public function __construct($params) {
|
||||
$this->fn = array_shift($params);
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
|
||||
function apply() {
|
||||
$params = func_get_args();
|
||||
array_splice($params, count($params), 0, $this->params);
|
||||
return call_user_func_array($this->fn, $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class left {
|
||||
protected $params;
|
||||
protected $params;
|
||||
protected $fn;
|
||||
|
||||
|
||||
public function __construct($params) {
|
||||
$this->fn = array_shift($params);
|
||||
$this->params = $params;
|
||||
|
|
@ -44,9 +44,9 @@ class left {
|
|||
|
||||
define('__', '_ARGUMENT_PLACE_');
|
||||
class partial {
|
||||
protected $params;
|
||||
protected $params;
|
||||
protected $fn;
|
||||
|
||||
|
||||
public function __construct($params) {
|
||||
$this->fn = array_shift($params);
|
||||
$this->params = $params;
|
||||
|
|
@ -66,7 +66,7 @@ class partial {
|
|||
}
|
||||
return call_user_func_array ($this->fn, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Композиция функций
|
||||
|
|
@ -99,7 +99,7 @@ class Functions {
|
|||
/**
|
||||
* Композиция функций
|
||||
* @param array $_rest
|
||||
* @return mixed
|
||||
* @return mixed
|
||||
*/
|
||||
static function compose($_rest) {
|
||||
$closure = new compose(func_get_args());
|
||||
|
|
@ -109,7 +109,7 @@ class Functions {
|
|||
/**
|
||||
* Карирование справа
|
||||
*
|
||||
* @return mixed
|
||||
* @return mixed
|
||||
*/
|
||||
static function rcurry($_rest) {
|
||||
$closure = new right(func_get_args ());
|
||||
|
|
@ -119,7 +119,7 @@ class Functions {
|
|||
/**
|
||||
* Карирование слева
|
||||
*
|
||||
* @return mixed
|
||||
* @return mixed
|
||||
*/
|
||||
static function lcurry($_rest) {
|
||||
$closure = new left(func_get_args ());
|
||||
|
|
@ -129,9 +129,9 @@ class Functions {
|
|||
/**
|
||||
* Разделение массива на два по условию
|
||||
* @param mixed $pred Условие по которому разделяется массив
|
||||
* @param array $lst
|
||||
* @param array $lst
|
||||
*
|
||||
* @return mixed
|
||||
* @return mixed
|
||||
*/
|
||||
static function partition($pred, $lst) {
|
||||
$left = [];
|
||||
|
|
@ -148,24 +148,24 @@ class Functions {
|
|||
|
||||
/**
|
||||
* @param array $value
|
||||
* @param string $name
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
static function __key($value, $name) {
|
||||
return $value[$name];
|
||||
}
|
||||
|
||||
|
||||
static function identity($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $a
|
||||
* @param array $b
|
||||
* @param $key
|
||||
*
|
||||
* @return int
|
||||
* @return int
|
||||
*/
|
||||
static function __cmp($a, $b, $key) {
|
||||
if ($a[$key] == $b[$key]) {
|
||||
|
|
@ -173,75 +173,81 @@ class Functions {
|
|||
}
|
||||
return ($a[$key] > $b[$key]) ? -1 : 1;
|
||||
}
|
||||
|
||||
|
||||
static function __cmp_less($a, $b, $key) {
|
||||
if ($a[$key] == $b[$key]) {
|
||||
return 0;
|
||||
}
|
||||
return ($a[$key] < $b[$key]) ? -1 : 1;
|
||||
}
|
||||
|
||||
|
||||
// Сравнение по ключу массиве
|
||||
static function __index($n, $key, $row) {
|
||||
return ($row[$key] == $n);
|
||||
}
|
||||
|
||||
|
||||
static function __div($x, $y) {
|
||||
return $x / $y;
|
||||
}
|
||||
|
||||
|
||||
static function __self($name, $o) {
|
||||
return call_user_func([$o, $name]);
|
||||
}
|
||||
|
||||
|
||||
static function concat(/* $args ...*/) {
|
||||
$args = func_get_args();
|
||||
return implode("", $args);
|
||||
}
|
||||
|
||||
|
||||
static function __empty($x) {
|
||||
return empty($x);
|
||||
}
|
||||
|
||||
|
||||
// Отрицание
|
||||
static function __not($x) {
|
||||
return !$x;
|
||||
}
|
||||
|
||||
|
||||
// Не равно
|
||||
static function __neq($x, $y) {
|
||||
return $x != $y;
|
||||
}
|
||||
|
||||
|
||||
// Равно
|
||||
static function __eq($x, $y) {
|
||||
return $x == $y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Извлекает из многомерого массива значения с определенным ключом
|
||||
* @example key_values('a', array(1 => array('a' => 1, 'b' => 2))) => array(1)
|
||||
*
|
||||
* @param string $key
|
||||
* @param array|ArrayIterator $array
|
||||
* @return mixed
|
||||
*/
|
||||
static function key_values($key, $array/*: array|ArrayIterator*/) {
|
||||
static function key_values($key, $array) {
|
||||
$result = [];
|
||||
|
||||
|
||||
foreach($array as $item) {
|
||||
$result[] = $item[$key];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
static function key_values_object($key, $array/*: array|ArrayIterator*/) {
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array|ArrayIterator $array
|
||||
*/
|
||||
static function key_values_object($key, $array) {
|
||||
$result = [];
|
||||
|
||||
|
||||
foreach($array as $item) {
|
||||
$result[] = $item->{$key};
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
static function assoc_key_values($key, $value, $array) {
|
||||
$result = [];
|
||||
foreach ($array as $item) {
|
||||
|
|
@ -249,7 +255,7 @@ class Functions {
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
static function assoc_key($key, $array) {
|
||||
$result = [];
|
||||
foreach ($array as $item) {
|
||||
|
|
@ -257,22 +263,28 @@ class Functions {
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
static function _get($key, $value/*: any*/, $array/*: array*/) {
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $array
|
||||
* @return mixed
|
||||
*/
|
||||
static function _get($key, $value, $array) {
|
||||
foreach ($array as $item) {
|
||||
if ($item[$key] == $value) return $item;
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static function _get_key($key, $value, $array) {
|
||||
foreach ($array as $name => $item) {
|
||||
if ($item[$key] == $value) return $name;
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Логическа операция && ко всем элементам массива
|
||||
* @return bool
|
||||
|
|
@ -285,17 +297,17 @@ class Functions {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Логическа операция || ко всем элементам массива
|
||||
* @param array $array
|
||||
* @param mixed $callback
|
||||
* @param array $array
|
||||
* @param mixed $callback
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
static function some(array $array, $callback) {
|
||||
assert(is_callable($callback));
|
||||
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (call_user_func($callback, $value) === true) {
|
||||
return $key;
|
||||
|
|
@ -303,10 +315,10 @@ class Functions {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static function span($length, array $array) {
|
||||
assert(is_int($length));
|
||||
|
||||
|
||||
$result = [];
|
||||
$count = count($array);
|
||||
for($i = 0; $i < $count; $i += $length) {
|
||||
|
|
@ -314,17 +326,17 @@ class Functions {
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
static function array_ref($data, $n) {
|
||||
return $data[$n];
|
||||
}
|
||||
|
||||
|
||||
static function call() {
|
||||
$args = func_get_args();
|
||||
$args = func_get_args();
|
||||
$name = array_shift($args);
|
||||
return call_user_func_array($name, $args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Поиск элемента в массиве
|
||||
* @param mixed $cb сравнение с элементом массива
|
||||
|
|
@ -337,19 +349,19 @@ class Functions {
|
|||
if (call_user_func_array($cb, [$value, $key, $strict])) return $key;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Выбирает все сроки из таблицы с уникальными значениями ключа
|
||||
* @param string $name Имя ключа
|
||||
* @param array $table Двухмерный массив
|
||||
* @example
|
||||
* key_unique_values ('name', array (array ('name' => 1), array ('name' => 2), array ('name' => 1)))
|
||||
=> array (1, 2)
|
||||
* => array (1, 2)
|
||||
* @end example
|
||||
*/
|
||||
static function key_unique_values ($name, $table) {
|
||||
// Ищем уникальные значения для заданного ключа
|
||||
// Ищем уникальные значения для заданного ключа
|
||||
$keys = [];
|
||||
foreach ($table as $row) {
|
||||
if (!in_array ($row[$name], $keys))
|
||||
|
|
@ -357,7 +369,7 @@ class Functions {
|
|||
}
|
||||
return $keys;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Сортировка двумерного массива по заданному ключу
|
||||
* @param array $array Массив
|
||||
|
|
@ -371,16 +383,18 @@ class Functions {
|
|||
}
|
||||
|
||||
/**
|
||||
* Преобразует ключи элементов для многомерного массива
|
||||
* Преобразует ключи элементов для многомерного массива
|
||||
* @param string $key_name Имя ключа
|
||||
* @param array $array Многомерный массив
|
||||
* @return mixed
|
||||
*/
|
||||
static function hash_key ($key_name,$array/*: array */) {
|
||||
static function hash_key ($key_name, $array) {
|
||||
$result = [];
|
||||
|
||||
foreach($array as $value) {
|
||||
$result[$value[$key_name]] = $value;
|
||||
$result[$value[$key_name]] = $value;
|
||||
}
|
||||
return $result;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class HttpRequest extends Collection
|
|||
return parent::get('data')->get($key, $default);
|
||||
}
|
||||
|
||||
function session(Session $value = null)
|
||||
function session(?Session $value = null)
|
||||
{
|
||||
if ($value) {
|
||||
$this->_session = $value;
|
||||
|
|
@ -63,7 +63,7 @@ class HttpRequest extends Collection
|
|||
return $this->_session;
|
||||
}
|
||||
|
||||
function set($key, $value/*: any*/)
|
||||
function set($key, mixed $value)
|
||||
{
|
||||
parent::get('data')->set($key, $value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class Manager extends Filter
|
|||
* Функция которая добавляет условие для проверки параметров $_GET
|
||||
* @param $get array() | true Ассоциативный массив ключей и значений для $_GET
|
||||
*
|
||||
* @example
|
||||
* @example
|
||||
* addConditionGet(array('module' => 'personal'), 'personal')
|
||||
* addConditionGet(array('module' => 'login'), 'login')
|
||||
*/
|
||||
|
|
@ -28,14 +28,19 @@ class Manager extends Filter
|
|||
}
|
||||
|
||||
/**
|
||||
* Условие для аякс запросов. Тоже самое что и addConditionGet но еще проверяется является ли запрос ajax
|
||||
* Условие для аякс запросов. Тоже самое что и addConditionGet но еще проверяется является ли запрос ajax
|
||||
*/
|
||||
public function addConditionXHR($get, Filter $layout)
|
||||
{
|
||||
$this->addCondition(Functions::rcurry([$this, 'checkXHR'], $get), $layout);
|
||||
}
|
||||
|
||||
public function checkGet($request/*: HttpRequest*/, $get)
|
||||
/**
|
||||
* @param HttpRequest $request
|
||||
* @param array $get
|
||||
* @return bool
|
||||
*/
|
||||
public function checkGet($request, $get)
|
||||
{
|
||||
if (is_array($get)) {
|
||||
foreach ($get as $key => $value) {
|
||||
|
|
@ -47,18 +52,23 @@ class Manager extends Filter
|
|||
return true;
|
||||
}
|
||||
|
||||
public function checkXHR($request/*: HttpRequest*/, $get)
|
||||
/**
|
||||
* @param HttpRequest $request
|
||||
* @param array $get
|
||||
* @return bool
|
||||
*/
|
||||
public function checkXHR($request, $get)
|
||||
{
|
||||
return $request->isAjax() && $this->checkGet($request, $get);
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет условие в общем виде
|
||||
* @parma $get function(HttpRequest) Функция
|
||||
* @parma $get function(HttpRequest) Функция
|
||||
* @parma $layout Layout Макет
|
||||
*/
|
||||
public function addCondition($get, Filter $layout)
|
||||
{
|
||||
{
|
||||
$this->condition [] = [$get, $layout];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class MailAlt
|
|||
function from($name)
|
||||
{
|
||||
$this->mailer->setFrom($name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка получателя
|
||||
|
|
@ -37,12 +37,13 @@ class MailAlt
|
|||
|
||||
/**
|
||||
* Установка получателей копии
|
||||
* @param string $name
|
||||
*/
|
||||
function copy($name) // recipient cc
|
||||
{
|
||||
$this->mailer->addCC($name);
|
||||
}
|
||||
|
||||
|
||||
function notify($notify)
|
||||
{
|
||||
$this->_notify = $notify;
|
||||
|
|
@ -50,29 +51,31 @@ class MailAlt
|
|||
|
||||
/**
|
||||
* Тема письма
|
||||
* @param string $subject
|
||||
*/
|
||||
function subject($subject/*: string*/)
|
||||
function subject($subject)
|
||||
{
|
||||
$this->mailer->Subject = $subject;
|
||||
$this->mailer->Subject = $subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Текст письма
|
||||
* @param string $text
|
||||
*/
|
||||
function setContent($text)
|
||||
function setContent($text)
|
||||
{
|
||||
$this->mailer->Body = $text;
|
||||
}
|
||||
|
||||
function setType($text)
|
||||
function setType($text)
|
||||
{
|
||||
$this->mailer->isHTML($text == 'text/html');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Кодировка текста в письме
|
||||
*/
|
||||
function setEncoding($encoding)
|
||||
function setEncoding($encoding)
|
||||
{
|
||||
$this->encoding = $encoding;
|
||||
}
|
||||
|
|
@ -86,7 +89,7 @@ class MailAlt
|
|||
}
|
||||
|
||||
/**
|
||||
* Отправка почты
|
||||
* Отправка почты
|
||||
*/
|
||||
function send()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -155,7 +155,10 @@ class Path
|
|||
}
|
||||
|
||||
// Сравнение двух путей на равентство
|
||||
public function equal($path/*: Path*/)
|
||||
/**
|
||||
* @param Path $path
|
||||
*/
|
||||
public function equal($path)
|
||||
{
|
||||
$count = count($this->path);
|
||||
if ($count == count($path->path)) {
|
||||
|
|
@ -199,11 +202,11 @@ class Path
|
|||
/**
|
||||
* Проверяет является ли папка родительской для другой папки
|
||||
*
|
||||
* @parma Path $path
|
||||
* @param Path $path
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isParent($path/*: Path*/)
|
||||
public function isParent($path)
|
||||
{
|
||||
if (isset($this->url['host']) && isset($path->url['host'])
|
||||
&& ($this->url['host'] != $path->url['host'])) return false;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
* $setup->set('target', 'dst');
|
||||
* $setup->executeActions('install');
|
||||
* </code>
|
||||
*/
|
||||
*/
|
||||
namespace ctiso;
|
||||
use ctiso\Tools\SQLStatementExtractor;
|
||||
use ctiso\Path;
|
||||
|
|
@ -22,7 +22,7 @@ class FakeZipArchive {
|
|||
}
|
||||
}
|
||||
|
||||
class Setup
|
||||
class Setup
|
||||
{
|
||||
protected $actions = array();
|
||||
public $context = array();
|
||||
|
|
@ -30,7 +30,7 @@ class Setup
|
|||
protected $action;
|
||||
protected $node;
|
||||
protected $stack = array();
|
||||
|
||||
|
||||
public $zip;
|
||||
|
||||
public $target;
|
||||
|
|
@ -56,7 +56,7 @@ class Setup
|
|||
}
|
||||
|
||||
/**
|
||||
* Регистрация новых действия для установки
|
||||
* Регистрация новых действия для установки
|
||||
*/
|
||||
public function registerAction($name, $action)
|
||||
{
|
||||
|
|
@ -71,7 +71,7 @@ class Setup
|
|||
$this->context[$name] = $value;
|
||||
}
|
||||
|
||||
function replaceFn($matches) {
|
||||
function replaceFn($matches) {
|
||||
if (isset($this->context[$matches[2]])) {
|
||||
$v = $this->context[$matches[2]];
|
||||
} else {
|
||||
|
|
@ -85,7 +85,7 @@ class Setup
|
|||
}
|
||||
|
||||
public function fileContent($file, array $tpl)
|
||||
{
|
||||
{
|
||||
$result = $this->zip->getFromName($file);
|
||||
$result = preg_replace_callback('/\{\{\s*(\*?)(\w+)\s*\}\}/', [$this, 'replaceFn'], $result);
|
||||
return $result;
|
||||
|
|
@ -113,48 +113,49 @@ class Setup
|
|||
* Для всех аттрибутов заменяет переменные на их значения
|
||||
*/
|
||||
function resolve($attributes)
|
||||
{
|
||||
{
|
||||
$result = [];
|
||||
foreach ($attributes as $key => $value) {
|
||||
$result [$key] = preg_replace_callback("/\\\${(\w+)}/", [$this, 'replaceVariable'], $value);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Выполняет список действий если для действия не указан аттрибут when то оно выполняется всегда
|
||||
*
|
||||
*
|
||||
* @param string $action специальное действие
|
||||
*/
|
||||
function executeActions($action = "install")
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->action = $action;
|
||||
if ($this->stack[count($this->stack) - 1] === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$item/*: \SimpleXMLElement*/ = $this->stack[count($this->stack) - 1];
|
||||
/** @var \SimpleXMLElement */
|
||||
$item = $this->stack[count($this->stack) - 1];
|
||||
$root = $item->children();
|
||||
foreach ($root as $node)
|
||||
{
|
||||
{
|
||||
$attributes = $node->attributes();
|
||||
array_push($this->stack, $node);
|
||||
$this->callAction($node->getName(), [$this->resolve($attributes)]);
|
||||
array_pop($this->stack);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Копирования файла
|
||||
* Копирования файла
|
||||
* preserve - Не переписывать файл если он существует
|
||||
* template Файл является шаблоном подставить параметры до копирования
|
||||
* src Исходный файл
|
||||
* dst Новый файл
|
||||
*
|
||||
*
|
||||
* @param array{preserve?: string, template: string, src: string, dst: string} $attributes
|
||||
*/
|
||||
public function copyFile(array $attributes)
|
||||
{
|
||||
{
|
||||
$path = $this->targetPath($attributes['dst']);
|
||||
|
||||
if (!(file_exists($path) && isset($attributes['preserve']))) {
|
||||
|
|
@ -164,7 +165,7 @@ class Setup
|
|||
|
||||
/**
|
||||
* Создает символическую ссылку на папку/файл
|
||||
* @param array{target: string, link: string} $attributes
|
||||
* @param array{target: string, link: string} $attributes
|
||||
*/
|
||||
public function makeLink(array $attributes)
|
||||
{
|
||||
|
|
@ -174,7 +175,7 @@ class Setup
|
|||
}
|
||||
|
||||
/**
|
||||
* Подключение файла установки
|
||||
* Подключение файла установки
|
||||
* @param array{file: string} $attributes Имя подключаемого файла
|
||||
*/
|
||||
public function includeFile(array $attributes)
|
||||
|
|
@ -182,7 +183,7 @@ class Setup
|
|||
$file = basename($this->file) . "/" . $attributes['file'];
|
||||
|
||||
$setup = new Setup($file);
|
||||
$setup->context = $this->context;
|
||||
$setup->context = $this->context;
|
||||
$setup->executeActions();
|
||||
}
|
||||
|
||||
|
|
@ -192,9 +193,9 @@ class Setup
|
|||
|
||||
/**
|
||||
* Создает новую папку
|
||||
* dst Имя папки
|
||||
*
|
||||
* @param array{dst:string} $attributes
|
||||
* dst Имя папки
|
||||
*
|
||||
* @param array{dst:string} $attributes
|
||||
*/
|
||||
public function makeDirectory(array $attributes)
|
||||
{
|
||||
|
|
@ -202,7 +203,7 @@ class Setup
|
|||
if (!file_exists($path)) {
|
||||
mkdir($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testWhen(array $attributes)
|
||||
{
|
||||
|
|
@ -212,9 +213,11 @@ class Setup
|
|||
}
|
||||
|
||||
/**
|
||||
* Выполнение Списка SQL команд
|
||||
*/
|
||||
function batchSQLZip($conn/*: Database*/, $file)
|
||||
* Выполнение Списка SQL команд из ZIP файла
|
||||
* @param Database $conn
|
||||
* @param string $file
|
||||
*/
|
||||
function batchSQLZip($conn, $file)
|
||||
{
|
||||
$stmtList = SQLStatementExtractor::extract($this->zip->getFromName($file));
|
||||
foreach ($stmtList as $stmt) {
|
||||
|
|
@ -222,7 +225,12 @@ class Setup
|
|||
}
|
||||
}
|
||||
|
||||
static function batchSQL($conn/*: Database*/, $file)
|
||||
/**
|
||||
* Выполнение Списка SQL команд
|
||||
* @param Database $conn
|
||||
* @param string $file
|
||||
*/
|
||||
static function batchSQL($conn, $file)
|
||||
{
|
||||
$stmtList = SQLStatementExtractor::extractFile($file);
|
||||
foreach ($stmtList as $stmt) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ class Tales_Assets implements PHPTAL_Tales
|
|||
}
|
||||
|
||||
class Tales {
|
||||
static $site/*: SiteInterface*/;
|
||||
/** @var SiteInterface */
|
||||
static $site;
|
||||
|
||||
static function phptal_date ($e) {
|
||||
return date("d.m.Y", $e);
|
||||
|
|
@ -61,12 +62,11 @@ class Tales {
|
|||
*/
|
||||
static function phptal_component($expression) {
|
||||
$begin = floatval(microtime(true));
|
||||
$component/*: Component*/ = null;
|
||||
|
||||
/** @var Component */
|
||||
$component = self::$site->loadComponent($expression);
|
||||
$req = new HttpRequest();
|
||||
$req = new HttpRequest();
|
||||
$result = $component->execute($req);
|
||||
|
||||
|
||||
echo "<!-- ", $expression, ", ", round(floatval(microtime(true)) - $begin, 4), "sec -->";
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Static class for extracting SQL statements from a string or file.
|
||||
*
|
||||
|
|
@ -30,12 +30,12 @@ namespace ctiso\Tools;
|
|||
use Exception;
|
||||
|
||||
class SQLStatementExtractor {
|
||||
|
||||
|
||||
protected static $delimiter = ';';
|
||||
|
||||
|
||||
/**
|
||||
* Get SQL statements from file.
|
||||
*
|
||||
*
|
||||
* @param string $filename Path to file to read.
|
||||
* @return array SQL statements
|
||||
*/
|
||||
|
|
@ -46,17 +46,17 @@ class SQLStatementExtractor {
|
|||
}
|
||||
throw new Exception("Unable to read file: " . $filename);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract statements from string.
|
||||
*
|
||||
*
|
||||
* @param string $buffer
|
||||
* @return array
|
||||
*/
|
||||
public static function extract($buffer) {
|
||||
return self::extractStatements(self::getLines($buffer));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract SQL statements from array of lines.
|
||||
*
|
||||
|
|
@ -64,20 +64,20 @@ class SQLStatementExtractor {
|
|||
* @return array
|
||||
*/
|
||||
protected static function extractStatements($lines) {
|
||||
|
||||
|
||||
$statements = [];
|
||||
$sql = "";
|
||||
|
||||
|
||||
foreach($lines as $line) {
|
||||
|
||||
|
||||
$line = trim($line);
|
||||
|
||||
if (self::startsWith("//", $line) ||
|
||||
|
||||
if (self::startsWith("//", $line) ||
|
||||
self::startsWith("--", $line) ||
|
||||
self::startsWith("#", $line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (strlen($line) > 4 && strtoupper(substr($line,0, 4)) == "REM ") {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -91,19 +91,19 @@ class SQLStatementExtractor {
|
|||
if (strpos($line, "--") !== false) {
|
||||
$sql .= "\n";
|
||||
}
|
||||
|
||||
|
||||
if (self::endsWith(self::$delimiter, $sql)) {
|
||||
$statements[] = self::substring($sql, 0, strlen($sql)-1 - strlen(self::$delimiter));
|
||||
$sql = "";
|
||||
}
|
||||
}
|
||||
return $statements;
|
||||
return $statements;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Some string helper methods
|
||||
//
|
||||
|
||||
//
|
||||
|
||||
/**
|
||||
* Tests if a string starts with a given string.
|
||||
* @param string $check The substring to check.
|
||||
|
|
@ -117,24 +117,24 @@ class SQLStatementExtractor {
|
|||
return (strpos($string, $check) === 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if a string ends with a given string.
|
||||
* @param string $check The substring to check.
|
||||
* @param string $string The string to check in (haystack).
|
||||
* @return boolean True if $string ends with $check, or they are equal, or $check is empty.
|
||||
*/
|
||||
protected static function endsWith($check/*: string*/, $string) {
|
||||
protected static function endsWith(string $check, $string) {
|
||||
if ($check === "" || $check === $string) {
|
||||
return true;
|
||||
} else {
|
||||
return (strpos(strrev($string), strrev($check)) === 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* a natural way of getting a subtring, php's circular string buffer and strange
|
||||
* return values suck if you want to program strict as of C or friends
|
||||
* return values suck if you want to program strict as of C or friends
|
||||
*/
|
||||
protected static function substring($string, $startpos, $endpos = -1) {
|
||||
$len = strlen($string);
|
||||
|
|
@ -152,16 +152,16 @@ class SQLStatementExtractor {
|
|||
}
|
||||
return substr($string, $startpos, $len+1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert string buffer into array of lines.
|
||||
*
|
||||
*
|
||||
* @param string $buffer
|
||||
* @return array string[] lines of file.
|
||||
*/
|
||||
protected static function getLines($buffer) {
|
||||
protected static function getLines($buffer) {
|
||||
$lines = preg_split("/\r?\n|\r/", $buffer);
|
||||
return $lines;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -41,9 +41,8 @@ class TemplateImage
|
|||
public $resource;
|
||||
public $filename;
|
||||
|
||||
function __construct ($template = null)
|
||||
function __construct (?string $template = null)
|
||||
{
|
||||
// assert(is_string($src));
|
||||
if ($template) {
|
||||
$this->data = $template;
|
||||
}
|
||||
|
|
@ -52,27 +51,21 @@ class TemplateImage
|
|||
/**
|
||||
* Путь к изображению
|
||||
*/
|
||||
function resourcePath($path)
|
||||
function resourcePath(string $path)
|
||||
{
|
||||
assert(is_string($path));
|
||||
|
||||
$this->resource = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Путь у шрифтам
|
||||
*/
|
||||
function fontPath($path)
|
||||
function fontPath(string $path)
|
||||
{
|
||||
assert(is_string($path));
|
||||
|
||||
$this->base = $path;
|
||||
}
|
||||
|
||||
function set($name, $value)
|
||||
function set(string $name, $value)
|
||||
{
|
||||
assert(is_string($name));
|
||||
|
||||
$this->context['['.$name.']'] = $this->encode($value);
|
||||
}
|
||||
|
||||
|
|
@ -90,10 +83,8 @@ class TemplateImage
|
|||
/**
|
||||
* Создает изображение из файла
|
||||
*/
|
||||
function imagefromfile($file)
|
||||
function imagefromfile(string $file)
|
||||
{
|
||||
assert(is_string($file));
|
||||
|
||||
$suffix = pathinfo($file, PATHINFO_EXTENSION);
|
||||
if (array_key_exists($suffix, self::$listfiles)) {
|
||||
return call_user_func('imagecreatefrom' . self::$listfiles[$suffix], $file);
|
||||
|
|
@ -101,17 +92,15 @@ class TemplateImage
|
|||
return null;
|
||||
}
|
||||
|
||||
function getFontFile($name)
|
||||
function getFontFile(string $name)
|
||||
{
|
||||
assert(is_string($name));
|
||||
|
||||
if(array_key_exists(strtolower($name), self::$listfonts)) {
|
||||
return $this->base . self::$listfonts[$name];
|
||||
}
|
||||
return $this->base . 'arial.ttf';
|
||||
}
|
||||
|
||||
function fontSuffix($style)
|
||||
function fontSuffix(array $style)
|
||||
{
|
||||
if($style[0] && $style[1]) return "z";
|
||||
|
||||
|
|
@ -121,7 +110,11 @@ class TemplateImage
|
|||
return "";
|
||||
}
|
||||
|
||||
function imageText($text, $value/*: \stdClass*/)
|
||||
/**
|
||||
* @param string $text
|
||||
* @param object $value
|
||||
*/
|
||||
function imageText($text, $value)
|
||||
{
|
||||
assert(is_string($text));
|
||||
|
||||
|
|
@ -130,29 +123,30 @@ class TemplateImage
|
|||
$fontfile = $this->getFontFile($value->fontFamily . $this->fontSuffix($value->fontStyle));
|
||||
|
||||
$color = intval(substr($value->color, 1), 16);
|
||||
if ($value->align[0]) {
|
||||
if ($value->align[0]) {
|
||||
$align = Drawing::ALIGN_LEFT;
|
||||
} elseif ($value->align[2]) {
|
||||
} elseif ($value->align[2]) {
|
||||
$align = Drawing::ALIGN_RIGHT;
|
||||
} else {
|
||||
$align = Drawing::ALIGN_CENTER;
|
||||
}
|
||||
|
||||
if ($value->valign[0]) {
|
||||
if ($value->valign[0]) {
|
||||
$valign = Drawing::ALIGN_TOP;
|
||||
} elseif ($value->valign[1]) {
|
||||
} elseif ($value->valign[1]) {
|
||||
$valign = Drawing::ALIGN_CENTER;
|
||||
} else {
|
||||
$valign = Drawing::ALIGN_BOTTOM;
|
||||
}
|
||||
|
||||
Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text,
|
||||
Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text,
|
||||
$value->width, $value->height,
|
||||
$align, $valign);
|
||||
}
|
||||
|
||||
/**
|
||||
* Перекодировка текста
|
||||
* @deprecated
|
||||
*/
|
||||
function encode($text)
|
||||
{
|
||||
|
|
@ -160,6 +154,10 @@ class TemplateImage
|
|||
return $text; //iconv("WINDOWS-1251", "UTF-8", $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $new_width
|
||||
* @param int $new_height
|
||||
*/
|
||||
function setSize($new_width, $new_height)
|
||||
{
|
||||
$width = imagesx($this->image);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ namespace ctiso;
|
|||
|
||||
class Url {
|
||||
public $parts = [];
|
||||
public $parent/*: Url*/;
|
||||
/** @var Url */
|
||||
public $parent;
|
||||
|
||||
function __construct() {
|
||||
}
|
||||
|
|
@ -23,5 +24,5 @@ class Url {
|
|||
|
||||
function toString() {
|
||||
return '?' . http_build_query(array_merge($this->parts, $this->parent ? $this->parent->parts : []));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ class Validator
|
|||
}
|
||||
}
|
||||
|
||||
public function addRule($rule/*:z any*/) {
|
||||
public function addRule($rule) {
|
||||
if (is_array($rule)) {
|
||||
$this->chain = array_merge($this->chain, $rule);
|
||||
} else {
|
||||
|
|
@ -91,7 +91,11 @@ class Validator
|
|||
}
|
||||
}
|
||||
|
||||
public function skip($rule/*z: AbstractRule*/, $container/*: Collection*/) // -> Rule_Abstract
|
||||
/**
|
||||
* @param AbstractRule $rule
|
||||
* @param Collection $container
|
||||
*/
|
||||
public function skip($rule, $container) // -> Rule_Abstract
|
||||
{
|
||||
if ($rule->skipEmpty()) {
|
||||
$data = $container->get($rule->field);
|
||||
|
|
|
|||
|
|
@ -20,30 +20,30 @@ class Pages
|
|||
}
|
||||
return [
|
||||
'all' => ($n > 1),
|
||||
'list' => $result,
|
||||
'first' => self::href($prefix, $url . 1),
|
||||
'last' => self::href($prefix, $url . $n),
|
||||
'next' => ($page == $n)? false : self::href($prefix, $url . ($page + 1)) ,
|
||||
'list' => $result,
|
||||
'first' => self::href($prefix, $url . 1),
|
||||
'last' => self::href($prefix, $url . $n),
|
||||
'next' => ($page == $n)? false : self::href($prefix, $url . ($page + 1)) ,
|
||||
'prev' => ($page == 1)? false : self::href($prefix, $url . ($page - 1))];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param $page int номер страницы
|
||||
* @param $onpage int количество элем на странице
|
||||
* @param int $page номер страницы
|
||||
* @param int $onpage количество элем на странице
|
||||
* @return string
|
||||
*/
|
||||
static function getLimit($page/*: number*/, $onpage/*: number*/) {
|
||||
static function getLimit(int $page, int $onpage) {
|
||||
if ($page <= 0) { $page = 1; }
|
||||
return "LIMIT $onpage OFFSET " . ($page - 1) * $onpage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $page int номер страницы
|
||||
* @param $onpage int количество элем на странице
|
||||
* @param int $page номер страницы
|
||||
* @param int $onpage количество элем на странице
|
||||
* @return array
|
||||
*/
|
||||
static function _getLimit($page, $onpage) {
|
||||
static function _getLimit(int $page, int $onpage) {
|
||||
if ($page <= 0) { $page = 1; }
|
||||
return [
|
||||
'count' => $onpage,
|
||||
|
|
@ -51,8 +51,8 @@ class Pages
|
|||
];
|
||||
}
|
||||
|
||||
static function href($prefix, $x) {
|
||||
return $prefix . $x;
|
||||
static function href($prefix, $x) {
|
||||
return $prefix . $x;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,11 +68,12 @@ class Top extends Composite
|
|||
}
|
||||
|
||||
$init = [];
|
||||
/** @var View $item */
|
||||
|
||||
foreach ($s->_section as $key => $item) {
|
||||
$ss /*: View*/= $item;
|
||||
if ($ss->codeGenerator !== null) {
|
||||
if ($item->codeGenerator !== null) {
|
||||
// функцию которая вычисляет а не результат
|
||||
$part = call_user_func($ss->codeGenerator, $this, $key, $value);
|
||||
$part = call_user_func($item->codeGenerator, $this, $key, $value);
|
||||
$init[] = $part;
|
||||
}
|
||||
}
|
||||
|
|
@ -89,14 +90,14 @@ class Top extends Composite
|
|||
|
||||
$this->set('title', $this->getTitle());
|
||||
$this->set('jspath', $this->config->get('system', 'web'));
|
||||
//
|
||||
//
|
||||
return $this->execute(); // execute+phptal ??
|
||||
}
|
||||
|
||||
/**
|
||||
* Массив имен файлов скриптов
|
||||
*
|
||||
* return array
|
||||
* return array
|
||||
*/
|
||||
public function getScripts()
|
||||
{
|
||||
|
|
@ -121,7 +122,7 @@ class Top extends Composite
|
|||
/**
|
||||
* Массив имен файлов стилей
|
||||
*
|
||||
* return array
|
||||
* return array
|
||||
*/
|
||||
public function getStyleSheet()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ class View extends \stdClass
|
|||
}
|
||||
|
||||
// FIXME: Префикс, конфликтует с протоколом
|
||||
function resolveName($alias, $file) {
|
||||
function resolveName($alias, $file): string {
|
||||
list($type, $filename) = explode(":", $file, 2);
|
||||
|
||||
// Сделать поиск а не просто замену папки при совпадении имени
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue