-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClassMapGenerator.php
48 lines (42 loc) · 1.08 KB
/
ClassMapGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Hobosoft\MegaLoader;
use Hobosoft\Finders\ClassFinder;
class ClassMapGenerator
{
private CLassFinder $classFinder;
private array $found;
public function __construct(
array $includes = [],
array $excludes = [],
)
{
$this->classFinder = new ClassFinder($includes, $excludes);
}
public function find(string $outputFile): self
{
$this->found = $this->classFinder->find();
return $this;
}
public function writeMap(string $filename, string $rootPath = null): self
{
$map = [];
$head =
"<?php\n"
."// autoload_psr4.php @generated by Composer\n"
."\n"
.'$rootPath = "'.($rootPath ?? ROOTPATH).'";'."\n"
."\n"
."return [\n"
;
$foot =
"];\n"
."\n"
;
foreach ($this->found as $file => $obj) {
$map[$file] = $obj;
}
$str = $head . implode("\n", $map) . $foot;;
file_put_contents($filename, $str);
return $this;
}
}