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

Génère les namespaces.

parent d188bf1d
......@@ -30,6 +30,11 @@ class ClassVisitor implements ClassVisitorInterface, UmlComponentInterface
*/
protected $arrows = [];
/**
* @var string[]
*/
protected $namespaces = [];
public function visitClass($className)
{
assert('is_string($className)', $className);
......@@ -65,6 +70,7 @@ class ClassVisitor implements ClassVisitorInterface, UmlComponentInterface
$node = new Class_($class->getName(), $class->isAbstract(), $class->isFinal());
}
$this->nodes[$class->getName()] = $node;
$this->visitNamespace($class->getNamespaceName());
$parentClass = $class->getParentClass();
$traitNames = $class->getTraitNames();
......@@ -101,8 +107,21 @@ class ClassVisitor implements ClassVisitorInterface, UmlComponentInterface
}
}
protected function visitNamespace($namespaceName)
{
$current =& $this->namespaces;
foreach(explode('\\', $namespaceName) as $part) {
if (!isset($current[$part])) {
$current[$part] = [];
}
$current = &$current[$part];
}
}
public function outputTo($stream)
{
$this->outputNamespacesTo($stream, $this->namespaces);
foreach ($this->nodes as $node) {
$node->outputTo($stream);
}
......@@ -110,4 +129,18 @@ class ClassVisitor implements ClassVisitorInterface, UmlComponentInterface
$arrow->outputTo($stream);
}
}
protected function outputNamespacesTo($stream, $namespaces)
{
foreach($namespaces as $name => $children) {
fputs($stream, "namespace ");
/*while(count($children) == 1) {
fputs($stream, $name.'.');
list($name, $children) = each($children);
}*/
fputs($stream, "$name {\n");
$this->outputNamespacesTo($stream, $children);
fputs($stream, "}\n");
}
}
}
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