When reading other people's code and without detailed documentation, how to quickly see the entire code structure (class structure) becomes a real problem. today I will introduce a method for automatically generating UML diagrams.
When reading other people's code and without detailed documentation, how to quickly see the entire code structure (class structure) becomes a real problem.
Today I will introduce a method for automatically generating UML diagrams.
Suppose that I have a project folder: laruence, which has a file Root. php (in fact, no matter how many levels of directories, multiple files ).
-
- abstract class Root {
- private $instance;
- abstract public function Hi();
- }
-
- interface Intro {
- public function Say();
- }
-
- class Sub extends Root implements Intro {
- private $instance;
- public function Say() {
- echo "I am Laruence";
- }
- public function Hi() {
- echo "Hello!";
- }
- }
- ?>
First, we need to use PHP_UML (PHP_UML) to generate XMI based on the code.
The usage is relatively simple. after installing PHP_UML, run:
- phpuml laruence/ -o laruence.xmi -n laruence -f xmi --pure-object --no-deployment-view --no-component-view --no-docblock
You will get a laruence. xmi file. you can learn the specific parameters of phpuml through phpuml-help.
With xmi, how can we convert it into a UML diagram?
Visio2007 does not support importing XMI. I found another tool: Altova Umodel, which supports conversion from XMI to UML diagrams and needs to be registered, however, a 30-day license is provided (if you have a better replacement solution, please add it ).
After Umodel imports laruence. xmi, a UML diagram is generated and the following PNG is obtained:
UML diagram
Is it convenient?
In addition, PHP_UML can also generate html format, which is also good for a doc gen tool. you can also generate php files through xmi.