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 @@
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);
}
......@@ -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)
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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();
......
......@@ -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);
}
......@@ -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;
}
......
......@@ -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()]);
}
}
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