An error occurred while loading the file. Please try again.
-
Guillaume Perréal authored051af78f
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace Irstea\PlantUmlBundle\Model;
use Irstea\PlantUmlBundle\Model\Filter\AcceptAllFilter;
use Irstea\PlantUmlBundle\Model\Namespace_\RootNamespace;
use Irstea\PlantUmlBundle\Model\Node\Class_;
use Irstea\PlantUmlBundle\Model\Node\Interface_;
use Irstea\PlantUmlBundle\Model\Node\Trait_;
use Irstea\PlantUmlBundle\Writer\WritableInterface;
use Irstea\PlantUmlBundle\Writer\WritableNodeInterface;
use Irstea\PlantUmlBundle\Writer\WriterInterface;
use ReflectionClass;
/**
* Description of Visitor
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class ClassVisitor implements ClassVisitorInterface, WritableInterface
{
/**
* @var RootNamespace
*/
protected $rootNamespace;
/**
* @var ClassFilterInterface
*/
protected $filter;
/**
* @var DecoratorInterface
*/
protected $decorator;
public function __construct(DecoratorInterface $decorator = null, ClassFilterInterface $filter = null)
{
$this->rootNamespace = new RootNamespace();
$this->filter = $filter ?: AcceptAllFilter::instance();
$this->decorator = $decorator ?: NullDecorator::instance();
}
/**
* @param ClassFilterInterface $filter
* @return self
*/
public function setClassFilter(ClassFilterInterface $filter)
{
$this->filter = $filter;
return $this;
}
/**
* @param DecoratorInterface $decorator
* @return self
*/
public function setDecorator(DecoratorInterface $decorator)
{
$this->decorator = $decorator;
return $this;
}
public function visitClass($className)
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
{
assert('is_string($className)', $className);
if (isset($this->nodes[$className])) {
return $this->nodes[$className];
}
if (!$this->filter->accept($className)) {
return $this->nodes[$className] = false;
}
return $this->createNode($className);
}
/**
*
* @param string $className
* @return NodeInterface
*/
protected function createNode($className)
{
$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());
}
$this->nodes[$class->getName()] = $node;
$namespace->addNode($node);
$this->decorator->decorate($className, $node, $this);
return $node;
}
public function outputTo(WriterInterface $writer)
{
return $this->rootNamespace->outputTo($writer);
}
}