Commit 709da3ad authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Associe les nodes à leur namespace.

Et laisse tomber le classement.
parent 3bdfbc13
......@@ -81,17 +81,17 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
*/
protected function visitClassReflection(ReflectionClass $class)
{
$namespace = $this->rootNamespace->getNamespace($class->getNamespaceName());
if ($class->isTrait()) {
$node = new Trait_($class->getName());
$node = new Trait_($namespace, $class->getName());
} elseif ($class->isInterface()) {
$node = new Interface_($class->getName());
$node = new Interface_($namespace, $class->getName());
} else {
$node = new Class_($class->getName(), $class->isAbstract(), $class->isFinal());
$node = new Class_($namespace, $class->getName(), $class->isAbstract(), $class->isFinal());
}
$this->nodes[$class->getName()] = $node;
$namespace = $this->rootNamespace->getNamespace($class->getNamespaceName());
$namespace->addNode($node);
$parentClass = $class->getParentClass();
......@@ -112,21 +112,21 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
if ($parentClass) {
$traitNames = array_diff($traitNames, $parentClass->getTraitNames());
$interfaceNames = array_diff($interfaceNames, $parentClass->getInterfaceNames());
$this->visitRelations($node, $namespace, [$parentClass->getName()], 'Irstea\PlantUmlBundle\Model\Arrow\ExtendsClass');
$this->visitRelations($node, [$parentClass->getName()], 'Irstea\PlantUmlBundle\Model\Arrow\ExtendsClass');
}
$this->visitRelations($node, $namespace, $interfaceNames, 'Irstea\PlantUmlBundle\Model\Arrow\ImplementsInterface');
$this->visitRelations($node, $namespace, $traitNames, 'Irstea\PlantUmlBundle\Model\Arrow\UsesTrait');
$this->visitRelations($node, $interfaceNames, 'Irstea\PlantUmlBundle\Model\Arrow\ImplementsInterface');
$this->visitRelations($node, $traitNames, 'Irstea\PlantUmlBundle\Model\Arrow\UsesTrait');
return $node;
}
protected function visitRelations(WritableNodeInterface $source, NamespaceInterface $namespace, array $classNames, $relationClass)
protected function visitRelations(NodeInterface $source, array $classNames, $relationClass)
{
foreach ($classNames as $className) {
$target = $this->visitClass($className);
if ($target) {
$namespace->addArrow(new $relationClass($source, $target));
$source->addArrow(new $relationClass($source, $target));
}
}
}
......
......@@ -8,6 +8,8 @@
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;
......@@ -44,18 +46,21 @@ class BaseNode implements NodeInterface
private $stereotypes;
/**
* @var int
* @var NamespaceInterface
*/
private $ordering;
private $namespace;
/**
* @param NamespaceInterface $namespace
* @param string $name
* @param string $nodeType
* @param array $classifiers
* @param array $stereotypes
*/
function __construct($name, $nodeType, array $classifiers = [], array $stereotypes = [], $ordering = 0)
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";
......@@ -63,7 +68,6 @@ class BaseNode implements NodeInterface
$this->nodeType = $nodeType;
$this->classifiers = $classifiers;
$this->stereotypes = $stereotypes;
$this->ordering = $ordering;
}
public function outputTo(WriterInterface $writer)
......@@ -123,4 +127,10 @@ class BaseNode implements NodeInterface
{
return $this;
}
public function addArrow(ArrowInterface $arrow)
{
$this->namespace->addArrow($arrow);
return $this;
}
}
......@@ -8,6 +8,8 @@
namespace Irstea\PlantUmlBundle\Model\Node;
use Irstea\PlantUmlBundle\Model\NamespaceInterface;
/**
* Description of Class_
*
......@@ -15,7 +17,7 @@ namespace Irstea\PlantUmlBundle\Model\Node;
*/
class Class_ extends BaseNode
{
public function __construct($name, $isAbstract, $isFinal)
public function __construct(NamespaceInterface $namespace, $name, $isAbstract, $isFinal)
{
$classifiers = [];
if ($isAbstract) {
......@@ -23,6 +25,6 @@ class Class_ extends BaseNode
} elseif ($isFinal) {
$classifiers[] = 'final';
}
parent::__construct($name, "class", $classifiers, [], $isAbstract ? 0 : ($isFinal ? 20 : 10));
parent::__construct($namespace, $name, "class", $classifiers, []);
}
}
......@@ -8,6 +8,8 @@
namespace Irstea\PlantUmlBundle\Model\Node;
use Irstea\PlantUmlBundle\Model\NamespaceInterface;
/**
* Description of Interface_
*
......@@ -15,8 +17,8 @@ namespace Irstea\PlantUmlBundle\Model\Node;
*/
class Interface_ extends BaseNode
{
public function __construct($name)
public function __construct(NamespaceInterface $namespace, $name)
{
parent::__construct($name, 'interface', [], [], -20);
parent::__construct($namespace, $name, 'interface', [], []);
}
}
......@@ -8,6 +8,8 @@
namespace Irstea\PlantUmlBundle\Model\Node;
use Irstea\PlantUmlBundle\Model\NamespaceInterface;
/**
* Description of Trait_
*
......@@ -15,8 +17,8 @@ namespace Irstea\PlantUmlBundle\Model\Node;
*/
class Trait_ extends BaseNode
{
public function __construct($name)
public function __construct(NamespaceInterface $namespace, $name)
{
parent::__construct($name, 'class', [], ['trait'], -10);
parent::__construct($namespace, $name, 'class', [], ['trait']);
}
}
......@@ -16,5 +16,9 @@ use Irstea\PlantUmlBundle\Writer\WritableNodeInterface;
*/
interface NodeInterface extends WritableNodeInterface
{
//put your code here
/**
* @param ArrowInterface $arrow
* @return self
*/
public function addArrow(ArrowInterface $arrow);
}
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