puml2php/puml2php

Generate php code from plantuml files.

v1.1.1 2021-11-14 07:53 UTC

This package is auto-updated.

Last update: 2024-05-14 13:07:57 UTC


README

Overview

Generate php code from plantuml files.

Installation

Via Composer

composer require --dev puml2php/puml2php

Usage

Assume you have a project with puml2php installed, and there are no files in the src directory yet.

$ ls
composer.json composer.lock sample.puml   src           vendor

$ tree src
src

0 directories, 0 files

As a sample, we will create a class diagram using PlantUML.

@startuml
package Sample\Sample2 {
    interface SampleInterface
    abstract class SampleAbstractClass implements SampleInterface
    class SampleClass

    SampleAbstractClass <|-- SampleClass
}
@enduml

Specify the PlantUML file and run puml2php. Create a directory based on the package defined in PlantUML and generate each class file.
If the namespace cannot be identified from composer.json, it will fail. Also, if the class file to be generated already exists, the process is skipped.

$ php vendor/bin/puml2php /path/to/sample.puml
Generating code from 'sample.puml'.

 - Created: src/Sample2/SampleInterface.php
 - Created: src/Sample2/SampleAbstractClass.php
 - Created: src/Sample2/SampleClass.php

Operations: 3 created, 0 skiped, 0 failed
$ tree src
src
└── Sample2
    ├── SampleAbstractClass.php
    ├── SampleClass.php
    └── SampleInterface.php

1 directory, 3 files
$ cat src/Sample2/SampleInterface.php
<?php
declare(strict_types=1);

namespace Sample\Sample2;

/**
 * Class SampleInterface
 * @package Sample\Sample2
 */
interface SampleInterface
{
}
$ cat src/Sample2/SampleAbstractClass.php
<?php
declare(strict_types=1);

namespace Sample\Sample2;

/**
 * Class SampleAbstractClass
 * @package Sample\Sample2
 */
abstract class SampleAbstractClass implements SampleInterface
{
}
$ cat src/Sample2/SampleClass.php
<?php
declare(strict_types=1);

namespace Sample\Sample2;

/**
 * Class SampleClass
 * @package Sample\Sample2
 */
class SampleClass extends SampleAbstractClass
{
}

License

The MIT License (MIT). Please see LICENSE for more information.