From: Arnaud Le Blanc Date: Thu, 13 Nov 2008 05:47:47 +0000 (+0000) Subject: MFH: Added stream_context_get_params() X-Git-Tag: php-5.3.0alpha2~170 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06119f4748066e61163764bbb31d1db4b21b6d07;p=php MFH: Added stream_context_get_params() --- diff --git a/NEWS b/NEWS index 9e55f5e7cf..67ba1db56d 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ PHP NEWS parameter validation. (Felipe) - Changed openssl info to show the shared library version number. (Scott) +- Added stream_context_get_params() function. (Arnaud) - Added optional parameter "new" to sybase_connect() (Timm) - Added parse_ini_string() function. (grange at lemonde dot fr, Arnaud) - Added str_getcsv() function. (Sara) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index c375a2c5f9..d8c8d66115 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2401,6 +2401,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_stream_context_set_params, 0) ZEND_ARG_INFO(0, options) /* ARRAY_INFO(0, options, 1) */ ZEND_END_ARG_INFO() +static +ZEND_BEGIN_ARG_INFO_EX(arginfo_stream_context_get_params, 0, ZEND_RETURN_VALUE, 1) + ZEND_ARG_INFO(0, stream_or_context) +ZEND_END_ARG_INFO() + static ZEND_BEGIN_ARG_INFO_EX(arginfo_stream_context_get_default, 0, 0, 0) ZEND_ARG_INFO(0, options) /* ARRAY_INFO(0, options, 1) */ @@ -3540,6 +3545,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(stream_select, arginfo_stream_select) PHP_FE(stream_context_create, arginfo_stream_context_create) PHP_FE(stream_context_set_params, arginfo_stream_context_set_params) + PHP_FE(stream_context_get_params, arginfo_stream_context_get_params) PHP_FE(stream_context_set_option, arginfo_stream_context_set_option) PHP_FE(stream_context_get_options, arginfo_stream_context_get_options) PHP_FE(stream_context_get_default, arginfo_stream_context_get_default) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 6384478a6e..a1eddf63f2 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -1038,6 +1038,34 @@ PHP_FUNCTION(stream_context_set_params) } /* }}} */ +/* {{{ proto bool stream_context_get_params(resource context|resource stream) + Get parameters of a file context */ +PHP_FUNCTION(stream_context_get_params) +{ + zval *zcontext, *options; + php_stream_context *context; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zcontext) == FAILURE) { + RETURN_FALSE; + } + + context = decode_context_param(zcontext TSRMLS_CC); + if (!context) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter"); + RETURN_FALSE; + } + + array_init(return_value); + if (context->notifier && context->notifier->ptr && context->notifier->func == user_space_stream_notifier) { + add_assoc_zval_ex(return_value, ZEND_STRS("notification"), context->notifier->ptr); + Z_ADDREF_P(context->notifier->ptr); + } + ALLOC_INIT_ZVAL(options); + ZVAL_ZVAL(options, context->options, 1, 0); + add_assoc_zval_ex(return_value, ZEND_STRS("options"), options); +} +/* }}} */ + /* {{{ proto resource stream_context_get_default([array options]) Get a handle on the default file/stream context and optionally set parameters */ PHP_FUNCTION(stream_context_get_default) diff --git a/ext/standard/streamsfuncs.h b/ext/standard/streamsfuncs.h index 90105919c6..65d679b928 100644 --- a/ext/standard/streamsfuncs.h +++ b/ext/standard/streamsfuncs.h @@ -46,6 +46,7 @@ PHP_FUNCTION(stream_wrapper_unregister); PHP_FUNCTION(stream_wrapper_restore); PHP_FUNCTION(stream_context_create); PHP_FUNCTION(stream_context_set_params); +PHP_FUNCTION(stream_context_get_params); PHP_FUNCTION(stream_context_set_option); PHP_FUNCTION(stream_context_get_options); PHP_FUNCTION(stream_context_get_default); diff --git a/ext/standard/tests/streams/stream_context_get_params_001.phpt b/ext/standard/tests/streams/stream_context_get_params_001.phpt new file mode 100644 index 0000000000..d946184f63 --- /dev/null +++ b/ext/standard/tests/streams/stream_context_get_params_001.phpt @@ -0,0 +1,121 @@ +--TEST-- +stream_context_get_params() +--FILE-- + "stream_notification_callback"))); +var_dump(stream_context_get_params($ctx)); + +var_dump(stream_context_set_params($ctx, array("notification" => array("stream","notification_callback")))); +var_dump(stream_context_get_params($ctx)); + +var_dump(stream_context_get_params($ctx)); +var_dump(stream_context_get_options($ctx)); +var_dump(stream_context_get_params($ctx)); +var_dump(stream_context_get_options($ctx)); + +?> +--EXPECTF-- +resource(%d) of type (stream-context) +array(1) { + [%u|b%"options"]=> + array(0) { + } +} +bool(true) +array(1) { + [%u|b%"options"]=> + array(1) { + [%u|b%"foo"]=> + array(1) { + [%u|b%"bar"]=> + %unicode|string%(3) "baz" + } + } +} +bool(true) +array(2) { + [%u|b%"notification"]=> + %unicode|string%(28) "stream_notification_callback" + [%u|b%"options"]=> + array(1) { + [%u|b%"foo"]=> + array(1) { + [%u|b%"bar"]=> + %unicode|string%(3) "baz" + } + } +} +bool(true) +array(2) { + [%u|b%"notification"]=> + array(2) { + [0]=> + %unicode|string%(6) "stream" + [1]=> + %unicode|string%(21) "notification_callback" + } + [%u|b%"options"]=> + array(1) { + [%u|b%"foo"]=> + array(1) { + [%u|b%"bar"]=> + %unicode|string%(3) "baz" + } + } +} +array(2) { + [%u|b%"notification"]=> + array(2) { + [0]=> + %unicode|string%(6) "stream" + [1]=> + %unicode|string%(21) "notification_callback" + } + [%u|b%"options"]=> + array(1) { + [%u|b%"foo"]=> + array(1) { + [%u|b%"bar"]=> + %unicode|string%(3) "baz" + } + } +} +array(1) { + [%u|b%"foo"]=> + array(1) { + [%u|b%"bar"]=> + %unicode|string%(3) "baz" + } +} +array(2) { + [%u|b%"notification"]=> + array(2) { + [0]=> + %unicode|string%(6) "stream" + [1]=> + %unicode|string%(21) "notification_callback" + } + [%u|b%"options"]=> + array(1) { + [%u|b%"foo"]=> + array(1) { + [%u|b%"bar"]=> + %unicode|string%(3) "baz" + } + } +} +array(1) { + [%u|b%"foo"]=> + array(1) { + [%u|b%"bar"]=> + %unicode|string%(3) "baz" + } +}