@@ 16-38 (lines=23) @@ | ||
13 | * |
|
14 | * @package Cart\Commands |
|
15 | */ |
|
16 | class MigrateCommand extends Command |
|
17 | { |
|
18 | protected function configure() : void |
|
19 | { |
|
20 | $this |
|
21 | ->setName('cart:migrate') |
|
22 | ->setDescription('Creates a new table cart.'); |
|
23 | } |
|
24 | ||
25 | protected function execute(InputInterface $input, OutputInterface $output) : void |
|
26 | { |
|
27 | foreach (Finder::create()->files()->name('*.php')-> |
|
28 | in(__DIR__. '/../../migrations') as $file) { |
|
29 | $classes = get_declared_classes(); |
|
30 | include $file->getRealPath(); |
|
31 | $diff = array_diff(get_declared_classes(), $classes); |
|
32 | $class = reset($diff); |
|
33 | ||
34 | (new $class())->up(); |
|
35 | $output->writeln('<fg=green>Success added migration: ' . basename($file->getFilename(), '.php') .'</>'); |
|
36 | } |
|
37 | } |
|
38 | } |
@@ 10-32 (lines=23) @@ | ||
7 | use Symfony\Component\Console\Output\OutputInterface; |
|
8 | use Symfony\Component\Finder\Finder; |
|
9 | ||
10 | class MigrateRollbackCommand extends Command |
|
11 | { |
|
12 | protected function configure() |
|
13 | { |
|
14 | $this |
|
15 | ->setName('cart:migrate:rollback') |
|
16 | ->setDescription('Deletes tables cart.'); |
|
17 | } |
|
18 | ||
19 | ||
20 | protected function execute(InputInterface $input, OutputInterface $output) |
|
21 | { |
|
22 | foreach (Finder::create()->files()->name('*.php') |
|
23 | ->in(__DIR__. '/../../migrations') as $file) { |
|
24 | $classes = get_declared_classes(); |
|
25 | include $file->getRealPath(); |
|
26 | $diff = array_diff(get_declared_classes(), $classes); |
|
27 | $class = reset($diff); |
|
28 | (new $class())->down(); |
|
29 | $output->writeln('<fg=green>Success rollback migration: ' . basename($file->getFilename(), '.php') .'</>'); |
|
30 | } |
|
31 | } |
|
32 | } |