BaseNode.php 4.08 KiB
<?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\Node\Member\AttributeInterface;
use Irstea\PlantUmlBundle\Model\Node\Member\MethodInterface;
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;
    /**
     * @var AttributeInterface[]
    private $attributes = [];
    /**
     * @var MethodInterface[]
    private $methods = [];
    /**
     * @param NamespaceInterface $namespace
     * @param string $name
     * @param string $nodeType
     * @param array $classifiers
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
* @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; } public function addClassifier($classifier) { $this->classifiers[] = $classifier; return $this; } public function addStereotype($stereotype) { $this->stereotypes[] = $stereotype; return $this; } public function addAttribute(AttributeInterface $attribute) { $this->attributes[] = $attribute; return $this; } public function addMethod(MethodInterface $method) { $this->methods[] = $method; return $this; } public function setLabel($label) { $this->label = $label; return $this; } public function writeTo(WriterInterface $writer) { $this ->writeClassifiersTo($writer) ->writeNodeTypeTo($writer); $writer->writeFormatted('"%s" as %s', $this->label, $this->id); $this ->writeStereotypesTo($writer); $writer ->write(" {\n") ->indent(); $this ->writeAttributesTo($writer) ->writeMethodsTo($writer); $writer ->dedent() ->write("}\n"); return $this; } public function writeAliasTo(WriterInterface $writer) { $writer->write($this->id); return $this; } protected function writeClassifiersTo(WriterInterface $writer)
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
{ foreach($this->classifiers as $classifier) { $writer->writeFormatted('%s ', $classifier); } return $this; } protected function writeNodeTypeTo(WriterInterface $writer) { $writer->writeFormatted('%s ', $this->nodeType); return $this; } protected function writeStereotypesTo(WriterInterface $writer) { foreach($this->stereotypes as $stereotype) { $writer->writeFormatted(' <<%s>>', $stereotype); } return $this; } protected function writeAttributesTo(WriterInterface $writer) { foreach($this->attributes as $attribute) { $attribute->writeTo($writer); } return $this; } protected function writeMethodsTo(WriterInterface $writer) { foreach($this->methods as $method) { $method->writeTo($writer); } return $this; } public function addArrow(ArrowInterface $arrow) { $this->namespace->addArrow($arrow); return $this; } }