From e5959457138a9bdf63add75181b21d533209345c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr> Date: Tue, 8 Mar 2016 16:51:47 +0100 Subject: [PATCH] =?UTF-8?q?G=C3=A9n=C3=A8re=20les=20namespaces.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/ClassVisitor.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Model/ClassVisitor.php b/Model/ClassVisitor.php index 10d61d5..b5c221d 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"); + } + } } -- GitLab