1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GarbuzIvan\LaravelGeneratorPackage\Builder; |
6
|
|
|
|
7
|
|
|
use GarbuzIvan\LaravelGeneratorPackage\Configuration; |
8
|
|
|
|
9
|
|
|
class Builder |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var Configuration |
13
|
|
|
*/ |
14
|
|
|
private Configuration $config; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string|null |
18
|
|
|
*/ |
19
|
|
|
private ?string $packageVendor = null; |
20
|
|
|
private ?string $packageName = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Builder constructor. |
24
|
|
|
* @param Configuration $config |
25
|
|
|
*/ |
26
|
7 |
|
public function __construct(Configuration $config) |
27
|
|
|
{ |
28
|
7 |
|
$this->config = $config; |
29
|
7 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string|null $package |
33
|
|
|
* @return bool |
34
|
|
|
*/ |
35
|
3 |
|
public function init(?string $package = null): bool |
36
|
|
|
{ |
37
|
3 |
|
$this->initFilter($package); |
38
|
3 |
|
$configGenerator = $this->config->getGenerator(); |
39
|
3 |
|
foreach ($configGenerator as $package) { |
40
|
|
|
if ($this->isIgnore($package['vendor'], $package['package'])) { |
41
|
|
|
continue; |
42
|
|
|
} |
43
|
|
|
/* Generation */ |
44
|
|
|
var_dump($this->packageVendor, $this->packageName); |
|
|
|
|
45
|
|
|
} |
46
|
3 |
|
return true; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $vandor |
51
|
|
|
* @param string $name |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
1 |
|
public function isIgnore(string $vandor, string $name): bool |
55
|
|
|
{ |
56
|
1 |
|
if ($this->getPackageVendor() != null && $this->getPackageVendor() != $vandor) { |
|
|
|
|
57
|
1 |
|
return true; |
58
|
|
|
} |
59
|
1 |
|
if ($this->getPackageName() != null && $this->getPackageName() != $name) { |
|
|
|
|
60
|
1 |
|
return true; |
61
|
|
|
} |
62
|
1 |
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string|null $package |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
7 |
|
public function initFilter(?string $package = null): bool |
70
|
|
|
{ |
71
|
7 |
|
if (is_null($package)) { |
72
|
3 |
|
return true; |
73
|
|
|
} |
74
|
4 |
|
$package = str_replace('\\', '/', $package); |
75
|
4 |
|
if (!mb_stripos($package, '/')) { |
76
|
|
|
$this->packageVendor = $package; |
77
|
|
|
return true; |
78
|
|
|
} |
79
|
4 |
|
$match = explode('/', $package, 2); |
80
|
4 |
|
$this->packageVendor = $match[0]; |
81
|
4 |
|
$this->packageName = mb_strlen(trim($match[1])) > 0 ? $match[1] : null; |
82
|
4 |
|
return true; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string|null |
87
|
|
|
*/ |
88
|
4 |
|
public function getPackageVendor(): ?string |
89
|
|
|
{ |
90
|
4 |
|
return $this->packageVendor; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return string|null |
95
|
|
|
*/ |
96
|
4 |
|
public function getPackageName(): ?string |
97
|
|
|
{ |
98
|
4 |
|
return $this->packageName; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|