style: Форматирование
This commit is contained in:
parent
8941f5f102
commit
d692538163
9 changed files with 92 additions and 92 deletions
|
|
@ -7,6 +7,7 @@ use Exception,
|
|||
ctiso\Model\Factory,
|
||||
ctiso\HttpRequest,
|
||||
ctiso\Settings,
|
||||
ctiso\Database,
|
||||
ctiso\View\Composite,
|
||||
ctiso\View\View,
|
||||
App\Controller\State;
|
||||
|
|
@ -31,7 +32,7 @@ class Action
|
|||
/**
|
||||
* Соединение с базой данных
|
||||
*/
|
||||
public $db;
|
||||
public Database $db;
|
||||
|
||||
// Фильтры
|
||||
public $access = null; // Обьект хранит параметры доступа
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@ use ctiso\HttpRequest,
|
|||
class FakeTemplate {
|
||||
public $_data = [];
|
||||
public $_name = '';
|
||||
|
||||
|
||||
function __construct($name) {
|
||||
$this->_name = $name;
|
||||
}
|
||||
|
||||
function __set($key, $value) {
|
||||
$this->_data[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
function execute() {
|
||||
return json_encode($this->_data);
|
||||
|
|
@ -49,7 +49,7 @@ class Component
|
|||
|
||||
public $COMPONENTS_WEB;
|
||||
|
||||
public Registry $config;
|
||||
public Registry $config;
|
||||
public Database $db;
|
||||
public Collection $parameter;
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ class Component
|
|||
} else {
|
||||
$action = 'action' . ucfirst($_action);
|
||||
}
|
||||
|
||||
|
||||
$this->before();
|
||||
if (method_exists($this, $action)) {
|
||||
return call_user_func([$this, $action], $crequest);
|
||||
|
|
@ -89,16 +89,16 @@ class Component
|
|||
}
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
public function getView($name)
|
||||
{
|
||||
if ($this->output == 'json') {
|
||||
return new FakeTemplate($name);
|
||||
}
|
||||
|
||||
|
||||
$config/*: Registry*/ = $this->config;
|
||||
$default = $config->get('site', 'template');
|
||||
$template = ($this->template) ? $this->template : $this->getTemplateName($config);
|
||||
|
|
@ -113,12 +113,12 @@ class Component
|
|||
$tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION);
|
||||
$selected = $index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($selected === null) {
|
||||
// Последний вариант viewPath, путь к папке компонента
|
||||
$selected = count($this->viewPath) - 1;
|
||||
$selected = count($this->viewPath) - 1;
|
||||
$tpl = new PHPTAL(Path::join($this->viewPath[$selected], 'templates', 'modern', $name));
|
||||
$tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION);
|
||||
$template = 'modern';
|
||||
|
|
@ -156,7 +156,7 @@ class Component
|
|||
return Path::join($this->viewPath[$index], 'templates', $template, $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
|
||||
*/
|
||||
public function getModel($name)
|
||||
|
|
@ -198,7 +198,7 @@ class Component
|
|||
function findFile($pathList, $name) {
|
||||
foreach($pathList as $item) {
|
||||
$filename = Path::join($item, $name);
|
||||
if (file_exists($filename)) {
|
||||
if (file_exists($filename)) {
|
||||
return $filename;
|
||||
}
|
||||
}
|
||||
|
|
@ -233,15 +233,14 @@ class Component
|
|||
|
||||
static function loadComponent($expression, $site/*: SiteInterface*/)
|
||||
{
|
||||
|
||||
|
||||
$expression = htmlspecialchars_decode($expression);
|
||||
$offset = strpos($expression, '?');
|
||||
$url = parse_url($expression);
|
||||
|
||||
|
||||
$arguments = [];
|
||||
if ($offset === false) {
|
||||
$path = $expression;
|
||||
} else if (is_int($offset)) {
|
||||
$path = $expression;
|
||||
if (is_int($offset)) {
|
||||
$path = substr($expression, 0, $offset);
|
||||
$query = substr($expression, $offset + 1);
|
||||
parse_str($query, $arguments);
|
||||
|
|
@ -254,10 +253,10 @@ class Component
|
|||
$className = implode("\\", ['Components', ucfirst($name), $filename]);
|
||||
|
||||
$component/*: Component*/ = null;
|
||||
|
||||
|
||||
if (file_exists($path)) {
|
||||
// require_once ($path);
|
||||
$component = new $className();
|
||||
$component = new $className();
|
||||
|
||||
$component->viewPath = [$config->get('site', 'components') . '/' . $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', 'components') . '/' . $name . '/',
|
||||
// Потом в общем хранилище
|
||||
$config->get('system', 'templates'). '/' . $template . '/_components/' . $name . '/',
|
||||
$config->get('system', 'components') . '/' . $name . '/',
|
||||
$config->get('system', 'templates'). '/' . $template . '/_components/' . $name . '/',
|
||||
$config->get('system', 'components') . '/' . $name . '/',
|
||||
];
|
||||
if (defined('COMPONENTS_WEB')) {
|
||||
$component->webPath = [
|
||||
// Сначало локально
|
||||
$config->get('site', 'templates.web') . '/' . $template . '/_components/' . $name,
|
||||
$config->get('site', 'components.web') . '/' . $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');
|
||||
} else {
|
||||
$component->webPath = ['', $config->get('site', 'components.web') . '/' . $name, '', ''];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$db = $site->getDatabase();
|
||||
|
||||
$component->db = $db;
|
||||
$component->config = $site->config;
|
||||
$component->site = $site;
|
||||
|
||||
|
||||
$stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?");
|
||||
$stmt->setString(1, $expression);
|
||||
$cid = $stmt->executeQuery();
|
||||
|
|
@ -339,7 +338,7 @@ class Component
|
|||
return null;
|
||||
}
|
||||
|
||||
function raw_query($request/*: ComponentRequest*/)
|
||||
function raw_query($request/*: ComponentRequest*/)
|
||||
{
|
||||
$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');
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
namespace ctiso\Controller;
|
||||
use ctiso\Controller\Action,
|
||||
ctiso\Registry,
|
||||
ctiso\Database,
|
||||
ctiso\Database,
|
||||
ctiso\Collection,
|
||||
ctiso\Filter\ActionAccess,
|
||||
ctiso\Filter\ActionLogger,
|
||||
|
|
@ -38,11 +38,11 @@ class Front extends Action
|
|||
|
||||
/**
|
||||
* Создает экземпляр модуля и выполняет действия для него
|
||||
* @param string $name Имя модуля
|
||||
* @param Collection $request Имя модуля
|
||||
* @return string
|
||||
* @param string $name Имя модуля
|
||||
* @param HttpRequest $request
|
||||
* @return string
|
||||
*/
|
||||
public function loadModule($name, Collection $request)
|
||||
public function loadModule($name, HttpRequest $request)
|
||||
{
|
||||
if ($this->isLoaded($name)) {
|
||||
$module = $this->modules[$name];
|
||||
|
|
@ -50,45 +50,43 @@ class Front extends Action
|
|||
}
|
||||
|
||||
$parts = explode('\\', $name);
|
||||
|
||||
|
||||
$config = $this->config;
|
||||
|
||||
|
||||
$moulesPath = Path::join($config->get('system', 'path'), 'modules');
|
||||
$logPath = Path::join($config->get('site', 'path'), $config->get('system', 'access.log'));
|
||||
|
||||
$first = $parts[0];
|
||||
$second = (count($parts) >= 2) ? $parts[1] : $parts[0];
|
||||
|
||||
|
||||
$ucname = ucfirst($first);
|
||||
$ucpart = ucfirst($second);
|
||||
|
||||
|
||||
$moduleClass = "Modules\\$ucname\\$ucpart";
|
||||
$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();
|
||||
|
||||
$this->modules[$name] = $module;
|
||||
$result = $module->access->execute($request);
|
||||
return $result;
|
||||
}
|
||||
return null; // throw new FileNotFoundException();
|
||||
// Инициализация модуля
|
||||
$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();
|
||||
|
||||
$this->modules[$name] = $module;
|
||||
$result = $module->access->execute($request);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ class Form extends View {
|
|||
* Устанавливает значения из масива
|
||||
*/
|
||||
function setValues(HttpRequest $request) {
|
||||
foreach ($this->field as $key => $el) {
|
||||
foreach ($this->field as $key => $_) {
|
||||
$value = $request->getRawData($this->method, $key);
|
||||
$this->field[$key]->setValue($value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class Mail
|
|||
|
||||
function __construct() {
|
||||
$this->setEncoding("UTF-8");
|
||||
$this->uniqid = strtoupper(uniqid(time())); // Идентефикатор разделителя
|
||||
$this->uniqid = strtoupper(uniqid((string)time())); // Идентефикатор разделителя
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class User implements UserInterface
|
|||
public $name;
|
||||
public $access;
|
||||
public $password;
|
||||
public $id;
|
||||
public $id;
|
||||
public $db;
|
||||
public $groups;
|
||||
|
||||
|
|
|
|||
|
|
@ -146,12 +146,12 @@ class Setup
|
|||
|
||||
/**
|
||||
* Копирования файла
|
||||
* preserver - Не переписывать файл если он существует
|
||||
* preserve - Не переписывать файл если он существует
|
||||
* template Файл является шаблоном подставить параметры до копирования
|
||||
* src Исходный файл
|
||||
* 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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ class Drawing
|
|||
const ALIGN_BOTTOM = "bottom";
|
||||
const ALIGN_CENTER = "center";
|
||||
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]);
|
||||
$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)
|
||||
{
|
||||
// echo $left,"\n", $top, "\n";
|
||||
// echo $max_width,"\n", $max_height, "\n";
|
||||
// self::drawrectnagle($image, $left, $top, $max_width, $max_height, array(0xFF,0,0));
|
||||
$text_lines = explode("\n", $text); // Supports manual line breaks!
|
||||
|
||||
|
||||
$lines = [];
|
||||
$line_widths = [];
|
||||
|
||||
$largest_line_height = 0;
|
||||
|
||||
$largest_line_height = 0;
|
||||
foreach ($text_lines as $block) {
|
||||
$current_line = ''; // Reset current line
|
||||
$words = explode(' ', $block); // Split the text into an array of single words
|
||||
$current_line = ''; // Reset current line
|
||||
$words = explode(' ', $block); // Split the text into an array of single words
|
||||
$first_word = true;
|
||||
|
||||
$last_width = 0;
|
||||
|
||||
$last_width = 0;
|
||||
$count = count($words);
|
||||
$item = '';
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$item = $words[$i];
|
||||
$dimensions = imagettfbbox($size, $angle, $font, $current_line . ($first_word ? '' : ' ') . $item);
|
||||
$line_width = $dimensions[2] - $dimensions[0];
|
||||
$line_height = $dimensions[1] - $dimensions[7];
|
||||
|
||||
|
||||
$largest_line_height = max($line_height, $largest_line_height);
|
||||
|
||||
|
||||
if ($line_width > $max_width && !$first_word) {
|
||||
$lines[] = $current_line;
|
||||
|
||||
|
||||
$line_widths[] = $last_width ?: $line_width;
|
||||
$current_line = $item;
|
||||
} else {
|
||||
$current_line .= ($first_word ? '' : ' ') . $item;
|
||||
}
|
||||
|
||||
|
||||
if ($i == count($words) - 1) {
|
||||
$lines[] = $current_line;
|
||||
$lines[] = $current_line;
|
||||
$line_widths[] = $line_width;
|
||||
}
|
||||
|
||||
$last_width = $line_width;
|
||||
|
||||
$last_width = $line_width;
|
||||
$first_word = false;
|
||||
}
|
||||
|
||||
|
||||
if ($current_line) {
|
||||
$current_line = $item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// vertical align
|
||||
$top_offset = 0;
|
||||
if ($valign == self::ALIGN_CENTER) {
|
||||
$top_offset = ($max_height - $largest_line_height * count($lines)) / 2;
|
||||
} elseif ($valign == self::ALIGN_BOTTOM) {
|
||||
$top_offset = $max_height - $largest_line_height * count($lines);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$top += $largest_line_height + $top_offset;
|
||||
|
||||
|
||||
$i = 0;
|
||||
foreach ($lines as $line) {
|
||||
// horizontal align
|
||||
|
|
@ -93,17 +94,17 @@ class Drawing
|
|||
} elseif ($align == self::ALIGN_RIGHT) {
|
||||
$left_offset = ($max_width - $line_widths[$i]);
|
||||
}
|
||||
|
||||
|
||||
imagettftext($image, $size, $angle, $left + $left_offset, $top + ($largest_line_height * $i), $color, $font, $line);
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
return $largest_line_height * count($lines);
|
||||
}
|
||||
|
||||
|
||||
function imagettftextSp($image, $size, $angle, $x, $y, $color, $font, $text, $spacing = 0)
|
||||
{
|
||||
{
|
||||
if ($spacing == 0)
|
||||
{
|
||||
imagettftext($image, $size, $angle, $x, $y, $color, $font, $text);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ class Time extends AbstractRule
|
|||
|
||||
public function isValid(Collection $container, $status = null)
|
||||
{
|
||||
/** @var array[string]|null */
|
||||
$tmp = explode($this->split, $container->get($this->field), 2);
|
||||
if ($tmp) {
|
||||
if (self::checktime ((int)$tmp[0], (int)$tmp[1])) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue