Commit 72c714b0 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Ajout d'un système de filtrage des classes à afficher.

No related merge requests found
Showing with 128 additions and 8 deletions
+128 -8
...@@ -8,6 +8,7 @@ namespace Irstea\PlantUmlBundle\Command; ...@@ -8,6 +8,7 @@ namespace Irstea\PlantUmlBundle\Command;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Irstea\PlantUmlBundle\Model\Filter\Whitelist;
use Irstea\PlantUmlBundle\Model\Namespace_; use Irstea\PlantUmlBundle\Model\Namespace_;
use Irstea\PlantUmlBundle\Model\Orm\EntityVisitor; use Irstea\PlantUmlBundle\Model\Orm\EntityVisitor;
use Irstea\PlantUmlBundle\Writer\OutputWriter; use Irstea\PlantUmlBundle\Writer\OutputWriter;
...@@ -46,11 +47,13 @@ class EntitySchemaCommand extends ContainerAwareCommand ...@@ -46,11 +47,13 @@ class EntitySchemaCommand extends ContainerAwareCommand
$allMetadata = $factory->getAllMetadata(); $allMetadata = $factory->getAllMetadata();
$classes = array_map(
function(ClassMetadata $metadata) { return $metadata->getName(); },
$allMetadata
);
$visitor = new EntityVisitor($allMetadata); $visitor = new EntityVisitor($allMetadata);
foreach($allMetadata as $metadata) { array_walk($classes, [$visitor, 'visitClass']);
/* @var $metadata ClassMetadata */
$visitor->visitClass($metadata->getName());
}
$writer = new OutputWriter($output); $writer = new OutputWriter($output);
$writer->write("@startuml\n"); $writer->write("@startuml\n");
......
<?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);
}
...@@ -28,9 +28,25 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface ...@@ -28,9 +28,25 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
*/ */
protected $rootNamespace; protected $rootNamespace;
public function __construct() /**
* @var ClassFilterInterface
*/
protected $filter;
public function __construct(ClassFilterInterface $filter = null)
{ {
$this->rootNamespace = new RootNamespace(); $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) public function visitClass($className)
...@@ -39,6 +55,9 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface ...@@ -39,6 +55,9 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
if (isset($this->nodes[$className])) { if (isset($this->nodes[$className])) {
return $this->nodes[$className]; return $this->nodes[$className];
} }
if (!$this->filter->accept($className)) {
return $this->nodes[$className] = false;
}
return $this->doVisitClass($className); return $this->doVisitClass($className);
} }
...@@ -104,7 +123,9 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface ...@@ -104,7 +123,9 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
{ {
foreach ($classNames as $className) { foreach ($classNames as $className) {
$target = $this->visitClass($className); $target = $this->visitClass($className);
$namespace->addArrow(new $relationClass($source, $target)); if ($target) {
$namespace->addArrow(new $relationClass($source, $target));
}
} }
} }
......
<?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;
}
}
<?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]);
}
}
...@@ -23,9 +23,9 @@ class EntityVisitor extends ClassVisitor ...@@ -23,9 +23,9 @@ class EntityVisitor extends ClassVisitor
*/ */
protected $metadata = []; 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) { foreach($metadata as $md) {
/* @var $md ClassMetadata */ /* @var $md ClassMetadata */
......
Supports Markdown
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