Commit 8e3d291b authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Trie les noeuds par type.

parent e5959457
...@@ -122,9 +122,11 @@ class ClassVisitor implements ClassVisitorInterface, UmlComponentInterface ...@@ -122,9 +122,11 @@ class ClassVisitor implements ClassVisitorInterface, UmlComponentInterface
{ {
$this->outputNamespacesTo($stream, $this->namespaces); $this->outputNamespacesTo($stream, $this->namespaces);
usort($this->nodes, 'Irstea\PlantUmlBundle\Model\Node\BaseNode::compare');
foreach ($this->nodes as $node) { foreach ($this->nodes as $node) {
$node->outputTo($stream); $node->outputTo($stream);
} }
foreach ($this->arrows as $arrow) { foreach ($this->arrows as $arrow) {
$arrow->outputTo($stream); $arrow->outputTo($stream);
} }
......
...@@ -37,18 +37,24 @@ class BaseNode implements UmlNodeInterface ...@@ -37,18 +37,24 @@ class BaseNode implements UmlNodeInterface
*/ */
private $stereotypes; private $stereotypes;
/**
* @var int
*/
private $ordering;
/** /**
* @param string $name * @param string $name
* @param string $nodeType * @param string $nodeType
* @param array $classifiers * @param array $classifiers
* @param array $stereotypes * @param array $stereotypes
*/ */
function __construct($name, $nodeType, array $classifiers = [], array $stereotypes = []) function __construct($name, $nodeType, array $classifiers = [], array $stereotypes = [], $ordering = 0)
{ {
$this->name = $name; $this->name = $name;
$this->nodeType = $nodeType; $this->nodeType = $nodeType;
$this->classifiers = $classifiers; $this->classifiers = $classifiers;
$this->stereotypes = $stereotypes; $this->stereotypes = $stereotypes;
$this->ordering = $ordering;
} }
public function outputTo($stream) public function outputTo($stream)
...@@ -96,4 +102,12 @@ class BaseNode implements UmlNodeInterface ...@@ -96,4 +102,12 @@ class BaseNode implements UmlNodeInterface
{ {
// NOP // NOP
} }
static public function compare(BaseNode $a, BaseNode $b)
{
if ($a->ordering === $b->ordering) {
return strcmp($a->name, $b->name);
}
return $a->ordering - $b->ordering;
}
} }
...@@ -23,6 +23,6 @@ class Class_ extends BaseNode ...@@ -23,6 +23,6 @@ class Class_ extends BaseNode
} elseif ($isFinal) { } elseif ($isFinal) {
$classifiers[] = 'final'; $classifiers[] = 'final';
} }
parent::__construct($name, "class", $classifiers); parent::__construct($name, "class", $classifiers, [], $isAbstract ? 0 : ($isFinal ? 20 : 10));
} }
} }
...@@ -17,6 +17,6 @@ class Interface_ extends BaseNode ...@@ -17,6 +17,6 @@ class Interface_ extends BaseNode
{ {
public function __construct($name) public function __construct($name)
{ {
parent::__construct($name, 'interface', [], ['interface']); parent::__construct($name, 'interface', [], [], -20);
} }
} }
...@@ -17,6 +17,6 @@ class Trait_ extends BaseNode ...@@ -17,6 +17,6 @@ class Trait_ extends BaseNode
{ {
public function __construct($name) public function __construct($name)
{ {
parent::__construct($name, 'class', [], ['trait']); parent::__construct($name, 'class', [], ['trait'], -10);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment