An error occurred while loading the file. Please try again.
-
Guillaume Perréal authored
Gère explicitement les cardinalités et terminaisons de lien.
07decdd8
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace Irstea\PlantUmlBundle\Model\Arrow;
use Irstea\PlantUmlBundle\Model\ArrowInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
use Irstea\PlantUmlBundle\Writer\WriterInterface;
/**
* Description of Arrow
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class BaseArrow implements ArrowInterface
{
/**
* @var NodeInterface
*/
private $source;
/**
* @var NodeInterface
*/
private $target;
/**
* @var string
*/
private $link;
/**
* @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 = ''
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
) {
$this->source = $source;
$this->target = $target;
$this->link = $link;
$this->label = $label;
$this->linkSource = $linkSource;
$this->linkTarget = $linkTarget;
$this->sourceCardinality = $sourceCardinality;
$this->targetCardinality = $targetCardinality;
}
public function writeTo(WriterInterface $writer)
{
$this->source->writeAliasTo($writer);
$this->writeLinkTo($writer);
$this->target->writeAliasTo($writer);
$this->writeLabelTo($writer);
$writer->write("\n");
return $this;
}
protected function writeLabelTo(WriterInterface $writer)
{
if ($this->label) {
$writer->writeFormatted(" : %s", $this->label);
}
return $this;
}
protected function writeLinkTo(WriterInterface $writer, $linkSource = null, $linkTarget = null)
{
$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;
}
}