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