Skip to content

Commit a5ad7e0

Browse files
committed
Implement stream_context_set_options()
1 parent d9a7f67 commit a5ad7e0

5 files changed

+79
-1
lines changed

ext/standard/basic_functions.stub.php

+3
Original file line numberDiff line numberDiff line change
@@ -3334,6 +3334,9 @@ function stream_context_get_params($context): array {}
33343334
/** @param resource $context */
33353335
function stream_context_set_option($context, array|string $wrapper_or_options, ?string $option_name = null, mixed $value = UNKNOWN): bool {}
33363336

3337+
/** @param resource $context */
3338+
function stream_context_set_options($context, array $options): bool {}
3339+
33373340
/**
33383341
* @param resource $stream_or_context
33393342
* @return array<string, mixed>

ext/standard/basic_functions_arginfo.h

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/streamsfuncs.c

+20
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,26 @@ PHP_FUNCTION(stream_context_set_option)
10641064
}
10651065
/* }}} */
10661066

1067+
PHP_FUNCTION(stream_context_set_options)
1068+
{
1069+
zval *zcontext = NULL;
1070+
php_stream_context *context;
1071+
HashTable *options;
1072+
1073+
ZEND_PARSE_PARAMETERS_START(2, 2)
1074+
Z_PARAM_RESOURCE(zcontext)
1075+
Z_PARAM_ARRAY_HT(options)
1076+
ZEND_PARSE_PARAMETERS_END();
1077+
1078+
/* figure out where the context is coming from exactly */
1079+
if (!(context = decode_context_param(zcontext))) {
1080+
zend_argument_type_error(1, "must be a valid stream/context");
1081+
RETURN_THROWS();
1082+
}
1083+
1084+
RETURN_BOOL(parse_context_options(context, options) == SUCCESS);
1085+
}
1086+
10671087
/* {{{ Set parameters for a file context */
10681088
PHP_FUNCTION(stream_context_set_params)
10691089
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Basic test for stream_context_set_options()
3+
--FILE--
4+
<?php
5+
$context = stream_context_create();
6+
7+
$options = [
8+
'http' => [
9+
'protocol_version' => 1.1,
10+
'user_agent' => 'PHPT Agent',
11+
],
12+
];
13+
var_dump(stream_context_set_options($context, $options));
14+
15+
var_dump(stream_context_get_options($context));
16+
?>
17+
--EXPECT--
18+
bool(true)
19+
array(1) {
20+
["http"]=>
21+
array(2) {
22+
["protocol_version"]=>
23+
float(1.1)
24+
["user_agent"]=>
25+
string(10) "PHPT Agent"
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Error test for stream_context_set_options()
3+
--FILE--
4+
<?php
5+
$pipes = [];
6+
$description = array(
7+
0 => array("pipe", "r"),
8+
1 => array("pipe", "w"),
9+
2 => array("pipe", "r")
10+
);
11+
12+
$process = proc_open('nothing', $description, $pipes);
13+
14+
try {
15+
stream_context_set_options($process, []);
16+
} catch (TypeError $e) {
17+
echo $e->getMessage();
18+
}
19+
?>
20+
--EXPECT--
21+
stream_context_set_options(): Argument #1 ($context) must be a valid stream/context

0 commit comments

Comments
 (0)