GenerateCommand.php 1.47 KB
Newer Older
1
<?php declare(strict_types=1);
2
/*
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
3
 * Copyright (C) 2016-2017 IRSTEA
4
5
 * All rights reserved.
 */
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
6

7
8
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
/**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
17
 * Description of ImportAffiliationCommand.
18
 */
19
class GenerateCommand extends ContainerAwareCommand
20
21
22
23
{
    protected function configure()
    {
        $this
24
            ->setName('irstea:plantuml:generate')
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
25
            ->setDescription('Génère un graphe en PlantUML.')
26
27
28
            ->addArgument('graph', InputArgument::REQUIRED, 'Nom du graphe à générer');
    }

29
    /**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
30
     * @param InputInterface  $input
31
32
33
34
35
     * @param OutputInterface $output
     * @SuppressWarnings(UnusedFormalParameter)
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
36
        $name = $input->getArgument('graph');
37
38
39
        $serviceId = "irstea_plant_uml.graph.$name";

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

43
        $writer = new OutputWriter($output);
44
45
        $graph = $this->getContainer()->get($serviceId);
        $graph->visitAll();
46
        $graph->writeTo($writer);
47
    }
48
}