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

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

9
use Irstea\PlantUmlBundle\Writer\OutputWriter;
10
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
11
use Symfony\Component\Console\Input\InputArgument;
12
13
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
15

16
17
18
19
20
/**
 * Description of ImportAffiliationCommand
 *
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
 */
21
class GenerateCommand extends ContainerAwareCommand
22
23
24
25
{
    protected function configure()
    {
        $this
26
27
28
29
30
            ->setName('irstea:plantuml:generate')
            ->setDescription("Génère un graphe en PlantUML.")
            ->addArgument('graph', InputArgument::REQUIRED, 'Nom du graphe à générer');
    }

31
32
33
34
35
36
37
38
39
    /**
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     *
     * @SuppressWarnings(UnusedFormalParameter)
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
40
        $name = $input->getArgument('graph');
41
42
43
        $serviceId = "irstea_plant_uml.graph.$name";

        if (!$this->getContainer()->has($serviceId)) {
44
45
            throw new InvalidArgumentException("Le graphe '$name' n'est pas défini.");
        }
46

47
        $writer = new OutputWriter($output);
48
49
        $graph = $this->getContainer()->get($serviceId);
        $graph->visitAll();
50
        $graph->writeTo($writer);
51
    }
52
}