]> granicus.if.org Git - php/commitdiff
Added stream_context_get_params()
authorArnaud Le Blanc <lbarnaud@php.net>
Thu, 13 Nov 2008 05:46:51 +0000 (05:46 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Thu, 13 Nov 2008 05:46:51 +0000 (05:46 +0000)
[DOC] proto bool stream_context_get_params(resource context|stream)
      Get parameters of a file context (parameters set by
      stream_context_set_params())

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]

index 29ca8591190814153f36e796072b0dfddc615f6a..071c624dd33dbbac04ee569333d6beeb204b4161 100644 (file)
@@ -2386,6 +2386,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) */
@@ -3564,6 +3569,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 8da886aef57834c4c4b1f369dee8ffe074813cd8..5506e76e1a1186c38e46517fd7a03ca756c79466 100644 (file)
@@ -1151,6 +1151,35 @@ PHP_FUNCTION(stream_context_set_params)
 }
 /* }}} */
 
+/* {{{ proto bool stream_context_get_params(resource context|resource stream) U
+   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_ascii_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_ascii_assoc_zval_ex(return_value, ZEND_STRS("options"), options);
+}
+/* }}} */
+
+
 /* {{{ proto resource stream_context_get_default([array options]) U
    Get a handle on the default file/stream context and optionally set parameters */
 PHP_FUNCTION(stream_context_get_default)
index 4963614bcf316e4f0f32fabcd61a9b2f1370d1b7..0d17bae7ca97fd4dd2ec8ebb4764362247c30356 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"
+  }
+}