{"id":22364100,"url":"https://github.com/11ways/doen","last_synced_at":"2025-07-30T15:31:33.322Z","repository":{"id":56976599,"uuid":"349212718","full_name":"11ways/doen","owner":"11ways","description":"A bridge between PHP \u0026 Node.js","archived":false,"fork":false,"pushed_at":"2022-08-23T13:34:40.000Z","size":32,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-02T20:16:15.236Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/11ways.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":".github/code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-18T20:46:53.000Z","updated_at":"2024-06-28T15:59:07.000Z","dependencies_parsed_at":"2022-08-21T08:10:59.527Z","dependency_job_id":null,"html_url":"https://github.com/11ways/doen","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/11ways%2Fdoen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/11ways%2Fdoen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/11ways%2Fdoen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/11ways%2Fdoen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/11ways","download_url":"https://codeload.github.com/11ways/doen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228070710,"owners_count":17864662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-04T17:18:30.443Z","updated_at":"2024-12-04T17:18:31.052Z","avatar_url":"https://github.com/11ways.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cb\u003eelevenways/doen\u003c/b\u003e\n\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003c!-- Github Actions --\u003e\n  \u003ca href=\"https://github.com/11ways/doen/actions\"\u003e\n    \u003cimg src=\"https://github.com/11ways/doen/actions/workflows/php.yml/badge.svg\" alt=\"Build Status\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- Coverage - Codecov --\u003e\n  \u003ca href=\"https://codecov.io/gh/11ways/doen\"\u003e\n    \u003cimg src=\"https://img.shields.io/codecov/c/github/11ways/doen/master.svg\" alt=\"Codecov Coverage report\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- Version - packagist --\u003e\n  \u003ca href=\"https://packagist.org/packages/elevenways/doen\"\u003e\n    \u003cimg src=\"https://img.shields.io/packagist/php-v/elevenways/doen.svg\" alt=\"Latest version on Packagist\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- License - MIT --\u003e\n  \u003ca href=\"https://github.com/11ways/doen#license\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/11ways/doen.svg\" alt=\"Project license\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\u003cdiv align=\"center\"\u003e\n  Asynchronously call JavaScript code from within PHP\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003csub\u003e\n    Coded with ❤️ by \u003ca href=\"#authors\"\u003eEleven Ways\u003c/a\u003e.\n  \u003c/sub\u003e\n\u003c/div\u003e\n\n\n## Introduction\n\nHave you ever needed to use the functionality of a node.js package in your PHP project, but don't want to spend hours writing a wrapper? Well now you can.\n\nThanks to ReactPHP it was quite a simple script to get working.\n\n## Installation\n\nInstallation is easy via [Composer](https://getcomposer.org/):\n\n```bash\n$ composer require elevenways/doen\n```\n\nOr you can add it manually to your `composer.json` file.\n\n## Usage\n\n### Simple `require()` example\n\n```php\n\n// You will need an event loop instance.\n// If this looks weird to you, you should lookup ReactPHP\n$loop = \\React\\EventLoop\\Factory::create();\n\n// Now we can create a Doen instance\n$doen = new \\Elevenways\\Doen\\Doen($loop);\n\n// Lets get our first, simple reference\n// $libpath is now an \\Elevenways\\Doen\\Reference instance\n$libpath = $doen-\u003eevaluateToRef('require(\"path\")');\n\n// Even though the code is happening asynchronously, we can already act upon it\n// This will return yet another \\Elevenways\\Doen\\Reference instance\n$str = $libpath-\u003ejoin('a', 'b', 'c');\n\n// Now we can get the value\n$str-\u003egetValue()-\u003ethen(function ($value) {\n    // This will print out a/b/c\n    echo $value;\n});\n\n// This, again, is part of ReactPHP.\n// It starts the event loop and will BLOCK the rest of the code!\n$loop-\u003erun();\n```\n\n## API\n\n### Doen\n\n#### new Doen(\\React\\EventLoop\\LoopInterface $loop, array $options = [])\n\nCreate a new Doen instance, which always creates a new Node.js instance too.\n\nBy default it'll use the `node` binary, but this can be overridden with the `node_path` option.\n\n#### require(string $name) ⇒ `\\Elevenways\\Doen\\Reference`\n\nRequire a node.js module and return a reference to it.\n\n```php\n$libpath = $doen-\u003erequire('path');\n```\n\n#### evaluate(string $code) ⇒ `\\React\\Promise\\Promise`\n\nExecute an expression and return its value.\n\n```php\n$promise = $doen-\u003eevaluate('1 + 1');\n```\n\n#### evaluateFunction(string $function, $args = []) ⇒ `\\React\\Promise\\Promise`\n\nExecute a function with the supplied arguments and return its value.\n\n```php\n$promise = $doen-\u003eevaluate('function(a, b) {return a * b}', [3, 2]);\n```\n\n#### evaluateToRef(string $code, $args = null) ⇒ `\\Elevenways\\Doen\\Reference`\n\nExecute an expression or a function and return a reference to its value.\n\n```php\n$libpath = $doen-\u003eevaluateToRef('require(\"path\")');\n```\n\n#### close() ⇒ `void`\n\nClose the node.js process\n\n```php\n$doen-\u003eclose();\n```\n\n### Reference\n\n#### getValue(callable $on_fulfilled = null, callable $on_rejected = null) ⇒ `\\React\\Promise\\Promise`\n\nGet the actual value of the reference\n\n```php\n$ref = $doen-\u003eevaluateToRef('1 + 1');\n$ref-\u003egetValue(function($result) {\n    // Outputs: 2\n    echo $result;\n});\n```\n\n#### then(callable $on_fulfilled = null, callable $on_rejected = null) ⇒ `\\React\\Promise\\Promise`\n\nExecute the callables when this reference resolves.\nIt will **not** resolve to its value, but to its type for primitives and to its class for objects.\n\n```php\n$ref = $doen-\u003eevaluateToRef('1 + 1');\n$ref-\u003ethen(function($type) {\n    // Outputs: \"number\"\n    echo $type;\n});\n\n$array = $doen-\u003eevaluateToRef('[]');\n$ref-\u003ethen(function($type) {\n    // Outputs: \"Array\"\n    echo $type;\n});\n```\n\n#### __monkeyPatch($method_name, Closure $fnc) ⇒ `void`\n\nAdd a method to this instance on-the-fly\n\n```php\n$ref = $doen-\u003eevaluateToRef('1 + 1');\n$ref-\u003e__monkeyPatch('weird', function() {\n    return 'weird';\n});\n\n// Returns \"weird\"\n$ref-\u003eweird();\n```\n\n\n## Contributing\nContributions are REALLY welcome.\nPlease check the [contributing guidelines](.github/contributing.md) for more details. Thanks!\n\n## Authors\n- **Jelle De Loecker** -  *Follow* me on *Github* ([:octocat:@skerit](https://github.com/skerit)) and on  *Twitter* ([🐦@skeriten](http://twitter.com/intent/user?screen_name=skeriten))\n\nSee also the list of [contributors](https://github.com/11ways/doen/contributors) who participated in this project.\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/11ways/doen/LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F11ways%2Fdoen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F11ways%2Fdoen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F11ways%2Fdoen/lists"}