asmblah / uniter

🎉 PHP in the browser and Node.js => Docs: https://phptojs.com/
https://asmblah.github.io/uniter/
Other
446 stars 42 forks source link

Defining extensions #27

Open IngwiePhoenix opened 8 years ago

IngwiePhoenix commented 8 years ago

PHP usually provides extensions; like pcntl, hprose, sockets and alike.

In order to reproduce these within Uniter, this is what I would suggest:

var Extension = require("uniter-extension");

var cURL = new Extension();

cURL.function("curl_init", function(){
    // Implement curl_init
});

function cURLClass(args) {}
    // a cURL class
}
cURL.addClass("cURL", cURLClass);

module.exports = cURL;

Now, we could extend Uniter by an additional function. Currently, we have .install() to install functions, constants and classes into the system. As far as I remember, they all go into global scope. Extensions could be registered similarily:

var rt = require("phpruntime");
rt.registerExtension( "curl", require("./myCurlExt.js") );
rt.loadExtension("curl");

This would also provide the extension_loaded function to Uniter. Also, we might be able to use dl().

To summarize:

Implementation is up to you, the above are just pseudo-code examples :) But i bet you get what I meant.

asmblah commented 8 years ago

This is a nice suggestion @IngwiePhoenix, I'll definitely implement this soon :+1: