Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pôle IS
Bundles Symfony 2
plantuml-bundle
Commits
e721fb6a
Commit
e721fb6a
authored
Mar 09, 2016
by
Guillaume Perréal
Browse files
Ajout des premiers décorateurs Doctrine.
parent
860eefb9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Command/EntitySchemaCommand.php
View file @
e721fb6a
...
...
@@ -8,11 +8,12 @@ namespace Irstea\PlantUmlBundle\Command;
use
Doctrine\ORM\EntityManagerInterface
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Irstea\PlantUmlBundle\Doctrine\AssociationDecorator
;
use
Irstea\PlantUmlBundle\Doctrine\EntityDecorator
;
use
Irstea\PlantUmlBundle\Model\ClassVisitor
;
use
Irstea\PlantUmlBundle\Model\Decorator\CompositeDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\FilteringDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\InheritanceDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\NullDecorator
;
use
Irstea\PlantUmlBundle\Model\Filter\Whitelist
;
use
Irstea\PlantUmlBundle\Writer\OutputWriter
;
use
Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
...
...
@@ -55,7 +56,11 @@ class EntitySchemaCommand extends ContainerAwareCommand
);
$decorator
=
new
FilteringDecorator
(
new
InheritanceDecorator
(),
new
CompositeDecorator
([
new
InheritanceDecorator
(),
new
EntityDecorator
(
$factory
),
new
AssociationDecorator
(
$factory
),
]),
new
Whitelist
(
$classes
)
);
...
...
Doctrine/AbstractDoctrineDecorator.php
0 → 100644
View file @
e721fb6a
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Doctrine
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Doctrine\ORM\Mapping\ClassMetadataFactory
;
use
Irstea\PlantUmlBundle\Model\ClassVisitorInterface
;
use
Irstea\PlantUmlBundle\Model\DecoratorInterface
;
use
Irstea\PlantUmlBundle\Model\NodeInterface
;
use
ReflectionClass
;
/**
* Description of AbstractDoctrineDecorator
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
abstract
class
AbstractDoctrineDecorator
implements
DecoratorInterface
{
/**
* @var ClassMetadataFactory
*/
protected
$metadataFactory
;
public
function
__construct
(
ClassMetadataFactory
$metadataFactory
)
{
$this
->
metadataFactory
=
$metadataFactory
;
}
public
function
decorate
(
ReflectionClass
$class
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
)
{
$className
=
$class
->
getName
();
if
(
$this
->
metadataFactory
->
hasMetadataFor
(
$className
))
{
$this
->
decorateEntity
(
$this
->
metadataFactory
->
getMetadataFor
(
$className
),
$node
,
$visitor
);
}
return
$this
;
}
abstract
protected
function
decorateEntity
(
ClassMetadata
$metadata
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
);
}
\ No newline at end of file
Doctrine/AssociationDecorator.php
0 → 100644
View file @
e721fb6a
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Doctrine
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Irstea\PlantUmlBundle\Model\Arrow\BaseArrow
;
use
Irstea\PlantUmlBundle\Model\ClassVisitorInterface
;
use
Irstea\PlantUmlBundle\Model\NodeInterface
;
use
ReflectionClass
;
/**
* Description of RelationDecorator
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
AssociationDecorator
extends
AbstractDoctrineDecorator
{
protected
function
decorateEntity
(
ClassMetadata
$metadata
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
)
{
$associations
=
$metadata
->
getAssociationMappings
();
if
(
empty
(
$associations
))
{
return
;
}
foreach
(
$associations
as
$association
)
{
$this
->
visitAssociation
(
$node
,
$visitor
,
$association
);
}
}
protected
function
visitAssociation
(
NodeInterface
$node
,
ClassVisitorInterface
$visitor
,
array
$association
)
{
if
(
!
$association
[
'isOwningSide'
])
{
return
;
}
$target
=
$visitor
->
visitClass
(
$association
[
'targetEntity'
]);
if
(
$target
===
false
)
{
return
;
}
$link
=
"-->"
;
if
(
$association
[
"isCascadeRemove"
])
{
$link
=
"o"
.
$link
;
}
$leftLabel
=
""
;
$rightLabel
=
""
;
switch
(
$association
[
"type"
])
{
case
ClassMetadata
::
ONE_TO_ONE
:
$leftLabel
=
'1'
;
$rightLabel
=
'1'
;
break
;
case
ClassMetadata
::
ONE_TO_MANY
:
$leftLabel
=
'1'
;
$rightLabel
=
'*'
;
break
;
case
ClassMetadata
::
MANY_TO_MANY
:
$leftLabel
=
'*'
;
$rightLabel
=
'*'
;
break
;
case
ClassMetadata
::
MANY_TO_ONE
:
$leftLabel
=
'*'
;
$rightLabel
=
'1'
;
break
;
}
$link
=
sprintf
(
'"%s" %s "%s"'
,
$leftLabel
,
$link
,
$rightLabel
);
$node
->
addArrow
(
new
BaseArrow
(
$node
,
$target
,
$link
,
$association
[
"fieldName"
]
.
" >"
)
);
}
}
Doctrine/EntityDecorator.php
0 → 100644
View file @
e721fb6a
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Doctrine
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Irstea\PlantUmlBundle\Model\ClassVisitorInterface
;
use
Irstea\PlantUmlBundle\Model\NodeInterface
;
/**
* Description of EntityDecorator
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
EntityDecorator
extends
AbstractDoctrineDecorator
{
protected
function
decorateEntity
(
ClassMetadata
$metadata
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
)
{
if
(
$metadata
->
isMappedSuperclass
)
{
$node
->
addStereotype
(
'mappedSuperClass'
);
}
elseif
(
$metadata
->
isEmbeddedClass
)
{
$node
->
addStereotype
(
'embedded'
);
}
else
{
$node
->
addStereotype
(
'entity'
);
}
}
}
Model/Node/BaseNode.php
View file @
e721fb6a
...
...
@@ -59,9 +59,9 @@ class BaseNode implements NodeInterface
*/
function
__construct
(
NamespaceInterface
$namespace
,
$name
,
$nodeType
,
array
$classifiers
=
[],
array
$stereotypes
=
[])
{
$this
->
namespace
=
$namespace
;
$this
->
namespace
=
$namespace
;
$pos
=
strrpos
(
$name
,
'\\'
);
$pos
=
strrpos
(
$name
,
'\\'
);
$this
->
name
=
substr
(
$name
,
$pos
+
1
);
$this
->
alias
=
str_replace
(
'\\'
,
'.'
,
$name
)
.
"_node"
;
...
...
@@ -70,6 +70,18 @@ class BaseNode implements NodeInterface
$this
->
stereotypes
=
$stereotypes
;
}
public
function
addClassifier
(
$classifier
)
{
$this
->
classifiers
[]
=
$classifier
;
return
$this
;
}
public
function
addStereotype
(
$stereotype
)
{
$this
->
stereotypes
[]
=
$stereotype
;
return
$this
;
}
public
function
outputTo
(
WriterInterface
$writer
)
{
$this
...
...
Model/NodeInterface.php
View file @
e721fb6a
...
...
@@ -21,4 +21,16 @@ interface NodeInterface extends WritableNodeInterface
* @return self
*/
public
function
addArrow
(
ArrowInterface
$arrow
);
/**
* @param string $classifier
* @return string
*/
public
function
addClassifier
(
$classifier
);
/**
* @param string $stereotype
* @return string
*/
public
function
addStereotype
(
$stereotype
);
}
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