diff --git a/admin/hosts.php b/admin/hosts.php index 1b3ca4d..7901529 100644 --- a/admin/hosts.php +++ b/admin/hosts.php @@ -21,6 +21,7 @@ use Core\Helpers\Pagination; use Core\ExternalServices\RemoteHosts; + use Core\SystemConfig; require_once __DIR__ . '/inc/header.php'; @@ -66,7 +67,7 @@ @@ -96,7 +98,7 @@

Отладка

- +
diff --git a/admin/nginx.php b/admin/nginx.php index f5eaa07..1ec5cea 100644 --- a/admin/nginx.php +++ b/admin/nginx.php @@ -21,6 +21,7 @@ use Core\Helpers\Pagination; use Core\Helpers\SystemFunctions; + use Core\SystemConfig; require_once __DIR__ . '/inc/header.php'; @@ -66,7 +67,7 @@ @@ -61,7 +62,7 @@ getAllCount(), PAGINATION_LIMIT); + Pagination::execute($_REQUEST['page'], $objectPosts->getAllCount(), SystemConfig::getValue('PAGINATION_LIMIT')); $limit = Pagination::getLimit(); $arPosts = $objectPosts->getPosts($limit); diff --git a/admin/users.php b/admin/users.php index 19edfaf..30d0d9c 100644 --- a/admin/users.php +++ b/admin/users.php @@ -21,6 +21,7 @@ use Core\Helpers\Pagination; use Core\Models\User; + use Core\SystemConfig; require_once __DIR__ . '/inc/header.php'; @@ -69,7 +70,7 @@ setChat(TELEGRAM_NOTIFICATION_CHANNEL)->sendMessage($message); + (new \Core\ExternalServices\TelegramSender(SystemConfig::getValue('TELEGRAM_BOT_TOKEN')))->setChat(SystemConfig::getValue('TELEGRAM_NOTIFICATION_CHANNEL'))->sendMessage($message); if (!empty($file)) { - (new \Core\ExternalServices\TelegramSender(TELEGRAM_BOT_TOKEN))->setChat(TELEGRAM_NOTIFICATION_CHANNEL)->sendDocument($file); + (new \Core\ExternalServices\TelegramSender(SystemConfig::getValue('TELEGRAM_BOT_TOKEN')))->setChat(SystemConfig::getValue('TELEGRAM_NOTIFICATION_CHANNEL'))->sendDocument($file); } } diff --git a/core/config.php b/core/config.php index ce6096a..ef396b9 100644 --- a/core/config.php +++ b/core/config.php @@ -28,7 +28,7 @@ * Флаг отладки */ if (!defined('DEBUG')) { - define('DEBUG', true); + define('DEBUG', true); //SystemConfig } diff --git a/core/lib/Core/Api/ApiController.class.php b/core/lib/Core/Api/ApiController.class.php index 33e2afe..6f319e6 100644 --- a/core/lib/Core/Api/ApiController.class.php +++ b/core/lib/Core/Api/ApiController.class.php @@ -25,6 +25,7 @@ use Core\Models\File; use Core\Models\MQ; use Core\Models\User; + use Core\SystemConfig; /** * Класс API контроллера @@ -69,7 +70,7 @@ if ($to !== null) { $this->to = (int)$to; } else { - $this->to = PAGINATION_LIMIT; + $this->to = SystemConfig::getValue('PAGINATION_LIMIT'); } } @@ -289,7 +290,7 @@ null, $this->request->getProperty('subject'), $this->request->getProperty('body'), - MAIL_TEMPLATE_DEFAULT, + SystemConfig::getValue('MAIL_TEMPLATE_DEFAULT'), ['TITLE' => $this->request->getProperty('subject')], ] ); diff --git a/core/lib/Core/App.class.php b/core/lib/Core/App.class.php index 37b1668..5db2dd5 100644 --- a/core/lib/Core/App.class.php +++ b/core/lib/Core/App.class.php @@ -89,7 +89,7 @@ { $buildInfo = [ 'Версия ядра' => CORE_VERSION, - 'Лимит пагинации' => PAGINATION_LIMIT, + 'Лимит пагинации' => SystemConfig::getValue('PAGINATION_LIMIT'), 'Время для расчета онлайна' => USER_ONLINE_TIME, 'Время жизни кеша' => CACHE_TTL, 'E-Mail сайта' => SERVER_EMAIL, @@ -139,7 +139,7 @@ public static function users() { - Pagination::execute($_REQUEST['page'], User::getAllCount(), PAGINATION_LIMIT); + Pagination::execute($_REQUEST['page'], User::getAllCount(), SystemConfig::getValue('PAGINATION_LIMIT')); $limit = Pagination::getLimit(); $limit= '0, 10'; $arUsers = User::getUsers($limit); diff --git a/core/lib/Core/DataBases/DB.class.php b/core/lib/Core/DataBases/DB.class.php index 50c284e..3177ab5 100644 --- a/core/lib/Core/DataBases/DB.class.php +++ b/core/lib/Core/DataBases/DB.class.php @@ -22,6 +22,7 @@ namespace Core\DataBases; use Core\CoreException; + use Core\SystemConfig; use PDO; use Throwable; @@ -305,7 +306,7 @@ '' . date('d.m.Y H:i:s') . '' . PHP_EOL . 'SQL ERROR: ' . PHP_EOL . $this->db->errorInfo()[2] . PHP_EOL . 'QUERY: ' . PHP_EOL . $sql ); - if(DEBUG) { + if(SystemConfig::getValue('DEBUG')) { throw new CoreException( 'В SQL запросе произошла ошибка: ' . $this->db->errorInfo()[2] . '. Запрос: ' . $sql, CoreException::ERROR_SQL_QUERY); diff --git a/core/lib/Core/Helpers/Mail.class.php b/core/lib/Core/Helpers/Mail.class.php index 01f4071..9621ce4 100644 --- a/core/lib/Core/Helpers/Mail.class.php +++ b/core/lib/Core/Helpers/Mail.class.php @@ -24,6 +24,7 @@ use Core\CoreException; use Core\DataBases\DB; use Core\Models\User; + use Core\SystemConfig; use Throwable; /** @@ -86,7 +87,7 @@ $this->user = $user; $this->setFrom(SERVER_EMAIL, SERVER_EMAIL_NAME) ->setTo($user->getEmail(), $user->getName()) - ->setTemplate(MAIL_TEMPLATE_DEFAULT); + ->setTemplate(SystemConfig::getValue('MAIL_TEMPLATE_DEFAULT')); } } diff --git a/core/lib/Core/Helpers/SystemFunctions.class.php b/core/lib/Core/Helpers/SystemFunctions.class.php index 69d8013..96e21f1 100644 --- a/core/lib/Core/Helpers/SystemFunctions.class.php +++ b/core/lib/Core/Helpers/SystemFunctions.class.php @@ -24,6 +24,7 @@ use Core\CoreException; use Core\DTO\System\Memory; + use Core\SystemConfig; /** * Класс вспомогательных методов @@ -480,7 +481,9 @@ */ public static function sendTelegram(string $message): void { - (new \Core\ExternalServices\TelegramSender(TELEGRAM_BOT_TOKEN))->setChat(TELEGRAM_NOTIFICATION_CHANNEL)->sendMessage($message); + (new \Core\ExternalServices\TelegramSender(SystemConfig::getValue('TELEGRAM_BOT_TOKEN'))) + ->setChat(SystemConfig::getValue('TELEGRAM_NOTIFICATION_CHANNEL')) + ->sendMessage($message); } /** @@ -488,6 +491,7 @@ * * @param array|string|null $var Массив * @param string $title Заголовок + * * * @return string|null */ diff --git a/core/lib/Core/MQTasks.class.php b/core/lib/Core/MQTasks.class.php index e00ce72..6f7af4f 100644 --- a/core/lib/Core/MQTasks.class.php +++ b/core/lib/Core/MQTasks.class.php @@ -272,7 +272,7 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);' if (date('H') > 21 || date('H') < 9) { return 'Нерабочее время :('; } - $telegram = new \Core\ExternalServices\TelegramSender(TELEGRAM_BOT_TOKEN); + $telegram = new \Core\ExternalServices\TelegramSender(SystemConfig::getValue('TELEGRAM_BOT_TOKEN')); $telegram->setChat(' -1001610334197'); /** @var DB $DB */ @@ -338,7 +338,7 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);' $post .= PHP_EOL . 'Подробнее'; - $telegram = new \Core\ExternalServices\TelegramSender(TELEGRAM_BOT_TOKEN); + $telegram = new \Core\ExternalServices\TelegramSender(SystemConfig::getValue('TELEGRAM_BOT_TOKEN')); $telegram->setChat('-1001789206618'); $res = $telegram->sendPhoto($tmpFile, $post); sendTelegram($post); diff --git a/core/lib/Core/SystemConfig.class.php b/core/lib/Core/SystemConfig.class.php new file mode 100644 index 0000000..41b1a3b --- /dev/null +++ b/core/lib/Core/SystemConfig.class.php @@ -0,0 +1,34 @@ + + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + namespace Core; + + /** + * Класс системных параметров + */ + class SystemConfig { + public static function getValue(string $param) + { + // TODO в текущей реализации берем просто заданную константу, в дальнейшем переделать + return constant($param); + } + } \ No newline at end of file diff --git a/telegramHandler.php b/telegramHandler.php index ad63a08..eb35ecb 100644 --- a/telegramHandler.php +++ b/telegramHandler.php @@ -3,6 +3,7 @@ use Core\CoreException; use Core\ExternalServices\Telegram2; use Core\ExternalServices\ChatGPT; + use Core\SystemConfig; require_once __DIR__ . '/core/bootstrap.php'; @@ -13,7 +14,7 @@ $data = json_decode($data, true); - $tg = new Telegram2(TELEGRAM_BOT_TOKEN); + $tg = new Telegram2(SystemConfig::getValue('TELEGRAM_BOT_TOKEN')); $tg->setRemoteRequest($data); $gptObject = new ChatGPT();