1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Implement stream_context_set_options()

This commit is contained in:
Máté Kocsis
2023-07-13 23:15:06 +02:00
parent d9a7f6741e
commit a5ad7e09d5
5 changed files with 79 additions and 1 deletions

View File

@@ -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<string, mixed>

View File

@@ -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)

View File

@@ -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)
{

View File

@@ -0,0 +1,27 @@
--TEST--
Basic test for stream_context_set_options()
--FILE--
<?php
$context = stream_context_create();
$options = [
'http' => [
'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"
}
}

View File

@@ -0,0 +1,21 @@
--TEST--
Error test for stream_context_set_options()
--FILE--
<?php
$pipes = [];
$description = array(
0 => 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