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