diff --git a/src/Controller/Action.php b/src/Controller/Action.php index d10d2eb..4393ab7 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -119,7 +119,8 @@ class Action if(file_exists($template)) { break; } } - $tpl/*: Composite*/ = new $viewClass($template); + /** @var \ctiso\View\Composite */ + $tpl = new $viewClass($template); $tpl->config = $this->config; $stylePath = Path::join($webPath, "assets", "css"); @@ -140,8 +141,6 @@ class Action 'template' => $list ]); - $tpl->loadImports(Path::skipExtension($template) . ".import"); - $this->addSuggest($tpl, $name); return $tpl; } diff --git a/src/Controller/Component.php b/src/Controller/Component.php index c0edb7c..6beb987 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -57,6 +57,10 @@ class Component public $module; public $item_module; + + /** + * @var \App\Controller\Site + */ public $site; function before() { diff --git a/src/Validator/Rule/Code.php b/src/Validator/Rule/Code.php index 4ae1b48..1102766 100644 --- a/src/Validator/Rule/Code.php +++ b/src/Validator/Rule/Code.php @@ -9,12 +9,11 @@ use ctiso\Validator\Rule\AbstractRule, class Code extends AbstractRule { - public function getErrorMsg() - { + public function getErrorMsg(): string { return "Неправильно указан персональный код"; } - function checkCode($code) { + function checkCode($code): bool { foreach($code as $c) { if (empty($c)) { return false; @@ -23,7 +22,7 @@ class Code extends AbstractRule return true; } - public function isValid(Collection $container, $status = null) + public function isValid(Collection $container, $status = null): bool { if ($status == 'update') return true; $name = $this->field; @@ -32,27 +31,27 @@ class Code extends AbstractRule $count = count($_POST[$name . '_code_genre']); for($n = 0; $n < $count; $n++) { $code = [ - $_POST[$name . '_code_genre'][$n], - $_POST[$name . '_code_f'][$n], - $_POST[$name . '_code_i'][$n], - $_POST[$name . '_code_o'][$n], - $_POST[$name . '_code_year'][$n], - $_POST[$name . '_code_month'][$n], - $_POST[$name . '_code_day'][$n] + $_POST[$name . '_code_genre'][$n], + $_POST[$name . '_code_f'][$n], + $_POST[$name . '_code_i'][$n], + $_POST[$name . '_code_o'][$n], + $_POST[$name . '_code_year'][$n], + $_POST[$name . '_code_month'][$n], + $_POST[$name . '_code_day'][$n] ]; if (!$this->checkCode($code)) { return false; } } return true; - } else { + } else { $code = [ - $_POST[$name . '_code_genre'], - $_POST[$name . '_code_f'], - $_POST[$name . '_code_i'], - $_POST[$name . '_code_o'], - $_POST[$name . '_code_year'], - $_POST[$name . '_code_month'], + $_POST[$name . '_code_genre'], + $_POST[$name . '_code_f'], + $_POST[$name . '_code_i'], + $_POST[$name . '_code_o'], + $_POST[$name . '_code_year'], + $_POST[$name . '_code_month'], $_POST[$name . '_code_day'] ]; diff --git a/src/View/Composite.php b/src/View/Composite.php index 6edba92..046e18e 100644 --- a/src/View/Composite.php +++ b/src/View/Composite.php @@ -35,7 +35,7 @@ class Composite extends View function execute() { - parent::execute(); + $this->processChild(); return $this->tal->execute(); } diff --git a/src/View/ListView.php b/src/View/ListView.php deleted file mode 100644 index 3acd298..0000000 --- a/src/View/ListView.php +++ /dev/null @@ -1,16 +0,0 @@ -_section as $key => $value) { - $result [] = $value->execute(); - } - return $result; - } -} diff --git a/src/View/View.php b/src/View/View.php index 141e541..036cc72 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -21,7 +21,7 @@ class View extends \stdClass public $suggestions; //подсказки - public $alias = array(); + public $alias = []; public $codeGenerator = null; public $parent_view = null; @@ -34,7 +34,7 @@ class View extends \stdClass * @param string $section переменная шаблона * @param View|string $view вложенный шаблон */ - public function setView($section, $view/*: View|string*/) + public function setView($section, $view) { $this->_section [$section] = $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["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)); $this->_script [] = $output; @@ -69,7 +64,7 @@ class View extends \stdClass * * @param string $name строка javascript кода */ - public function addScriptRaw($name, $startup = false) + public function addScriptRaw($name, $startup = false): void { if ($startup) { $this->_startup [] = $name; @@ -84,16 +79,16 @@ class View extends \stdClass /** * Добавляет стили к текущему шаблону - * + * * @param string $name путь к стилю */ public function addStyleSheet($name) { - $output = $this->resolveName($this->alias, $name . '?' . http_build_query($this->prefix)); - $this->_stylesheet [] = $output; + $output = $this->resolveName($this->alias, $name . '?' . http_build_query($this->prefix)); + $this->_stylesheet [] = $output; } - /** + /** * Рекурсивно извлекает из значение свойства обьекта * * @param string $list Имя свойства @@ -117,11 +112,11 @@ class View extends \stdClass /*abstract*/ public function set($key, $value) { } - + /** * Обработка всех вложенных шаблонов */ - public function execute() + public function processChild(): void { foreach ($this->_section as $key => $value) { $this->set($key, (is_object($value)) ? $value->execute() : $value); // ? @@ -133,28 +128,28 @@ class View extends \stdClass * * @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; } - function addAlias($name, $path) + function addAlias($name, $path): void { $this->alias[$name] = $path; $this->set($name, $path); } - function find_file($pathlist, $file) { + function findFile($pathlist, string $file): string { foreach($pathlist as $key => $www) { if (file_exists($key . '/' . $file)) { @@ -162,16 +157,16 @@ class View extends \stdClass } } throw new Exception("file not found: $file"); - } + } // FIXME: Префикс, конфликтует с протоколом function resolveName($alias, $file) { list($type, $filename) = explode(":", $file, 2); - - // Сделать поиск а не просто замену папки при совпадении имени + + // Сделать поиск а не просто замену папки при совпадении имени if (isset($alias[$type])) { if (is_array($alias[$type])) { - $output = $this->find_file($alias[$type], $filename); + $output = $this->findFile($alias[$type], $filename); } else { $output = $alias[$type] . '/' . $filename; } @@ -180,26 +175,6 @@ class View extends \stdClass 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) { $result = []; foreach($list as $item) { diff --git a/src/ZipFile.php b/src/ZipFile.php index e858432..99ae70b 100644 --- a/src/ZipFile.php +++ b/src/ZipFile.php @@ -8,17 +8,18 @@ use ZipArchive; class ZipFile extends ZipArchive { - private $ignore = array('.', '..'); + /** + * @var list + */ + private $ignore = ['.', '..']; - public function addIgnore($name) + public function addIgnore(string $name): void { $this->ignore [] = $name; } - private function addDirDo($location, $name) + private function addDirDo(string $location, string $name): void { - assert(is_string($location) && is_string($name)); - $name .= '/'; $location .= '/'; $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->addDirDo($location, $name); }