1 | <?php |
||
2 | |||
3 | namespace Src\Cli; |
||
4 | |||
5 | use Luke\Migration\Config\FileCreate; |
||
6 | use Luke\Migration\Config\MigrationFile; |
||
7 | |||
8 | class Cli |
||
9 | { |
||
10 | public $array = []; |
||
11 | |||
12 | public function __construct($commnad) |
||
13 | { |
||
14 | $this->array = [ |
||
15 | "--migration" => function ($file) { |
||
16 | (new FileCreate)->createFile($file); |
||
17 | echo "\e[32mMigration " . $file . " on successfully"; |
||
18 | }, |
||
19 | "--migrate" => function () { |
||
20 | echo "\e[32mStarting the migration\n"; |
||
21 | (new MigrationFile)->actionMigration(); |
||
22 | } |
||
23 | ]; |
||
24 | |||
25 | $this->handleAction($commnad); |
||
26 | } |
||
27 | |||
28 | private function handleAction($commnad) |
||
29 | { |
||
30 | try { |
||
31 | unset($commnad[0]); |
||
32 | $commnad = implode(" ", $commnad); |
||
33 | $values = explode("=", $commnad); |
||
34 | $function = $this->array[$values[0]]; |
||
35 | $function($values[1] ?? null); |
||
36 | } catch (\Exception $e) { |
||
37 | throw new \Exception($e->getMessage); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
38 | } |
||
39 | } |
||
40 | } |
||
41 |