bastien-wink / php-class-diagram
A CLI tool that parses the PHP source directory and outputs PlantUML scripts.
dev-main
2022-11-24 13:48 UTC
Requires
- php: >=7.4
- nikic/php-parser: ^4.13
- symfony/finder: ^5.3|^6.0
Requires (Dev)
- clue/phar-composer: ^1.2
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-03-24 18:49:00 UTC
README
A CLI tool that parses the PHP source directory and outputs PlantUML class diagram scripts.
Forked from https://packagist.org/packages/smeghead/php-class-diagram
Features
- Generating class diagrams from source code helps improve continuous design.
- Generates expressive class diagrams with an emphasis on namespaces and relationships.
- A simple CLI tool that is easy to handle.
- It is also possible to output a package relationship diagram that visualizes the dependency on the external namespace.
php-class-diagram class diagram
php-class-diagram package related diagram
Install
From DockerHub
You can use docker image includes php-class-diagram and plantuml, from below URL.
From Composer
$ mkdir sample
$ cd sample
$ composer init
$ composer require --dev smeghead/php-class-diagram
you can execute ./vendor/bin/php-class-diagram
.
for instance, try to display help message.
$ vendor/bin/php-class-diagram --help usage: php-class-diagram [OPTIONS] <target php source directory> A CLI tool that parses the PHP source directory and outputs PlantUML class diagram scripts. OPTIONS -h, --help show this help page. --class-diagram output class diagram script. (default) --package-diagram output package diagram script. --jig-diagram output class diagram and package diagram script. --enable-class-properties describe properties in class diagram. (default) --disable-class-properties not describe properties in class diagram. --enable-class-methods describe methods in class diagram. (default) --disable-class-methods not describe methods in class diagram. --php5 parse php source file as php5. --php7 parse php source file as php7. --php8 parse php source file as php8. (not suppoted)
How to execute
When three php source files that TYPE commented exist in test/fixtures/no-namespace
,
- php source files.
└─test
└─fixtures
└─no-namespace
└─product
Product.php
Name.php
Price.php
- Product.php
<?php class Product { /** @var Name product name. */ private $name; /** @var Price price of product. */ private $price; }
- Name.php
<?php class Name { /** @var string name. */ private $name; }
- Price.php
<?php class Price { /** @var int price. */ private int $price; }
To execute php-class-diagram
will print PlantUML script.
$ vendor/bin/php-class-diagram test/fixtures/no-namespace @startuml class-diagram package product as product <<Rectangle>> { class product.Price { -price : int } class product.Name { -name : string } class product.Product { -name : Name -price : Price +method1(param1) } } product.Product ..> product.Name product.Product ..> product.Price @enduml
Use PlnatUML to convert the PlantUML script to an image.
Development
Open shell
docker-compose build docker-compose run --rm php_cli bash
install dependencies
composer install
execute tests
composer test