PHPackages                             elevenways/doen - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. elevenways/doen

ActiveLibrary

elevenways/doen
===============

A bridge between PHP &amp; Node.js

v0.1.2(4y ago)447MITPHP

Since Mar 19Pushed 3y ago1 watchersCompare

[ Source](https://github.com/11ways/doen)[ Packagist](https://packagist.org/packages/elevenways/doen)[ RSS](/packages/elevenways-doen/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (4)Used By (0)

 **elevenways/doen**
====================

[](#--elevenwaysdoen)

 [ ![Build Status](https://github.com/11ways/doen/actions/workflows/php.yml/badge.svg) ](https://github.com/11ways/doen/actions) [ ![Codecov Coverage report](https://camo.githubusercontent.com/032879269e938943b62ff81e5a4fd5cefe08e55f75aac4b26c4048fefe739c7e/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f3131776179732f646f656e2f6d61737465722e737667) ](https://codecov.io/gh/11ways/doen) [ ![Latest version on Packagist](https://camo.githubusercontent.com/83bb47bc01d58568e5a2afb4b735d0b42454e0d8c58e6ca13ea3008d5c0f2324/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f656c6576656e776179732f646f656e2e737667) ](https://packagist.org/packages/elevenways/doen) [ ![Project license](https://camo.githubusercontent.com/0234a465c907d256c8ea4009308a65e4820be3bcb057ecf76677638eb4f875c0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f3131776179732f646f656e2e737667) ](https://github.com/11ways/doen#license)

 Asynchronously call JavaScript code from within PHP

  Coded with ❤️ by [Eleven Ways](#authors).

Introduction
------------

[](#introduction)

Have 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.

Thanks to ReactPHP it was quite a simple script to get working.

Installation
------------

[](#installation)

Installation is easy via [Composer](https://getcomposer.org/):

```
$ composer require elevenways/doen
```

Or you can add it manually to your `composer.json` file.

Usage
-----

[](#usage)

### Simple `require()` example

[](#simple-require-example)

```
// You will need an event loop instance.
// If this looks weird to you, you should lookup ReactPHP
$loop = \React\EventLoop\Factory::create();

// Now we can create a Doen instance
$doen = new \Elevenways\Doen\Doen($loop);

// Lets get our first, simple reference
// $libpath is now an \Elevenways\Doen\Reference instance
$libpath = $doen->evaluateToRef('require("path")');

// Even though the code is happening asynchronously, we can already act upon it
// This will return yet another \Elevenways\Doen\Reference instance
$str = $libpath->join('a', 'b', 'c');

// Now we can get the value
$str->getValue()->then(function ($value) {
    // This will print out a/b/c
    echo $value;
});

// This, again, is part of ReactPHP.
// It starts the event loop and will BLOCK the rest of the code!
$loop->run();
```

API
---

[](#api)

### Doen

[](#doen)

#### new Doen(\\React\\EventLoop\\LoopInterface $loop, array $options = \[\])

[](#new-doenreacteventlooploopinterface-loop-array-options--)

Create a new Doen instance, which always creates a new Node.js instance too.

By default it'll use the `node` binary, but this can be overridden with the `node_path` option.

#### require(string $name) ⇒ `\Elevenways\Doen\Reference`

[](#requirestring-name--elevenwaysdoenreference)

Require a node.js module and return a reference to it.

```
$libpath = $doen->require('path');
```

#### evaluate(string $code) ⇒ `\React\Promise\Promise`

[](#evaluatestring-code--reactpromisepromise)

Execute an expression and return its value.

```
$promise = $doen->evaluate('1 + 1');
```

#### evaluateFunction(string $function, $args = \[\]) ⇒ `\React\Promise\Promise`

[](#evaluatefunctionstring-function-args----reactpromisepromise)

Execute a function with the supplied arguments and return its value.

```
$promise = $doen->evaluate('function(a, b) {return a * b}', [3, 2]);
```

#### evaluateToRef(string $code, $args = null) ⇒ `\Elevenways\Doen\Reference`

[](#evaluatetorefstring-code-args--null--elevenwaysdoenreference)

Execute an expression or a function and return a reference to its value.

```
$libpath = $doen->evaluateToRef('require("path")');
```

#### close() ⇒ `void`

[](#close--void)

Close the node.js process

```
$doen->close();
```

### Reference

[](#reference)

#### getValue(callable $on\_fulfilled = null, callable $on\_rejected = null) ⇒ `\React\Promise\Promise`

[](#getvaluecallable-on_fulfilled--null-callable-on_rejected--null--reactpromisepromise)

Get the actual value of the reference

```
$ref = $doen->evaluateToRef('1 + 1');
$ref->getValue(function($result) {
    // Outputs: 2
    echo $result;
});
```

#### then(callable $on\_fulfilled = null, callable $on\_rejected = null) ⇒ `\React\Promise\Promise`

[](#thencallable-on_fulfilled--null-callable-on_rejected--null--reactpromisepromise)

Execute the callables when this reference resolves. It will **not** resolve to its value, but to its type for primitives and to its class for objects.

```
$ref = $doen->evaluateToRef('1 + 1');
$ref->then(function($type) {
    // Outputs: "number"
    echo $type;
});

$array = $doen->evaluateToRef('[]');
$ref->then(function($type) {
    // Outputs: "Array"
    echo $type;
});
```

#### \_\_monkeyPatch($method\_name, Closure $fnc) ⇒ `void`

[](#__monkeypatchmethod_name-closure-fnc--void)

Add a method to this instance on-the-fly

```
$ref = $doen->evaluateToRef('1 + 1');
$ref->__monkeyPatch('weird', function() {
    return 'weird';
});

// Returns "weird"
$ref->weird();
```

Contributing
------------

[](#contributing)

Contributions are REALLY welcome. Please check the [contributing guidelines](.github/contributing.md) for more details. Thanks!

Authors
-------

[](#authors)

- **Jelle De Loecker** - *Follow* me on *Github* ([![:octocat:](https://github.githubassets.com/images/icons/emoji/octocat.png ":octocat:")@skerit](https://github.com/skerit)) and on *Twitter* ([🐦@skeriten](http://twitter.com/intent/user?screen_name=skeriten))

See also the list of [contributors](https://github.com/11ways/doen/contributors) who participated in this project.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](https://github.com/11ways/doen/LICENSE) file for details.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~72 days

Total

3

Last Release

1739d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e06d657fe8292815b3efc4e3a3a5a94c4b79004bc0ef341d46edc69bb67baa0b?d=identicon)[skerit](/maintainers/skerit)

---

Top Contributors

[![skerit](https://avatars.githubusercontent.com/u/755212?v=4)](https://github.com/skerit "skerit (14 commits)")

---

Tags

Bridgenodejs

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/elevenways-doen/health.svg)

```
[![Health](https://phpackages.com/badges/elevenways-doen/health.svg)](https://phpackages.com/packages/elevenways-doen)
```

###  Alternatives

[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k379.4k24](/packages/team-reflex-discord-php)[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.3M26](/packages/league-geotools)[php-pm/php-pm

PHP-PM is a process manager, supercharger and load balancer for PHP applications.

6.6k441.3k8](/packages/php-pm-php-pm)[foxy/foxy

Fast, reliable, and secure NPM/Yarn/pnpm bridge for Composer

177287.5k25](/packages/foxy-foxy)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

134391.5k12](/packages/rector-rector-src)[toin0u/geotools

Geo-related tools PHP 7.3+ library

1.4k1.3k](/packages/toin0u-geotools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
