From 61b72268286d2d850d2889fed645f1eb86e79826 Mon Sep 17 00:00:00 2001 From: Sergei Solovev Date: Sun, 12 Nov 2023 17:26:34 +0300 Subject: [PATCH] Major updates Added support: 1. Composer for packages below; 2. symfony/polyfill to work with newer versions of php 3. filp/whoops to display php errors on screen 4. monolog/monolog for logging errors to a file and browser console --- .gitignore | 2 ++ acp/index.php | 8 +++++++- composer.json | 7 +++++++ index.php | 8 +++++++- system/acp/distributor.php | 15 +++++++++++++++ system/distributor.php | 16 +++++++++++++++- 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 composer.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d48c759 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +.vscode \ No newline at end of file diff --git a/acp/index.php b/acp/index.php index 3a0ff36..4b34bf1 100644 --- a/acp/index.php +++ b/acp/index.php @@ -22,7 +22,13 @@ $start_point = $_SERVER['REQUEST_TIME']; $mcache = new Memcache; - $mcache->connect('127.0.0.1', 11211) or exit('Ошибка: #mc0, обновите страницу позже, если ошибка повторяется, обратитесь в тех.поддержку: EGPv3'); + $mcache->connect('127.0.0.1', 11211) or exit('Ошибка подключения Memcache'); + +// Composer +if (!file_exists(ROOT.'vendor/autoload.php')) { + die('Please install composer and run composer install'); +} +require(ROOT.'vendor/autoload.php'); // Настройки include(DATA.'config.php'); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a27f2f6 --- /dev/null +++ b/composer.json @@ -0,0 +1,7 @@ +{ + "require": { + "symfony/polyfill": "1.28.0", + "filp/whoops": "2.15.4", + "monolog/monolog": "2.9.2" + } +} \ No newline at end of file diff --git a/index.php b/index.php index 911e99f..572bb2d 100644 --- a/index.php +++ b/index.php @@ -24,7 +24,13 @@ $start_point = $_SERVER['REQUEST_TIME']; $mcache = new Memcache; - $mcache->connect('127.0.0.1', 11211) or exit('Ошибка: #mc0, обновите страницу позже, если ошибка повторяется, обратитесь в тех.поддержку: EGPv3'); + $mcache->connect('127.0.0.1', 11211) or exit('Ошибка подключения Memcache'); + +// Composer +if (!file_exists(ROOT.'vendor/autoload.php')) { + die('Please install composer and run composer install'); +} +require(ROOT.'vendor/autoload.php'); // Настройки include(DATA.'config.php'); diff --git a/system/acp/distributor.php b/system/acp/distributor.php index 2827342..d2f9cf4 100644 --- a/system/acp/distributor.php +++ b/system/acp/distributor.php @@ -2,6 +2,21 @@ if(!DEFINED('EGP')) exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404')); +// Подключение filp/whoops +$whoops = new \Whoops\Run; +$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler); +$whoops->register(); +// Логи в консоль браузера +$loggingInConsole = new \Whoops\Handler\PlainTextHandler(); +$loggingInConsole->loggerOnly(true); +$loggingInConsole->setLogger((new \Monolog\Logger('EngineGP', [(new \Monolog\Handler\BrowserConsoleHandler())->setFormatter((new \Monolog\Formatter\LineFormatter(null, null, true)))]))); +$whoops->pushHandler($loggingInConsole); +// Логи в файл +$loggingInFile = new \Whoops\Handler\PlainTextHandler(); +$loggingInFile->loggerOnly(true); +$loggingInFile->setLogger((new \Monolog\Logger('EngineGP', [(new \Monolog\Handler\StreamHandler(DIR . 'logs/enginegp.log'))->setFormatter((new \Monolog\Formatter\LineFormatter(null, null, true)))]))); +$whoops->pushHandler($loggingInFile); + $device = '!mobile'; // Парсинг адреса diff --git a/system/distributor.php b/system/distributor.php index 8fce0c9..07896e3 100644 --- a/system/distributor.php +++ b/system/distributor.php @@ -1,8 +1,22 @@ pushHandler(new \Whoops\Handler\PrettyPageHandler); +$whoops->register(); +// логи в консоль браузера +$loggingInConsole = new \Whoops\Handler\PlainTextHandler(); +$loggingInConsole->loggerOnly(true); +$loggingInConsole->setLogger((new \Monolog\Logger('EngineGP', [(new \Monolog\Handler\BrowserConsoleHandler())->setFormatter((new \Monolog\Formatter\LineFormatter(null, null, true)))]))); +$whoops->pushHandler($loggingInConsole); +// логи в файл +$loggingInFile = new \Whoops\Handler\PlainTextHandler(); +$loggingInFile->loggerOnly(true); +$loggingInFile->setLogger((new \Monolog\Logger('EngineGP', [(new \Monolog\Handler\StreamHandler(DIR . 'logs/enginegp.log'))->setFormatter((new \Monolog\Formatter\LineFormatter(null, null, true)))]))); +$whoops->pushHandler($loggingInFile); + // Парсинг адреса $url = is_array(sys::url()) ? sys::url() : array(); $route = sys::url(false);