* Tous droits réservés. */ namespace Irstea\PlantUmlBundle\Model\Node; use Irstea\PlantUmlBundle\Model\UmlNodeInterface; use Irstea\PlantUmlBundle\Writer\WriterInterface; /** * Description of Class * * @author Guillaume Perréal */ class BaseNode implements UmlNodeInterface { /** * @var string */ private $name; /** * @var string */ private $alias; /** * @var string */ private $nodeType; /** * @var string[] */ private $classifiers; /** * @var string[] */ private $stereotypes; /** * @var int */ private $ordering; /** * @param string $name * @param string $nodeType * @param array $classifiers * @param array $stereotypes */ function __construct($name, $nodeType, array $classifiers = [], array $stereotypes = [], $ordering = 0) { $pos = strrpos($name, '\\'); $this->name = substr($name, $pos + 1); $this->alias = str_replace('\\', '.', $name)."_node"; $this->nodeType = $nodeType; $this->classifiers = $classifiers; $this->stereotypes = $stereotypes; $this->ordering = $ordering; } 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; } static public function compare(BaseNode $a, BaseNode $b) { if ($a->ordering === $b->ordering) { return strcmp($a->name, $b->name); } return $a->ordering - $b->ordering; } }