From e0d3d7dbabcb27164ff1f2573107b85ba47c8edf Mon Sep 17 00:00:00 2001 From: Maxim Harder Date: Fri, 17 Mar 2023 13:10:48 +0100 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= =?UTF-8?q?=20-=20[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20(https://skripters.biz/forum/threads/dle-api.507?= =?UTF-8?q?09/post-499483)[=D0=B7=D0=B0=D1=8F=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0],=20-?= =?UTF-8?q?=20[FIX]=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20(https://skripters.biz/forum/threads/dle-api.507?= =?UTF-8?q?09/post-499640)[=D0=B7=D0=B0=D1=8F=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- upload/api/composer.lock | 52 +---- .../src/Monolog/Formatter/SyslogFormatter.php | 66 ++++++ .../monolog/monolog/src/Monolog/Level.php | 209 ++++++++++++++++++ .../Processor/ClosureContextProcessor.php | 51 +++++ .../api/vendor/psr/log/src/AbstractLogger.php | 15 ++ .../psr/log/src/InvalidArgumentException.php | 7 + upload/api/vendor/psr/log/src/LogLevel.php | 18 ++ .../psr/log/src/LoggerAwareInterface.php | 18 ++ .../vendor/psr/log/src/LoggerAwareTrait.php | 26 +++ .../vendor/psr/log/src/LoggerInterface.php | 125 +++++++++++ upload/api/vendor/psr/log/src/LoggerTrait.php | 142 ++++++++++++ upload/api/vendor/psr/log/src/NullLogger.php | 30 +++ upload/engine/inc/dleapi.php | 44 ++-- upload/install.xml | 2 +- 14 files changed, 736 insertions(+), 69 deletions(-) create mode 100644 upload/api/vendor/monolog/monolog/src/Monolog/Formatter/SyslogFormatter.php create mode 100644 upload/api/vendor/monolog/monolog/src/Monolog/Level.php create mode 100644 upload/api/vendor/monolog/monolog/src/Monolog/Processor/ClosureContextProcessor.php create mode 100644 upload/api/vendor/psr/log/src/AbstractLogger.php create mode 100644 upload/api/vendor/psr/log/src/InvalidArgumentException.php create mode 100644 upload/api/vendor/psr/log/src/LogLevel.php create mode 100644 upload/api/vendor/psr/log/src/LoggerAwareInterface.php create mode 100644 upload/api/vendor/psr/log/src/LoggerAwareTrait.php create mode 100644 upload/api/vendor/psr/log/src/LoggerInterface.php create mode 100644 upload/api/vendor/psr/log/src/LoggerTrait.php create mode 100644 upload/api/vendor/psr/log/src/NullLogger.php diff --git a/upload/api/composer.lock b/upload/api/composer.lock index 020e47b..73b5170 100644 --- a/upload/api/composer.lock +++ b/upload/api/composer.lock @@ -4,56 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fe0a38e04772d434bbb79c6ea0e4631c", + "content-hash": "42467b225df038dc1129fd92346bc081", "packages": [ - { - "name": "lincanbin/php-pdo-mysql-class", - "version": "v2.2", - "source": { - "type": "git", - "url": "https://github.com/lincanbin/PHP-PDO-MySQL-Class.git", - "reference": "7517d30ffc514a3c54217717b97721ab394fa87a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/lincanbin/PHP-PDO-MySQL-Class/zipball/7517d30ffc514a3c54217717b97721ab394fa87a", - "reference": "7517d30ffc514a3c54217717b97721ab394fa87a", - "shasum": "" - }, - "require": { - "ext-pdo": "*", - "ext-pdo_mysql": "*", - "php": ">=5.3.6" - }, - "type": "library", - "autoload": { - "files": [ - "src/PDO.class.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "lincanbin", - "email": "lincanbin@hotmail.com" - } - ], - "description": "A PHP MySQL PDO class similar to the Python MySQLdb, which supports iterator and parameter binding when using 'WHERE IN' statement.", - "keywords": [ - "database", - "iterator", - "mysql", - "pdo" - ], - "support": { - "issues": "https://github.com/lincanbin/PHP-PDO-MySQL-Class/issues", - "source": "https://github.com/lincanbin/PHP-PDO-MySQL-Class/tree/v2.2" - }, - "time": "2020-11-27T02:02:36+00:00" - }, { "name": "monolog/monolog", "version": "3.3.1", @@ -511,5 +463,5 @@ "platform-overrides": { "php": "8.1" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/upload/api/vendor/monolog/monolog/src/Monolog/Formatter/SyslogFormatter.php b/upload/api/vendor/monolog/monolog/src/Monolog/Formatter/SyslogFormatter.php new file mode 100644 index 0000000..6ed7e92 --- /dev/null +++ b/upload/api/vendor/monolog/monolog/src/Monolog/Formatter/SyslogFormatter.php @@ -0,0 +1,66 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Formatter; + +use Monolog\Level; +use Monolog\LogRecord; + +/** + * Serializes a log message according to RFC 5424 + * + * @author Dalibor Karlović + * @author Renat Gabdullin + */ +class SyslogFormatter extends LineFormatter +{ + private const SYSLOG_FACILITY_USER = 1; + private const FORMAT = "<%extra.priority%>1 %datetime% %extra.hostname% %extra.app-name% %extra.procid% %channel% %extra.structured-data% %level_name%: %message% %context% %extra%\n"; + private const NILVALUE = '-'; + + private string $hostname; + private int $procid; + + public function __construct(private string $applicationName = self::NILVALUE) + { + parent::__construct(self::FORMAT, 'Y-m-d\TH:i:s.uP', true, true); + $this->hostname = (string) gethostname(); + $this->procid = (int) getmypid(); + } + + public function format(LogRecord $record): string + { + $record->extra = $this->formatExtra($record); + + return parent::format($record); + } + + /** + * @param LogRecord $record + * @return array + */ + private function formatExtra(LogRecord $record): array + { + $extra = $record->extra; + $extra['app-name'] = $this->applicationName; + $extra['hostname'] = $this->hostname; + $extra['procid'] = $this->procid; + $extra['priority'] = self::calculatePriority($record->level); + $extra['structured-data'] = self::NILVALUE; + + return $extra; + } + + private static function calculatePriority(Level $level): int + { + return (self::SYSLOG_FACILITY_USER * 8) + $level->toRFC5424Level(); + } +} diff --git a/upload/api/vendor/monolog/monolog/src/Monolog/Level.php b/upload/api/vendor/monolog/monolog/src/Monolog/Level.php new file mode 100644 index 0000000..097d421 --- /dev/null +++ b/upload/api/vendor/monolog/monolog/src/Monolog/Level.php @@ -0,0 +1,209 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog; + +use Psr\Log\LogLevel; + +/** + * Represents the log levels + * + * Monolog supports the logging levels described by RFC 5424 {@see https://datatracker.ietf.org/doc/html/rfc5424} + * but due to BC the severity values used internally are not 0-7. + * + * To get the level name/value out of a Level there are several options: + * + * - Use ->getName() to get the standard Monolog name which is full uppercased (e.g. "DEBUG") + * - Use ->toPsrLogLevel() to get the standard PSR-3 name which is full lowercased (e.g. "debug") + * - Use ->toRFC5424Level() to get the standard RFC 5424 value (e.g. 7 for debug, 0 for emergency) + * - Use ->name to get the enum case's name which is capitalized (e.g. "Debug") + * + * To get the internal value for filtering, if the includes/isLowerThan/isHigherThan methods are + * not enough, you can use ->value to get the enum case's integer value. + */ +enum Level: int +{ + /** + * Detailed debug information + */ + case Debug = 100; + + /** + * Interesting events + * + * Examples: User logs in, SQL logs. + */ + case Info = 200; + + /** + * Uncommon events + */ + case Notice = 250; + + /** + * Exceptional occurrences that are not errors + * + * Examples: Use of deprecated APIs, poor use of an API, + * undesirable things that are not necessarily wrong. + */ + case Warning = 300; + + /** + * Runtime errors + */ + case Error = 400; + + /** + * Critical conditions + * + * Example: Application component unavailable, unexpected exception. + */ + case Critical = 500; + + /** + * Action must be taken immediately + * + * Example: Entire website down, database unavailable, etc. + * This should trigger the SMS alerts and wake you up. + */ + case Alert = 550; + + /** + * Urgent alert. + */ + case Emergency = 600; + + /** + * @param value-of|LogLevel::*|'Debug'|'Info'|'Notice'|'Warning'|'Error'|'Critical'|'Alert'|'Emergency' $name + * @return static + */ + public static function fromName(string $name): self + { + return match ($name) { + 'debug', 'Debug', 'DEBUG' => self::Debug, + 'info', 'Info', 'INFO' => self::Info, + 'notice', 'Notice', 'NOTICE' => self::Notice, + 'warning', 'Warning', 'WARNING' => self::Warning, + 'error', 'Error', 'ERROR' => self::Error, + 'critical', 'Critical', 'CRITICAL' => self::Critical, + 'alert', 'Alert', 'ALERT' => self::Alert, + 'emergency', 'Emergency', 'EMERGENCY' => self::Emergency, + }; + } + + /** + * @param value-of $value + * @return static + */ + public static function fromValue(int $value): self + { + return self::from($value); + } + + /** + * Returns true if the passed $level is higher or equal to $this + */ + public function includes(Level $level): bool + { + return $this->value <= $level->value; + } + + public function isHigherThan(Level $level): bool + { + return $this->value > $level->value; + } + + public function isLowerThan(Level $level): bool + { + return $this->value < $level->value; + } + + /** + * Returns the monolog standardized all-capitals name of the level + * + * Use this instead of $level->name which returns the enum case name (e.g. Debug vs DEBUG if you use getName()) + * + * @return value-of + */ + public function getName(): string + { + return match ($this) { + self::Debug => 'DEBUG', + self::Info => 'INFO', + self::Notice => 'NOTICE', + self::Warning => 'WARNING', + self::Error => 'ERROR', + self::Critical => 'CRITICAL', + self::Alert => 'ALERT', + self::Emergency => 'EMERGENCY', + }; + } + + /** + * Returns the PSR-3 level matching this instance + * + * @phpstan-return \Psr\Log\LogLevel::* + */ + public function toPsrLogLevel(): string + { + return match ($this) { + self::Debug => LogLevel::DEBUG, + self::Info => LogLevel::INFO, + self::Notice => LogLevel::NOTICE, + self::Warning => LogLevel::WARNING, + self::Error => LogLevel::ERROR, + self::Critical => LogLevel::CRITICAL, + self::Alert => LogLevel::ALERT, + self::Emergency => LogLevel::EMERGENCY, + }; + } + + /** + * Returns the RFC 5424 level matching this instance + * + * @phpstan-return int<0, 7> + */ + public function toRFC5424Level(): int + { + return match ($this) { + self::Debug => 7, + self::Info => 6, + self::Notice => 5, + self::Warning => 4, + self::Error => 3, + self::Critical => 2, + self::Alert => 1, + self::Emergency => 0, + }; + } + + public const VALUES = [ + 100, + 200, + 250, + 300, + 400, + 500, + 550, + 600, + ]; + + public const NAMES = [ + 'DEBUG', + 'INFO', + 'NOTICE', + 'WARNING', + 'ERROR', + 'CRITICAL', + 'ALERT', + 'EMERGENCY', + ]; +} diff --git a/upload/api/vendor/monolog/monolog/src/Monolog/Processor/ClosureContextProcessor.php b/upload/api/vendor/monolog/monolog/src/Monolog/Processor/ClosureContextProcessor.php new file mode 100644 index 0000000..514b354 --- /dev/null +++ b/upload/api/vendor/monolog/monolog/src/Monolog/Processor/ClosureContextProcessor.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Processor; + +use Monolog\LogRecord; + +/** + * Generates a context from a Closure if the Closure is the only value + * in the context + * + * It helps reduce the performance impact of debug logs if they do + * need to create lots of context information. If this processor is added + * on the correct handler the context data will only be generated + * when the logs are actually logged to that handler, which is useful when + * using FingersCrossedHandler or other filtering handlers to conditionally + * log records. + */ +class ClosureContextProcessor implements ProcessorInterface +{ + public function __invoke(LogRecord $record): LogRecord + { + $context = $record->context; + if (isset($context[0]) && 1 === \count($context) && $context[0] instanceof \Closure) { + try { + $context = $context[0](); + } catch (\Throwable $e) { + $context = [ + 'error_on_context_generation' => $e->getMessage(), + 'exception' => $e, + ]; + } + + if (!\is_array($context)) { + $context = [$context]; + } + + $record = $record->with(context: $context); + } + + return $record; + } +} diff --git a/upload/api/vendor/psr/log/src/AbstractLogger.php b/upload/api/vendor/psr/log/src/AbstractLogger.php new file mode 100644 index 0000000..d60a091 --- /dev/null +++ b/upload/api/vendor/psr/log/src/AbstractLogger.php @@ -0,0 +1,15 @@ +logger = $logger; + } +} diff --git a/upload/api/vendor/psr/log/src/LoggerInterface.php b/upload/api/vendor/psr/log/src/LoggerInterface.php new file mode 100644 index 0000000..b3a24b5 --- /dev/null +++ b/upload/api/vendor/psr/log/src/LoggerInterface.php @@ -0,0 +1,125 @@ +log(LogLevel::EMERGENCY, $message, $context); + } + + /** + * Action must be taken immediately. + * + * Example: Entire website down, database unavailable, etc. This should + * trigger the SMS alerts and wake you up. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function alert(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::ALERT, $message, $context); + } + + /** + * Critical conditions. + * + * Example: Application component unavailable, unexpected exception. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function critical(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::CRITICAL, $message, $context); + } + + /** + * Runtime errors that do not require immediate action but should typically + * be logged and monitored. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function error(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::ERROR, $message, $context); + } + + /** + * Exceptional occurrences that are not errors. + * + * Example: Use of deprecated APIs, poor use of an API, undesirable things + * that are not necessarily wrong. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function warning(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::WARNING, $message, $context); + } + + /** + * Normal but significant events. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function notice(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::NOTICE, $message, $context); + } + + /** + * Interesting events. + * + * Example: User logs in, SQL logs. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function info(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::INFO, $message, $context); + } + + /** + * Detailed debug information. + * + * @param string|\Stringable $message + * @param array $context + * + * @return void + */ + public function debug(string|\Stringable $message, array $context = []): void + { + $this->log(LogLevel::DEBUG, $message, $context); + } + + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string|\Stringable $message + * @param array $context + * + * @return void + * + * @throws \Psr\Log\InvalidArgumentException + */ + abstract public function log($level, string|\Stringable $message, array $context = []): void; +} diff --git a/upload/api/vendor/psr/log/src/NullLogger.php b/upload/api/vendor/psr/log/src/NullLogger.php new file mode 100644 index 0000000..c1cc3c0 --- /dev/null +++ b/upload/api/vendor/psr/log/src/NullLogger.php @@ -0,0 +1,30 @@ +logger) { }` + * blocks. + */ +class NullLogger extends AbstractLogger +{ + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string|\Stringable $message + * @param array $context + * + * @return void + * + * @throws \Psr\Log\InvalidArgumentException + */ + public function log($level, string|\Stringable $message, array $context = []): void + { + // noop + } +} diff --git a/upload/engine/inc/dleapi.php b/upload/engine/inc/dleapi.php index 47e9b32..bc81a71 100644 --- a/upload/engine/inc/dleapi.php +++ b/upload/engine/inc/dleapi.php @@ -22,8 +22,12 @@ $version = [ 'name' => 'DLE-API', 'descr' => 'Неофициальное API', - 'version' => '0.3.0', + 'version' => '0.3.1', 'changelog' => [ + '0.3.1' => [ + '[FIX] Исправлена заявленная ошибка', + '[FIX] Исправлена заявленная ошибка', + ], '0.3.0' => [ 'Оптимизация кода под PHP 8.2', 'Минимально поддерживаемая версия DLE - 16.0', @@ -99,7 +103,7 @@ * @param string|null $class * @return void */ -function showRow(?string $title, ?string $description, ?string $field, ?string $class) : void { +function showRow(?string $title = null, ?string $description = null, ?string $field = null, ?string $class = null) : void { echo "
{$title}
{$description} @@ -116,7 +120,7 @@ function showRow(?string $title, ?string $description, ?string $field, ?string $ * * @return string */ -function makeDropDown(array $options, string $name, ?string $selected) : string { +function makeDropDown(array $options, string $name, ?string $selected = null) : string { $output = "