Commit 07decdd8 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Amélioration du modèle BaseArraow

Gère explicitement les cardinalités et terminaisons de lien.
No related merge requests found
Showing with 78 additions and 140 deletions
+78 -140
......@@ -50,35 +50,35 @@ class AssociationDecorator extends AbstractDoctrineDecorator
return;
}
$link = "->";
$linkSource = '';
$linkTarget = ">";
if ($association["isCascadeRemove"]) {
$link = "o".$link;
$linkSource = "o";
}
$leftLabel = "";
$rightLabel = "";
$sourceCardinality = "";
$targetCardinality = "";
switch($association["type"]) {
case ClassMetadata::ONE_TO_ONE:
$leftLabel = '1';
$rightLabel = '1';
$sourceCardinality = '1';
$targetCardinality = '1';
break;
case ClassMetadata::ONE_TO_MANY:
$leftLabel = '1';
$rightLabel = '*';
$sourceCardinality = '1';
$targetCardinality = '*';
break;
case ClassMetadata::MANY_TO_MANY:
$leftLabel = '*';
$rightLabel = '*';
$sourceCardinality = '*';
$targetCardinality = '*';
break;
case ClassMetadata::MANY_TO_ONE:
$leftLabel = '*';
$rightLabel = '1';
$sourceCardinality = '*';
$targetCardinality = '1';
break;
}
$link = sprintf('"%s" %s "%s"', $leftLabel, $link, $rightLabel);
$node->addArrow(
new BaseArrow($node, $target, $link, $association["fieldName"]." >")
new BaseArrow($node, $target, "--", $association["fieldName"]." >", $linkSource, $linkTarget, $sourceCardinality, $targetCardinality)
);
}
}
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace Irstea\PlantUmlBundle\Factory;
use Irstea\PlantUmlBundle\Model\ClassFilterInterface;
use Irstea\PlantUmlBundle\Model\Filter\AcceptAllFilter;
use Irstea\PlantUmlBundle\Model\Filter\ClassFilter;
use Irstea\PlantUmlBundle\Model\Filter\Composite\AllFilter;
use Irstea\PlantUmlBundle\Model\Filter\DirectoryFilter;
use Irstea\PlantUmlBundle\Model\Filter\NamespaceFilter;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Description of FilterFactory
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class FilterFactory
{
/**
* @var KernelInterface
*/
private $kernel;
public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
}
/**
* @param array $include
* @param array $exclude
* @return ClassFilterInterface
*/
public function create($include = [], $exclude = [])
{
$filters = [];
if (!empty($include)) {
$this->appendFilters($filters, $include, false);
}
if (!empty($exclude)) {
$this->appendFilters($filters, $exclude, true);
}
switch(count($filters)) {
case 0:
$filter = AcceptAllFilter::instance();
break;
case 1:
$filter = $filters[0];
break;
default:
$filter = new AllFilter($filters);
}
return $filter;
}
protected function appendFilters(array &$filters, array $config, $notFound)
{
if (!empty($config['directories'])) {
$paths = $this->expandBundlePaths($config['directories']);
$filters[] = new DirectoryFilter($paths, $notFound);
}
if (!empty($config['namespaces'])) {
$namespaces = $this->expandBundleNamespaces($config['namespaces']);
$filters[] = new NamespaceFilter($namespaces, $notFound);
}
if (!empty($config['classes'])) {
$classes = $this->expandBundleNamespaces($config['classes']);
$filters[] = new ClassFilter($classes, $notFound);
}
}
/**
* @param array $paths
* @return array
*/
protected function expandBundlePaths(array $paths)
{
$actualPaths = [];
foreach($paths as $path) {
if (preg_match('/^@(\w+)(.*)$/', $path, $groups)) {
$bundle = $this->kernel->getBundle($groups[1]);
$path = $bundle->getPath() . $groups[2];
}
$actualPaths[] = realpath($path);
}
return $actualPaths;
}
/**
* @param array $paths
* @return array
*/
protected function expandBundleNamespaces(array $names)
{
$actualNames = [];
foreach($names as $name) {
if (preg_match('/^@(\w+)(.*)$/', $name, $groups)) {
$bundle = $this->kernel->getBundle($groups[1]);
$name = $bundle->getNamespace() . $groups[2];
}
$actualNames[] = $name;
}
return $actualNames;
}
}
......@@ -34,12 +34,49 @@ class BaseArrow implements ArrowInterface
*/
private $link;
public function __construct(NodeInterface $source, NodeInterface $target, $link = "--", $label = null)
{
/**
* @var string
*/
private $linkSource;
/**
* @var string
*/
private $linkTarget;
/**
* @var string
*/
private $sourceCardinality;
/**
* @var string
*/
private $targetCardinality;
/**
* @var int
*/
static private $splitCount = 0;
public function __construct(
NodeInterface $source,
NodeInterface $target,
$link = "--",
$label = null,
$linkSource = '',
$linkTarget = '',
$sourceCardinality = '',
$targetCardinality = ''
) {
$this->source = $source;
$this->target = $target;
$this->link = $link;
$this->label = $label;
$this->link = $link;
$this->label = $label;
$this->linkSource = $linkSource;
$this->linkTarget = $linkTarget;
$this->sourceCardinality = $sourceCardinality;
$this->targetCardinality = $targetCardinality;
}
public function writeTo(WriterInterface $writer)
......@@ -60,9 +97,27 @@ class BaseArrow implements ArrowInterface
return $this;
}
protected function writeLinkTo(WriterInterface $writer)
protected function writeLinkTo(WriterInterface $writer, $linkSource = null, $linkTarget = null)
{
$writer->writeFormatted(" %s ", $this->link);
$this->writeSourceCardinalityTo($writer);
$writer->writeFormatted(" %s%s%s ", $linkSource ?: $this->linkSource, $this->link, $linkTarget ?: $this->linkTarget);
$this->writeTargetCardinalityTo($writer);
return $this;
}
protected function writeSourceCardinalityTo(WriterInterface $writer)
{
if ($this->sourceCardinality !== '') {
$writer->writeFormatted(' "%s"', $this->sourceCardinality);
}
return $this;
}
protected function writeTargetCardinalityTo(WriterInterface $writer)
{
if ($this->targetCardinality !== '') {
$writer->writeFormatted('"%s" ', $this->targetCardinality);
}
return $this;
}
}
......@@ -19,6 +19,6 @@ class ExtendsClass extends BaseArrow
{
public function __construct(WritableNodeInterface $source, WritableNodeInterface $target)
{
parent::__construct($target, $source, "<|--");
parent::__construct($target, $source, "--", null, "<|");
}
}
......@@ -20,6 +20,6 @@ class ImplementsInterface extends BaseArrow
{
public function __construct(WritableNodeInterface $source, Interface_ $target)
{
parent::__construct($target, $source, "<|..");
parent::__construct($target, $source, "..", null, "<|");
}
}
......@@ -20,6 +20,6 @@ class UsesTrait extends BaseArrow
{
public function __construct(WritableNodeInterface $source, Trait_ $trait)
{
parent::__construct($trait, $source, "<|--");
parent::__construct($trait, $source, "--", null, "<|");
}
}
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