PHP code example of atelier / diagram

1. Go to this page and download the library: Download atelier/diagram library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

atelier / diagram example snippets


echo Diagram::fromMermaid($source)->toSvg();

use Atelier\Diagram\Diagram;

$source = <<<'MERMAID'
stateDiagram-v2
    [*] --> Draft
    Draft --> Review: submit
    Review --> [*]: approve
MERMAID;

file_put_contents('order.svg', Diagram::fromMermaid($source)->toSvg());

use Atelier\Diagram\Diagram;

$order = Diagram::state()
    ->title('Order lifecycle')
    ->initial('Draft')
    ->transition('Draft', 'Review', 'submit')
    ->transition('Review', 'Approved', 'approve')
    ->transition('Review', 'Draft', 'reject')
    ->final('Approved')
    ->build();

Diagram::of($order)->saveSvg('order.svg');

$diagram = Diagram::fromMermaid($source);   // throws on anything unsupported
$maybe   = Diagram::tryFromMermaid($source); // null instead of an exception

$diagram = Diagram::fromMermaid($source);

$diagram->toSvg();        // a string of SVG markup
$diagram->saveSvg($path); // the same, written to a file
$diagram->toMermaid();    // canonical Mermaid, back from the model
$diagram->toMarkdown();   // a fenced Mermaid block, for a README

use Atelier\Diagram\Theme\Theme;

$diagram->toSvg(Theme::dark());