uniter
uniter copied to clipboard
More Root Level Functions
Hi @asmblah ,
I'd like to add new functions to the Root Level of "Uniterland" Apps. I'd be happy to begin with something along the lines of https://github.com/asmblah/uniter/issues/24 , as I have a couple of good remote Node Devs who I'd quite like to task with some extensions and integrations for this (and tests :) ). I'd quite like to use the defined method and so I'd like to start there.
I'd also like to be able to use Locutus, http://locutus.io/php/ . They've got 300+ functions which have proven useful to us so far. The only issue there is that we use a wrapper class and access these methods like
$current_time = $php->time() ;
Where it would be more PHP like to be able to include that whole library of methods at root level so we could do...
$current_time = time() ;
So, would there be a way of having a if function exists in PHPRuntime, use it. Otherwise look in xyz Objects for those functions? Then i could include that PHP/Locutus object/variable there and use those functions at root level. I could also write something like "Issue24Class", that includes those functions mentioned in that issue, including defined.
Would that be possible? If so, could you point in the direction of how to do it please? Hopefully we can put those functions into a PR once they're done. It's fine to use all the Node Jargon in describing it, as its likely to be Node guys implementing this one.
Thanks, Dave
Hi @phpengine,
Once you have an Engine instance, you can define an "auto-coercing" function like so (contrived example):
my_module.php
<?php
var_dump(my_multiply(21, 100));
index.js
var engine = require('./php/my_module.php')();
engine.defineCoercingFunction('my_multiply', function (value1, value2) {
return value1 * value2;
});
engine.execute();
so you could use this for each function you want to define. There isn't currently a way to define a "magic" function that would be called for undefined functions, but it's something I think could come in handy so I'll look into adding that as a feature soon.
Cheers
Perfect - Thanks :)
defineCoercingFunction
seems to be useless now.
@yi-ge apologies for not responding before; I must have missed your message. If it's still relevant could you elaborate a bit on what problem you were having with defineCoercingFunction(...)
please, ie. is there a specific error you saw raised? I appreciate a lot of time has passed since though!