phpjs
Version:
56 lines (48 loc) • 2.12 kB
Markdown
layout: page
title: "JavaScript stream_context_set_params function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/stream_context_set_params:850
- /functions/view/stream_context_set_params
- /functions/view/850
- /functions/stream_context_set_params:850
- /functions/850
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's stream_context_set_params
{% codeblock stream/stream_context_set_params.js lang:js https://raw.github.com/kvz/phpjs/master/functions/stream/stream_context_set_params.js raw on github %}
function stream_context_set_params (stream_or_context, params) {
// http://kevin.vanzonneveld.net
// + original by: Brett Zamir (http://brett-zamir.me)
// * example 1: var context = stream_context_create();
// * example 1: stream_context_set_params({notification:function (notification_code, severity, message, message_code, bytes_transferred, bytes_max) {}});
// * returns 1: true
var param = '';
// Docs also allow for "options" as a parameter here (i.e., setting options instead of parameters) and source seems to allow encoding, input_encoding, output_encoding, and default_mode
for (param in params) { // Overwrites all, or just supplied? Seems like just supplied
if (param === 'options') {
stream_or_context.stream_options = params[param]; // Overwrite all?
} else {
stream_or_context.stream_params[param] = params[param];
}
}
return true;
}
{% endcodeblock %}
- [view on github](https://github.com/kvz/phpjs/blob/master/functions/stream/stream_context_set_params.js)
- [edit on github](https://github.com/kvz/phpjs/edit/master/functions/stream/stream_context_set_params.js)
### Example 1
This code
{% codeblock lang:js example %}
var context = stream_context_create();
stream_context_set_params({notification:function (notification_code, severity, message, message_code, bytes_transferred, bytes_max) {}});
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
true
{% endcodeblock %}
### Other PHP functions in the stream extension
{% render_partial _includes/custom/stream.html %}