diff --git a/Command/EntitySchemaCommand.php b/Command/EntitySchemaCommand.php index 6edbc7cd9d24e7447aa57b2167339e9b54b5586f..0a2a7374c6dcac3873b3688ec1dfccc7d8123ecf 100644 --- a/Command/EntitySchemaCommand.php +++ b/Command/EntitySchemaCommand.php @@ -15,9 +15,12 @@ use Irstea\PlantUmlBundle\Model\ClassVisitor; use Irstea\PlantUmlBundle\Model\Decorator\CompositeDecorator; use Irstea\PlantUmlBundle\Model\Decorator\FilteringDecorator; use Irstea\PlantUmlBundle\Model\Decorator\InheritanceDecorator; +use Irstea\PlantUmlBundle\Model\Filter\DirectoryFilter; +use Irstea\PlantUmlBundle\Model\Filter\NamespaceFilter; use Irstea\PlantUmlBundle\Model\Filter\Whitelist; use Irstea\PlantUmlBundle\Model\Namespace_\BundleNamespace; use Irstea\PlantUmlBundle\Model\Namespace_\FlatNamespace; +use Irstea\PlantUmlBundle\Model\Namespace_\MappedNamespace; use Irstea\PlantUmlBundle\Writer\OutputWriter; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; @@ -49,16 +52,22 @@ class EntitySchemaCommand extends ContainerAwareCommand { /* @var $manager EntityManagerInterface */ $manager = $this->getContainer()->get('doctrine.orm.entity_manager'); - $factory = $manager->getMetadataFactory(); + $factory = $manager->getMetadataFactory(); $allMetadata = $factory->getAllMetadata(); - $classes = array_map( - function(ClassMetadata $metadata) { return $metadata->getName(); }, - $allMetadata + $decorationFilter = new DirectoryFilter( + [ + realpath($this->getContainer()->getParameter('kernel.root_dir').'/../src') + ] ); - $namespace = new BundleNamespace($this->getContainer()->getParameter('kernel.bundles')); + $bundleNamespace = 'Irstea\\SygadeBundle\\Entity\\'; + + $entityFilter = new NamespaceFilter([$bundleNamespace]); + + //$namespace = new BundleNamespace($this->getContainer()->getParameter('kernel.bundles')); + $namespace = new MappedNamespace([$bundleNamespace => '']); $decorator = new FilteringDecorator( new CompositeDecorator([ @@ -66,12 +75,17 @@ class EntitySchemaCommand extends ContainerAwareCommand new EntityDecorator($factory), new AssociationDecorator($factory), ]), - new Whitelist($classes) + $decorationFilter ); $visitor = new ClassVisitor($decorator, null, $namespace); - array_walk($classes, [$visitor, 'visitClass']); + foreach($allMetadata as $metadata) { + /* @var $metadata ClassMetadata */ + if ($entityFilter->accept($metadata->getReflectionClass())) { + $visitor->visitClass($metadata->getName()); + } + } $writer = new OutputWriter($output); $writer->write("@startuml\n"); diff --git a/Model/Filter/DirectoryFilter.php b/Model/Filter/DirectoryFilter.php new file mode 100644 index 0000000000000000000000000000000000000000..02a8f81dd78da225c8644ae8d8c31d403af418ad --- /dev/null +++ b/Model/Filter/DirectoryFilter.php @@ -0,0 +1,40 @@ +<?php + +/* + * © 2016 IRSTEA + * Guillaume Perréal <guillaume.perreal@irstea.fr> + * Tous droits réservés. + */ + +namespace Irstea\PlantUmlBundle\Model\Filter; + +use Irstea\PlantUmlBundle\Model\ClassFilterInterface; +use ReflectionClass; + +/** + * Description of DirectoryFilter + * + * @author Guillaume Perréal <guillaume.perreal@irstea.fr> + */ +class DirectoryFilter implements ClassFilterInterface +{ + /** + * @var string[] + */ + private $accepted = []; + + public function __construct(array $accepted) + { + $this->accepted = $accepted; + } + + public function accept(ReflectionClass $class) + { + foreach($this->accepted as $path) { + if (strpos($class->getFileName(), $path) === 0) { + return true; + } + } + return false; + } +} diff --git a/Model/Filter/NamespaceFilter.php b/Model/Filter/NamespaceFilter.php new file mode 100644 index 0000000000000000000000000000000000000000..dcafefc871fb3095526a91eef3cd80e9e9023e16 --- /dev/null +++ b/Model/Filter/NamespaceFilter.php @@ -0,0 +1,40 @@ +<?php + +/* + * © 2016 IRSTEA + * Guillaume Perréal <guillaume.perreal@irstea.fr> + * Tous droits réservés. + */ + +namespace Irstea\PlantUmlBundle\Model\Filter; + +use Irstea\PlantUmlBundle\Model\ClassFilterInterface; +use ReflectionClass; + +/** + * Description of DirectoryFilter + * + * @author Guillaume Perréal <guillaume.perreal@irstea.fr> + */ +class NamespaceFilter implements ClassFilterInterface +{ + /** + * @var string[] + */ + private $accepted = []; + + public function __construct(array $accepted) + { + $this->accepted = $accepted; + } + + public function accept(ReflectionClass $class) + { + foreach($this->accepted as $namespace) { + if (strpos($class->getName(), $namespace) === 0) { + return true; + } + } + return false; + } +}