Created
April 15, 2016 19:10
-
-
Save chalasr/579d48a98cf6b3d915d2ad9a8a4185de to your computer and use it in GitHub Desktop.
Overridde the Doctrine UpdateSchemaCommand (doctrine:schema:update command).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/AppBundle/Command/CustomUpdateSchemaCommand.php | |
<?php | |
namespace AppBundle\Command; | |
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand; | |
use Doctrine\ORM\EntityManagerInterface; | |
use Symfony\Component\Console\Input\ArrayInput; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Console\Command\Command; | |
class CustomUpdateSchemaCommand extends UpdateSchemaDoctrineCommand | |
{ | |
/** @var EntityManagerInterface */ | |
private $em; | |
/** | |
* @param EntityManagerInterface $em | |
*/ | |
public function __construct(EntityManagerInterface $em) | |
{ | |
$this->em = $em; | |
parent::__construct(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
protected function configure() | |
{ | |
parent::configure(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$output->writeln('Hello world'); | |
$repository = $this->em->getRepository('AppBundle:Foo'); | |
// Perform your custom query | |
return parent::execute($input, $output); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
app.command.custom_schema_update_command: | |
class: App\SportBundle\Command\CustomUpdateSchemaCommand | |
arguments: ["@doctrine.orm.entity_manager"] | |
tags: | |
- { name: console.command } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related http://stackoverflow.com/a/36655069/4363634