1: | <?php |
2: | |
3: | namespace Aurora\System\Console\Commands; |
4: | |
5: | use Symfony\Component\Console\Command\Command; |
6: | use Illuminate\Support\Facades\File; |
7: | use Symfony\Component\Finder\Finder; |
8: | use Symfony\Component\Finder\SplFileInfo; |
9: | |
10: | class BaseCommand extends Command |
11: | { |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | protected function getMigrationPaths($input) |
18: | { |
19: | |
20: | |
21: | |
22: | if ($input->getOption('path')) { |
23: | return collect($input->getOption('path'))->map(function ($path) use ($input) { |
24: | return !$this->usingRealPath($input) |
25: | ? \Aurora\Api::RootPath() . $path |
26: | : $path; |
27: | })->all(); |
28: | } |
29: | |
30: | return array_merge( |
31: | [$this->getSystemMigrationsPath()], |
32: | $this->migrator->paths(), |
33: | $this->getMigrationPath() |
34: | ); |
35: | } |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | protected function usingRealPath($input) |
43: | { |
44: | return $input->hasOption('realpath') && $input->getOption('realpath'); |
45: | } |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | |
52: | |
53: | protected function getMigrationPath($sRequiredModule = null) |
54: | { |
55: | if ($sRequiredModule) { |
56: | if ($sRequiredModule === 'system') { |
57: | $sPath = $this->getSystemMigrationsPath(); |
58: | } else { |
59: | $sPath = \Aurora\Api::GetModuleManager()->GetModulePath($sRequiredModule) . $sRequiredModule . DIRECTORY_SEPARATOR . 'Migrations'; |
60: | } |
61: | |
62: | if (!file_exists($sPath)) { |
63: | mkdir($sPath, 0755, true); |
64: | } |
65: | |
66: | return $sPath; |
67: | } else { |
68: | $aModules = \Aurora\Api::GetModuleManager()->GetModulesPaths(); |
69: | return array_map(function ($sModule, $sPath) { |
70: | return $sPath . $sModule . DIRECTORY_SEPARATOR . 'Migrations'; |
71: | }, array_keys($aModules), $aModules); |
72: | } |
73: | } |
74: | |
75: | public function getAllModels() |
76: | { |
77: | $finder = Finder::create(); |
78: | $aModules = \Aurora\Api::GetModuleManager()->GetModulesPaths(); |
79: | $aModulesModelsPaths = array_map(function ($sModule, $sPath) { |
80: | return $sPath . $sModule . DIRECTORY_SEPARATOR . 'Models'; |
81: | }, array_keys($aModules), $aModules); |
82: | |
83: | $aDirModels = []; |
84: | foreach ($aModulesModelsPaths as $sModuleModel) { |
85: | if (is_dir($sModuleModel)) { |
86: | $finder |
87: | ->in($sModuleModel) |
88: | ->depth(0); |
89: | $aDirModels = array_keys(\iterator_to_array($finder)); |
90: | } |
91: | } |
92: | |
93: | $aFormatedDirModels = []; |
94: | foreach ($aDirModels as $sDirModel) { |
95: | $fileWithoutExtenstion = explode('.', $sDirModel); |
96: | array_pop($fileWithoutExtenstion); |
97: | $fileWithoutExtenstion = implode('.', $fileWithoutExtenstion); |
98: | $sModelName = explode(DIRECTORY_SEPARATOR, $fileWithoutExtenstion); |
99: | $sModelName = array_pop($sModelName); |
100: | $aFormatedDirModels[$sModelName] = $fileWithoutExtenstion; |
101: | } |
102: | return $aFormatedDirModels; |
103: | } |
104: | |
105: | |
106: | |
107: | |
108: | private function getSystemMigrationsPath() |
109: | { |
110: | return \Aurora\Api::RootPath() . DIRECTORY_SEPARATOR . 'Migrations'; |
111: | } |
112: | } |
113: | |