dereuromark / cakephp-model-graph
A tool to generate a graph of model relationships
Installs: 8 670
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 4
Type:cakephp-plugin
Requires
- php: >=7.3
- cakephp/cakephp: ^4.2
- phpdocumentor/graphviz: ^1.0 || ^2.0
Requires (Dev)
- dereuromark/cakephp-shim: ^2.0.0
- fig-r/psr2r-sniffer: dev-master
This package is auto-updated.
Last update: 2024-12-17 22:03:14 UTC
README
This is a CakePHP plugin that will find all Tables in your CakePHP application and plugins, figure out the relationships between them, and will build a nice graph, visualizing those relationships for you.
Note: This branch is for CakePHP 4.2+. See version map for details.
Requirements
This script relies on phpDocumentor/Graphviz
package, rather than directly on the command-line dot tool.
For a graphical result instead of just text-info you will need to install the Graphviz command line tool incl. dot
.
If on Windows, make sure you set the path in Configure key GraphViz.path
:
// config/app.php 'GraphViz' => [ 'path' => 'C:\...\graphviz\bin\\', ],
Installation
You can install this plugin into your CakePHP application using composer:
composer require --dev dereuromark/cakephp-model-graph:dev-master
Note: This is not meant for production, so make sure you use the --dev
flag and install it as development-only tool.
Setup
Don't forget to load it under your bootstrap function in Application.php
:
$this->addPlugin('ModelGraph');
Usage
The simplest way to use this shell is just to run it via CakePHP console:
$ bin/cake model_graph
This should generate a graph.png image in your TMP directory. Please have a look.
If you need more control, there are two options that this shell understand from the command line: filename and format. You can use either the filename option like so:
$ bin/cake model_graph /tmp/relations.dot
It will derive the format from the extension if possible.
You can provide the format manually, as well:
$ bin/cake model_graph -f svg
No special magic is done about the filename. What You Give Is What You Get. As for the format, you can use anything that GraphViz supports and understands.
If you are still looking for more control, have a look inside the script. There are plenty of settings, options, parameters, and comments for you to make sense of it all. It might be helpful to get familiar with GraphViz Dot Language, just to feel a tiny bit more confident.
In case you rendered a dot file first, you can use the render
command to make an image out of it:
$ bin/cake model_graph render /tmp/relations.dot /tmp/relations.svg
Enjoy!