1<?php
2
3namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
4
5use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand;
6use Doctrine\ORM\Tools\Export\Driver\AbstractExporter;
7use Doctrine\ORM\Tools\Export\Driver\XmlExporter;
8use Doctrine\ORM\Tools\Export\Driver\YamlExporter;
9use Symfony\Component\Console\Input\InputInterface;
10use Symfony\Component\Console\Input\InputOption;
11use Symfony\Component\Console\Output\OutputInterface;
12
13/**
14 * Convert Doctrine ORM metadata mapping information between the various supported
15 * formats.
16 */
17class ConvertMappingDoctrineCommand extends ConvertMappingCommand
18{
19    /**
20     * {@inheritDoc}
21     */
22    protected function configure()
23    {
24        parent::configure();
25        $this
26            ->setName('doctrine:mapping:convert')
27            ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
28    }
29
30    /**
31     * {@inheritDoc}
32     */
33    protected function execute(InputInterface $input, OutputInterface $output)
34    {
35        DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
36
37        return parent::execute($input, $output);
38    }
39
40    /**
41     * @param string $toType
42     * @param string $destPath
43     *
44     * @return AbstractExporter
45     */
46    protected function getExporter($toType, $destPath)
47    {
48        /** @var AbstractExporter $exporter */
49        $exporter = parent::getExporter($toType, $destPath);
50        if ($exporter instanceof XmlExporter) {
51            $exporter->setExtension('.orm.xml');
52        } elseif ($exporter instanceof YamlExporter) {
53            $exporter->setExtension('.orm.yml');
54        }
55
56        return $exporter;
57    }
58}
59