From 07decdd88201c88dfe46fddb01cb5ef77557fe2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr> Date: Fri, 13 May 2016 10:15:10 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20du=20mod=C3=A8le=20BaseArra?= =?UTF-8?q?ow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gère explicitement les cardinalités et terminaisons de lien. --- Doctrine/AssociationDecorator.php | 28 +++---- Factory/FilterFactory.php | 117 ---------------------------- Model/Arrow/BaseArrow.php | 67 ++++++++++++++-- Model/Arrow/ExtendsClass.php | 2 +- Model/Arrow/ImplementsInterface.php | 2 +- Model/Arrow/UsesTrait.php | 2 +- 6 files changed, 78 insertions(+), 140 deletions(-) delete mode 100644 Factory/FilterFactory.php diff --git a/Doctrine/AssociationDecorator.php b/Doctrine/AssociationDecorator.php index ae4fb6b..c98e569 100644 --- a/Doctrine/AssociationDecorator.php +++ b/Doctrine/AssociationDecorator.php @@ -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) ); } } diff --git a/Factory/FilterFactory.php b/Factory/FilterFactory.php deleted file mode 100644 index 04d2cf7..0000000 --- a/Factory/FilterFactory.php +++ /dev/null @@ -1,117 +0,0 @@ -<?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; - } -} diff --git a/Model/Arrow/BaseArrow.php b/Model/Arrow/BaseArrow.php index e96270a..3be960a 100644 --- a/Model/Arrow/BaseArrow.php +++ b/Model/Arrow/BaseArrow.php @@ -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; } } diff --git a/Model/Arrow/ExtendsClass.php b/Model/Arrow/ExtendsClass.php index 28aa52b..5e8dca1 100644 --- a/Model/Arrow/ExtendsClass.php +++ b/Model/Arrow/ExtendsClass.php @@ -19,6 +19,6 @@ class ExtendsClass extends BaseArrow { public function __construct(WritableNodeInterface $source, WritableNodeInterface $target) { - parent::__construct($target, $source, "<|--"); + parent::__construct($target, $source, "--", null, "<|"); } } diff --git a/Model/Arrow/ImplementsInterface.php b/Model/Arrow/ImplementsInterface.php index ad51562..5bf208e 100644 --- a/Model/Arrow/ImplementsInterface.php +++ b/Model/Arrow/ImplementsInterface.php @@ -20,6 +20,6 @@ class ImplementsInterface extends BaseArrow { public function __construct(WritableNodeInterface $source, Interface_ $target) { - parent::__construct($target, $source, "<|.."); + parent::__construct($target, $source, "..", null, "<|"); } } diff --git a/Model/Arrow/UsesTrait.php b/Model/Arrow/UsesTrait.php index ce564c0..c37d293 100644 --- a/Model/Arrow/UsesTrait.php +++ b/Model/Arrow/UsesTrait.php @@ -20,6 +20,6 @@ class UsesTrait extends BaseArrow { public function __construct(WritableNodeInterface $source, Trait_ $trait) { - parent::__construct($trait, $source, "<|--"); + parent::__construct($trait, $source, "--", null, "<|"); } } -- GitLab