Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Command;
  6.  
  7. use Doctrine\DBAL\Schema\Visitor\Graphviz;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\Console\Command\Command;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12. use Symfony\Component\Console\Style\SymfonyStyle;
  13.  
  14. class DoctrinevizCommand extends Command
  15. {
  16. /**
  17. * {@inheritdoc}
  18. */
  19. protected static $defaultName = 'doctrine:schema:graphviz';
  20.  
  21. /**
  22. * @var EntityManagerInterface
  23. */
  24. protected $em;
  25.  
  26. /**
  27. * Constructor.
  28. */
  29. public function __construct(EntityManagerInterface $em)
  30. {
  31. parent::__construct();
  32. $this->em = $em;
  33. }
  34.  
  35. /**
  36. * {@inheritdoc}
  37. */
  38. protected function configure(): void
  39. {
  40. $this
  41. ->setDescription('Get dot from database schema.')
  42. ->setHelp(sprintf('Usage: bin/console %s > /tmp/db-schema.dot && dot -Tpdf /tmp/db-schema.dot > docs/db-schema.pdf && rm -f /tmp/db-schema.dot', $this->getName()))
  43. ;
  44. }
  45.  
  46. /**
  47. * {@inheritdoc}
  48. */
  49. protected function execute(InputInterface $input, OutputInterface $output): void
  50. {
  51. $io = new SymfonyStyle($input, $output);
  52. $io->writeln($this->getDot());
  53. }
  54.  
  55. /**
  56. * Get dot from database schema.
  57. */
  58. protected function getDot(): string
  59. {
  60. $schema = $this->em->getConnection()->getSchemaManager()->createSchema();
  61. $visitor = new Graphviz();
  62. $schema->visit($visitor);
  63.  
  64. return $visitor->getOutput();
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement