Comments (4)
Hi @danieleratti!
It's possible to call any PHP function/method from js runtime, pass data in a both way and so on. Actually, in php-v8 you can do everything V8 provides. Unfortunately, there is no documentation yet (here is a ticket for that - #48). However, you may look into tests
folder and see some examples.
I'd like to note php-v8 key difference from v8js: php-v8 is a low-level binding to V8 API, while v8js provides high-level abstraction. I actually like v8js and it's a great tool, however for my need I had to make php-v8 as it is. To deal with php-v8 and v8 complexity I have a PHP library which I plan to open source soon. With raw php-v8 you will operate on a V8 C++ API level, so here comes php-v8 pros and cons: you can do anything, but you have to know how.
In short, from js perspective there is no big difference between function and method - everything is a function and you can add/remove object "methods" in js at runtime, so here comes a difference between PHP and JS and how it glues together: you wrap any PHP callback with with a new FunctionObject(Context $context, callable $callable)
(or you can use FunctionTempalte
for that, but it's a bit advanced level).
To compose JS object form PHP you would probably build new ObjectValue(Context $context)
and set it properties with ObjectValue::set(Context $context, StingValue $name, Value $value)
. It might be a bit verbose, but it's handled in my php library.
Note, that php-v8 is under heavy development so at the moment it's API could not be considered as final and it might be a subject of further changes. However, in a pending v0.2.0 release which I schedule to the end of September (actually, I plan to do that during this weekend) the API is stabilized. In advance PHP library that provides high-level abstraction to php-v8 will take care of any BC-breaking changes in php-v8 and will have much more stable API.
Feels free to write more if you have any question or you need assistance to dive into php-v8 or solve particular case.
from php-v8.
@pinepain great! Thank you very much for your clarifications. I will try the FunctionObjects and wait for the v0.2.0 release :-)
from php-v8.
Hi! Short status update: v0.2.0 release tagged.
In advance, I published wrapper library for php-v8 - https://github.com/pinepain/php-v8-js-sandbox/tree/wip-public-release. The work is still in progress, so feels free to suggest changes and ask questions. It was made for my side projects needs and you may find ad-hoc solutions there. If you will be lucky to do that, I would appreciate if you report that to me. Also, feels free to ask questions: the doc and tests are not the strongest part and they are also in WIP state.
If you like what I'm doing and you use it in you work, I'd love if you support me on Patreon. I have plenty ideas and improvements in mind, but doing all that over evenings and weekends is not sustainable in the long term.
UPD: First version of https://github.com/pinepain/js-sandbox released. As it is under heavy development, use at your own risk.
from php-v8.
Closing this issue for now as not much to do about it. Some docs available at https://pinepain.gitbooks.io/php-v8/content/. It's a bit limited for now, though, more to come. For more docs feels free to look into stubs and tests. As always, I'm glad to answer any question regards php-v8 and it's usage. PRs to code, stubs and docs are more then welcomed.
from php-v8.
Related Issues (20)
- Write docs on how to use caching and snapshots HOT 2
- Add support for BigInt API HOT 1
- Call to undefined method V8\ObjectValue::value() HOT 2
- Reflect changes to libv8 PPA layout
- Add support for near-heap-limit callback HOT 1
- PHP API HOT 2
- Rep 404 HOT 2
- Hello, can you tell me how to compile v8js? HOT 3
- what is the difference HOT 2
- Still maintained? HOT 1
- it is not installing - PHP 7.4 / umbuntu server 18.4 HOT 2
- Create and publish docker image for php-v8 HOT 2
- V8Js::executeString HOT 4
- v8::Proxy API has changed (V8 6.5.164) HOT 6
- Warning: Calling <<-EOS.undent is deprecated HOT 2
- Resolving/rejecting Promise in non-pending state leads to segfault HOT 2
- GetOwnPropertyNames and GetPropertyNames should return Strings
- Implement v8::Object::SetLazyDataProperty.
- Add BigInt64Array, BigUint64Array
- Script cache creating is broken after bumping v8 version to 6.6.313 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-v8.