style: Форматирование

This commit is contained in:
origami11@yandex.ru 2024-08-29 11:11:20 +03:00
parent 8941f5f102
commit d692538163
9 changed files with 92 additions and 92 deletions

View file

@ -7,6 +7,7 @@ use Exception,
ctiso\Model\Factory, ctiso\Model\Factory,
ctiso\HttpRequest, ctiso\HttpRequest,
ctiso\Settings, ctiso\Settings,
ctiso\Database,
ctiso\View\Composite, ctiso\View\Composite,
ctiso\View\View, ctiso\View\View,
App\Controller\State; App\Controller\State;
@ -31,7 +32,7 @@ class Action
/** /**
* Соединение с базой данных * Соединение с базой данных
*/ */
public $db; public Database $db;
// Фильтры // Фильтры
public $access = null; // Обьект хранит параметры доступа public $access = null; // Обьект хранит параметры доступа

View file

@ -19,14 +19,14 @@ use ctiso\HttpRequest,
class FakeTemplate { class FakeTemplate {
public $_data = []; public $_data = [];
public $_name = ''; public $_name = '';
function __construct($name) { function __construct($name) {
$this->_name = $name; $this->_name = $name;
} }
function __set($key, $value) { function __set($key, $value) {
$this->_data[$key] = $value; $this->_data[$key] = $value;
} }
function execute() { function execute() {
return json_encode($this->_data); return json_encode($this->_data);
@ -49,7 +49,7 @@ class Component
public $COMPONENTS_WEB; public $COMPONENTS_WEB;
public Registry $config; public Registry $config;
public Database $db; public Database $db;
public Collection $parameter; public Collection $parameter;
@ -79,7 +79,7 @@ class Component
} else { } else {
$action = 'action' . ucfirst($_action); $action = 'action' . ucfirst($_action);
} }
$this->before(); $this->before();
if (method_exists($this, $action)) { if (method_exists($this, $action)) {
return call_user_func([$this, $action], $crequest); return call_user_func([$this, $action], $crequest);
@ -89,16 +89,16 @@ class Component
} }
public function getTemplateName($_registry/*: \ctiso\Settings*/) { public function getTemplateName($_registry/*: \ctiso\Settings*/) {
return (isset($_COOKIE['with_template']) && preg_match('/^[\w\d-]{3,20}$/', $_COOKIE['with_template'])) return (isset($_COOKIE['with_template']) && preg_match('/^[\w\d-]{3,20}$/', $_COOKIE['with_template']))
? $_COOKIE['with_template'] : ($_registry ? $_registry->get('site', 'template') : 'modern'); ? $_COOKIE['with_template'] : ($_registry ? $_registry->get('site', 'template') : 'modern');
} }
public function getView($name) public function getView($name)
{ {
if ($this->output == 'json') { if ($this->output == 'json') {
return new FakeTemplate($name); return new FakeTemplate($name);
} }
$config/*: Registry*/ = $this->config; $config/*: Registry*/ = $this->config;
$default = $config->get('site', 'template'); $default = $config->get('site', 'template');
$template = ($this->template) ? $this->template : $this->getTemplateName($config); $template = ($this->template) ? $this->template : $this->getTemplateName($config);
@ -113,12 +113,12 @@ class Component
$tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION); $tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION);
$selected = $index; $selected = $index;
break; break;
} }
} }
if ($selected === null) { if ($selected === null) {
// Последний вариант viewPath, путь к папке компонента // Последний вариант viewPath, путь к папке компонента
$selected = count($this->viewPath) - 1; $selected = count($this->viewPath) - 1;
$tpl = new PHPTAL(Path::join($this->viewPath[$selected], 'templates', 'modern', $name)); $tpl = new PHPTAL(Path::join($this->viewPath[$selected], 'templates', 'modern', $name));
$tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION); $tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION);
$template = 'modern'; $template = 'modern';
@ -156,7 +156,7 @@ class Component
return Path::join($this->viewPath[$index], 'templates', $template, $name); return Path::join($this->viewPath[$index], 'templates', $template, $name);
} }
} }
return Path::join($this->viewPath[count($this->viewPath) - 1], 'templates', 'modern', $name); return Path::join($this->viewPath[count($this->viewPath) - 1], 'templates', 'modern', $name);
} }
@ -167,7 +167,7 @@ class Component
/** /**
* Создает модель * Создает модель
* @param string $name * @param string $name
* @return mixed * @return mixed
*/ */
public function getModel($name) public function getModel($name)
@ -198,7 +198,7 @@ class Component
function findFile($pathList, $name) { function findFile($pathList, $name) {
foreach($pathList as $item) { foreach($pathList as $item) {
$filename = Path::join($item, $name); $filename = Path::join($item, $name);
if (file_exists($filename)) { if (file_exists($filename)) {
return $filename; return $filename;
} }
} }
@ -233,15 +233,14 @@ class Component
static function loadComponent($expression, $site/*: SiteInterface*/) static function loadComponent($expression, $site/*: SiteInterface*/)
{ {
$expression = htmlspecialchars_decode($expression); $expression = htmlspecialchars_decode($expression);
$offset = strpos($expression, '?'); $offset = strpos($expression, '?');
$url = parse_url($expression); $url = parse_url($expression);
$arguments = []; $arguments = [];
if ($offset === false) { $path = $expression;
$path = $expression; if (is_int($offset)) {
} else if (is_int($offset)) {
$path = substr($expression, 0, $offset); $path = substr($expression, 0, $offset);
$query = substr($expression, $offset + 1); $query = substr($expression, $offset + 1);
parse_str($query, $arguments); parse_str($query, $arguments);
@ -254,10 +253,10 @@ class Component
$className = implode("\\", ['Components', ucfirst($name), $filename]); $className = implode("\\", ['Components', ucfirst($name), $filename]);
$component/*: Component*/ = null; $component/*: Component*/ = null;
if (file_exists($path)) { if (file_exists($path)) {
// require_once ($path); // require_once ($path);
$component = new $className(); $component = new $className();
$component->viewPath = [$config->get('site', 'components') . '/' . $name . '/']; $component->viewPath = [$config->get('site', 'components') . '/' . $name . '/'];
$component->webPath = [$config->get('site', 'components.web') . '/' . $name]; $component->webPath = [$config->get('site', 'components.web') . '/' . $name];
@ -272,30 +271,30 @@ class Component
$config->get('site', 'templates') . '/'. $template . '/_components/' . $name . '/', $config->get('site', 'templates') . '/'. $template . '/_components/' . $name . '/',
$config->get('site', 'components') . '/' . $name . '/', $config->get('site', 'components') . '/' . $name . '/',
// Потом в общем хранилище // Потом в общем хранилище
$config->get('system', 'templates'). '/' . $template . '/_components/' . $name . '/', $config->get('system', 'templates'). '/' . $template . '/_components/' . $name . '/',
$config->get('system', 'components') . '/' . $name . '/', $config->get('system', 'components') . '/' . $name . '/',
]; ];
if (defined('COMPONENTS_WEB')) { if (defined('COMPONENTS_WEB')) {
$component->webPath = [ $component->webPath = [
// Сначало локально // Сначало локально
$config->get('site', 'templates.web') . '/' . $template . '/_components/' . $name, $config->get('site', 'templates.web') . '/' . $template . '/_components/' . $name,
$config->get('site', 'components.web') . '/' . $name, $config->get('site', 'components.web') . '/' . $name,
// Потом в общем хранилище // Потом в общем хранилище
$config->get('system', 'templates.web') . '/' . $template . '/_components/' . $name, $config->get('system', 'templates.web') . '/' . $template . '/_components/' . $name,
$config->get('system', 'components.web') . '/' . $name, $config->get('system', 'components.web') . '/' . $name,
]; ];
$component->COMPONENTS_WEB = $config->get('system', 'components.web'); $component->COMPONENTS_WEB = $config->get('system', 'components.web');
} else { } else {
$component->webPath = ['', $config->get('site', 'components.web') . '/' . $name, '', '']; $component->webPath = ['', $config->get('site', 'components.web') . '/' . $name, '', ''];
} }
} }
$db = $site->getDatabase(); $db = $site->getDatabase();
$component->db = $db; $component->db = $db;
$component->config = $site->config; $component->config = $site->config;
$component->site = $site; $component->site = $site;
$stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?"); $stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?");
$stmt->setString(1, $expression); $stmt->setString(1, $expression);
$cid = $stmt->executeQuery(); $cid = $stmt->executeQuery();
@ -339,7 +338,7 @@ class Component
return null; return null;
} }
function raw_query($request/*: ComponentRequest*/) function raw_query($request/*: ComponentRequest*/)
{ {
$arr = $request->r->export('get'); $arr = $request->r->export('get');
@ -362,7 +361,7 @@ class Component
} }
function query($request/*: ComponentRequest*/, $list) function query($request/*: ComponentRequest*/, $list)
{ {
$arr = $request->r->export('get'); $arr = $request->r->export('get');

View file

@ -7,7 +7,7 @@
namespace ctiso\Controller; namespace ctiso\Controller;
use ctiso\Controller\Action, use ctiso\Controller\Action,
ctiso\Registry, ctiso\Registry,
ctiso\Database, ctiso\Database,
ctiso\Collection, ctiso\Collection,
ctiso\Filter\ActionAccess, ctiso\Filter\ActionAccess,
ctiso\Filter\ActionLogger, ctiso\Filter\ActionLogger,
@ -38,11 +38,11 @@ class Front extends Action
/** /**
* Создает экземпляр модуля и выполняет действия для него * Создает экземпляр модуля и выполняет действия для него
* @param string $name Имя модуля * @param string $name Имя модуля
* @param Collection $request Имя модуля * @param HttpRequest $request
* @return string * @return string
*/ */
public function loadModule($name, Collection $request) public function loadModule($name, HttpRequest $request)
{ {
if ($this->isLoaded($name)) { if ($this->isLoaded($name)) {
$module = $this->modules[$name]; $module = $this->modules[$name];
@ -50,45 +50,43 @@ class Front extends Action
} }
$parts = explode('\\', $name); $parts = explode('\\', $name);
$config = $this->config; $config = $this->config;
$moulesPath = Path::join($config->get('system', 'path'), 'modules'); $moulesPath = Path::join($config->get('system', 'path'), 'modules');
$logPath = Path::join($config->get('site', 'path'), $config->get('system', 'access.log')); $logPath = Path::join($config->get('site', 'path'), $config->get('system', 'access.log'));
$first = $parts[0]; $first = $parts[0];
$second = (count($parts) >= 2) ? $parts[1] : $parts[0]; $second = (count($parts) >= 2) ? $parts[1] : $parts[0];
$ucname = ucfirst($first); $ucname = ucfirst($first);
$ucpart = ucfirst($second); $ucpart = ucfirst($second);
$moduleClass = "Modules\\$ucname\\$ucpart"; $moduleClass = "Modules\\$ucname\\$ucpart";
$module = new $moduleClass(); $module = new $moduleClass();
if ($module) {
// Инициализация модуля
$modPath = Path::join($moulesPath, $first);
$module->modulePath = $modPath;
$module->name = $name;
//
$module->config = $this->config;
$module->db = $this->db;
$module->user = $this->user;
$module->front = $this;
// Ведение лога
$logger = new ActionLogger($module, $logPath, $this->user);
$filename = Path::join($modPath, 'filters', 'logger.json');
$logger->before = $this->loadSettings($filename);
// Управление доступом
$module->access = new ActionAccess($logger, $this->user);
$module->access->access = $this->loadSettings(Path::join($modPath, 'filters', 'access.json'));
$module->setUp(); // Инициализация модуля
$modPath = Path::join($moulesPath, $first);
$this->modules[$name] = $module; $module->modulePath = $modPath;
$result = $module->access->execute($request); $module->name = $name;
return $result; //
} $module->config = $this->config;
return null; // throw new FileNotFoundException(); $module->db = $this->db;
$module->user = $this->user;
$module->front = $this;
// Ведение лога
$logger = new ActionLogger($module, $logPath, $this->user);
$filename = Path::join($modPath, 'filters', 'logger.json');
$logger->before = $this->loadSettings($filename);
// Управление доступом
$module->access = new ActionAccess($logger, $this->user);
$module->access->access = $this->loadSettings(Path::join($modPath, 'filters', 'access.json'));
$module->setUp();
$this->modules[$name] = $module;
$result = $module->access->execute($request);
return $result;
} }

View file

@ -153,7 +153,7 @@ class Form extends View {
* Устанавливает значения из масива * Устанавливает значения из масива
*/ */
function setValues(HttpRequest $request) { function setValues(HttpRequest $request) {
foreach ($this->field as $key => $el) { foreach ($this->field as $key => $_) {
$value = $request->getRawData($this->method, $key); $value = $request->getRawData($this->method, $key);
$this->field[$key]->setValue($value); $this->field[$key]->setValue($value);
} }

View file

@ -25,7 +25,7 @@ class Mail
function __construct() { function __construct() {
$this->setEncoding("UTF-8"); $this->setEncoding("UTF-8");
$this->uniqid = strtoupper(uniqid(time())); // Идентефикатор разделителя $this->uniqid = strtoupper(uniqid((string)time())); // Идентефикатор разделителя
} }
/** /**

View file

@ -13,7 +13,7 @@ class User implements UserInterface
public $name; public $name;
public $access; public $access;
public $password; public $password;
public $id; public $id;
public $db; public $db;
public $groups; public $groups;

View file

@ -146,12 +146,12 @@ class Setup
/** /**
* Копирования файла * Копирования файла
* preserver - Не переписывать файл если он существует * preserve - Не переписывать файл если он существует
* template Файл является шаблоном подставить параметры до копирования * template Файл является шаблоном подставить параметры до копирования
* src Исходный файл * src Исходный файл
* dst Новый файл * dst Новый файл
* *
* @param array{preserve: string, template: string, src: string, dst: string} $attributes * @param array{preserve?: string, template: string, src: string, dst: string} $attributes
*/ */
public function copyFile(array $attributes) public function copyFile(array $attributes)
{ {

View file

@ -9,8 +9,8 @@ class Drawing
const ALIGN_BOTTOM = "bottom"; const ALIGN_BOTTOM = "bottom";
const ALIGN_CENTER = "center"; const ALIGN_CENTER = "center";
const ALIGN_RIGHT = "right"; const ALIGN_RIGHT = "right";
static function drawrectnagle(&$image, $left, $top, $width, $height, $rgb) static function drawrectnagle(&$image, $left, $top, $width, $height, $rgb)
{ {
$color = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]); $color = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);
$right = $left + $width; $right = $left + $width;
@ -22,68 +22,69 @@ class Drawing
} }
/** /**
* http://ru2.php.net/imagettftext * http://ru2.php.net/imagettftext
*/ */
static function imagettftextbox(&$image, $size, $angle, $left, $top, $color, $font, $text, static function imagettftextbox(&$image, $size, $angle, $left, $top, $color, $font, $text,
$max_width, $max_height, $align, $valign) $max_width, $max_height, $align, $valign)
{ {
// echo $left,"\n", $top, "\n"; // echo $left,"\n", $top, "\n";
// echo $max_width,"\n", $max_height, "\n"; // echo $max_width,"\n", $max_height, "\n";
// self::drawrectnagle($image, $left, $top, $max_width, $max_height, array(0xFF,0,0)); // self::drawrectnagle($image, $left, $top, $max_width, $max_height, array(0xFF,0,0));
$text_lines = explode("\n", $text); // Supports manual line breaks! $text_lines = explode("\n", $text); // Supports manual line breaks!
$lines = []; $lines = [];
$line_widths = []; $line_widths = [];
$largest_line_height = 0; $largest_line_height = 0;
foreach ($text_lines as $block) { foreach ($text_lines as $block) {
$current_line = ''; // Reset current line $current_line = ''; // Reset current line
$words = explode(' ', $block); // Split the text into an array of single words $words = explode(' ', $block); // Split the text into an array of single words
$first_word = true; $first_word = true;
$last_width = 0; $last_width = 0;
$count = count($words); $count = count($words);
$item = '';
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$item = $words[$i]; $item = $words[$i];
$dimensions = imagettfbbox($size, $angle, $font, $current_line . ($first_word ? '' : ' ') . $item); $dimensions = imagettfbbox($size, $angle, $font, $current_line . ($first_word ? '' : ' ') . $item);
$line_width = $dimensions[2] - $dimensions[0]; $line_width = $dimensions[2] - $dimensions[0];
$line_height = $dimensions[1] - $dimensions[7]; $line_height = $dimensions[1] - $dimensions[7];
$largest_line_height = max($line_height, $largest_line_height); $largest_line_height = max($line_height, $largest_line_height);
if ($line_width > $max_width && !$first_word) { if ($line_width > $max_width && !$first_word) {
$lines[] = $current_line; $lines[] = $current_line;
$line_widths[] = $last_width ?: $line_width; $line_widths[] = $last_width ?: $line_width;
$current_line = $item; $current_line = $item;
} else { } else {
$current_line .= ($first_word ? '' : ' ') . $item; $current_line .= ($first_word ? '' : ' ') . $item;
} }
if ($i == count($words) - 1) { if ($i == count($words) - 1) {
$lines[] = $current_line; $lines[] = $current_line;
$line_widths[] = $line_width; $line_widths[] = $line_width;
} }
$last_width = $line_width; $last_width = $line_width;
$first_word = false; $first_word = false;
} }
if ($current_line) { if ($current_line) {
$current_line = $item; $current_line = $item;
} }
} }
// vertical align // vertical align
$top_offset = 0; $top_offset = 0;
if ($valign == self::ALIGN_CENTER) { if ($valign == self::ALIGN_CENTER) {
$top_offset = ($max_height - $largest_line_height * count($lines)) / 2; $top_offset = ($max_height - $largest_line_height * count($lines)) / 2;
} elseif ($valign == self::ALIGN_BOTTOM) { } elseif ($valign == self::ALIGN_BOTTOM) {
$top_offset = $max_height - $largest_line_height * count($lines); $top_offset = $max_height - $largest_line_height * count($lines);
} }
$top += $largest_line_height + $top_offset; $top += $largest_line_height + $top_offset;
$i = 0; $i = 0;
foreach ($lines as $line) { foreach ($lines as $line) {
// horizontal align // horizontal align
@ -93,17 +94,17 @@ class Drawing
} elseif ($align == self::ALIGN_RIGHT) { } elseif ($align == self::ALIGN_RIGHT) {
$left_offset = ($max_width - $line_widths[$i]); $left_offset = ($max_width - $line_widths[$i]);
} }
imagettftext($image, $size, $angle, $left + $left_offset, $top + ($largest_line_height * $i), $color, $font, $line); imagettftext($image, $size, $angle, $left + $left_offset, $top + ($largest_line_height * $i), $color, $font, $line);
$i++; $i++;
} }
return $largest_line_height * count($lines); return $largest_line_height * count($lines);
} }
function imagettftextSp($image, $size, $angle, $x, $y, $color, $font, $text, $spacing = 0) function imagettftextSp($image, $size, $angle, $x, $y, $color, $font, $text, $spacing = 0)
{ {
if ($spacing == 0) if ($spacing == 0)
{ {
imagettftext($image, $size, $angle, $x, $y, $color, $font, $text); imagettftext($image, $size, $angle, $x, $y, $color, $font, $text);

View file

@ -25,6 +25,7 @@ class Time extends AbstractRule
public function isValid(Collection $container, $status = null) public function isValid(Collection $container, $status = null)
{ {
/** @var array[string]|null */
$tmp = explode($this->split, $container->get($this->field), 2); $tmp = explode($this->split, $container->get($this->field), 2);
if ($tmp) { if ($tmp) {
if (self::checktime ((int)$tmp[0], (int)$tmp[1])) { if (self::checktime ((int)$tmp[0], (int)$tmp[1])) {