En raison du déménagement des baies serveurs, les services gitlab.irstea.fr et mattermost.irstea.fr seront interrompus le samedi 2 octobre 2021 au matin. Ils devraient revenir à la normale dans la journée.

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

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

parent b8bcadb6
......@@ -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");
......
<?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
*/
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));
}
}
}
......
<?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
*/
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 */
......
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