Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
plantuml-bundle
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Pôle IS
Bundles Symfony 2
plantuml-bundle
Commits
23467d72
Commit
23467d72
authored
May 13, 2016
by
Guillaume Perréal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
N'affiche plus les asoociations et champs hérités de Doctrine.
parent
136fe0ff
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
39 deletions
+111
-39
Doctrine/AbstractDoctrineDecorator.php
Doctrine/AbstractDoctrineDecorator.php
+15
-7
Doctrine/AssociationDecorator.php
Doctrine/AssociationDecorator.php
+10
-10
Doctrine/EntityDecorator.php
Doctrine/EntityDecorator.php
+13
-8
Doctrine/FieldDecorator.php
Doctrine/FieldDecorator.php
+19
-14
Model/Decorator/InheritableItemDecoratorTrait.php
Model/Decorator/InheritableItemDecoratorTrait.php
+54
-0
No files found.
Doctrine/AbstractDoctrineDecorator.php
View file @
23467d72
...
...
@@ -33,14 +33,22 @@ abstract class AbstractDoctrineDecorator implements DecoratorInterface
$this
->
metadataFactory
=
$manager
->
getMetadataFactory
();
}
public
function
decorate
(
ReflectionClass
$class
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
)
/**
* @param callable $callback
* @param ReflectionClass $class
* @return mixed
*/
protected
function
withMetadata
(
$callback
,
ReflectionClass
$class
=
null
)
{
if
(
!
$class
)
{
return
null
;
}
$className
=
$class
->
getName
();
if
(
$this
->
metadataFactory
->
hasMetadataFor
(
$className
))
{
$this
->
decorateEntity
(
$this
->
metadataFactory
->
getMetadataFor
(
$className
),
$node
,
$visitor
)
;
if
(
!
$this
->
metadataFactory
->
hasMetadataFor
(
$className
))
{
return
null
;
}
return
$this
;
return
$callback
(
$this
->
metadataFactory
->
getMetadataFor
(
$className
));
}
abstract
protected
function
decorateEntity
(
ClassMetadata
$metadata
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
);
}
\ No newline at end of file
}
Doctrine/AssociationDecorator.php
View file @
23467d72
...
...
@@ -22,19 +22,19 @@ use ReflectionClass;
*/
class
AssociationDecorator
extends
AbstractDoctrineDecorator
{
protected
function
decorateEntity
(
ClassMetadata
$metadata
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
)
use
\
Irstea\PlantUmlBundle\Model\Decorator\InheritableItemDecoratorTrait
;
protected
function
extractItems
(
ReflectionClass
$class
)
{
$associations
=
$metadata
->
getAssociationMappings
();
if
(
empty
(
$associations
))
{
return
;
}
foreach
(
$associations
as
$association
)
{
$this
->
visitAssociation
(
$node
,
$visitor
,
$association
);
}
return
$this
->
withMetadata
(
function
(
$metadata
)
{
return
$metadata
->
getAssociationMappings
();
},
$class
);
}
protected
function
visitAssociation
(
NodeInterface
$node
,
ClassVisitorInterface
$visitor
,
array
$association
)
protected
function
decorateItem
(
ReflectionClass
$class
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
,
$association
)
{
if
(
!
$association
[
'isOwningSide'
])
{
return
;
...
...
Doctrine/EntityDecorator.php
View file @
23467d72
...
...
@@ -19,14 +19,19 @@ use Irstea\PlantUmlBundle\Model\NodeInterface;
*/
class
EntityDecorator
extends
AbstractDoctrineDecorator
{
p
rotected
function
decorateEntity
(
ClassMetadata
$metadata
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
)
p
ublic
function
decorate
(
\
ReflectionClass
$class
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
)
{
if
(
$metadata
->
isMappedSuperclass
)
{
$node
->
addStereotype
(
'mappedSuperClass'
);
}
elseif
(
$metadata
->
isEmbeddedClass
)
{
$node
->
addStereotype
(
'embedded'
);
}
else
{
$node
->
addStereotype
(
'entity'
);
}
$this
->
withMetadata
(
function
(
$metadata
)
use
(
$node
)
{
if
(
$metadata
->
isMappedSuperclass
)
{
$node
->
addStereotype
(
'mappedSuperClass'
);
}
elseif
(
$metadata
->
isEmbeddedClass
)
{
$node
->
addStereotype
(
'embedded'
);
}
else
{
$node
->
addStereotype
(
'entity'
);
}
},
$class
);
}
}
Doctrine/FieldDecorator.php
View file @
23467d72
...
...
@@ -11,6 +11,7 @@ namespace Irstea\PlantUmlBundle\Doctrine;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Irstea\PlantUmlBundle\Model\ClassVisitorInterface
;
use
Irstea\PlantUmlBundle\Model\NodeInterface
;
use
ReflectionClass
;
/**
* Description of RelationDecorator
...
...
@@ -19,28 +20,32 @@ use Irstea\PlantUmlBundle\Model\NodeInterface;
*/
class
FieldDecorator
extends
AbstractDoctrineDecorator
{
protected
function
decorateEntity
(
ClassMetadata
$metadata
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
)
{
if
(
empty
(
$metadata
->
fieldMappings
))
{
return
;
}
use
\
Irstea\PlantUmlBundle\Model\Decorator\InheritableItemDecoratorTrait
;
foreach
(
$metadata
->
fieldMappings
as
$field
)
{
$this
->
visitField
(
$node
,
$visitor
,
$field
,
$metadata
->
isIdentifier
(
$field
[
'fieldName'
]));
}
protected
function
extractItems
(
ReflectionClass
$class
)
{
return
$this
->
withMetadata
(
function
(
$metadata
)
{
return
$metadata
->
fieldMappings
;
},
$class
);
}
protected
function
visitField
(
NodeInterface
$node
,
ClassVisitorInterface
$visitor
,
array
$field
,
$isIdentifier
)
protected
function
decorateItem
(
ReflectionClass
$class
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
,
$field
)
{
if
(
isset
(
$field
[
'inherited'
])
||
isset
(
$field
[
'declared'
]))
{
return
;
}
$isIdentifier
=
$this
->
withMetadata
(
function
(
$metadata
)
use
(
$field
)
{
return
$metadata
->
isIdentifier
(
$field
[
'fieldName'
]);
},
$class
);
$node
->
addAttribute
(
new
Field
(
$field
[
'fieldName'
],
$field
[
'type'
],
$field
[
'unique'
],
$field
[
'nullable'
],
$isIdentifier
$field
[
'nullable'
]
));
}
}
Model/Decorator/InheritableItemDecoratorTrait.php
0 → 100644
View file @
23467d72
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Model\Decorator
;
use
Irstea\PlantUmlBundle\Model\ClassVisitorInterface
;
use
Irstea\PlantUmlBundle\Model\NodeInterface
;
use
ReflectionClass
;
/**
* Décorateur abstrait pour les éléments d'une classe qui peuvent être hérités d'une classe base.
*
* Ce décorateur s'assure de n'afficher que les éléments propres à la classe.
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
trait
InheritableItemDecoratorTrait
{
/**
*
* @param \ReflectionClass $class
* @param NodeInterface $node
* @param ClassVisitorInterface $visitor
* @return self
*/
public
function
decorate
(
ReflectionClass
$class
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
)
{
$items
=
$this
->
extractItems
(
$class
);
if
(
empty
(
$items
))
{
return
;
}
$parent
=
$class
->
getParentClass
();
if
(
$parent
)
{
$parentItems
=
$this
->
extractItems
(
$parent
);
if
(
!
empty
(
$parentItems
))
{
$items
=
array_diff_key
(
$items
,
$parentItems
);
}
}
foreach
(
$items
as
$item
)
{
$this
->
decorateItem
(
$class
,
$node
,
$visitor
,
$item
);
}
}
abstract
protected
function
extractItems
(
ReflectionClass
$class
);
abstract
protected
function
decorateItem
(
ReflectionClass
$class
,
NodeInterface
$node
,
ClassVisitorInterface
$visitor
,
$item
);
}
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