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

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

No related merge requests found
Showing with 101 additions and 2 deletions
+101 -2
...@@ -17,10 +17,12 @@ use Irstea\PlantUmlBundle\Finder\FilteringFinder; ...@@ -17,10 +17,12 @@ use Irstea\PlantUmlBundle\Finder\FilteringFinder;
use Irstea\PlantUmlBundle\Finder\FinderInterface; use Irstea\PlantUmlBundle\Finder\FinderInterface;
use Irstea\PlantUmlBundle\Model\ClassFilterInterface; use Irstea\PlantUmlBundle\Model\ClassFilterInterface;
use Irstea\PlantUmlBundle\Model\ClassVisitor; use Irstea\PlantUmlBundle\Model\ClassVisitor;
use Irstea\PlantUmlBundle\Model\Decorator\AttributeDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\CompositeDecorator; use Irstea\PlantUmlBundle\Model\Decorator\CompositeDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\FilteringDecorator; use Irstea\PlantUmlBundle\Model\Decorator\FilteringDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\InheritanceDecorator; use Irstea\PlantUmlBundle\Model\Decorator\InheritanceDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\InterfaceDecorator; use Irstea\PlantUmlBundle\Model\Decorator\InterfaceDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\MethodDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\NullDecorator; use Irstea\PlantUmlBundle\Model\Decorator\NullDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\TraitDecorator; use Irstea\PlantUmlBundle\Model\Decorator\TraitDecorator;
use Irstea\PlantUmlBundle\Model\DecoratorInterface; use Irstea\PlantUmlBundle\Model\DecoratorInterface;
...@@ -205,12 +207,18 @@ class GenerateCommand extends ContainerAwareCommand ...@@ -205,12 +207,18 @@ class GenerateCommand extends ContainerAwareCommand
return new InterfaceDecorator(); return new InterfaceDecorator();
case 'traits': case 'traits':
return new TraitDecorator(); return new TraitDecorator();
case 'attributes':
return new AttributeDecorator();
case 'methods':
return new MethodDecorator();
case 'entity': case 'entity':
return new EntityDecorator($this->entityManager->getMetadataFactory()); return new EntityDecorator($this->entityManager->getMetadataFactory());
case 'associations': case 'associations':
return new AssociationDecorator($this->entityManager->getMetadataFactory()); return new AssociationDecorator($this->entityManager->getMetadataFactory());
case 'fields': case 'fields':
return new FieldDecorator($this->entityManager->getMetadataFactory()); return new FieldDecorator($this->entityManager->getMetadataFactory());
default:
return NullDecorator::instance();
} }
} }
......
...@@ -48,6 +48,8 @@ class Configuration implements ConfigurationInterface ...@@ -48,6 +48,8 @@ class Configuration implements ConfigurationInterface
{ {
$node = (new TreeBuilder())->root('graphs'); $node = (new TreeBuilder())->root('graphs');
$decorators = ['inheritance', 'traits', 'interfaces', 'entity', 'associations', 'properties', 'methods', 'fields', 'attributes'];
$node $node
->useAttributeAsKey('name') ->useAttributeAsKey('name')
->prototype('array') ->prototype('array')
...@@ -85,9 +87,9 @@ class Configuration implements ConfigurationInterface ...@@ -85,9 +87,9 @@ class Configuration implements ConfigurationInterface
->addDefaultsIfNotSet() ->addDefaultsIfNotSet()
->children() ->children()
->arrayNode('decorators') ->arrayNode('decorators')
->defaultValue(['inheritance', 'traits', 'interfaces', 'entity', 'associations', 'properties', 'methods', 'fields']) ->defaultValue($decorators)
->prototype('enum') ->prototype('enum')
->values(['inheritance', 'traits', 'interfaces', 'entity', 'associations', 'properties', 'methods', 'fields']) ->values($decorators)
->end() ->end()
->end() ->end()
->append($this->buildFilterNode('include')) ->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))
)
);
}
}
}
Supports Markdown
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