1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GarbuzIvan\LaravelGeneratorPackage\Builder; |
6
|
|
|
|
7
|
|
|
use GarbuzIvan\LaravelGeneratorPackage\Configuration; |
8
|
|
|
use Illuminate\Support\Facades\File; |
9
|
|
|
use OpenApi\Annotations\Components; |
|
|
|
|
10
|
|
|
|
11
|
|
|
class FileGenerator |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Configuration |
15
|
|
|
*/ |
16
|
|
|
private Configuration $config; |
17
|
|
|
/** |
18
|
|
|
* @var Package |
19
|
|
|
*/ |
20
|
|
|
private Package $package; |
21
|
|
|
|
22
|
2 |
|
public function __construct(Configuration $config) |
23
|
|
|
{ |
24
|
2 |
|
$this->config = $config; |
25
|
2 |
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Package $package |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
2 |
|
public function make(Package $package): bool |
32
|
|
|
{ |
33
|
2 |
|
$this->package = $package; |
34
|
2 |
|
$this->templates(); |
35
|
2 |
|
return true; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Copy all templates file |
40
|
|
|
* |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
2 |
|
public function templates(): bool |
44
|
|
|
{ |
45
|
2 |
|
$templatesDir = realpath(__DIR__ . '/../../templates'); |
46
|
2 |
|
$files = File::allFiles($templatesDir, true); |
47
|
2 |
|
foreach ($files as $file) { |
48
|
2 |
|
$content = $this->replacement(file_get_contents($file->getRealPath())); |
49
|
2 |
|
$newPathFile = str_replace([$templatesDir, '.stub'], null, $file->getRealPath()); |
50
|
2 |
|
$newPathFile = $this->package->getPath($newPathFile); |
51
|
2 |
|
file_put_contents($newPathFile, $content); |
52
|
|
|
} |
53
|
2 |
|
return true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string|null $content |
58
|
|
|
* @return string|null |
59
|
|
|
*/ |
60
|
2 |
|
public function replacement(?string $content = null): ?string |
61
|
|
|
{ |
62
|
2 |
|
$content = str_replace([ |
63
|
2 |
|
'%PACKAGE_GIT%', |
64
|
|
|
'%PACKAGE_PVENDOR%', |
65
|
|
|
'%PACKAGE_PNAME%', |
66
|
|
|
'%PACKAGE_NAMESPACE%', |
67
|
|
|
'%PACKAGE_NAMESPACE_SLASHES%', |
68
|
|
|
'%PACKAGE_CONFIG_NAME%', |
69
|
|
|
'%PACKAGE_NAME%', |
70
|
|
|
'%PACKAGE_DESCRIPTIONS%', |
71
|
|
|
], [ |
72
|
2 |
|
$this->package->getPackageVendor() . '/' . $this->package->getPackageName(), |
73
|
2 |
|
$this->package->getPackageVendor(), |
74
|
2 |
|
$this->package->getPackageName(), |
75
|
2 |
|
$this->spacer($this->package->getPackageVendor()) . '\\' . $this->spacer($this->package->getPackageName()), |
|
|
|
|
76
|
2 |
|
$this->spacer($this->package->getPackageVendor()) . '\\\\' . $this->spacer($this->package->getPackageName()), |
77
|
2 |
|
$this->package->getPackageVendor() . '-' . $this->package->getPackageName(), |
78
|
2 |
|
$this->package->getName(), |
79
|
2 |
|
$this->package->getDescripton(), |
80
|
|
|
], $content); |
81
|
2 |
|
return $content; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $name |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
2 |
|
public function spacer(string $name): string |
89
|
|
|
{ |
90
|
2 |
|
$name = preg_replace('~[^a-z0-9]~isuU', ' ', $name); |
91
|
2 |
|
$name = ucwords($name); |
92
|
2 |
|
$name = str_replace(' ', null, $name); |
93
|
2 |
|
return $name; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths