-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkModules.php
36 lines (33 loc) · 990 Bytes
/
linkModules.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
<?php
$file = $argv[1];
if (strpos($file, '/') !== false) {
list($workdir, ) = explode('/', $file, 2);
} else {
$workdir = '.';
}
if (is_readable($file) && is_writable($file)) {
$lines = file($file);
foreach ($lines as $nr => $line) {
if (preg_match('/^(use \*.+;)(.+)$/', $line, $matches)) {
$modules = explode(' ', $matches[2]);
foreach ($modules as $module) {
if (is_dir($workdir . '/' . $module)) {
$lines[$nr] = preg_replace('/\*/', $module, $matches[1]);
break;
} elseif ($module == 'none') {
unset($lines[$nr]);
break;
}
}
} elseif (preg_match('/^(class|trait)/', $line)) {
break;
}
}
if ($fp = fopen($file, 'w')) {
foreach ($lines as $line) {
fwrite($fp, str_replace("\n", '', $line) . "\n");
}
fclose($fp);
}
}
?>