Commit 762ddf49 authored by Guillaume Perréal's avatar Guillaume Perréal

Première version du support des attributs et des méthodes.

parent bd67bea6
......@@ -17,10 +17,12 @@ use Irstea\PlantUmlBundle\Finder\FilteringFinder;
use Irstea\PlantUmlBundle\Finder\FinderInterface;
use Irstea\PlantUmlBundle\Model\ClassFilterInterface;
use Irstea\PlantUmlBundle\Model\ClassVisitor;
use Irstea\PlantUmlBundle\Model\Decorator\AttributeDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\CompositeDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\FilteringDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\InheritanceDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\InterfaceDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\MethodDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\NullDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\TraitDecorator;
use Irstea\PlantUmlBundle\Model\DecoratorInterface;
......@@ -205,12 +207,18 @@ class GenerateCommand extends ContainerAwareCommand
return new InterfaceDecorator();
case 'traits':
return new TraitDecorator();
case 'attributes':
return new AttributeDecorator();
case 'methods':
return new MethodDecorator();
case 'entity':
return new EntityDecorator($this->entityManager->getMetadataFactory());
case 'associations':
return new AssociationDecorator($this->entityManager->getMetadataFactory());
case 'fields':
return new FieldDecorator($this->entityManager->getMetadataFactory());
default:
return NullDecorator::instance();
}
}
......
......@@ -48,6 +48,8 @@ class Configuration implements ConfigurationInterface
{
$node = (new TreeBuilder())->root('graphs');
$decorators = ['inheritance', 'traits', 'interfaces', 'entity', 'associations', 'properties', 'methods', 'fields', 'attributes'];
$node
->useAttributeAsKey('name')
->prototype('array')
......@@ -85,9 +87,9 @@ class Configuration implements ConfigurationInterface
->addDefaultsIfNotSet()
->children()
->arrayNode('decorators')
->defaultValue(['inheritance', 'traits', 'interfaces', 'entity', 'associations', 'properties', 'methods', 'fields'])
->defaultValue($decorators)
->prototype('enum')
->values(['inheritance', 'traits', 'interfaces', 'entity', 'associations', 'properties', 'methods', 'fields'])
->values($decorators)
->end()
->end()
->append($this->buildFilterNode('include'))
......
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace Irstea\PlantUmlBundle\Model\Decorator;
use Irstea\PlantUmlBundle\Model\ClassVisitorInterface;
use Irstea\PlantUmlBundle\Model\DecoratorInterface;
use Irstea\PlantUmlBundle\Model\Node\Member\Member;
use Irstea\PlantUmlBundle\Model\Node\Member\MemberInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
use ReflectionClass;
use ReflectionProperty;
/**
* Description of AttributeDecorator
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class AttributeDecorator implements DecoratorInterface
{
public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor)
{
foreach($class->getProperties() as $property) {
/* @var $property ReflectionProperty */
$node->addAttribute(
new Member(
$property->getName(),
false,
$property->isPrivate() ? MemberInterface::PRIVATE_ :
$property->isProtected() ? MemberInterface::PROTECTED_ :
$property->isPublic() ? MemberInterface::PUBLIC_ :
MemberInterface::UNKNOWN
)
);
}
}
}
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace Irstea\PlantUmlBundle\Model\Decorator;
use Irstea\PlantUmlBundle\Model\ClassVisitorInterface;
use Irstea\PlantUmlBundle\Model\DecoratorInterface;
use Irstea\PlantUmlBundle\Model\Node\Member\Member;
use Irstea\PlantUmlBundle\Model\Node\Member\MemberInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
use ReflectionClass;
use ReflectionMethod;
/**
* Description of AttributeDecorator
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class MethodDecorator implements DecoratorInterface
{
public function decorate(ReflectionClass $class, NodeInterface $node, ClassVisitorInterface $visitor)
{
foreach($class->getMethods() as $method) {
/* @var $method ReflectionMethod */
if ($method->getDeclaringClass() != $class) {
continue;
}
$node->addMethod(
new Member(
$method->getName().'(...)',
'',
$method->isPrivate() ? MemberInterface::PRIVATE_ :
($method->isProtected() ? MemberInterface::PROTECTED_ :
($method->isPublic() ? MemberInterface::PUBLIC_ :
MemberInterface::UNKNOWN))
)
);
}
}
}
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