| @@ 18-63 (lines=46) @@ | ||
| 15 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
| 16 | ||
| 17 | ||
| 18 | final class RegisterMigrationsEventSubscriber implements EventSubscriberInterface | |
| 19 | { | |
| 20 | ||
| 21 | /** | |
| 22 | * @var Configuration | |
| 23 | */ | |
| 24 | private $configuration; | |
| 25 | ||
| 26 | ||
| 27 | public function __construct(Configuration $configuration) | |
| 28 | 	{ | |
| 29 | $this->configuration = $configuration; | |
| 30 | } | |
| 31 | ||
| 32 | ||
| 33 | /** | |
| 34 | 	 * {@inheritdoc} | |
| 35 | */ | |
| 36 | public static function getSubscribedEvents() | |
| 37 | 	{ | |
| 38 | return [ConsoleEvents::COMMAND => 'registerMigrations']; | |
| 39 | } | |
| 40 | ||
| 41 | ||
| 42 | public function registerMigrations(ConsoleCommandEvent $event) | |
| 43 | 	{ | |
| 44 | $command = $event->getCommand(); | |
| 45 | 		if ( ! $this->isMigrationCommand($command)) { | |
| 46 | return; | |
| 47 | } | |
| 48 | ||
| 49 | $this->configuration->registerMigrationsFromDirectory( | |
| 50 | $this->configuration->getMigrationsDirectory() | |
| 51 | ); | |
| 52 | } | |
| 53 | ||
| 54 | ||
| 55 | /** | |
| 56 | * @return bool | |
| 57 | */ | |
| 58 | private function isMigrationCommand(Command $command) | |
| 59 | 	{ | |
| 60 | return $command instanceof AbstractCommand; | |
| 61 | } | |
| 62 | ||
| 63 | } | |
| 64 | ||
| @@ 18-61 (lines=44) @@ | ||
| 15 | use Zenify\DoctrineMigrations\OutputWriter; | |
| 16 | ||
| 17 | ||
| 18 | final class SetConsoleOutputEventSubscriber implements EventSubscriberInterface | |
| 19 | { | |
| 20 | ||
| 21 | /** | |
| 22 | * @var OutputWriter | |
| 23 | */ | |
| 24 | private $outputWriter; | |
| 25 | ||
| 26 | ||
| 27 | public function __construct(OutputWriter $outputWriter) | |
| 28 | 	{ | |
| 29 | $this->outputWriter = $outputWriter; | |
| 30 | } | |
| 31 | ||
| 32 | ||
| 33 | /** | |
| 34 | 	 * {@inheritdoc} | |
| 35 | */ | |
| 36 | public static function getSubscribedEvents() | |
| 37 | 	{ | |
| 38 | return [ConsoleEvents::COMMAND => 'setOutputWriter']; | |
| 39 | } | |
| 40 | ||
| 41 | ||
| 42 | public function setOutputWriter(ConsoleCommandEvent $event) | |
| 43 | 	{ | |
| 44 | $command = $event->getCommand(); | |
| 45 | 		if ( ! $this->isMigrationCommand($command)) { | |
| 46 | return; | |
| 47 | } | |
| 48 | ||
| 49 | $this->outputWriter->setConsoleOutput($event->getOutput()); | |
| 50 | } | |
| 51 | ||
| 52 | ||
| 53 | /** | |
| 54 | * @return bool | |
| 55 | */ | |
| 56 | private function isMigrationCommand(Command $command) | |
| 57 | 	{ | |
| 58 | return $command instanceof AbstractCommand; | |
| 59 | } | |
| 60 | ||
| 61 | } | |
| 62 | ||