Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
dea25f97
Commit
dea25f97
authored
Apr 07, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-107'
parents
cf31d762
580c37c9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
0 deletions
+156
-0
Graphviz.php
lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php
+156
-0
No files found.
lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php
0 → 100644
View file @
dea25f97
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Schema\Visitor
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
,
Doctrine\DBAL\Schema\Table
,
Doctrine\DBAL\Schema\Schema
,
Doctrine\DBAL\Schema\Column
,
Doctrine\DBAL\Schema\ForeignKeyConstraint
,
Doctrine\DBAL\Schema\Constraint
,
Doctrine\DBAL\Schema\Sequence
,
Doctrine\DBAL\Schema\Index
;
class
Graphviz
implements
\Doctrine\DBAL\Schema\Visitor\Visitor
{
private
$output
=
''
;
public
function
acceptColumn
(
Table
$table
,
Column
$column
)
{
}
public
function
acceptForeignKey
(
Table
$localTable
,
ForeignKeyConstraint
$fkConstraint
)
{
$this
->
output
.=
$this
->
createNodeRelation
(
$fkConstraint
->
getLocalTableName
(),
$fkConstraint
->
getForeignTableName
(),
array
(
'dir'
=>
'back'
,
'arrowtail'
=>
'dot'
,
'arrowhead'
=>
'normal'
,
)
);
}
public
function
acceptIndex
(
Table
$table
,
Index
$index
)
{
}
public
function
acceptSchema
(
Schema
$schema
)
{
$this
->
output
=
'digraph "'
.
sha1
(
mt_rand
()
)
.
'" {'
.
"
\n
"
;
$this
->
output
.=
'splines = true;'
.
"
\n
"
;
$this
->
output
.=
'overlap = false;'
.
"
\n
"
;
$this
->
output
.=
'mindist = 0.6;'
.
"
\n
"
;
$this
->
output
.=
'sep = .2;'
.
"
\n
"
;
}
public
function
acceptSequence
(
Sequence
$sequence
)
{
}
public
function
acceptTable
(
Table
$table
)
{
$name
=
$table
->
getName
();
$columns
=
array
();
foreach
(
$table
->
getColumns
()
AS
$column
)
{
$name
=
$column
->
getName
();
if
(
in_array
(
$name
,
$table
->
getPrimaryKey
()
->
getColumns
()))
{
$name
=
$name
.
"
\xe2\x9c\xb6
"
;
}
$columns
[]
=
$name
;
}
$this
->
output
.=
$this
->
createNode
(
$table
->
getName
(),
array
(
'label'
=>
$this
->
createTableLabel
(
$name
,
$columns
),
'shape'
=>
'plaintext'
,
)
);
}
private
function
createTableLabel
(
$name
,
$columns
)
{
// Start the table
$label
=
'<<TABLE CELLSPACING="0" BORDER="0" ALIGN="LEFT">'
;
// The title
$label
.=
'<TR><TD BORDER="1" ALIGN="CENTER" BGCOLOR="#fcaf3e"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="12">'
.
$name
.
'</FONT></TD></TR>'
;
// The attributes block
$label
.=
'<TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#eeeeec">'
;
if
(
count
(
$columns
)
===
0
)
{
$label
.=
' '
;
}
foreach
(
$columns
as
$attribute
)
{
$label
.=
'<FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">'
.
$attribute
.
'</FONT><BR ALIGN="LEFT"/>'
;
}
$label
.=
'</TD></TR>'
;
// End the table
$label
.=
'</TABLE>>'
;
return
$label
;
}
private
function
createNode
(
$name
,
$options
)
{
$node
=
$name
.
" ["
;
foreach
(
$options
as
$key
=>
$value
)
{
$node
.=
$key
.
'='
.
$value
.
' '
;
}
$node
.=
"]
\n
"
;
return
$node
;
}
private
function
createNodeRelation
(
$node1
,
$node2
,
$options
)
{
$relation
=
$node1
.
' -> '
.
$node2
.
' ['
;
foreach
(
$options
as
$key
=>
$value
)
{
$relation
.=
$key
.
'='
.
$value
.
' '
;
}
$relation
.=
"]
\n
"
;
return
$relation
;
}
/**
* Write dot language output to a file. This should usually be a *.dot file.
*
* You have to convert the output into a viewable format. For example use "neato" on linux systems
* and execute:
*
* neato -Tpng -o er.png er.dot
*
* @param string $filename
* @return void
*/
public
function
write
(
$filename
)
{
file_put_contents
(
$filename
,
$this
->
output
.
"}"
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment