EntitySchemaCommand.php 2.40 KiB
<?php
/*
 * Copyright (C) 2015 IRSTEA
 * All rights reserved.
 */
namespace Irstea\PlantUmlBundle\Command;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Irstea\PlantUmlBundle\Doctrine\AssociationDecorator;
use Irstea\PlantUmlBundle\Doctrine\EntityDecorator;
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\Whitelist;
use Irstea\PlantUmlBundle\Model\Namespace_\FlatNamespace;
use Irstea\PlantUmlBundle\Writer\OutputWriter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
 * 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');
        $factory = $manager->getMetadataFactory();
        $allMetadata = $factory->getAllMetadata();
        $classes = array_map(
            function(ClassMetadata $metadata) { return $metadata->getName(); },
            $allMetadata
        $decorator = new FilteringDecorator(
            new CompositeDecorator([
                new InheritanceDecorator(),
                new EntityDecorator($factory),
                new AssociationDecorator($factory),
            ]),
            new Whitelist($classes)
        $visitor = new ClassVisitor($decorator, null, new FlatNamespace());
        array_walk($classes, [$visitor, 'visitClass']);
7172737475767778
$writer = new OutputWriter($output); $writer->write("@startuml\n"); $visitor->outputTo($writer); $writer->write("@enduml\n"); } }