diff --git a/Model/ClassVisitor.php b/Model/ClassVisitor.php index 10d61d51f4f1d521781b6cbdd5d6dde78471a960..b5c221dbb84619969c4fac54cb2e640017837d62 100644 --- a/Model/ClassVisitor.php +++ b/Model/ClassVisitor.php @@ -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"); + } + } }