Skip to content

Add/version constants #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions brotli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -1413,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
Expand Down
12 changes: 12 additions & 0 deletions brotli.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 0 additions & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion php_brotli.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading