An error occurred while loading the file. Please try again.
-
Guillaume Perréal authored5e787728
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace Irstea\PlantUmlBundle\Model\Node;
use Irstea\PlantUmlBundle\Model\ArrowInterface;
use Irstea\PlantUmlBundle\Model\NamespaceInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
use Irstea\PlantUmlBundle\Writer\WriterInterface;
/**
* Description of Class
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class BaseNode implements NodeInterface
{
/**
* @var string
*/
private $label;
/**
* @var string
*/
private $id;
/**
* @var string
*/
private $nodeType;
/**
* @var string[]
*/
private $classifiers;
/**
* @var string[]
*/
private $stereotypes;
/**
* @var NamespaceInterface
*/
private $namespace;
/**
* @param NamespaceInterface $namespace
* @param string $name
* @param string $nodeType
* @param array $classifiers
* @param array $stereotypes
*/
function __construct(NamespaceInterface $namespace, $name, $nodeType, array $classifiers = [], array $stereotypes = [])
{
$this->namespace = $namespace;
$this->id = $namespace->getNodeId($name);
$this->label = $namespace->getNodeLabel($name);
$this->nodeType = $nodeType;
$this->classifiers = $classifiers;
$this->stereotypes = $stereotypes;
}
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
public function addClassifier($classifier)
{
$this->classifiers[] = $classifier;
return $this;
}
public function addStereotype($stereotype)
{
$this->stereotypes[] = $stereotype;
return $this;
}
public function setLabel($label)
{
$this->label = $label;
return $this;
}
public function outputTo(WriterInterface $writer)
{
$this
->outputClassifiersTo($writer)
->outputNodeTypeTo($writer);
$writer->printf('"%s" as %s', $this->label, $this->id);
$this
->outputStereotypesTo($writer);
$writer
->write(" {\n")
->indent();
$this
->outputAttributesTo($writer)
->outputMethodsTo($writer);
$writer
->dedent()
->write("}\n");
return $this;
}
public function outputAliasTo(WriterInterface $writer)
{
$writer->write($this->id);
return $this;
}
protected function outputClassifiersTo(WriterInterface $writer)
{
foreach($this->classifiers as $classifier) {
$writer->printf('%s ', $classifier);
}
return $this;
}
protected function outputNodeTypeTo(WriterInterface $writer)
{
$writer->printf('%s ', $this->nodeType);
return $this;
}
protected function outputStereotypesTo(WriterInterface $writer)
{
foreach($this->stereotypes as $stereotype) {
$writer->printf(' <<%s>>', $stereotype);
}
return $this;
}
protected function outputAttributesTo(WriterInterface $writer)
{
return $this;
}
141142143144145146147148149150151152153
protected function outputMethodsTo(WriterInterface $writer)
{
return $this;
}
public function addArrow(ArrowInterface $arrow)
{
$this->namespace->addArrow($arrow);
return $this;
}
}