GenerateCommand.php 1.45 KB
Newer Older
1
2
<?php
/*
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
36
     * @param OutputInterface $output
     *
     * @SuppressWarnings(UnusedFormalParameter)
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
37
        $name = $input->getArgument('graph');
38
39
40
        $serviceId = "irstea_plant_uml.graph.$name";

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

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