ConvertMappingDoctrineCommand.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\DoctrineBundle\Command\Proxy;
  11. use Symfony\Component\Console\Input\InputArgument;
  12. use Symfony\Component\Console\Input\InputOption;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\Console\Output\Output;
  16. use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand;
  17. use Doctrine\ORM\Tools\Export\Driver\XmlExporter;
  18. use Doctrine\ORM\Tools\Export\Driver\YamlExporter;
  19. /**
  20. * Convert Doctrine ORM metadata mapping information between the various supported
  21. * formats.
  22. *
  23. * @author Fabien Potencier <fabien@symfony.com>
  24. * @author Jonathan H. Wage <jonwage@gmail.com>
  25. */
  26. class ConvertMappingDoctrineCommand extends ConvertMappingCommand
  27. {
  28. protected function configure()
  29. {
  30. parent::configure();
  31. $this
  32. ->setName('doctrine:mapping:convert')
  33. ->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
  34. ->setHelp(<<<EOT
  35. The <info>doctrine:mapping:convert</info> command converts mapping information
  36. between supported formats:
  37. <info>php app/console doctrine:mapping:convert xml /path/to/output</info>
  38. EOT
  39. );
  40. }
  41. protected function execute(InputInterface $input, OutputInterface $output)
  42. {
  43. DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
  44. return parent::execute($input, $output);
  45. }
  46. protected function getExporter($toType, $destPath)
  47. {
  48. $exporter = parent::getExporter($toType, $destPath);
  49. if ($exporter instanceof XmlExporter) {
  50. $exporter->setExtension('.orm.xml');
  51. } elseif ($exporter instanceof YamlExporter) {
  52. $exporter->setExtension('.orm.yml');
  53. }
  54. return $exporter;
  55. }
  56. }