ConvertMappingDoctrineCommand.php 1.7 KB

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