En raison du déménagement des baies serveurs, les services gitlab.irstea.fr et mattermost.irstea.fr seront interrompus le samedi 2 octobre 2021 au matin. Ils devraient revenir à la normale dans la journée.

GenerateCommand.php 3.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<?php

/*
 * Copyright (C) 2015 IRSTEA
 * All rights reserved.
 */
namespace Irstea\PlantUmlBundle\Command;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
11
use Irstea\PlantUmlBundle\Doctrine\AssociationDecorator;
12
use Irstea\PlantUmlBundle\Doctrine\DoctrineNamespace;
13
use Irstea\PlantUmlBundle\Doctrine\EntityDecorator;
14
15
16
17
use Irstea\PlantUmlBundle\Model\ClassVisitor;
use Irstea\PlantUmlBundle\Model\Decorator\CompositeDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\FilteringDecorator;
use Irstea\PlantUmlBundle\Model\Decorator\InheritanceDecorator;
18
19
use Irstea\PlantUmlBundle\Model\Filter\DirectoryFilter;
use Irstea\PlantUmlBundle\Model\Filter\NamespaceFilter;
20
use Irstea\PlantUmlBundle\Model\Filter\Whitelist;
21
use Irstea\PlantUmlBundle\Model\Namespace_\BundleNamespace;
22
use Irstea\PlantUmlBundle\Model\Namespace_\FlatNamespace;
23
use Irstea\PlantUmlBundle\Model\Namespace_\MappedNamespace;
24
use Irstea\PlantUmlBundle\Writer\OutputWriter;
25
26
27
28
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
 * Description of ImportAffiliationCommand
 *
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
 */
class EntitySchemaCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('irstea:plantuml:entities')
            ->setDescription("Génère un schéma PlantUML à partir des métadonnées de Doctrine.");
    }

    /**
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     *
     * @SuppressWarnings(UnusedFormalParameter)
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /* @var $manager EntityManagerInterface */
        $manager = $this->getContainer()->get('doctrine.orm.entity_manager');

56
        $factory = $manager->getMetadataFactory();
57
58
        $allMetadata = $factory->getAllMetadata();

59
60
61
62
        $decorationFilter = new DirectoryFilter(
            [
                realpath($this->getContainer()->getParameter('kernel.root_dir').'/../src')
            ]
63
64
        );

65
66
67
68
69
70
        $bundleNamespace = 'Irstea\\SygadeBundle\\Entity\\';

        $entityFilter = new NamespaceFilter([$bundleNamespace]);

        //$namespace = new BundleNamespace($this->getContainer()->getParameter('kernel.bundles'));
        $namespace = new MappedNamespace([$bundleNamespace => '']);
71

72
        $decorator = new FilteringDecorator(
73
74
75
76
77
            new CompositeDecorator([
                new InheritanceDecorator(),
                new EntityDecorator($factory),
                new AssociationDecorator($factory),
            ]),
78
            $decorationFilter
79
80
        );

81
        $visitor = new ClassVisitor($decorator, null, $namespace);
82

83
84
85
86
87
88
        foreach($allMetadata as $metadata) {
            /* @var $metadata ClassMetadata */
            if ($entityFilter->accept($metadata->getReflectionClass())) {
                $visitor->visitClass($metadata->getName());
            }
        }
89

90
91
92
93
        $writer = new OutputWriter($output);
        $writer->write("@startuml\n");
        $visitor->outputTo($writer);
        $writer->write("@enduml\n");
94
95
    }
}