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

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

herrira/mermaid
===============

A mermaid syntax builder for PHP.

0.1.2(3y ago)113MITPHP

Since Nov 5Pushed 3y ago1 watchersCompare

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

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

Mermaid syntax generator for PHP
================================

[](#mermaid-syntax-generator-for-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/19ad08f75034297192e59a76b4a8023d46b74be3097bcac93d443188c638278e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686572726972612f6d65726d616964)](https://packagist.org/packages/herrira/mermaid)[![Test Status](https://camo.githubusercontent.com/e6ecc914576c12067dfbdb354c09527a9ecb63b63fdbeda6e2df0411e7abb081/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f72616d79686572726972612f6d65726d6169642f556e697425323074657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/e6ecc914576c12067dfbdb354c09527a9ecb63b63fdbeda6e2df0411e7abb081/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f72616d79686572726972612f6d65726d6169642f556e697425323074657374733f6c6162656c3d7465737473)

A PHP library that enables to you generate mermaid-js syntax.

### Available diagrams:

[](#available-diagrams)

- Class diagram

What's mermaid ?
----------------

[](#whats-mermaid-)

From the [docs](https://mermaid-js.github.io/mermaid/#/):

> It is a JavaScript based diagramming and charting tool that renders Markdown-inspired text definitions to create and modify diagrams dynamically.

You can also use it in [Github's markdown](https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/).

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

[](#installation)

You can install the package via composer:

```
composer require herrira/mermaid

```

Use:
----

[](#use)

```
use Herrira\Mermaid\ClassDiagram\Builder;

$builder = new Builder();
$builder->inheritance('Duck', 'Animal')
    ->inheritance('Fish', 'Animal')
    ->inheritance('Zebra', 'Animal')
    ->publicAttribute('Animal', 'age', 'int')
    ->publicAttribute('Animal', 'gender', 'String')
    ->publicMethod('Animal', 'isMammal')
    ->publicMethod('Animal', 'mate')
    ->class(function ($class) {
        $class->name('Duck')
            ->publicAttribute('beakColor', 'String')
            ->publicMethod('swim')
            ->publicMethod('quack');
    })
    ->class(function ($class) {
        $class->name('Fish')
            ->privateAttribute('sizeInFeet', 'int')
            ->privateMethod('canEat');
    })
    ->class(function ($class) {
        $class->name('Zebra')
            ->publicAttribute('is_wild', 'bool')
            ->publicMethod('run');
    });
```

Will result in:

```
classDiagram
Animal
