Commit 1d5a1de6 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Ajout de nouveaux filtres.

Et expérimentations.
parent 5e787728
......@@ -15,9 +15,12 @@ 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\Filter\DirectoryFilter;
use Irstea\PlantUmlBundle\Model\Filter\NamespaceFilter;
use Irstea\PlantUmlBundle\Model\Filter\Whitelist;
use Irstea\PlantUmlBundle\Model\Namespace_\BundleNamespace;
use Irstea\PlantUmlBundle\Model\Namespace_\FlatNamespace;
use Irstea\PlantUmlBundle\Model\Namespace_\MappedNamespace;
use Irstea\PlantUmlBundle\Writer\OutputWriter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
......@@ -49,16 +52,22 @@ class EntitySchemaCommand extends ContainerAwareCommand
{
/* @var $manager EntityManagerInterface */
$manager = $this->getContainer()->get('doctrine.orm.entity_manager');
$factory = $manager->getMetadataFactory();
$factory = $manager->getMetadataFactory();
$allMetadata = $factory->getAllMetadata();
$classes = array_map(
function(ClassMetadata $metadata) { return $metadata->getName(); },
$allMetadata
$decorationFilter = new DirectoryFilter(
[
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(
new CompositeDecorator([
......@@ -66,12 +75,17 @@ class EntitySchemaCommand extends ContainerAwareCommand
new EntityDecorator($factory),
new AssociationDecorator($factory),
]),
new Whitelist($classes)
$decorationFilter
);
$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->write("@startuml\n");
......
<?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;
}
}
<?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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment