4
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
* This software consists of voluntary contributions made by many individuals
17
* and is licensed under the MIT license. For more information, see
18
* <http://www.doctrine-project.org>.
21
namespace Doctrine\DBAL\Schema\Visitor;
23
use Doctrine\DBAL\Platforms\AbstractPlatform,
24
Doctrine\DBAL\Schema\Table,
25
Doctrine\DBAL\Schema\Schema,
26
Doctrine\DBAL\Schema\Column,
27
Doctrine\DBAL\Schema\ForeignKeyConstraint,
28
Doctrine\DBAL\Schema\Constraint,
29
Doctrine\DBAL\Schema\Sequence,
30
Doctrine\DBAL\Schema\Index;
32
class Graphviz implements \Doctrine\DBAL\Schema\Visitor\Visitor
36
public function acceptColumn(Table $table, Column $column)
41
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
43
$this->output .= $this->createNodeRelation(
44
$fkConstraint->getLocalTableName() . ":col" . current($fkConstraint->getLocalColumns()).":se",
45
$fkConstraint->getForeignTableName() . ":col" . current($fkConstraint->getForeignColumns()).":se",
49
'arrowhead' => 'normal',
54
public function acceptIndex(Table $table, Index $index)
59
public function acceptSchema(Schema $schema)
61
$this->output = 'digraph "' . sha1( mt_rand() ) . '" {' . "\n";
62
$this->output .= 'splines = true;' . "\n";
63
$this->output .= 'overlap = false;' . "\n";
64
$this->output .= 'outputorder=edgesfirst;'."\n";
65
$this->output .= 'mindist = 0.6;' . "\n";
66
$this->output .= 'sep = .2;' . "\n";
69
public function acceptSequence(Sequence $sequence)
74
public function acceptTable(Table $table)
76
$this->output .= $this->createNode(
79
'label' => $this->createTableLabel( $table ),
80
'shape' => 'plaintext',
85
private function createTableLabel( Table $table )
88
$label = '<<TABLE CELLSPACING="0" BORDER="1" ALIGN="LEFT">';
91
$label .= '<TR><TD BORDER="1" COLSPAN="3" ALIGN="CENTER" BGCOLOR="#fcaf3e"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12">' . $table->getName() . '</FONT></TD></TR>';
93
// The attributes block
94
foreach( $table->getColumns() as $column ) {
95
$columnLabel = $column->getName();
98
$label .= '<TD BORDER="0" ALIGN="LEFT" BGCOLOR="#eeeeec">';
99
$label .= '<FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12">' . $columnLabel . '</FONT>';
100
$label .= '</TD><TD BORDER="0" ALIGN="LEFT" BGCOLOR="#eeeeec"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">' . strtolower($column->getType()) . '</FONT></TD>';
101
$label .= '<TD BORDER="0" ALIGN="RIGHT" BGCOLOR="#eeeeec" PORT="col'.$column->getName().'">';
102
if ($table->hasPrimaryKey() && in_array($column->getName(), $table->getPrimaryKey()->getColumns())) {
103
$label .= "\xe2\x9c\xb7";
105
$label .= '</TD></TR>';
109
$label .= '</TABLE>>';
114
private function createNode( $name, $options )
116
$node = $name . " [";
117
foreach( $options as $key => $value )
119
$node .= $key . '=' . $value . ' ';
125
private function createNodeRelation( $node1, $node2, $options )
127
$relation = $node1 . ' -> ' . $node2 . ' [';
128
foreach( $options as $key => $value )
130
$relation .= $key . '=' . $value . ' ';
137
* Write dot language output to a file. This should usually be a *.dot file.
139
* You have to convert the output into a viewable format. For example use "neato" on linux systems
142
* neato -Tpng -o er.png er.dot
144
* @param string $filename
147
public function write($filename)
149
file_put_contents($filename, $this->output . "}");