diff --git a/Command/GenerateCommand.php b/Command/GenerateCommand.php index 79f06f3ac55c36a85ca053d0bd416d8458bc764c..70978c8cacdbd137e2dce4c156e9fdc12f4f544e 100644 --- a/Command/GenerateCommand.php +++ b/Command/GenerateCommand.php @@ -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(); } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 4cd2751af482f29a77ac10d72c20f4c8aa932085..1445d992aba8c402ec8d0acd6ce06e7043e6396e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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')) diff --git a/Model/Decorator/AttributeDecorator.php b/Model/Decorator/AttributeDecorator.php new file mode 100644 index 0000000000000000000000000000000000000000..e10be2838d38b469222b57ae02062cd060aca1ca --- /dev/null +++ b/Model/Decorator/AttributeDecorator.php @@ -0,0 +1,42 @@ +<?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 + ) + ); + } + } +} diff --git a/Model/Decorator/MethodDecorator.php b/Model/Decorator/MethodDecorator.php new file mode 100644 index 0000000000000000000000000000000000000000..f66ca54acf7f1908ad97074ca4dd64b3cd13ce31 --- /dev/null +++ b/Model/Decorator/MethodDecorator.php @@ -0,0 +1,47 @@ +<?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)) + ) + ); + } + } +}