diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 0f2381c321b..6fed9c8064a 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -3334,6 +3334,9 @@ function stream_context_get_params($context): array {} /** @param resource $context */ function stream_context_set_option($context, array|string $wrapper_or_options, ?string $option_name = null, mixed $value = UNKNOWN): bool {} +/** @param resource $context */ +function stream_context_set_options($context, array $options): bool {} + /** * @param resource $stream_or_context * @return array diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 89f746aa571..f325634e95c 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: e01f6a979e72b1c3baf4602421cc966edfe50312 */ + * Stub hash: decfa1e3d862d81880ea18150e2ba239bf15b8af */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0) @@ -1849,6 +1849,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_set_option, 0, 2, ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_set_options, 0, 2, _IS_BOOL, 0) + ZEND_ARG_INFO(0, context) + ZEND_ARG_TYPE_INFO(0, options, IS_ARRAY, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_get_options, 0, 1, IS_ARRAY, 0) ZEND_ARG_INFO(0, stream_or_context) ZEND_END_ARG_INFO() @@ -2718,6 +2723,7 @@ ZEND_FUNCTION(stream_context_create); ZEND_FUNCTION(stream_context_set_params); ZEND_FUNCTION(stream_context_get_params); ZEND_FUNCTION(stream_context_set_option); +ZEND_FUNCTION(stream_context_set_options); ZEND_FUNCTION(stream_context_get_options); ZEND_FUNCTION(stream_context_get_default); ZEND_FUNCTION(stream_context_set_default); @@ -3358,6 +3364,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(stream_context_set_params, arginfo_stream_context_set_params) ZEND_FE(stream_context_get_params, arginfo_stream_context_get_params) ZEND_FE(stream_context_set_option, arginfo_stream_context_set_option) + ZEND_FE(stream_context_set_options, arginfo_stream_context_set_options) ZEND_FE(stream_context_get_options, arginfo_stream_context_get_options) ZEND_FE(stream_context_get_default, arginfo_stream_context_get_default) ZEND_FE(stream_context_set_default, arginfo_stream_context_set_default) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 5cb91959e2a..be1d4347a3f 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -1064,6 +1064,26 @@ PHP_FUNCTION(stream_context_set_option) } /* }}} */ +PHP_FUNCTION(stream_context_set_options) +{ + zval *zcontext = NULL; + php_stream_context *context; + HashTable *options; + + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_RESOURCE(zcontext) + Z_PARAM_ARRAY_HT(options) + ZEND_PARSE_PARAMETERS_END(); + + /* figure out where the context is coming from exactly */ + if (!(context = decode_context_param(zcontext))) { + zend_argument_type_error(1, "must be a valid stream/context"); + RETURN_THROWS(); + } + + RETURN_BOOL(parse_context_options(context, options) == SUCCESS); +} + /* {{{ Set parameters for a file context */ PHP_FUNCTION(stream_context_set_params) { diff --git a/ext/standard/tests/streams/stream_context_set_options_basic.phpt b/ext/standard/tests/streams/stream_context_set_options_basic.phpt new file mode 100644 index 00000000000..6d011de2246 --- /dev/null +++ b/ext/standard/tests/streams/stream_context_set_options_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +Basic test for stream_context_set_options() +--FILE-- + [ + 'protocol_version' => 1.1, + 'user_agent' => 'PHPT Agent', + ], +]; +var_dump(stream_context_set_options($context, $options)); + +var_dump(stream_context_get_options($context)); +?> +--EXPECT-- +bool(true) +array(1) { + ["http"]=> + array(2) { + ["protocol_version"]=> + float(1.1) + ["user_agent"]=> + string(10) "PHPT Agent" + } +} diff --git a/ext/standard/tests/streams/stream_context_set_options_error.phpt b/ext/standard/tests/streams/stream_context_set_options_error.phpt new file mode 100644 index 00000000000..b047e14f133 --- /dev/null +++ b/ext/standard/tests/streams/stream_context_set_options_error.phpt @@ -0,0 +1,21 @@ +--TEST-- +Error test for stream_context_set_options() +--FILE-- + array("pipe", "r"), + 1 => array("pipe", "w"), + 2 => array("pipe", "r") +); + +$process = proc_open('nothing', $description, $pipes); + +try { + stream_context_set_options($process, []); +} catch (TypeError $e) { + echo $e->getMessage(); +} +?> +--EXPECT-- +stream_context_set_options(): Argument #1 ($context) must be a valid stream/context