Use PHP functions in JavaScript

JavaScript stream_context_set_params

Set parameters for a file context

1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
function stream_context_set_params (stream_or_context, params) {
    // Set parameters for a file context  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/stream_context_set_params    // +   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;    
}
external links: original PHP docs | raw js source

Examples

Running

1
2
var context = stream_context_create();
stream_context_set_params({notification:function (notification_code, severity, message, message_code, bytes_transferred, bytes_max) {}});

Should return

1
true

Dependencies

No dependencies, you can use this function standalone.

Open syntax issues

php.js uses JsLint to help us keep our code consistent and prevent some common bugs.

Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.


Authors

Thanks to the following developers, you get to have stream_context_set_params goodness in JavaScript.

Comments

Add Comment
Use:
[CODE]
your_stuff('here');
[/CODE]
for proper code formatting
By submitting code here you are allowing us to use it in php.js hence dual licensing it under the MIT and GPL licenses

No comments yet. Be the first!


Contribute a New function

More functions

In this category

stream_context_create
stream_context_get_default
stream_context_get_options
stream_context_get_params
stream_context_set_default
stream_context_set_option
» stream_context_set_params
stream_get_contents
stream_get_line
stream_is_local

Support us

spread the word:


Use any PHP function in JavaScript


These kind folks have already donated: @HalfWinter, Paulo Freitas, Andros Peña Romo, Nitin Gupta, @nikosdion, Anonymous, Anonymous and Shawn Houser.
<your name here>

Click here to lend your support to: phpjs and make a donation at www.pledgie.com !