[+] добавлен класс для работы с конфигурацией (пока базовая реализация)

This commit is contained in:
rsgrinko committed 2023-10-24 13:53:05 +03:00
1 parent 12ee13c3d1
commit 9708ec5419
15 files changed
+68 -19

No files matched your search

+2 -1
View File
@@ -21,6 +21,7 @@
use Core\Helpers\Pagination; use Core\Helpers\Pagination;
use Core\ExternalServices\RemoteHosts; use Core\ExternalServices\RemoteHosts;
use Core\SystemConfig;
require_once __DIR__ . '/inc/header.php'; require_once __DIR__ . '/inc/header.php';
@@ -66,7 +67,7 @@
</thead> </thead>
<tbody> <tbody>
<?php <?php
Pagination::execute($_REQUEST['page'], RemoteHosts::getAllCount(), PAGINATION_LIMIT); Pagination::execute($_REQUEST['page'], RemoteHosts::getAllCount(), SystemConfig::getValue('PAGINATION_LIMIT'));
$limit = Pagination::getLimit(); $limit = Pagination::getLimit();
$arHosts = RemoteHosts::getHosts($limit); $arHosts = RemoteHosts::getHosts($limit);
+4 -2
View File
@@ -20,7 +20,9 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
use Core\Helpers\Cache;use Core\Helpers\Files;use Core\Models\{User, Roles}; use Core\Helpers\Cache;use Core\Helpers\Files;
use Core\SystemConfig;
use Core\Models\{User, Roles};
require_once __DIR__ . '/inc/header.php'; require_once __DIR__ . '/inc/header.php';
?> ?>
@@ -96,7 +98,7 @@
<h3 class="panel-title">Отладка</h3> <h3 class="panel-title">Отладка</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<?= DEBUG ? 'Включена' : 'Отключена' ?> <?= SystemConfig::getValue('DEBUG') ? 'Включена' : 'Отключена' ?>
</div> </div>
</div> </div>
</div> </div>
+2 -1
View File
@@ -21,6 +21,7 @@
use Core\Helpers\Pagination; use Core\Helpers\Pagination;
use Core\Helpers\SystemFunctions; use Core\Helpers\SystemFunctions;
use Core\SystemConfig;
require_once __DIR__ . '/inc/header.php'; require_once __DIR__ . '/inc/header.php';
@@ -66,7 +67,7 @@
<?php <?php
$nginxLogFile = $_SERVER['DOCUMENT_ROOT'].'/../../log/it-stories.ru_access'; $nginxLogFile = $_SERVER['DOCUMENT_ROOT'].'/../../log/it-stories.ru_access';
//$nginxLogFile = $_SERVER['DOCUMENT_ROOT'].'/../../log/test.log'; //$nginxLogFile = $_SERVER['DOCUMENT_ROOT'].'/../../log/test.log';
Pagination::execute($_REQUEST['page'], SystemFunctions::getNginxLogData($nginxLogFile, true), PAGINATION_LIMIT); Pagination::execute($_REQUEST['page'], SystemFunctions::getNginxLogData($nginxLogFile, true), SystemConfig::getValue('PAGINATION_LIMIT'));
$limit = Pagination::getLimit(); $limit = Pagination::getLimit();
$arLogs = SystemFunctions::getNginxLogData($nginxLogFile, false, $limit, true); $arLogs = SystemFunctions::getNginxLogData($nginxLogFile, false, $limit, true);
+2 -1
View File
@@ -23,6 +23,7 @@
use Core\Models\File; use Core\Models\File;
use Core\Models\Posts; use Core\Models\Posts;
use Core\Models\User; use Core\Models\User;
use Core\SystemConfig;
require_once __DIR__ . '/inc/header.php'; require_once __DIR__ . '/inc/header.php';
?> ?>
@@ -61,7 +62,7 @@
<tbody> <tbody>
<?php <?php
$objectPosts = new Posts(); $objectPosts = new Posts();
Pagination::execute($_REQUEST['page'], $objectPosts->getAllCount(), PAGINATION_LIMIT); Pagination::execute($_REQUEST['page'], $objectPosts->getAllCount(), SystemConfig::getValue('PAGINATION_LIMIT'));
$limit = Pagination::getLimit(); $limit = Pagination::getLimit();
$arPosts = $objectPosts->getPosts($limit); $arPosts = $objectPosts->getPosts($limit);
+2 -1
View File
@@ -21,6 +21,7 @@
use Core\Helpers\Pagination; use Core\Helpers\Pagination;
use Core\Models\User; use Core\Models\User;
use Core\SystemConfig;
require_once __DIR__ . '/inc/header.php'; require_once __DIR__ . '/inc/header.php';
@@ -69,7 +70,7 @@
</thead> </thead>
<tbody> <tbody>
<?php <?php
Pagination::execute($_REQUEST['page'], User::getAllCount(), PAGINATION_LIMIT); Pagination::execute($_REQUEST['page'], User::getAllCount(), SystemConfig::getValue('PAGINATION_LIMIT'));
$limit = Pagination::getLimit(); $limit = Pagination::getLimit();
$arUsers = User::getUsers($limit); $arUsers = User::getUsers($limit);
+3 -2
View File
@@ -26,6 +26,7 @@
use Core\Models\Router; use Core\Models\Router;
use Core\Models\User; use Core\Models\User;
use Core\Models\UTM; use Core\Models\UTM;
use Core\SystemConfig;
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING); error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
//error_reporting(E_ALL); //error_reporting(E_ALL);
@@ -170,10 +171,10 @@
// debug // debug
function sendTelegram(?string $message, ?string $file = null): void function sendTelegram(?string $message, ?string $file = null): 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);
if (!empty($file)) { 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);
} }
} }
+1 -1
View File
@@ -28,7 +28,7 @@
* Флаг отладки * Флаг отладки
*/ */
if (!defined('DEBUG')) { if (!defined('DEBUG')) {
define('DEBUG', true); define('DEBUG', true); //SystemConfig
} }
+3 -2
View File
@@ -25,6 +25,7 @@
use Core\Models\File; use Core\Models\File;
use Core\Models\MQ; use Core\Models\MQ;
use Core\Models\User; use Core\Models\User;
use Core\SystemConfig;
/** /**
* Класс API контроллера * Класс API контроллера
@@ -69,7 +70,7 @@
if ($to !== null) { if ($to !== null) {
$this->to = (int)$to; $this->to = (int)$to;
} else { } else {
$this->to = PAGINATION_LIMIT; $this->to = SystemConfig::getValue('PAGINATION_LIMIT');
} }
} }
@@ -289,7 +290,7 @@
null, null,
$this->request->getProperty('subject'), $this->request->getProperty('subject'),
$this->request->getProperty('body'), $this->request->getProperty('body'),
MAIL_TEMPLATE_DEFAULT, SystemConfig::getValue('MAIL_TEMPLATE_DEFAULT'),
['TITLE' => $this->request->getProperty('subject')], ['TITLE' => $this->request->getProperty('subject')],
] ]
); );
+2 -2
View File
@@ -89,7 +89,7 @@
{ {
$buildInfo = [ $buildInfo = [
'Версия ядра' => CORE_VERSION, 'Версия ядра' => CORE_VERSION,
'Лимит пагинации' => PAGINATION_LIMIT, 'Лимит пагинации' => SystemConfig::getValue('PAGINATION_LIMIT'),
'Время для расчета онлайна' => USER_ONLINE_TIME, 'Время для расчета онлайна' => USER_ONLINE_TIME,
'Время жизни кеша' => CACHE_TTL, 'Время жизни кеша' => CACHE_TTL,
'E-Mail сайта' => SERVER_EMAIL, 'E-Mail сайта' => SERVER_EMAIL,
@@ -139,7 +139,7 @@
public static function users() 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 = Pagination::getLimit();
$limit= '0, 10'; $limit= '0, 10';
$arUsers = User::getUsers($limit); $arUsers = User::getUsers($limit);
+2 -1
View File
@@ -22,6 +22,7 @@
namespace Core\DataBases; namespace Core\DataBases;
use Core\CoreException; use Core\CoreException;
use Core\SystemConfig;
use PDO; use PDO;
use Throwable; use Throwable;
@@ -305,7 +306,7 @@
'<b><u>' . date('d.m.Y H:i:s') . '</u></b>' . PHP_EOL . '</b><b>SQL ERROR:</b> ' . PHP_EOL . $this->db->errorInfo()[2] . PHP_EOL '<b><u>' . date('d.m.Y H:i:s') . '</u></b>' . PHP_EOL . '</b><b>SQL ERROR:</b> ' . PHP_EOL . $this->db->errorInfo()[2] . PHP_EOL
. '<b>QUERY:</b> ' . PHP_EOL . $sql . '<b>QUERY:</b> ' . PHP_EOL . $sql
); );
if(DEBUG) { if(SystemConfig::getValue('DEBUG')) {
throw new CoreException( throw new CoreException(
'В SQL запросе произошла ошибка: ' . $this->db->errorInfo()[2] 'В SQL запросе произошла ошибка: ' . $this->db->errorInfo()[2]
. '. Запрос: ' . $sql, CoreException::ERROR_SQL_QUERY); . '. Запрос: ' . $sql, CoreException::ERROR_SQL_QUERY);
+2 -1
View File
@@ -24,6 +24,7 @@
use Core\CoreException; use Core\CoreException;
use Core\DataBases\DB; use Core\DataBases\DB;
use Core\Models\User; use Core\Models\User;
use Core\SystemConfig;
use Throwable; use Throwable;
/** /**
@@ -86,7 +87,7 @@
$this->user = $user; $this->user = $user;
$this->setFrom(SERVER_EMAIL, SERVER_EMAIL_NAME) $this->setFrom(SERVER_EMAIL, SERVER_EMAIL_NAME)
->setTo($user->getEmail(), $user->getName()) ->setTo($user->getEmail(), $user->getName())
->setTemplate(MAIL_TEMPLATE_DEFAULT); ->setTemplate(SystemConfig::getValue('MAIL_TEMPLATE_DEFAULT'));
} }
} }
@@ -24,6 +24,7 @@
use Core\CoreException; use Core\CoreException;
use Core\DTO\System\Memory; use Core\DTO\System\Memory;
use Core\SystemConfig;
/** /**
* Класс вспомогательных методов * Класс вспомогательных методов
@@ -480,7 +481,9 @@
*/ */
public static function sendTelegram(string $message): void 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 array|string|null $var Массив
* @param string $title Заголовок * @param string $title Заголовок
*
* *
* @return string|null * @return string|null
*/ */
+2 -2
View File
@@ -272,7 +272,7 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);'
if (date('H') > 21 || date('H') < 9) { if (date('H') > 21 || date('H') < 9) {
return 'Нерабочее время :('; return 'Нерабочее время :(';
} }
$telegram = new \Core\ExternalServices\TelegramSender(TELEGRAM_BOT_TOKEN); $telegram = new \Core\ExternalServices\TelegramSender(SystemConfig::getValue('TELEGRAM_BOT_TOKEN'));
$telegram->setChat(' -1001610334197'); $telegram->setChat(' -1001610334197');
/** @var DB $DB */ /** @var DB $DB */
@@ -338,7 +338,7 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);'
$post .= PHP_EOL . '<a href="' . $link . '">Подробнее</a>'; $post .= PHP_EOL . '<a href="' . $link . '">Подробнее</a>';
$telegram = new \Core\ExternalServices\TelegramSender(TELEGRAM_BOT_TOKEN); $telegram = new \Core\ExternalServices\TelegramSender(SystemConfig::getValue('TELEGRAM_BOT_TOKEN'));
$telegram->setChat('-1001789206618'); $telegram->setChat('-1001789206618');
$res = $telegram->sendPhoto($tmpFile, $post); $res = $telegram->sendPhoto($tmpFile, $post);
sendTelegram($post); sendTelegram($post);
+34
View File
@@ -0,0 +1,34 @@
<?php
/**
* Copyright (c) 2023 Roman Grinko <rsgrinko@gmail.com>
* 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);
}
}
+2 -1
View File
@@ -3,6 +3,7 @@
use Core\CoreException; use Core\CoreException;
use Core\ExternalServices\Telegram2; use Core\ExternalServices\Telegram2;
use Core\ExternalServices\ChatGPT; use Core\ExternalServices\ChatGPT;
use Core\SystemConfig;
require_once __DIR__ . '/core/bootstrap.php'; require_once __DIR__ . '/core/bootstrap.php';
@@ -13,7 +14,7 @@
$data = json_decode($data, true); $data = json_decode($data, true);
$tg = new Telegram2(TELEGRAM_BOT_TOKEN); $tg = new Telegram2(SystemConfig::getValue('TELEGRAM_BOT_TOKEN'));
$tg->setRemoteRequest($data); $tg->setRemoteRequest($data);
$gptObject = new ChatGPT(); $gptObject = new ChatGPT();