* 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 */ class BaseNode implements NodeInterface { /** * @var string */ private $name; /** * @var string */ private $alias; /** * @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; $pos = strrpos($name, '\\'); $this->name = substr($name, $pos + 1); $this->alias = str_replace('\\', '.', $name)."_node"; $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 outputTo(WriterInterface $writer) { $this ->outputClassifiersTo($writer) ->outputNodeTypeTo($writer); $writer->printf('"%s" as %s', $this->name, $this->alias); $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->alias); 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; } protected function outputMethodsTo(WriterInterface $writer) { return $this; } public function addArrow(ArrowInterface $arrow) { $this->namespace->addArrow($arrow); return $this; } }