diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 548c033..c3c7b32 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -184,9 +184,9 @@ class Login extends Filter return $text; } - /* --------------------- + /** * Проверка на попадание реквеста в белый список - */ + */ public function requestIsWhite(Collection $request) { $module = $request->get('module'); $action = $request->get('action'); diff --git a/src/HttpRequest.php b/src/HttpRequest.php index 459bb82..35b6529 100644 --- a/src/HttpRequest.php +++ b/src/HttpRequest.php @@ -14,8 +14,9 @@ use Exception, */ class HttpRequest extends Collection { - + /** @var Session */ public $_session; + /** * Constructor * Stores "request data" in GPC order. @@ -94,6 +95,12 @@ class HttpRequest extends Collection return null; } + /** + * @param string $var + * @param string $key + * @param mixed $val + * @return mixed + */ public function setRawData($var, $key, $val) { $data = parent::get(strtolower($var)); @@ -102,28 +109,31 @@ class HttpRequest extends Collection } } - public function setAction($name) + /** + * @param string $name + */ + public function setAction($name): void { $this->setRawData('get', 'action', $name); } - public function getAction() + public function getAction(): string { $result = $this->getRawData('get', 'action'); return ($result) ? $result : 'index'; } - public function isAjax() + public function isAjax(): bool { return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); } - public function redirect($url) { + public function redirect($url): void { header('location: ' . $url); exit(); } - static function getProtocol() { + static function getProtocol(): string { return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; } } diff --git a/src/Mail.php b/src/Mail.php index a92e0a4..ca785a0 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -12,17 +12,27 @@ use ctiso\Path, class Mail { + /** @var string */ public $_from; + /** @var string */ public $_to; + /** @var string */ public $_subject; + /** @var string */ public $content; + /** @var string */ public $copy; + /** @var string */ private $encoding; + /** @var string */ private $_notify = null; + /** @var array */ protected $attachment = array(); + /** @var string */ protected $uniqid; + /** @var string */ protected $type = "text/plain"; function __construct() @@ -34,7 +44,7 @@ class Mail /** * Установка отправителя */ - function from(string $name) + function from(string $name): void { // filter_var($name, FILTER_VALIDATE_EMAIL); $this->_from = $name; @@ -43,23 +53,23 @@ class Mail /** * Установка получателя */ - function to(string $name) // recipient + function to(string $name): void // recipient { $this->_to = $name; } - function replyTo($name) // recipient + function replyTo($name): void // recipient {} /** * Установка получателей копии */ - function copy(string $name) // recipient cc + function copy(string $name): void // recipient cc { $this->copy = $name; } - function notify(string $notify) + function notify(string $notify): void { $this->_notify = $notify; } @@ -67,7 +77,7 @@ class Mail /** * Тема письма */ - function subject(string $subject) + function subject(string $subject): void { $this->_subject = $subject; } @@ -75,7 +85,7 @@ class Mail /** * Текст письма */ - function setContent(string $text) + function setContent(string $text): void { $this->content = $text; } @@ -83,7 +93,7 @@ class Mail /** * Кодировка текста в письме */ - function setEncoding(string $encoding) + function setEncoding(string $encoding): void { $this->encoding = $encoding; } @@ -91,7 +101,7 @@ class Mail /** * Добавление вложения из файла */ - function addAttachment(string $filename, $name = false) + function addAttachment(string $filename, $name = false): void { if (file_exists($filename)) { // assert ?? $file = fopen($filename, "rb"); @@ -102,7 +112,7 @@ class Mail } } - function setType($type) + function setType($type): void { $this->type = $type; } @@ -110,12 +120,16 @@ class Mail /** * Добавление вложения из строки с указанием имени файла */ - function addAttachmentRaw($data, string $name) + function addAttachmentRaw($data, string $name): void { $this->attachment[] = [$data, $name]; } - function quote($var, $val) + /** + * @param string $var + * @param string $val + */ + function quote($var, $val): string { return ";" . PHP_EOL . "\t" . $var . "=\"" . $val . "\""; } @@ -123,8 +137,12 @@ class Mail /** * Общий формат тегов MIME * @see http://tools.ietf.org/html/rfc2045 + * + * @param string $name + * @param string $value + * @param array $args */ - function mimeTag($name, $value, array $args = []) + function mimeTag($name, $value, array $args = []): string { assert(is_string($name)); assert(is_string($value)); @@ -136,7 +154,7 @@ class Mail * * @see http://tools.ietf.org/html/rfc2047 */ - function encodedWord(string $text, string $encoding = 'B') + function encodedWord(string $text, string $encoding = 'B'): string { return "=?{$this->encoding}?$encoding?" . base64_encode($text) . "?="; } diff --git a/src/MailAlt.php b/src/MailAlt.php index 1a08d50..c9cae8a 100644 --- a/src/MailAlt.php +++ b/src/MailAlt.php @@ -5,8 +5,11 @@ use PHPMailer\PHPMailer\PHPMailer; class MailAlt { + /** @var PHPMailer */ public $mailer; + /** @var string */ public $_notify; + /** @var string */ public $encoding; function __construct() { @@ -17,7 +20,7 @@ class MailAlt /** * Установка отправителя */ - function from(string $name) + function from(string $name): void { $this->mailer->setFrom($name); } @@ -25,26 +28,26 @@ class MailAlt /** * Установка получателя */ - function to(string $name) // recipient + function to(string $name): void // recipient { $this->mailer->addAddress($name); } - function replyTo(string $name) // recipient + function replyTo(string $name): void // recipient { - $this->mailer->AddReplyTo($name); + $this->mailer->addReplyTo($name); } /** * Установка получателей копии * @param string $name */ - function copy(string $name) // recipient cc + function copy(string $name): void // recipient cc { $this->mailer->addCC($name); } - function notify(string $notify) + function notify(string $notify): void { $this->_notify = $notify; } @@ -53,7 +56,7 @@ class MailAlt * Тема письма * @param string $subject */ - function subject(string $subject) + function subject(string $subject): void { $this->mailer->Subject = $subject; } @@ -62,12 +65,12 @@ class MailAlt * Текст письма * @param string $text */ - function setContent(string $text) + function setContent(string $text): void { $this->mailer->Body = $text; } - function setType(string $text) + function setType(string $text): void { $this->mailer->isHTML($text == 'text/html'); } @@ -75,7 +78,7 @@ class MailAlt /** * Кодировка текста в письме */ - function setEncoding(string $encoding) + function setEncoding(string $encoding): void { $this->encoding = $encoding; } @@ -83,7 +86,7 @@ class MailAlt /** * Добавление вложения из файла */ - function addAttachment(string $filename, ?string $name = null) + function addAttachment(string $filename, ?string $name = null): void { $this->mailer->addAttachment($filename, $name); } diff --git a/src/Numbers.php b/src/Numbers.php index ed98b61..368db12 100644 --- a/src/Numbers.php +++ b/src/Numbers.php @@ -24,4 +24,3 @@ class Numbers return $result; } } - diff --git a/src/Path.php b/src/Path.php index dcb6a2f..1e435c4 100644 --- a/src/Path.php +++ b/src/Path.php @@ -217,7 +217,6 @@ class Path * Находит путь относительно текущего путя * * @param string $name Полный путь к файлу - * * @return string Относительный путь к файлу */ public function relPath($name) @@ -258,6 +257,9 @@ class Path return implode("/", $result); } + /** + * @param string $path + */ public function append($path) { $base = $this->__toString(); @@ -270,7 +272,7 @@ class Path * @param string ...$args * @return string */ - static function fromJoin(string ...$args) { + static function fromJoin(...$args) { $result = []; $parts0 = new Path(array_shift($args)); $result [] = $parts0->getParts(); @@ -291,7 +293,7 @@ class Path * @param string ...$args * @return string */ - static function join(string ...$args) + static function join(...$args) { $path = call_user_func_array([self::class, "fromJoin"], $args); return self::makeUrl($path->url); diff --git a/src/Process.php b/src/Process.php index a1728f5..fd319f9 100644 --- a/src/Process.php +++ b/src/Process.php @@ -2,25 +2,39 @@ namespace ctiso; -if (!function_exists('str_getcsv')) { - function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { - $fiveMBs = 1024; - $fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+'); - $data = ''; - if (is_resource($fp)) { - fputs($fp, $input); - rewind($fp); - $data = fgetcsv($fp, 1000, $delimiter, $enclosure); - fclose($fp); - } - return $data; - } +/** + * str_getcsv + * @param string $input + * @param string $delimiter + * @param string $enclosure + * @param string $escape + * @return array + */ +function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") +{ + $fiveMBs = 1024; + $fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+'); + $data = ''; + if (is_resource($fp)) { + fputs($fp, $input); + rewind($fp); + $data = fgetcsv($fp, 1000, $delimiter, $enclosure); + fclose($fp); + } + return $data; } -function process_exists($pid) { + +/** + * process_exists + * @param int $pid + * @return bool + */ +function process_exists($pid) +{ if (PHP_OS == 'WINNT') { $processes = explode("\n", shell_exec("tasklist.exe /NH /FO CSV")); - foreach($processes as $process) { + foreach ($processes as $process) { if ($process != "") { $csv = str_getcsv($process); if ($pid == $csv[1]) return true; @@ -32,13 +46,19 @@ function process_exists($pid) { } } -function create_single_proces($fpid, $fn) { +/** + * create_single_proces + * @param string $fpid + * @param callable $fn + * @return int + */ +function create_single_process($fpid, $fn) +{ if (file_exists($fpid)) { - print_r(realpath($fpid)); - if (process_exists(file_get_contents($fpid))) { - return 1; + if (process_exists((int)file_get_contents($fpid))) { + return 1; } - } + } call_user_func($fn); return 0; } diff --git a/src/Settings.php b/src/Settings.php index 1f38299..d87e266 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -5,21 +5,30 @@ use ctiso\File, Exception; /** - * Класс реестра + * Класс реестра * Реестр организован как ассоциативный многомерный массив * array( 'name1' => parameters1, 'name2' => parameters1, ... ) * - * name1, name2 ... - Имена модулей + * name1, name2 ... - Имена модулей * parameters1, parameters1 - Массивы с параметрами модуля * Имя необходимо чтобы потом легко было удалить ненужные ветки дерева */ class Settings { + /** @var array */ public $data = []; + /** @var string */ protected $file; + /** @var string */ protected $format = 'php'; + /** @var bool */ protected $is_read = false; + /** + * Конструктор + * @param string $file Путь к файлу + * @param 'php'|'json'|false $format Формат файла + */ public function __construct ($file = null, $format = false) { $fileFormat = ['theme' => 'json']; @@ -33,7 +42,7 @@ class Settings * Чтение настроек из файла * @return Boolean */ - public function read() + public function read(): bool { if (!file_exists ($this->file)) { $this->is_read = true; @@ -59,7 +68,7 @@ class Settings /** * Запись ключа в реестр (Реестр это многомерный массив) */ - public function writeKey(array $key, $value) + public function writeKey(array $key, $value) { // assert(count($key) >= 1); $data = &$this->data; @@ -67,8 +76,8 @@ class Settings while (count($key) > 1) { $name = array_shift($key); $data = &$data[$name]; - } - + } + // assert(count($key) == 1); $name = array_shift($key); if (is_array($value)) { @@ -97,14 +106,20 @@ class Settings } /** - * Чтение ключа из реестра + * Чтение ключа из реестра * @param array $key Путь к значению ключа + * @return mixed */ public function readKey(array $key) { return $this->readKeyData($key, $this->data); } + /** + * Чтение ключа из реестра + * @param array $key Путь к значению ключа + * @return mixed + */ protected function readKeyData(array $key, $data) { // assert(count($key) >= 1); @@ -115,8 +130,8 @@ class Settings } else { return null; } - } - + } + // assert(count($key) == 1); $name = array_shift($key); if (isset($data[$name])) { @@ -131,7 +146,7 @@ class Settings * @param mixed $key Путь к значению ключа внутри модуля */ public function readKeyList(...$key) - { + { $result = []; foreach ($this->data as $name => $value) { $output = $this->readKeyData($key, $value); @@ -142,13 +157,17 @@ class Settings return $result; } - public function removeKey($name) + /** + * Удаление ключа из реестра + * @param string $name Имя ключа + */ + public function removeKey($name): void { unset($this->data[$name]); } - public function removeNode(array $key) + public function removeNode(array $key): void { $data = &$this->data; while (count($key) > 1) { @@ -158,11 +177,11 @@ class Settings $name = array_shift($key); unset($data[$name]); } - + /** * Запись настроек в файл (Может переименовать в store) * - * @param File $file + * @param File $file * @return void */ public function write($file = null) @@ -198,7 +217,7 @@ class Settings } /** - * Список модулей/ключей + * Список модулей/ключей */ public function getKeys() { diff --git a/src/Tools/Image.php b/src/Tools/Image.php index b1c2395..31e1c7c 100644 --- a/src/Tools/Image.php +++ b/src/Tools/Image.php @@ -6,6 +6,10 @@ use GdImage; class Image { + /** + * @param $uri + * @return GdImage|false + */ static function load($uri): GdImage|false { $e = strtolower(pathinfo($uri, PATHINFO_EXTENSION)); @@ -32,6 +36,11 @@ class Image return $image_p; } + /** + * @param GdImage $image + * @param string $uri + * @return bool + */ static function save($image, $uri): bool { $e = strtolower(pathinfo($uri, PATHINFO_EXTENSION)); diff --git a/src/Tools/StringUtil.php b/src/Tools/StringUtil.php index 87e5db7..661c14b 100644 --- a/src/Tools/StringUtil.php +++ b/src/Tools/StringUtil.php @@ -51,11 +51,10 @@ class StringUtil { } //Проверка равенства двух строк на русском языке. - static function equalRussianCheck($str1,$str2) { + static function equalRussianCheck($str1,$str2): bool { return self::normalizeRussian($str1) == self::normalizeRussian($str2); } - /** * Попадает ли строка в список вариантов * input: $str="foo1" $variants="foo1|foo2|foo3" diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index 161c68a..62c8e9c 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -32,12 +32,15 @@ class TemplateImage ); + /** @var string */ protected $src; protected array $context = []; protected array $data = []; protected string $base = "c:\\windows\\fonts\\"; protected GdImage $image; + /** @var bool */ protected $_prepare = true; + /** @var bool */ public $debug = false; public string $resource; public string $filename; diff --git a/src/Validator/Rule/AbstractRule.php b/src/Validator/Rule/AbstractRule.php index 52619ea..052d4a7 100644 --- a/src/Validator/Rule/AbstractRule.php +++ b/src/Validator/Rule/AbstractRule.php @@ -21,7 +21,7 @@ abstract class AbstractRule return $this; } - public function setErrorMsg($errorMsg): self + public function setErrorMsg(?string $errorMsg): self { $this->errorMsg = $errorMsg; return $this; diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index 2b8bd32..f6acfee 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -55,7 +55,7 @@ class Validator * fieldname - Имя переменой для проверки * ruletext - Описание правила см. формат правила ниже */ - public function addRuleList(array $input) + public function addRuleList(array $input): void { // Разбор правила проверки // Формат правила 'rule1|rule2,param1=value1|rule3,param1=value1,param2=value2' diff --git a/src/View/Pages.php b/src/View/Pages.php index a37633b..a5f2170 100644 --- a/src/View/Pages.php +++ b/src/View/Pages.php @@ -8,6 +8,14 @@ namespace ctiso\View; class Pages { static int $range = 5; + + /** + * @param int $page номер страницы + * @param int $onpage количество страниц на странице + * @param int $count количество всех страниц + * @param string $prefix префикс + * @return array{'all': bool, 'list': array, 'first': string, 'last': string, 'next': string, 'prev': string} + */ static function getPages($page, $onpage, $count, $prefix = '?') { $n = ceil($count / $onpage); @@ -51,6 +59,11 @@ class Pages ]; } + /** + * @param string $prefix префикс + * @param string $x строка + * @return string + */ static function href($prefix, $x) { return $prefix . $x; } diff --git a/src/View/Plain.php b/src/View/Plain.php index 032c259..feb617c 100644 --- a/src/View/Plain.php +++ b/src/View/Plain.php @@ -7,35 +7,60 @@ namespace ctiso\View; */ class Plain extends \stdClass { + /** @var string */ protected $document; + /** @var array */ protected $values = []; + /** + * Конструктор + * @param string $document шаблон + */ public function __construct ($document) { $this->document = $document; } + /** + * Установка значения + * @param string $key ключ + * @param mixed $value значение + */ public function set($key, $value) { $this->values[$key] = $value; } - public function import($list) + /** + * Импорт значений + * @param array $list список значений + */ + public function import($list): void { $this->values = array_merge($this->values, $list); } - public function __set($key, $value) + public function __set($key, $value): void { $this->set($key, $value); } + /** + * Выполнение шаблона + * @return string + */ public function execute() { $result = $this->values; return self::getTemplateContent ($this->document, $result); } + /** + * Получение содержимого шаблона + * @param string $document шаблон + * @param array $result результат + * @return string содержимое шаблона + */ static function getTemplateContent(string $document, $result): string { ob_start (); diff --git a/src/View/Top.php b/src/View/Top.php index ed707d2..17f81f0 100644 --- a/src/View/Top.php +++ b/src/View/Top.php @@ -13,11 +13,22 @@ class Top extends Composite public $require = array(); public $deps = array(); + /** + * Заголовок страницы + * + * @return string + */ public function getTitle() { return implode(" - ", array_filter($this->doTree('_title', false), [$this, 'isNotNull'])); } + /** + * Идентификатор + * + * @param string $pref + * @return string + */ function getId($pref) { $this->mid++; @@ -97,7 +108,7 @@ class Top extends Composite /** * Массив имен файлов скриптов * - * return array + * @return array */ public function getScripts() { @@ -114,6 +125,11 @@ class Top extends Composite return implode("\n", $this->doTree('_scriptstring')); } + /** + * Строка со скриптом + * + * @return string + */ public function getScriptStartup() { return implode("\n", $this->doTree('_startup')); @@ -122,7 +138,7 @@ class Top extends Composite /** * Массив имен файлов стилей * - * return array + * @return array */ public function getStyleSheet() { diff --git a/src/View/View.php b/src/View/View.php index 807892e..e35f147 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -39,7 +39,7 @@ class View extends \stdClass * @param string $section переменная шаблона * @param View|string $view вложенный шаблон */ - public function setView($section, $view) + public function setView($section, $view): void { $this->_section [$section] = $view; if (is_object($view)) {