1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GarbuzIvan\LaravelGeneratorPackage\Builder; |
6
|
|
|
|
7
|
|
|
class DirGenerator |
8
|
|
|
{ |
9
|
|
|
private Package $package; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @param Package $package |
13
|
|
|
* @return bool |
14
|
|
|
*/ |
15
|
3 |
|
public function make(Package $package): bool |
16
|
|
|
{ |
17
|
3 |
|
$this->package = $package; |
18
|
3 |
|
$this->mkdir($this->package->getPath('.github/workflows')); |
19
|
3 |
|
$this->mkdir($this->package->getPath('config')); |
20
|
3 |
|
$this->mkdir($this->package->getPath('database/migrations')); |
21
|
3 |
|
$this->mkdir($this->package->getPath('src/Controllers')); |
22
|
3 |
|
$this->mkdir($this->package->getPath('src/Models')); |
23
|
3 |
|
$this->mkdir($this->package->getPath('src/Cases')); |
24
|
3 |
|
$this->makeTests(); |
25
|
3 |
|
$this->makeSeeds(); |
26
|
3 |
|
$this->makeApi(); |
27
|
3 |
|
$this->makeApiFrontend(); |
28
|
3 |
|
$this->makeLaravelAdmin(); |
29
|
3 |
|
return true; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return bool |
34
|
|
|
*/ |
35
|
3 |
|
public function makeTests(): bool |
36
|
|
|
{ |
37
|
3 |
|
if (!$this->package->getGeneratorTests()) { |
38
|
1 |
|
return false; |
39
|
|
|
} |
40
|
2 |
|
$this->mkdir($this->package->getPath('tests')); |
41
|
2 |
|
return true; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
3 |
|
public function makeSeeds(): bool |
48
|
|
|
{ |
49
|
3 |
|
if (!$this->package->getGeneratorSeed()) { |
50
|
1 |
|
return false; |
51
|
|
|
} |
52
|
2 |
|
$this->mkdir($this->package->getPath('database/Seeders')); |
53
|
2 |
|
$this->mkdir($this->package->getPath('database/Factories')); |
54
|
|
|
return true; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return bool |
59
|
3 |
|
*/ |
60
|
|
|
public function makeApi(): bool |
61
|
3 |
|
{ |
62
|
1 |
|
if (!$this->package->getGeneratorApi()) { |
63
|
|
|
return false; |
64
|
2 |
|
} |
65
|
2 |
|
$this->mkdir($this->package->getPath('src/Cases/Api')); |
66
|
|
|
return true; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return bool |
71
|
3 |
|
*/ |
72
|
|
|
public function makeApiFrontend(): bool |
73
|
3 |
|
{ |
74
|
1 |
|
if (!$this->package->getGeneratorApiFrontend()) { |
75
|
|
|
return false; |
76
|
2 |
|
} |
77
|
2 |
|
$this->mkdir($this->package->getPath('src/Cases/Api/Frontend')); |
78
|
|
|
return true; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return bool |
83
|
3 |
|
*/ |
84
|
|
|
public function makeLaravelAdmin(): bool |
85
|
3 |
|
{ |
86
|
1 |
|
if (!$this->package->getGeneratorLaravelAdmin()) { |
87
|
|
|
return false; |
88
|
2 |
|
} |
89
|
2 |
|
$this->mkdir($this->package->getPath('src/Admin')); |
90
|
|
|
return true; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $path |
95
|
|
|
* @return bool |
96
|
4 |
|
*/ |
97
|
|
|
public function mkdir(string $path): bool |
98
|
4 |
|
{ |
99
|
1 |
|
if (!file_exists($path)) { |
100
|
1 |
|
mkdir($path, 0777, true); |
101
|
|
|
return true; |
102
|
4 |
|
} |
103
|
|
|
return false; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|