diff --git a/NEWS b/NEWS index cadfda9bde6b..eb60953f8ece 100644 --- a/NEWS +++ b/NEWS @@ -84,6 +84,8 @@ PHP NEWS . Fixed bug GH-20370 (User stream filters could violate typed property constraints). (alexandre-daubois) . Allowed filtered streams to be casted as fd for select. (Jakub Zelenka) + . Added "read_filters" and "write_filters" keys to stream_get_meta_data(). + (ndossche) - Zip: . Fixed ZipArchive callback being called after executor has shut down. diff --git a/UPGRADING b/UPGRADING index 0ea423b32d38..048be0f61207 100644 --- a/UPGRADING +++ b/UPGRADING @@ -53,6 +53,8 @@ PHP 8.6 UPGRADE NOTES tcp_keepintvl and tcp_keepcnt that allow setting socket keepalive options. . Allowed casting casting filtered streams as file descriptor for select. + . Added "read_filters" and "write_filters" keys to stream_get_meta_data() + if the stream has read filters/write filters attached. ======================================== 3. Changes in SAPI modules diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 506ce0dafed8..cfde7c05a98b 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -507,6 +507,20 @@ PHP_FUNCTION(stream_copy_to_stream) } /* }}} */ +static void stream_fill_filters_array(zval *array, const char *name, const php_stream_filter_chain *chain) +{ + if (chain->head) { + zval filters; + array_init(&filters); + + for (const php_stream_filter *filter = chain->head; filter != NULL; filter = filter->next) { + add_next_index_string(&filters, filter->fops->label); + } + + add_assoc_zval(array, name, &filters); + } +} + /* {{{ Retrieves header/meta data from streams/file pointers */ PHP_FUNCTION(stream_get_meta_data) { @@ -535,20 +549,8 @@ PHP_FUNCTION(stream_get_meta_data) add_assoc_string(return_value, "mode", stream->mode); -#if 0 /* TODO: needs updating for new filter API */ - if (stream->filterhead) { - php_stream_filter *filter; - - MAKE_STD_ZVAL(newval); - array_init(newval); - - for (filter = stream->filterhead; filter != NULL; filter = filter->next) { - add_next_index_string(newval, filter->fops->label); - } - - add_assoc_zval(return_value, "filters", newval); - } -#endif + stream_fill_filters_array(return_value, "read_filters", &stream->readfilters); + stream_fill_filters_array(return_value, "write_filters", &stream->writefilters); add_assoc_long(return_value, "unread_bytes", stream->writepos - stream->readpos); diff --git a/ext/standard/tests/streams/stream_get_meta_data_filters_list.phpt b/ext/standard/tests/streams/stream_get_meta_data_filters_list.phpt new file mode 100644 index 000000000000..3d44c61f2a96 --- /dev/null +++ b/ext/standard/tests/streams/stream_get_meta_data_filters_list.phpt @@ -0,0 +1,50 @@ +--TEST-- +stream_get_meta_data() filters list +--FILE-- + +--EXPECTF-- +array(11) { + ["timed_out"]=> + bool(false) + ["blocked"]=> + bool(true) + ["eof"]=> + bool(false) + ["wrapper_type"]=> + string(9) "plainfile" + ["stream_type"]=> + string(5) "STDIO" + ["mode"]=> + string(1) "r" + ["read_filters"]=> + array(2) { + [0]=> + string(12) "string.rot13" + [1]=> + string(14) "string.tolower" + } + ["write_filters"]=> + array(2) { + [0]=> + string(14) "string.toupper" + [1]=> + string(14) "string.tolower" + } + ["unread_bytes"]=> + int(0) + ["seekable"]=> + bool(true) + ["uri"]=> + string(%d) "%s" +}