From 98c5ce0fb5314ccfabe2e6a5d1581163a90668fd Mon Sep 17 00:00:00 2001 From: kjdev Date: Thu, 12 Jun 2025 08:58:46 +0900 Subject: [PATCH 1/3] add: BROTLI_VERSION_{TEXT,NUMBER} constants --- brotli.c | 12 ++++++++++++ brotli.stub.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/brotli.c b/brotli.c index 607aed0..22bee40 100644 --- a/brotli.c +++ b/brotli.c @@ -1309,6 +1309,18 @@ ZEND_MINIT_FUNCTION(brotli) CONST_CS | CONST_PERSISTENT); #endif + uint32_t version_number = BrotliDecoderVersion(); + char version_text[64]; + snprintf(version_text, sizeof(version_text), "%d.%d.%d", + version_number >> 24, + (version_number >> 12) & 0xfff, + version_number & 0xfff); + + REGISTER_LONG_CONSTANT("BROTLI_VERSION_NUMBER", version_number, + CONST_CS | CONST_PERSISTENT); + REGISTER_STRING_CONSTANT("BROTLI_VERSION_TEXT", version_text, + CONST_CS | CONST_PERSISTENT); + php_output_handler_alias_register(ZEND_STRL(PHP_BROTLI_OUTPUT_HANDLER), php_brotli_output_handler_init); php_output_handler_conflict_register(ZEND_STRL(PHP_BROTLI_OUTPUT_HANDLER), diff --git a/brotli.stub.php b/brotli.stub.php index 122e3de..be9d990 100644 --- a/brotli.stub.php +++ b/brotli.stub.php @@ -63,6 +63,18 @@ */ const BROTLI_DICTIONARY_SUPPORT = UNKNOWN; + /** + * @var string + * @cvalue BROTLI_VERSION_TEXT + */ + const BROTLI_VERSION_TEXT = UNKNOWN; + + /** + * @var int + * @cvalue BROTLI_VERSION_NUMBER + */ + const BROTLI_VERSION_NUMBER = UNKNOWN; + /** * @note dict parameter can be used when BROTLI_DICTIONARY_SUPPORT is enabled */ From 6141c69eb69b63844a6c5d7633d2a49469e2cbff Mon Sep 17 00:00:00 2001 From: kjdev Date: Thu, 12 Jun 2025 09:01:52 +0900 Subject: [PATCH 2/3] refactor: change library version acquisition in ZEND_MINFO_FUNCTION to constant --- brotli.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/brotli.c b/brotli.c index 22bee40..0ea5574 100644 --- a/brotli.c +++ b/brotli.c @@ -1425,15 +1425,9 @@ ZEND_MINFO_FUNCTION(brotli) php_info_print_table_start(); php_info_print_table_row(2, "Brotli support", "enabled"); php_info_print_table_row(2, "Extension Version", BROTLI_EXT_VERSION); -#ifdef BROTLI_LIB_VERSION - php_info_print_table_row(2, "Library Version", BROTLI_LIB_VERSION); -#else - uint32_t version = BrotliDecoderVersion(); - char buffer[64]; - snprintf(buffer, sizeof(buffer), "%d.%d.%d", - version >> 24, (version >> 12) & 0xfff, version & 0xfff); - php_info_print_table_row(2, "Library Version", buffer); -#endif + const zval *ver = zend_get_constant_str("BROTLI_VERSION_TEXT", + sizeof("BROTLI_VERSION_TEXT") - 1); + php_info_print_table_row(2, "Library Version", Z_STRVAL_P(ver)); #if defined(USE_BROTLI_DICTIONARY) php_info_print_table_row(2, "Dictionary support", "enabled"); #else From 1b261000b895424d73e51cf46a72b11f9ac5b555 Mon Sep 17 00:00:00 2001 From: kjdev Date: Thu, 12 Jun 2025 09:03:02 +0900 Subject: [PATCH 3/3] remove: BROTLI_LIB_VERSION that is no longer needed --- config.m4 | 1 - php_brotli.h | 1 - 2 files changed, 2 deletions(-) diff --git a/config.m4 b/config.m4 index b0d485e..106bf34 100644 --- a/config.m4 +++ b/config.m4 @@ -62,7 +62,6 @@ if test "$PHP_BROTLI" != "no"; then fi PHP_EVAL_INCLINE($LIBBROTLIDEC_CFLAGS) PHP_EVAL_LIBLINE($LIBBROTLIDEC_LIBS, BROTLI_SHARED_LIBADD) - AC_DEFINE_UNQUOTED(BROTLI_LIB_VERSION, "$LIBBROTLIDEC_VERSION", [system library version]) AC_MSG_CHECKING(for brotli dictionary) if $PKG_CONFIG libbrotlidec --atleast-version 1.1.0; then diff --git a/php_brotli.h b/php_brotli.h index 60f3085..f03829f 100644 --- a/php_brotli.h +++ b/php_brotli.h @@ -5,7 +5,6 @@ extern "C" { #endif -/* Don't forget to check BROTLI_LIB_VERSION in config.m4/w32 */ #define BROTLI_EXT_VERSION "0.17.0" #define BROTLI_NS "Brotli"