PHPackages                             bound1ess/mermaid-php - 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. bound1ess/mermaid-php

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

bound1ess/mermaid-php
=====================

PHP adapter for the Mermaid project by @knsv (github.com/knsv/mermaid).

1.1.1(11y ago)87.4k1MITPHP

Since Dec 6Pushed 11y ago1 watchersCompare

[ Source](https://github.com/bound1ess/mermaid-php)[ Packagist](https://packagist.org/packages/bound1ess/mermaid-php)[ RSS](/packages/bound1ess-mermaid-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

MermaidPhp
==========

[](#mermaidphp)

[![Build Status](https://camo.githubusercontent.com/991859736d80de6c5922bd789a7ee1d3babf38a1ecc0445806f462af20efcf44/68747470733a2f2f7472617669732d63692e6f72672f626f756e64316573732f6d65726d6169642d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bound1ess/mermaid-php)

First, make yourself familiar with the brilliant [Mermaid project](https://github.com/knsv/mermaid).

Basically, **MermaidPhp** provides you a nice and clean interface to generate compatible with **Mermaid** code.

Now (if you want to give it a try), lets review the installation process.

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

[](#installation)

In order to install MermaidPhp, you need Composer.

Run the following command in your project root directory:

```
composer require bound1ess/mermaid-php:~1.0
```

Ok, now include `vendor/autoload.php` file in your project (if you have not done this yet) and you are all set to go!

Example of usage
----------------

[](#example-of-usage)

This PHP code:

```
use Bound1ess\MermaidPhp\Graph,
	Bound1ess\MermaidPhp\Printer,
	Bound1ess\MermaidPhp\Node,
	Bound1ess\MermaidPhp\Link;

$graph = new Graph('from left to right');

$graph->addNodes(
	$a = new Node('A', ['Hard edge']),
	$b = new Node('B', ['Round edge', Node::ROUND_EDGE]),
	$c = new Node('C', ['Decision', Node::RHOMBUS]),
	$d = new Node('D', ['Result one']),
	$e = new Node('E', ['Result two'])
);

$graph->addLinks(
	new Link($a, $b, 'Link text'),
	new Link($b, $c),
	new Link($c, $d, 'One'),
	new Link($c, $e, 'Two')
);

$code = (new Printer)->printGraph($graph);
```

Will produce something like this: [![](https://camo.githubusercontent.com/33dde7c54c5debf12cf383ce609d1ea6c1726332302c901359c454d5efd85e6f/687474703a2f2f692e696d6775722e636f6d2f684532634772732e706e67)](https://camo.githubusercontent.com/33dde7c54c5debf12cf383ce609d1ea6c1726332302c901359c454d5efd85e6f/687474703a2f2f692e696d6775722e636f6d2f684532634772732e706e67)

If you want to see this example in your browser, do the following:

- Execute `vendor/bound1ess/php-mermaid/examples/create` file, it will produce `example.html` file in your project root directory.
- Now set up a PHP development server by running this command: `php -S localhost:8000`.
- View the `example.html` file in your browser by visiting `localhost:8000/example.html`.

API
---

[](#api)

- `Bound1ess\MermaidPhp\Printer`

    - `__construct($testMode = false)`
        - `$testMode`: when set to `true`, `Printer` will produce code that is invalid, but much easier to test.
    - `printGraph(Graph $graph, $wrapInDiv = false)`
        - `$graph`: an instance of `Bound1ess\MermaidPhp\Graph` is expected.
        - `$wrapInDiv`: when set to `true`, the code produced will be wrapped in a `` element with the class `mermaid`.
        - *This method will return a string.*
- `Bound1ess\MermaidPhp\Graph`

    - `__construct($direction = null)`
        - `$direction`: if not `null`, `setDirection` method will be called.
    - `setDirection($direction)`
        - `$direction`: valid values are `Node::TOP_BOTTOM`, `Node::BOTTOM_TOP`, `Node::LEFT_RIGHT`, `Node::RIGHT_LEFT`, `from top to bottom`, `from bottom to top`, `from left to right`, `from right to left`.
        - *This method will return nothing (void).*
        - *This method can throw an instance of `Bound1ess\MermaidPhp\Exceptions\InvalidDirectionException`.*
    - `addNode(Node $node)`
        - `$node`: an instance of `Bound1ess\MermaidPhp\Node` is expected.
        - *This method will return nothing (void).*
    - `addNodes(Node $node, ...)`
    - `addLink(Link $link)`
        - `$link`: an instance of `Bound1ess\MermaidPhp\Link` is expected.
        - *This method will return nothing (void).*
    - `addLinks(Link $link, ...)`
    - `addClass(NodeClass $class)`
        - `$class`: an instance of `Bound1ess\MermaidPhp\NodeClass`.
        - *This method will return nothing (void).*
    - `addClasses`
        - `dynamic`: as many `Bound1ess\MermaidPhp\NodeClass` instances as you need.
        - *This method will return nothing (void).*
- `Bound1ess\MermaidPhp\Node`

    - `__construct($id, array $settings = null)`
        - `$id`: the node id *(should be a string)*.
        - `$settings`: if not `null`, `setText` method will be called.
    - `setText($text, $style = null)`
        - `$text`: the node text *(should be a string)*.
        - `$style`: valid values are `Node::ROUND_EDGE`, `Node::SQUARE_EDGE`, `Node::CIRCLE`, `Node::RHOMBUS`, `Node::ASYMETRIC_SHAPE`. If `null` is passed, `Node::SQUARE_EDGE`will be used.
        - *This method can throw an instance of `Bound1ess\MermaidPhp\Exceptions\InvalidStyleException`.*
        - *This method will return nothing (void).*
    - `attachClass($name)`
        - `$name`: the class name as a `string`.
        - *This method will return nothing (void).*
    - `attachClasses`
        - `dynamic`: as many `string`s as you need.
        - *This method will return nothing (void).*
- `Bound1ess\MermaidPhp\Link`

    - `__construct(Node $node, Node $anotherNode, $text = null, $isOpen = false)`
        - `$node`: an instance of `Bound1ess\MermaidPhp\Node` is expected.
        - `$anotherNode`: an instance of `Bound1ess\MermaidPhp\Node` is expected.
        - `$text`: the text on link *(should be a string or `null`)*.
        - `$isOpen`: whether the link should be open or with arrow head *(should be a boolean, the default value is `false`)*.
    - `setText($text)`
        - `$text`: the text on link *(should be a string)*.
        - *This method will return nothing (void).*
    - `isOpen($newValue = null)`
        - `$newValue`: if `null` is passed, this method will return the current value, otherwise new value will be set *(should be a boolean value)*.
        - *This method will return a boolean value or nothing (void).*
- `Bound1ess\MermaidPhp\NodeClass`

    - `__construct($name)`
        - `$name`: the class name as a `string`.
    - `add($property, $value)`
        - `$property`: the property name as a `string`.
        - `$value`: the property value as a `string`.
        - *This method will return the class instance itself.*

License information
-------------------

[](#license-information)

This project is licensed under the MIT license (*see the license file for detailed information*).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Total

4

Last Release

4041d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/270a6b451bb75c99beae25836d16453daf58531cfac6baecd8d0a72059baa44b?d=identicon)[bound1ess](/maintainers/bound1ess)

---

Top Contributors

[![bound1ess](https://avatars.githubusercontent.com/u/10074992?v=4)](https://github.com/bound1ess "bound1ess (45 commits)")

### Embed Badge

![Health badge](/badges/bound1ess-mermaid-php/health.svg)

```
[![Health](https://phpackages.com/badges/bound1ess-mermaid-php/health.svg)](https://phpackages.com/packages/bound1ess-mermaid-php)
```

###  Alternatives

[vdb/php-spider

A configurable and extensible PHP web spider

1.4k181.0k7](/packages/vdb-php-spider)[igorw/config-service-provider

A config ServiceProvider for Silex with support for php, json and yaml.

215636.5k13](/packages/igorw-config-service-provider)[emadadly/laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

120415.9k3](/packages/emadadly-laravel-uuid)[skyronic/laravel-file-generator

Laravel package to help you automate creation of files. Build your own custom generators like 'artisan make:model'.

6748.3k](/packages/skyronic-laravel-file-generator)[outl1ne/nova-media-hub

A Laravel Nova tool for managing media.

4652.0k](/packages/outl1ne-nova-media-hub)[conquer/select2

Yii2 Select2 widget

1678.0k4](/packages/conquer-select2)

PHPackages © 2026

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