]> granicus.if.org Git - php/commitdiff
MFH: Added stream_context_get_params()
authorArnaud Le Blanc <lbarnaud@php.net>
Thu, 13 Nov 2008 05:47:47 +0000 (05:47 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Thu, 13 Nov 2008 05:47:47 +0000 (05:47 +0000)
NEWS
ext/standard/basic_functions.c
ext/standard/streamsfuncs.c
ext/standard/streamsfuncs.h
ext/standard/tests/streams/stream_context_get_params_001.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 9e55f5e7cf5975fa67eca018d4080b62e1558d92..67ba1db56d09bfc283e546cfac094b4a0a44e856 100644 (file)
--- 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)
index c375a2c5f92e2fdb5b0554f95ec5ac88b41bb776..d8c8d66115a7412f7fa36662935ee5ea3bc635ce 100644 (file)
@@ -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)
index 6384478a6e00312ef8556c8fe2e192d21bae2062..a1eddf63f2735357db3f1d6d6946c8c093a64fe6 100644 (file)
@@ -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)
index 90105919c624d0bad048c7515fd38673a0f9337f..65d679b928fa94a9689c166acdbbd302c083023e 100644 (file)
@@ -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 (file)
index 0000000..d946184
--- /dev/null
@@ -0,0 +1,121 @@
+--TEST--
+stream_context_get_params()
+--FILE--
+<?php
+
+$ctx = stream_context_create();
+var_dump($ctx);
+var_dump(stream_context_get_params($ctx));
+
+var_dump(stream_context_set_option($ctx, "foo","bar","baz"));
+var_dump(stream_context_get_params($ctx));
+
+var_dump(stream_context_set_params($ctx, array("notification" => "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"
+  }
+}