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
1d5a1de6
Commit
1d5a1de6
authored
Mar 09, 2016
by
Guillaume Perréal
Browse files
Ajout de nouveaux filtres.
Et expérimentations.
parent
5e787728
Changes
3
Hide whitespace changes
Inline
Side-by-side
Command/EntitySchemaCommand.php
View file @
1d5a1de6
...
@@ -15,9 +15,12 @@ use Irstea\PlantUmlBundle\Model\ClassVisitor;
...
@@ -15,9 +15,12 @@ use Irstea\PlantUmlBundle\Model\ClassVisitor;
use
Irstea\PlantUmlBundle\Model\Decorator\CompositeDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\CompositeDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\FilteringDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\FilteringDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\InheritanceDecorator
;
use
Irstea\PlantUmlBundle\Model\Decorator\InheritanceDecorator
;
use
Irstea\PlantUmlBundle\Model\Filter\DirectoryFilter
;
use
Irstea\PlantUmlBundle\Model\Filter\NamespaceFilter
;
use
Irstea\PlantUmlBundle\Model\Filter\Whitelist
;
use
Irstea\PlantUmlBundle\Model\Filter\Whitelist
;
use
Irstea\PlantUmlBundle\Model\Namespace_\BundleNamespace
;
use
Irstea\PlantUmlBundle\Model\Namespace_\BundleNamespace
;
use
Irstea\PlantUmlBundle\Model\Namespace_\FlatNamespace
;
use
Irstea\PlantUmlBundle\Model\Namespace_\FlatNamespace
;
use
Irstea\PlantUmlBundle\Model\Namespace_\MappedNamespace
;
use
Irstea\PlantUmlBundle\Writer\OutputWriter
;
use
Irstea\PlantUmlBundle\Writer\OutputWriter
;
use
Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
use
Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
use
Symfony\Component\Console\Input\InputInterface
;
use
Symfony\Component\Console\Input\InputInterface
;
...
@@ -49,16 +52,22 @@ class EntitySchemaCommand extends ContainerAwareCommand
...
@@ -49,16 +52,22 @@ class EntitySchemaCommand extends ContainerAwareCommand
{
{
/* @var $manager EntityManagerInterface */
/* @var $manager EntityManagerInterface */
$manager
=
$this
->
getContainer
()
->
get
(
'doctrine.orm.entity_manager'
);
$manager
=
$this
->
getContainer
()
->
get
(
'doctrine.orm.entity_manager'
);
$factory
=
$manager
->
getMetadataFactory
();
$factory
=
$manager
->
getMetadataFactory
();
$allMetadata
=
$factory
->
getAllMetadata
();
$allMetadata
=
$factory
->
getAllMetadata
();
$classes
=
array_map
(
$decorationFilter
=
new
DirectoryFilter
(
function
(
ClassMetadata
$metadata
)
{
return
$metadata
->
getName
();
},
[
$allMetadata
realpath
(
$this
->
getContainer
()
->
getParameter
(
'kernel.root_dir'
)
.
'/../src'
)
]
);
);
$namespace
=
new
BundleNamespace
(
$this
->
getContainer
()
->
getParameter
(
'kernel.bundles'
));
$bundleNamespace
=
'Irstea\\SygadeBundle\\Entity\\'
;
$entityFilter
=
new
NamespaceFilter
([
$bundleNamespace
]);
//$namespace = new BundleNamespace($this->getContainer()->getParameter('kernel.bundles'));
$namespace
=
new
MappedNamespace
([
$bundleNamespace
=>
''
]);
$decorator
=
new
FilteringDecorator
(
$decorator
=
new
FilteringDecorator
(
new
CompositeDecorator
([
new
CompositeDecorator
([
...
@@ -66,12 +75,17 @@ class EntitySchemaCommand extends ContainerAwareCommand
...
@@ -66,12 +75,17 @@ class EntitySchemaCommand extends ContainerAwareCommand
new
EntityDecorator
(
$factory
),
new
EntityDecorator
(
$factory
),
new
AssociationDecorator
(
$factory
),
new
AssociationDecorator
(
$factory
),
]),
]),
new
Whitelist
(
$classes
)
$decorationFilter
);
);
$visitor
=
new
ClassVisitor
(
$decorator
,
null
,
$namespace
);
$visitor
=
new
ClassVisitor
(
$decorator
,
null
,
$namespace
);
array_walk
(
$classes
,
[
$visitor
,
'visitClass'
]);
foreach
(
$allMetadata
as
$metadata
)
{
/* @var $metadata ClassMetadata */
if
(
$entityFilter
->
accept
(
$metadata
->
getReflectionClass
()))
{
$visitor
->
visitClass
(
$metadata
->
getName
());
}
}
$writer
=
new
OutputWriter
(
$output
);
$writer
=
new
OutputWriter
(
$output
);
$writer
->
write
(
"@startuml
\n
"
);
$writer
->
write
(
"@startuml
\n
"
);
...
...
Model/Filter/DirectoryFilter.php
0 → 100644
View file @
1d5a1de6
<?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
;
use
ReflectionClass
;
/**
* Description of DirectoryFilter
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
DirectoryFilter
implements
ClassFilterInterface
{
/**
* @var string[]
*/
private
$accepted
=
[];
public
function
__construct
(
array
$accepted
)
{
$this
->
accepted
=
$accepted
;
}
public
function
accept
(
ReflectionClass
$class
)
{
foreach
(
$this
->
accepted
as
$path
)
{
if
(
strpos
(
$class
->
getFileName
(),
$path
)
===
0
)
{
return
true
;
}
}
return
false
;
}
}
Model/Filter/NamespaceFilter.php
0 → 100644
View file @
1d5a1de6
<?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
;
use
ReflectionClass
;
/**
* Description of DirectoryFilter
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class
NamespaceFilter
implements
ClassFilterInterface
{
/**
* @var string[]
*/
private
$accepted
=
[];
public
function
__construct
(
array
$accepted
)
{
$this
->
accepted
=
$accepted
;
}
public
function
accept
(
ReflectionClass
$class
)
{
foreach
(
$this
->
accepted
as
$namespace
)
{
if
(
strpos
(
$class
->
getName
(),
$namespace
)
===
0
)
{
return
true
;
}
}
return
false
;
}
}
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