Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- namespace App\Command;
- use Doctrine\DBAL\Schema\Visitor\Graphviz;
- use Doctrine\ORM\EntityManagerInterface;
- use Symfony\Component\Console\Command\Command;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Style\SymfonyStyle;
- class DoctrinevizCommand extends Command
- {
- /**
- * {@inheritdoc}
- */
- protected static $defaultName = 'doctrine:schema:graphviz';
- /**
- * @var EntityManagerInterface
- */
- protected $em;
- /**
- * Constructor.
- */
- public function __construct(EntityManagerInterface $em)
- {
- parent::__construct();
- $this->em = $em;
- }
- /**
- * {@inheritdoc}
- */
- protected function configure(): void
- {
- $this
- ->setDescription('Get dot from database schema.')
- ->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()))
- ;
- }
- /**
- * {@inheritdoc}
- */
- protected function execute(InputInterface $input, OutputInterface $output): void
- {
- $io = new SymfonyStyle($input, $output);
- $io->writeln($this->getDot());
- }
- /**
- * Get dot from database schema.
- */
- protected function getDot(): string
- {
- $schema = $this->em->getConnection()->getSchemaManager()->createSchema();
- $visitor = new Graphviz();
- $schema->visit($visitor);
- return $visitor->getOutput();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement