From 762ddf49187559dfba5fe7bf9591c5e6242d6670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr> Date: Fri, 11 Mar 2016 16:13:32 +0100 Subject: [PATCH] =?UTF-8?q?Premi=C3=A8re=20version=20du=20support=20des=20?= =?UTF-8?q?attributs=20et=20des=20m=C3=A9thodes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Command/GenerateCommand.php | 8 +++++ DependencyInjection/Configuration.php | 6 ++-- Model/Decorator/AttributeDecorator.php | 42 +++++++++++++++++++++++ Model/Decorator/MethodDecorator.php | 47 ++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 Model/Decorator/AttributeDecorator.php create mode 100644 Model/Decorator/MethodDecorator.php diff --git a/Command/GenerateCommand.php b/Command/GenerateCommand.php index 79f06f3..70978c8 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 4cd2751..1445d99 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 0000000..e10be28 --- /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 0000000..f66ca54 --- /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)) + ) + ); + } + } +} -- GitLab