chore: Типы для параметров
This commit is contained in:
parent
6ef65fc826
commit
36c81135f3
7 changed files with 55 additions and 95 deletions
|
|
@ -119,7 +119,8 @@ class Action
|
||||||
if(file_exists($template)) { break; }
|
if(file_exists($template)) { break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl/*: Composite*/ = new $viewClass($template);
|
/** @var \ctiso\View\Composite */
|
||||||
|
$tpl = new $viewClass($template);
|
||||||
$tpl->config = $this->config;
|
$tpl->config = $this->config;
|
||||||
|
|
||||||
$stylePath = Path::join($webPath, "assets", "css");
|
$stylePath = Path::join($webPath, "assets", "css");
|
||||||
|
|
@ -140,8 +141,6 @@ class Action
|
||||||
'template' => $list
|
'template' => $list
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$tpl->loadImports(Path::skipExtension($template) . ".import");
|
|
||||||
|
|
||||||
$this->addSuggest($tpl, $name);
|
$this->addSuggest($tpl, $name);
|
||||||
return $tpl;
|
return $tpl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,10 @@ class Component
|
||||||
|
|
||||||
public $module;
|
public $module;
|
||||||
public $item_module;
|
public $item_module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \App\Controller\Site
|
||||||
|
*/
|
||||||
public $site;
|
public $site;
|
||||||
|
|
||||||
function before() {
|
function before() {
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,11 @@ use ctiso\Validator\Rule\AbstractRule,
|
||||||
|
|
||||||
class Code extends AbstractRule
|
class Code extends AbstractRule
|
||||||
{
|
{
|
||||||
public function getErrorMsg()
|
public function getErrorMsg(): string {
|
||||||
{
|
|
||||||
return "Неправильно указан персональный код";
|
return "Неправильно указан персональный код";
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCode($code) {
|
function checkCode($code): bool {
|
||||||
foreach($code as $c) {
|
foreach($code as $c) {
|
||||||
if (empty($c)) {
|
if (empty($c)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -23,7 +22,7 @@ class Code extends AbstractRule
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isValid(Collection $container, $status = null)
|
public function isValid(Collection $container, $status = null): bool
|
||||||
{
|
{
|
||||||
if ($status == 'update') return true;
|
if ($status == 'update') return true;
|
||||||
$name = $this->field;
|
$name = $this->field;
|
||||||
|
|
@ -32,27 +31,27 @@ class Code extends AbstractRule
|
||||||
$count = count($_POST[$name . '_code_genre']);
|
$count = count($_POST[$name . '_code_genre']);
|
||||||
for($n = 0; $n < $count; $n++) {
|
for($n = 0; $n < $count; $n++) {
|
||||||
$code = [
|
$code = [
|
||||||
$_POST[$name . '_code_genre'][$n],
|
$_POST[$name . '_code_genre'][$n],
|
||||||
$_POST[$name . '_code_f'][$n],
|
$_POST[$name . '_code_f'][$n],
|
||||||
$_POST[$name . '_code_i'][$n],
|
$_POST[$name . '_code_i'][$n],
|
||||||
$_POST[$name . '_code_o'][$n],
|
$_POST[$name . '_code_o'][$n],
|
||||||
$_POST[$name . '_code_year'][$n],
|
$_POST[$name . '_code_year'][$n],
|
||||||
$_POST[$name . '_code_month'][$n],
|
$_POST[$name . '_code_month'][$n],
|
||||||
$_POST[$name . '_code_day'][$n]
|
$_POST[$name . '_code_day'][$n]
|
||||||
];
|
];
|
||||||
if (!$this->checkCode($code)) {
|
if (!$this->checkCode($code)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$code = [
|
$code = [
|
||||||
$_POST[$name . '_code_genre'],
|
$_POST[$name . '_code_genre'],
|
||||||
$_POST[$name . '_code_f'],
|
$_POST[$name . '_code_f'],
|
||||||
$_POST[$name . '_code_i'],
|
$_POST[$name . '_code_i'],
|
||||||
$_POST[$name . '_code_o'],
|
$_POST[$name . '_code_o'],
|
||||||
$_POST[$name . '_code_year'],
|
$_POST[$name . '_code_year'],
|
||||||
$_POST[$name . '_code_month'],
|
$_POST[$name . '_code_month'],
|
||||||
$_POST[$name . '_code_day']
|
$_POST[$name . '_code_day']
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class Composite extends View
|
||||||
|
|
||||||
function execute()
|
function execute()
|
||||||
{
|
{
|
||||||
parent::execute();
|
$this->processChild();
|
||||||
return $this->tal->execute();
|
return $this->tal->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace ctiso\View;
|
|
||||||
use ctiso\View\View;
|
|
||||||
|
|
||||||
class ListView extends View
|
|
||||||
{
|
|
||||||
function execute()
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
foreach ($this->_section as $key => $value) {
|
|
||||||
$result [] = $value->execute();
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -21,7 +21,7 @@ class View extends \stdClass
|
||||||
|
|
||||||
public $suggestions; //подсказки
|
public $suggestions; //подсказки
|
||||||
|
|
||||||
public $alias = array();
|
public $alias = [];
|
||||||
public $codeGenerator = null;
|
public $codeGenerator = null;
|
||||||
public $parent_view = null;
|
public $parent_view = null;
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ class View extends \stdClass
|
||||||
* @param string $section переменная шаблона
|
* @param string $section переменная шаблона
|
||||||
* @param View|string $view вложенный шаблон
|
* @param View|string $view вложенный шаблон
|
||||||
*/
|
*/
|
||||||
public function setView($section, $view/*: View|string*/)
|
public function setView($section, $view)
|
||||||
{
|
{
|
||||||
$this->_section [$section] = $view;
|
$this->_section [$section] = $view;
|
||||||
if (is_object($view)) {
|
if (is_object($view)) {
|
||||||
|
|
@ -42,23 +42,18 @@ class View extends \stdClass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function assignValues($values)
|
public function assignValues($values): void
|
||||||
{
|
{
|
||||||
$this->_values = $values;
|
$this->_values = $values;
|
||||||
$this->_values["suggestions"] = $this->suggestions;
|
$this->_values["suggestions"] = $this->suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setGlobal($name, $args)
|
|
||||||
{
|
|
||||||
$this->addScriptRaw("var " . $name . " = " . json_encode($args) . ";\n", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Добавляет скипт к текущему шаблону
|
* Добавляет скипт к текущему шаблону
|
||||||
*
|
*
|
||||||
* @param string $name путь к скрипту
|
* @param string $name путь к скрипту
|
||||||
*/
|
*/
|
||||||
public function addScript($name)
|
public function addScript($name): void
|
||||||
{
|
{
|
||||||
$output = $this->resolveName($this->alias, $name . '?' . http_build_query($this->prefix));
|
$output = $this->resolveName($this->alias, $name . '?' . http_build_query($this->prefix));
|
||||||
$this->_script [] = $output;
|
$this->_script [] = $output;
|
||||||
|
|
@ -69,7 +64,7 @@ class View extends \stdClass
|
||||||
*
|
*
|
||||||
* @param string $name строка javascript кода
|
* @param string $name строка javascript кода
|
||||||
*/
|
*/
|
||||||
public function addScriptRaw($name, $startup = false)
|
public function addScriptRaw($name, $startup = false): void
|
||||||
{
|
{
|
||||||
if ($startup) {
|
if ($startup) {
|
||||||
$this->_startup [] = $name;
|
$this->_startup [] = $name;
|
||||||
|
|
@ -84,16 +79,16 @@ class View extends \stdClass
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Добавляет стили к текущему шаблону
|
* Добавляет стили к текущему шаблону
|
||||||
*
|
*
|
||||||
* @param string $name путь к стилю
|
* @param string $name путь к стилю
|
||||||
*/
|
*/
|
||||||
public function addStyleSheet($name)
|
public function addStyleSheet($name)
|
||||||
{
|
{
|
||||||
$output = $this->resolveName($this->alias, $name . '?' . http_build_query($this->prefix));
|
$output = $this->resolveName($this->alias, $name . '?' . http_build_query($this->prefix));
|
||||||
$this->_stylesheet [] = $output;
|
$this->_stylesheet [] = $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Рекурсивно извлекает из значение свойства обьекта
|
* Рекурсивно извлекает из значение свойства обьекта
|
||||||
*
|
*
|
||||||
* @param string $list Имя свойства
|
* @param string $list Имя свойства
|
||||||
|
|
@ -117,11 +112,11 @@ class View extends \stdClass
|
||||||
/*abstract*/ public function set($key, $value)
|
/*abstract*/ public function set($key, $value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Обработка всех вложенных шаблонов
|
* Обработка всех вложенных шаблонов
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function processChild(): void
|
||||||
{
|
{
|
||||||
foreach ($this->_section as $key => $value) {
|
foreach ($this->_section as $key => $value) {
|
||||||
$this->set($key, (is_object($value)) ? $value->execute() : $value); // ?
|
$this->set($key, (is_object($value)) ? $value->execute() : $value); // ?
|
||||||
|
|
@ -133,28 +128,28 @@ class View extends \stdClass
|
||||||
*
|
*
|
||||||
* @param string $title
|
* @param string $title
|
||||||
*/
|
*/
|
||||||
public function setTitle($title)
|
public function setTitle($title): void
|
||||||
{
|
{
|
||||||
$this->_title = $title;
|
$this->_title = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isNotNull($title)
|
protected function isNotNull($title): bool
|
||||||
{
|
{
|
||||||
return $title !== null;
|
return $title !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAlias($alias)
|
function setAlias($alias): void
|
||||||
{
|
{
|
||||||
$this->alias = $alias;
|
$this->alias = $alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addAlias($name, $path)
|
function addAlias($name, $path): void
|
||||||
{
|
{
|
||||||
$this->alias[$name] = $path;
|
$this->alias[$name] = $path;
|
||||||
$this->set($name, $path);
|
$this->set($name, $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
function find_file($pathlist, $file) {
|
function findFile($pathlist, string $file): string {
|
||||||
|
|
||||||
foreach($pathlist as $key => $www) {
|
foreach($pathlist as $key => $www) {
|
||||||
if (file_exists($key . '/' . $file)) {
|
if (file_exists($key . '/' . $file)) {
|
||||||
|
|
@ -162,16 +157,16 @@ class View extends \stdClass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Exception("file not found: $file");
|
throw new Exception("file not found: $file");
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Префикс, конфликтует с протоколом
|
// FIXME: Префикс, конфликтует с протоколом
|
||||||
function resolveName($alias, $file) {
|
function resolveName($alias, $file) {
|
||||||
list($type, $filename) = explode(":", $file, 2);
|
list($type, $filename) = explode(":", $file, 2);
|
||||||
|
|
||||||
// Сделать поиск а не просто замену папки при совпадении имени
|
// Сделать поиск а не просто замену папки при совпадении имени
|
||||||
if (isset($alias[$type])) {
|
if (isset($alias[$type])) {
|
||||||
if (is_array($alias[$type])) {
|
if (is_array($alias[$type])) {
|
||||||
$output = $this->find_file($alias[$type], $filename);
|
$output = $this->findFile($alias[$type], $filename);
|
||||||
} else {
|
} else {
|
||||||
$output = $alias[$type] . '/' . $filename;
|
$output = $alias[$type] . '/' . $filename;
|
||||||
}
|
}
|
||||||
|
|
@ -180,26 +175,6 @@ class View extends \stdClass
|
||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadImports($importFile)
|
|
||||||
{
|
|
||||||
$types = [
|
|
||||||
'js' => [$this, 'addScript'],
|
|
||||||
'css' => [$this, 'addStyleSheet']
|
|
||||||
];
|
|
||||||
// Подключение стилей и скриптов
|
|
||||||
if (file_exists($importFile)) {
|
|
||||||
$files = file($importFile);
|
|
||||||
foreach ($files as $file) {
|
|
||||||
// Получить расширение вместо strpos
|
|
||||||
$file = trim($file);
|
|
||||||
if (!empty($file)) {
|
|
||||||
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
|
||||||
call_user_func($types[$ext], $file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function resolveAllNames($alias, $list) {
|
public function resolveAllNames($alias, $list) {
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach($list as $item) {
|
foreach($list as $item) {
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,18 @@ use ZipArchive;
|
||||||
|
|
||||||
class ZipFile extends ZipArchive
|
class ZipFile extends ZipArchive
|
||||||
{
|
{
|
||||||
private $ignore = array('.', '..');
|
/**
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
private $ignore = ['.', '..'];
|
||||||
|
|
||||||
public function addIgnore($name)
|
public function addIgnore(string $name): void
|
||||||
{
|
{
|
||||||
$this->ignore [] = $name;
|
$this->ignore [] = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addDirDo($location, $name)
|
private function addDirDo(string $location, string $name): void
|
||||||
{
|
{
|
||||||
assert(is_string($location) && is_string($name));
|
|
||||||
|
|
||||||
$name .= '/';
|
$name .= '/';
|
||||||
$location .= '/';
|
$location .= '/';
|
||||||
$file = null;
|
$file = null;
|
||||||
|
|
@ -34,10 +35,8 @@ class ZipFile extends ZipArchive
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addDir($location, $name)
|
public function addDir(string $location, string $name): void
|
||||||
{
|
{
|
||||||
assert(is_string($location) && is_string($name));
|
|
||||||
|
|
||||||
$this->addEmptyDir($name);
|
$this->addEmptyDir($name);
|
||||||
$this->addDirDo($location, $name);
|
$this->addDirDo($location, $name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue