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

Passe des classe (\ReflectionClass) plutôt que des $className.

parent 051af78f
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
namespace Irstea\PlantUmlBundle\Model; namespace Irstea\PlantUmlBundle\Model;
use ReflectionClass;
/** /**
* *
* @author Guillaume Perréal <guillaume.perreal@irstea.fr> * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
...@@ -15,8 +17,8 @@ namespace Irstea\PlantUmlBundle\Model; ...@@ -15,8 +17,8 @@ namespace Irstea\PlantUmlBundle\Model;
interface ClassFilterInterface interface ClassFilterInterface
{ {
/** /**
* @param type $className * @param ReflectionClass $class
* @return bool * @return bool
*/ */
public function accept($className); public function accept(ReflectionClass $class);
} }
...@@ -73,37 +73,39 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface ...@@ -73,37 +73,39 @@ class ClassVisitor implements ClassVisitorInterface, WritableInterface
if (isset($this->nodes[$className])) { if (isset($this->nodes[$className])) {
return $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->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 * @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()) { if ($class->isTrait()) {
$node = new Trait_($namespace, $className); return new Trait_($namespace, $class->getName());
} elseif ($class->isInterface()) {
$node = new Interface_($namespace, $className);
} else {
$node = new Class_($namespace, $className, $class->isAbstract(), $class->isFinal());
} }
$this->nodes[$class->getName()] = $node; if ($class->isInterface()) {
$namespace->addNode($node); return new Interface_($namespace, $class->getName());
}
$this->decorator->decorate($className, $node, $this);
return $node; return new Class_($namespace, $class->getName(), $class->isAbstract(), $class->isFinal());
} }
public function outputTo(WriterInterface $writer) public function outputTo(WriterInterface $writer)
......
...@@ -11,6 +11,7 @@ namespace Irstea\PlantUmlBundle\Model\Decorator; ...@@ -11,6 +11,7 @@ namespace Irstea\PlantUmlBundle\Model\Decorator;
use Irstea\PlantUmlBundle\Model\ClassVisitorInterface; use Irstea\PlantUmlBundle\Model\ClassVisitorInterface;
use Irstea\PlantUmlBundle\Model\DecoratorInterface; use Irstea\PlantUmlBundle\Model\DecoratorInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface; use Irstea\PlantUmlBundle\Model\NodeInterface;
use ReflectionClass;
/** /**
* Description of CompositeDecorator * Description of CompositeDecorator
...@@ -35,10 +36,10 @@ class CompositeDecorator implements DecoratorInterface ...@@ -35,10 +36,10 @@ class CompositeDecorator implements DecoratorInterface
return $this; return $this;
} }
public function decorate($className, NodeInterface $node, ClassVisitorInterface $visitor) public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor)
{ {
foreach($this->decorators as $decorator) { foreach($this->decorators as $decorator) {
$decorator->decorate($className, $node, $visitor); $decorator->decorate($class, $node, $visitor);
} }
return $this; return $this;
} }
......
...@@ -12,6 +12,7 @@ use Irstea\PlantUmlBundle\Model\ClassFilterInterface; ...@@ -12,6 +12,7 @@ use Irstea\PlantUmlBundle\Model\ClassFilterInterface;
use Irstea\PlantUmlBundle\Model\ClassVisitorInterface; use Irstea\PlantUmlBundle\Model\ClassVisitorInterface;
use Irstea\PlantUmlBundle\Model\DecoratorInterface; use Irstea\PlantUmlBundle\Model\DecoratorInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface; use Irstea\PlantUmlBundle\Model\NodeInterface;
use ReflectionClass;
/** /**
* Description of FilteringDecorator * Description of FilteringDecorator
...@@ -40,10 +41,10 @@ class FilteringDecorator implements DecoratorInterface ...@@ -40,10 +41,10 @@ class FilteringDecorator implements DecoratorInterface
$this->filter = $filter; $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)) { if ($this->filter->accept($class)) {
$this->next->decorate($className, $node, $visitor); $this->next->decorate($class, $node, $visitor);
} }
return $this; return $this;
} }
......
...@@ -21,10 +21,8 @@ use ReflectionClass; ...@@ -21,10 +21,8 @@ use ReflectionClass;
*/ */
class InheritanceDecorator implements DecoratorInterface 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(); $parent = $class->getParentClass();
$traits = $class->getTraitNames(); $traits = $class->getTraitNames();
$interfaces = $class->getInterfaceNames(); $interfaces = $class->getInterfaceNames();
......
...@@ -8,11 +8,13 @@ ...@@ -8,11 +8,13 @@
namespace Irstea\PlantUmlBundle\Model; namespace Irstea\PlantUmlBundle\Model;
use ReflectionClass;
/** /**
* *
* @author Guillaume Perréal <guillaume.perreal@irstea.fr> * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/ */
interface DecoratorInterface interface DecoratorInterface
{ {
public function decorate($className, NodeInterface $node, ClassVisitorInterface $visitor); public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor);
} }
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
namespace Irstea\PlantUmlBundle\Model\Filter; namespace Irstea\PlantUmlBundle\Model\Filter;
use Irstea\PlantUmlBundle\Model\ClassFilterInterface; use Irstea\PlantUmlBundle\Model\ClassFilterInterface;
use ReflectionClass;
/** /**
* Description of AcceptAllFilter * Description of AcceptAllFilter
...@@ -19,7 +20,7 @@ class AcceptAllFilter implements ClassFilterInterface ...@@ -19,7 +20,7 @@ class AcceptAllFilter implements ClassFilterInterface
{ {
use \Irstea\PlantUmlBundle\Utils\Singleton; use \Irstea\PlantUmlBundle\Utils\Singleton;
public function accept($className) public function accept(ReflectionClass $class)
{ {
return true; return true;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
namespace Irstea\PlantUmlBundle\Model\Filter; namespace Irstea\PlantUmlBundle\Model\Filter;
use Irstea\PlantUmlBundle\Model\ClassFilterInterface; use Irstea\PlantUmlBundle\Model\ClassFilterInterface;
use ReflectionClass;
/** /**
* Description of Whiltelist * Description of Whiltelist
...@@ -27,8 +28,8 @@ class Whitelist implements ClassFilterInterface ...@@ -27,8 +28,8 @@ class Whitelist implements ClassFilterInterface
$this->accepted = array_fill_keys($classNames, true); $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()]);
} }
} }
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