GenerateCommand.php 1.51 KiB
<?php
/*
 * Copyright (C) 2015 IRSTEA
 * All rights reserved.
 */
namespace Irstea\PlantUmlBundle\Command;
use Irstea\PlantUmlBundle\Writer\OutputWriter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
/**
 * Description of ImportAffiliationCommand
 * @author Guillaume Perréal <guillaume.perreal@irstea.fr>
class GenerateCommand extends ContainerAwareCommand
    protected function configure()
        $this
            ->setName('irstea:plantuml:generate')
            ->setDescription("Génère un graphe en PlantUML.")
            ->addArgument('graph', InputArgument::REQUIRED, 'Nom du graphe à générer');
    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @SuppressWarnings(UnusedFormalParameter)
    protected function execute(InputInterface $input, OutputInterface $output)
        $name = $input->getArgument('graph');
        $serviceId = "irstea_plant_uml.graph.$name";
        if (!$this->getContainer()->has($serviceId)) {
            throw new InvalidArgumentException("Le graphe '$name' n'est pas défini.");
        $writer = new OutputWriter($output);
        $graph = $this->getContainer()->get($serviceId);
        $graph->visitAll();
        $graph->writeTo($writer);