1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelModulize\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use LaravelModulize\Contracts\ModulizerRepositoryInterface; |
8
|
|
|
|
9
|
|
|
class CreateModuleCommand extends Command |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The name and signature of the console command. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $signature = 'modulize:make:module {module}'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Sets up the default folder structure for the module.'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Instance of the repository |
27
|
|
|
* |
28
|
|
|
* @var \LaravelModulize\Contracts\ModulizerRepositoryInterface |
29
|
|
|
*/ |
30
|
|
|
protected $repository; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create a new command instance. |
34
|
|
|
* |
35
|
|
|
* @param \LaravelModulize\Contracts\ModulizerRepositoryInterface $repository |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
public function __construct(ModulizerRepositoryInterface $repository) |
39
|
|
|
{ |
40
|
|
|
parent::__construct(); |
41
|
|
|
|
42
|
|
|
$this->repository = $repository; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Execute the console command. |
47
|
|
|
* |
48
|
|
|
* @return mixed |
49
|
|
|
*/ |
50
|
|
|
public function handle() |
51
|
|
|
{ |
52
|
|
|
$module = $this->argument('module'); |
53
|
|
|
|
54
|
|
|
$this->generateDirectives($module); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function generateDirectives(string $module) |
58
|
|
|
{ |
59
|
|
|
$folders = config('modulizer.default_folders'); |
60
|
|
|
$modulePath = $this->repository->getModulePath($module); |
61
|
|
|
|
62
|
|
|
foreach ($folders as $folder) { |
63
|
|
|
$this->makeFileTree($modulePath, $folder); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function makeFileTree($path, $folders) |
68
|
|
|
{ |
69
|
|
|
if(is_array($folders)) { |
70
|
|
|
if (is_string(key($folders))) { |
71
|
|
|
$folderName = key($folders); |
72
|
|
|
$path = "{$path}/{$folderName}"; |
73
|
|
|
} |
74
|
|
|
foreach ($folders as $subFolders) { |
75
|
|
|
$this->makeFileTree($path, $subFolders); |
76
|
|
|
} |
77
|
|
|
} else { |
78
|
|
|
$this->repository->createDirectory("{$path}/{$folders}"); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|