Skip to content
Open
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions ext/standard/streamsfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--TEST--
stream_get_meta_data() filters list
--FILE--
<?php

$fp = fopen(__FILE__, "r");
stream_filter_append($fp, 'string.rot13', STREAM_FILTER_READ);
stream_filter_append($fp, 'string.toupper', STREAM_FILTER_WRITE);
stream_filter_append($fp, 'string.tolower', STREAM_FILTER_ALL);

var_dump(stream_get_meta_data($fp));

fclose($fp);

?>
--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"
}