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
72c714b0
Commit
72c714b0
authored
Mar 09, 2016
by
Guillaume Perréal
Browse files
Ajout d'un système de filtrage des classes à afficher.
parent
b8bcadb6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Command/EntitySchemaCommand.php
View file @
72c714b0
...
...
@@ -8,6 +8,7 @@ namespace Irstea\PlantUmlBundle\Command;
use
Doctrine\ORM\EntityManagerInterface
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Irstea\PlantUmlBundle\Model\Filter\Whitelist
;
use
Irstea\PlantUmlBundle\Model\Namespace_
;
use
Irstea\PlantUmlBundle\Model\Orm\EntityVisitor
;
use
Irstea\PlantUmlBundle\Writer\OutputWriter
;
...
...
@@ -46,11 +47,13 @@ class EntitySchemaCommand extends ContainerAwareCommand
$allMetadata
=
$factory
->
getAllMetadata
();
$classes
=
array_map
(
function
(
ClassMetadata
$metadata
)
{
return
$metadata
->
getName
();
},
$allMetadata
);
$visitor
=
new
EntityVisitor
(
$allMetadata
);
foreach
(
$allMetadata
as
$metadata
)
{
/* @var $metadata ClassMetadata */
$visitor
->
visitClass
(
$metadata
->
getName
());
}
array_walk
(
$classes
,
[
$visitor
,
'visitClass'
]);
$writer
=
new
OutputWriter
(
$output
);
$writer
->
write
(
"@startuml
\n
"
);
...
...
Model/ClassFilterInterface.php
0 → 100644
View file @
72c714b0
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Model
;
/**
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
interface
ClassFilterInterface
{
/**
* @param type $className
* @return bool
*/
public
function
accept
(
$className
);
}
Model/ClassVisitor.php
View file @
72c714b0
...
...
@@ -28,9 +28,25 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
*/
protected
$rootNamespace
;
public
function
__construct
()
/**
* @var ClassFilterInterface
*/
protected
$filter
;
public
function
__construct
(
ClassFilterInterface
$filter
=
null
)
{
$this
->
rootNamespace
=
new
RootNamespace
();
$this
->
filter
=
$filter
?:
Filter\AcceptAllFilter
::
instance
();
}
/**
* @param \Irstea\PlantUmlBundle\Model\ClassFilterInterface $filter
* @return self
*/
public
function
setClassFilter
(
ClassFilterInterface
$filter
)
{
$this
->
filter
=
$filter
;
return
$this
;
}
public
function
visitClass
(
$className
)
...
...
@@ -39,6 +55,9 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
if
(
isset
(
$this
->
nodes
[
$className
]))
{
return
$this
->
nodes
[
$className
];
}
if
(
!
$this
->
filter
->
accept
(
$className
))
{
return
$this
->
nodes
[
$className
]
=
false
;
}
return
$this
->
doVisitClass
(
$className
);
}
...
...
@@ -104,7 +123,9 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
{
foreach
(
$classNames
as
$className
)
{
$target
=
$this
->
visitClass
(
$className
);
$namespace
->
addArrow
(
new
$relationClass
(
$source
,
$target
));
if
(
$target
)
{
$namespace
->
addArrow
(
new
$relationClass
(
$source
,
$target
));
}
}
}
...
...
Model/Filter/AcceptAllFilter.php
0 → 100644
View file @
72c714b0
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Model\Filter
;
use
Irstea\PlantUmlBundle\Model\ClassFilterInterface
;
/**
* Description of AcceptAllFilter
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
AcceptAllFilter
implements
ClassFilterInterface
{
public
function
accept
(
$className
)
{
return
true
;
}
/**
* @var self
*/
static
private
$instance
;
/**
* @return self
*/
static
public
function
instance
()
{
if
(
!
static
::
$instance
)
{
static
::
$instance
=
new
static
();
}
return
static
::
$instance
;
}
}
Model/Filter/Whitelist.php
0 → 100644
View file @
72c714b0
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace
Irstea\PlantUmlBundle\Model\Filter
;
use
Irstea\PlantUmlBundle\Model\ClassFilterInterface
;
/**
* Description of Whiltelist
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
Whitelist
implements
ClassFilterInterface
{
/**
* @var string[]
*/
private
$accepted
;
public
function
__construct
(
array
$classNames
)
{
$this
->
accepted
=
array_fill_keys
(
$classNames
,
true
);
}
public
function
accept
(
$className
)
{
return
isset
(
$this
->
accepted
[
$className
]);
}
}
Model/Orm/EntityVisitor.php
View file @
72c714b0
...
...
@@ -23,9 +23,9 @@ class EntityVisitor extends ClassVisitor
*/
protected
$metadata
=
[];
public
function
__construct
(
array
$metadata
)
public
function
__construct
(
array
$metadata
,
\
Irstea\PlantUmlBundle\Model\ClassFilterInterface
$filter
=
null
)
{
parent
::
__construct
();
parent
::
__construct
(
$filter
);
foreach
(
$metadata
as
$md
)
{
/* @var $md ClassMetadata */
...
...
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