diff --git a/Model/ClassFilterInterface.php b/Model/ClassFilterInterface.php index 6c8ac88b073d525f4739bf60f608cf3766966cb4..7eca71463b0db0873d327c85d35e0e66bd67a613 100644 --- a/Model/ClassFilterInterface.php +++ b/Model/ClassFilterInterface.php @@ -8,6 +8,8 @@ namespace Irstea\PlantUmlBundle\Model; +use ReflectionClass; + /** * * @author Guillaume PerrÊal <guillaume.perreal@irstea.fr> @@ -15,8 +17,8 @@ namespace Irstea\PlantUmlBundle\Model; interface ClassFilterInterface { /** - * @param type $className + * @param ReflectionClass $class * @return bool */ - public function accept($className); + public function accept(ReflectionClass $class); } diff --git a/Model/ClassVisitor.php b/Model/ClassVisitor.php index d39a4f47b5335c2e9d3577bdaaca612d5d0b05c3..3a57ad53b924d506e40852a4c9effecffdec3051 100644 --- a/Model/ClassVisitor.php +++ b/Model/ClassVisitor.php @@ -73,37 +73,39 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface if (isset($this->nodes[$className])) { return $this->nodes[$className]; } - if (!$this->filter->accept($className)) { + + $class = new ReflectionClass($className); + + if (!$this->filter->accept($class)) { return $this->nodes[$className] = false; } - return $this->createNode($className); + $namespace = $this->rootNamespace->getNamespace($class->getNamespaceName()); + $node = $this->nodes[$className] = $this->createNode($namespace, $class); + $namespace->addNode($node); + + $this->decorator->decorate($class, $node, $this); + + return $node; } /** * - * @param string $className + * @param \Irstea\PlantUmlBundle\Model\NamespaceInterface $namespace + * @param ReflectionClass $class * @return NodeInterface */ - protected function createNode($className) + protected function createNode(NamespaceInterface $namespace, ReflectionClass $class) { - $class = new ReflectionClass($className); - $namespace = $this->rootNamespace->getNamespace($class->getNamespaceName()); - if ($class->isTrait()) { - $node = new Trait_($namespace, $className); - } elseif ($class->isInterface()) { - $node = new Interface_($namespace, $className); - } else { - $node = new Class_($namespace, $className, $class->isAbstract(), $class->isFinal()); + return new Trait_($namespace, $class->getName()); } - $this->nodes[$class->getName()] = $node; - $namespace->addNode($node); - - $this->decorator->decorate($className, $node, $this); + if ($class->isInterface()) { + return new Interface_($namespace, $class->getName()); + } - return $node; + return new Class_($namespace, $class->getName(), $class->isAbstract(), $class->isFinal()); } public function outputTo(WriterInterface $writer) diff --git a/Model/Decorator/CompositeDecorator.php b/Model/Decorator/CompositeDecorator.php index 788210a9c0e7d664b53d7b2541f5581da10ce7bb..8e6759df04ea8db49cb78a2e671a9965294ebebc 100644 --- a/Model/Decorator/CompositeDecorator.php +++ b/Model/Decorator/CompositeDecorator.php @@ -11,6 +11,7 @@ namespace Irstea\PlantUmlBundle\Model\Decorator; use Irstea\PlantUmlBundle\Model\ClassVisitorInterface; use Irstea\PlantUmlBundle\Model\DecoratorInterface; use Irstea\PlantUmlBundle\Model\NodeInterface; +use ReflectionClass; /** * Description of CompositeDecorator @@ -35,10 +36,10 @@ class CompositeDecorator implements DecoratorInterface return $this; } - public function decorate($className, NodeInterface $node, ClassVisitorInterface $visitor) + public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor) { foreach($this->decorators as $decorator) { - $decorator->decorate($className, $node, $visitor); + $decorator->decorate($class, $node, $visitor); } return $this; } diff --git a/Model/Decorator/FilteringDecorator.php b/Model/Decorator/FilteringDecorator.php index 6025de1d5b76d21be1277083c52da69cf2f7160c..7fb1ade60c5f82486b2c9d7ebfdee006cd3d7652 100644 --- a/Model/Decorator/FilteringDecorator.php +++ b/Model/Decorator/FilteringDecorator.php @@ -12,6 +12,7 @@ use Irstea\PlantUmlBundle\Model\ClassFilterInterface; use Irstea\PlantUmlBundle\Model\ClassVisitorInterface; use Irstea\PlantUmlBundle\Model\DecoratorInterface; use Irstea\PlantUmlBundle\Model\NodeInterface; +use ReflectionClass; /** * Description of FilteringDecorator @@ -40,10 +41,10 @@ class FilteringDecorator implements DecoratorInterface $this->filter = $filter; } - public function decorate($className, NodeInterface $node, ClassVisitorInterface $visitor) + public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor) { - if ($this->filter->accept($className)) { - $this->next->decorate($className, $node, $visitor); + if ($this->filter->accept($class)) { + $this->next->decorate($class, $node, $visitor); } return $this; } diff --git a/Model/Decorator/InheritanceDecorator.php b/Model/Decorator/InheritanceDecorator.php index d3b52c462295aa727f517af0061c212884866901..ff901f04a717f7c8281e3dd04028c5ab90dab4ae 100644 --- a/Model/Decorator/InheritanceDecorator.php +++ b/Model/Decorator/InheritanceDecorator.php @@ -21,10 +21,8 @@ use ReflectionClass; */ class InheritanceDecorator implements DecoratorInterface { - public function decorate($className, NodeInterface $node, ClassVisitorInterface $visitor) + public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor) { - $class = new ReflectionClass($className); - $parent = $class->getParentClass(); $traits = $class->getTraitNames(); $interfaces = $class->getInterfaceNames(); diff --git a/Model/DecoratorInterface.php b/Model/DecoratorInterface.php index 72c530bc7d3fe6e9f3dc056b1cf41bc51cd8df23..c391a909762426a803444ba80b474c7a46edb4b8 100644 --- a/Model/DecoratorInterface.php +++ b/Model/DecoratorInterface.php @@ -8,11 +8,13 @@ namespace Irstea\PlantUmlBundle\Model; +use ReflectionClass; + /** * * @author Guillaume PerrÊal <guillaume.perreal@irstea.fr> */ interface DecoratorInterface { - public function decorate($className, NodeInterface $node, ClassVisitorInterface $visitor); + public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor); } diff --git a/Model/Filter/AcceptAllFilter.php b/Model/Filter/AcceptAllFilter.php index 7ec74eec90f4d6628db0c4ea587afaeab41f5c46..1fd59bf3a164150ee7b406debb864ef7cafc4771 100644 --- a/Model/Filter/AcceptAllFilter.php +++ b/Model/Filter/AcceptAllFilter.php @@ -9,6 +9,7 @@ namespace Irstea\PlantUmlBundle\Model\Filter; use Irstea\PlantUmlBundle\Model\ClassFilterInterface; +use ReflectionClass; /** * Description of AcceptAllFilter @@ -19,7 +20,7 @@ class AcceptAllFilter implements ClassFilterInterface { use \Irstea\PlantUmlBundle\Utils\Singleton; - public function accept($className) + public function accept(ReflectionClass $class) { return true; } diff --git a/Model/Filter/Whitelist.php b/Model/Filter/Whitelist.php index ecbd66381a5bb119778b987bd1c95a08aa6cdfca..582960a970892ee68fb5b2a569b95a654cf114e1 100644 --- a/Model/Filter/Whitelist.php +++ b/Model/Filter/Whitelist.php @@ -9,6 +9,7 @@ namespace Irstea\PlantUmlBundle\Model\Filter; use Irstea\PlantUmlBundle\Model\ClassFilterInterface; +use ReflectionClass; /** * Description of Whiltelist @@ -27,8 +28,8 @@ class Whitelist implements ClassFilterInterface $this->accepted = array_fill_keys($classNames, true); } - public function accept($className) + public function accept(ReflectionClass $class) { - return isset($this->accepted[$className]); + return isset($this->accepted[$class->getName()]); } }