From dacf48a32cdbe8bc610f05114b037f8872489a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Colombaro?= Date: Mon, 25 Mar 2024 11:07:30 +0000 Subject: [PATCH 1/3] Allow `psr/log` v3 when using composer --- composer.json | 5 ++++- composer.lock | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 14807df1..ecb482d1 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "require": { "cloudflare/cf-ip-rewrite": "^1.0.0", "symfony/polyfill-intl-idn": "*", - "psr/log": "^1.0" + "psr/log": "^1.0 || ^3.0" }, "require-dev": { "symfony/yaml": "~2.6", @@ -40,5 +40,8 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } + }, + "extra": { + "installer-name": "cloudflare" } } diff --git a/composer.lock b/composer.lock index ee41ae54..f2eaa43e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e8665bcdae6db5846ed6b42aef3e563e", + "content-hash": "38f0352fff5fc31da5152c8912eb191e", "packages": [ { "name": "cloudflare/cf-ip-rewrite", From 020bb38311111b7b002151fc330882b0f228d5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Colombaro?= Date: Mon, 25 Mar 2024 18:28:05 +0100 Subject: [PATCH 2/3] Prevent duplicated loading of Composer autoload --- cloudflare.loader.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cloudflare.loader.php b/cloudflare.loader.php index c5305212..95d5b099 100644 --- a/cloudflare.loader.php +++ b/cloudflare.loader.php @@ -1,6 +1,8 @@ Date: Tue, 2 Apr 2024 22:14:38 +0200 Subject: [PATCH 3/3] Ensure proper function signatures depending on `psr/log` version --- src/Integration/DefaultLogger.php | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/Integration/DefaultLogger.php b/src/Integration/DefaultLogger.php index 65671e63..720e8475 100644 --- a/src/Integration/DefaultLogger.php +++ b/src/Integration/DefaultLogger.php @@ -6,6 +6,9 @@ use Psr\Log\LogLevel; use Psr\Log\LoggerInterface; +# if (Psr\Log version < 2) +if (class_exists('Psr\Log\Test\DummyTest')): + class DefaultLogger extends AbstractLogger implements LoggerInterface { private $debug; @@ -46,3 +49,48 @@ public function debug($message, array $context = array()) } } } + +else: + +class DefaultLogger extends AbstractLogger implements LoggerInterface +{ + private $debug; + + const PREFIX = '[Cloudflare]'; + + /** + * @param bool|false $debug + */ + public function __construct($debug = false) + { + $this->debug = $debug; + } + + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param Stringable|string $message + * @param array $context + */ + public function log($level, Stringable|string $message, array $context = []): void + { + error_log(self::PREFIX.' '.strtoupper($level).': '.$message.' '. + (!empty($context) ? print_r($context, true) : '')); + } + + /** + * Detailed debug information. + * + * @param Stringable|string $message + * @param array $context + */ + public function debug(Stringable|string $message, array $context = []): void + { + if ($this->debug) { + $this->log(LogLevel::DEBUG, $message, $context); + } + } +} + +endif;