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('config')); |
19
|
3 |
|
$this->mkdir($this->package->getPath('migrations')); |
20
|
3 |
|
$this->mkdir($this->package->getPath('src/Controllers')); |
21
|
3 |
|
$this->mkdir($this->package->getPath('src/Models')); |
22
|
3 |
|
$this->mkdir($this->package->getPath('src/Cases')); |
23
|
3 |
|
$this->makeTests(); |
24
|
3 |
|
$this->makeSeeds(); |
25
|
3 |
|
$this->makeApi(); |
26
|
3 |
|
$this->makeApiFrontend(); |
27
|
3 |
|
$this->makeLaravelAdmin(); |
28
|
3 |
|
return true; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return bool |
33
|
|
|
*/ |
34
|
3 |
|
public function makeTests(): bool |
35
|
|
|
{ |
36
|
3 |
|
if (!$this->package->getGeneratorTests()) { |
37
|
1 |
|
return false; |
38
|
|
|
} |
39
|
2 |
|
$this->mkdir($this->package->getPath('tests')); |
40
|
2 |
|
return true; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
3 |
|
public function makeSeeds(): bool |
47
|
|
|
{ |
48
|
3 |
|
if (!$this->package->getGeneratorSeed()) { |
49
|
1 |
|
return false; |
50
|
|
|
} |
51
|
2 |
|
$this->mkdir($this->package->getPath('seeds')); |
52
|
2 |
|
return true; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
3 |
|
public function makeApi(): bool |
59
|
|
|
{ |
60
|
3 |
|
if (!$this->package->getGeneratorApi()) { |
61
|
1 |
|
return false; |
62
|
|
|
} |
63
|
2 |
|
$this->mkdir($this->package->getPath('src/Cases/Api')); |
64
|
2 |
|
return true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
3 |
|
public function makeApiFrontend(): bool |
71
|
|
|
{ |
72
|
3 |
|
if (!$this->package->getGeneratorApiFrontend()) { |
73
|
1 |
|
return false; |
74
|
|
|
} |
75
|
2 |
|
$this->mkdir($this->package->getPath('src/Cases/Api/Frontend')); |
76
|
2 |
|
return true; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return bool |
81
|
|
|
*/ |
82
|
3 |
|
public function makeLaravelAdmin(): bool |
83
|
|
|
{ |
84
|
3 |
|
if (!$this->package->getGeneratorLaravelAdmin()) { |
85
|
1 |
|
return false; |
86
|
|
|
} |
87
|
2 |
|
$this->mkdir($this->package->getPath('src/Admin')); |
88
|
2 |
|
return true; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $path |
93
|
|
|
* @return bool |
94
|
|
|
*/ |
95
|
4 |
|
public function mkdir(string $path): bool |
96
|
|
|
{ |
97
|
4 |
|
if (!file_exists($path)) { |
98
|
1 |
|
mkdir($path, 0777, true); |
99
|
1 |
|
return true; |
100
|
|
|
} |
101
|
4 |
|
return false; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|