PHPackages                             blackprint/engine - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. blackprint/engine

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

blackprint/engine
=================

PHP Engine for Blackprint

0.9.0(2y ago)24MITPHPPHP ^8.1

Since Nov 16Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/Blackprint/engine-php)[ Packagist](https://packagist.org/packages/blackprint/engine)[ GitHub Sponsors](https://github.com/stefansarya)[ RSS](/packages/blackprint-engine/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (10)Dependencies (1)Versions (11)Used By (0)

[![Blackprint](https://user-images.githubusercontent.com/11073373/141421213-5decd773-a870-4324-8324-e175e83b0f55.png)](#)

Blackprint Engine for PHP
=========================

[](#blackprint-engine-for-php)

Run exported Blackprint on PHP environment.

 [![](https://camo.githubusercontent.com/1a2e0606685ce00663bf829868f794fd3fc9c86f8d80cae324734129e0723a58/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d627269676874677265656e2e737667)](https://github.com/Blackprint/Blackprint/blob/master/LICENSE)

Documentation
-------------

[](#documentation)

> Warning: This project haven't reach it stable version (semantic versioning at v1.0.0)
> But please try to use it and help improve this project

This engine is designed to be similar with `engine-js`, some API and property will be similar.

**Minimum PHP version `>= 8.1`**

---

### Defining Blackprint Node and Interface

[](#defining-blackprint-node-and-interface)

Because PHP does support class-based programming and to make the node import more effective and easier, this engine will only support Node/Interface that declared with classes.

But before that, we need to create a folder to store our Node/Interface logic. For the example `/BPNode`.

#### Registering Namespace folder

[](#registering-namespace-folder)

```
require_once('../vendor/autoload.php');

// This can be called on different PHP libraries
\Blackprint\registerNamespace(__DIR__.'/BPNode');

// When registering with Namespace, the default root namespace is always "BPNode"
// Please name your nodes namespace along with your library name to avoid conflict with other library
```

#### Define Node and Interface

[](#define-node-and-interface)

After the namespace folder `./BPNode` has been registered, you can now create a folder with your library name. For the example: `./BPNode/Example`.

```
// file: ./BPNode/Example/Hello.php
namespace \BPNode\Example;

// The class name must match with the file name
// This will be registered as Node definition
class Hello extends \Blackprint\Node {
    // Please remember to capitalize the port name
    // Set the output port structure for your node (Optional)
    static $output = [
        'Changed'=> Types::Trigger,
        // Callable: $this->output['Changed']()

        'Output'=> Types::Number,
        // $this->output['Value'] = 246
    ];

    // Set the input port structure for your node (Optional)
    static $input = [
        'Multiply'=> Types::Number,
        // $val = $this->output['Value']
    ]

    function __construct($instance){
        // Call the parent constructor first, passing the $instance (Blackprint\Engine)
        parent::__construct($instance);

        // Set the Interface, let it empty if you want
        // to use default empty interface "setInterface()"
        $iface = $this->setInterface('BPIC/Example/Hello');
        $iface->title = "Hello"; // Set the title for debugging
    }
}
```

Let's also define our custom interface, this is optional and needed only if you want to provide access for other developer. Just like an API (Application Programming Interface).

```
// same file: ./BPNode/Example/Hello.php
namespace \BPNode\Example;

// Your Interface namespace must use "BPIC" as the prefix
\Blackprint\registerInterface('BPIC/Example/Hello', HelloIFace::class);
class HelloIFace extends \Blackprint\Interfaces {
    function __construct($node){
        // Call the parent constructor first, passing the $node (Blackprint\Node)
        parent::__construct($node);
        // $this->node => Blackprint\Node

        // Define IFace's data (optional if you want to export/import data from JSON)
        // Because getter/setter feature only available on class, we will create from `class MyData`
        $this->data = new MyData($this);
        // $this->data->value === 123 (if the default value is not replaced when importing JSON)
    }

    function recalculate(){
        // Get value from input port
        $multiplyBy = $this->node->input['Multiply'];

        // Assign new value to output port
        $this->node->output['Output'] = $this->data->value * $multiplyBy;
    }
}

// Getter and setter should be changed with basic property accessor
class MyData {
    // Constructor promotion, $iface as private MyData property
    function __construct(private $iface){}

    // Draft: please design it like below after
    // this PR was merged to PHP https://github.com/php/php-src/pull/6873
    private $_value = 123;
    public $value {
        get { return $this->_value };
        set {
            $this->_value = $value;
            $this->iface->recalculate(); // Call recalculate() on HelloIFace
        };
    };

    // Current polyfill for property accessor (https://github.com/php/php-src/pull/6873)
    private $data = ["value"=> 123];
    function __get($key) {
        return $this->data[$key];
    }

    function __set($key, $val) {
        $this->data[$key] = &$val;

        if($key === 'value')
            $this->iface->recalculate($val); // Call recalculate() on HelloIFace
    }
}
```

Creating new Engine instance
----------------------------

[](#creating-new-engine-instance)

```
// Create Blackprint Engine instance
$instance = new Blackprint\Engine();

// You can import nodes with JSON
// if the nodes haven't been registered, this will throw an error
$instance->importJSON(`{...}`);

// You can also create the node dynamically
$iface = $instance->createNode('Example/Hello', /* [..options..] */);

// ----

// Change the default data 'value' property
$iface->data->value = 123;

// Assign the 'Multiply' input port = 2
$iface->node->input['Multiply'] = 2;

// Get the value from 'Output' output port
echo $iface->node->output['Output']; // 246
```

---

### Example

[](#example)

[![wKKLQb1Y0D](https://user-images.githubusercontent.com/11073373/194293978-329fd7df-5f13-4243-9005-bf13c4a4734f.jpg)](https://user-images.githubusercontent.com/11073373/194293978-329fd7df-5f13-4243-9005-bf13c4a4734f.jpg)

This repository provide an example with the JSON too, and you can try it with PHP CLI:

```
# Change your working directory into empty folder first
$ git clone --depth 1 https://github.com/Blackprint/engine-php .
$ composer install
$ php ./example/init.php
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance46

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~64 days

Recently: every ~29 days

Total

10

Last Release

1056d ago

### Community

Maintainers

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

---

Top Contributors

[![StefansArya](https://avatars.githubusercontent.com/u/11073373?v=4)](https://github.com/StefansArya "StefansArya (150 commits)")

---

Tags

engineblackprint

### Embed Badge

![Health badge](/badges/blackprint-engine/health.svg)

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

###  Alternatives

[uuf6429/rune

PHP Rule Engine.

7011.8k](/packages/uuf6429-rune)[malios/php-to-ascii-table

A PHP library to generate plain text tables.

30118.8k1](/packages/malios-php-to-ascii-table)[subzeta/ruling

An stateless rule engine

2011.9k](/packages/subzeta-ruling)[samsara/fermat

A library providing math and statistics operations for numbers of arbitrary size.

653.1k3](/packages/samsara-fermat)

PHPackages © 2026

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