-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-dto.php
87 lines (78 loc) · 2.18 KB
/
update-dto.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
$files = glob("inc.lib/classes/MusicProductionManager/Data/Dto/*.php");
function getLast($haystack, $needle)
{
$lastFound = false;
$found = false;
$offset = 0;
do
{
$lastFound = strpos($haystack, $needle, $offset);
if($lastFound !== false)
{
$found = $lastFound;
$offset = $lastFound + 1;
}
}
while($lastFound !== false);
return $found;
}
function getFirst($haystack, $needle)
{
return strpos($haystack, $needle);
}
function updateBody($body)
{
$arr = explode("\r\n", $body);
foreach($arr as $key=>$line)
{
$arr[$key] = rtrim($line);
if(substr($arr[$key], strlen($arr[$key]) - 2) != "**" && substr($arr[$key], strlen($arr[$key]) - 1) == "*")
{
$arr[$key] = $arr[$key]." ";
}
}
$body = implode("\r\n", $arr);
$arr = explode("\r\n\r\n", $body);
foreach($arr as $key=>$block)
{
$arr[$key] = updateBlock($block);
}
return implode("\r\n\r\n", $arr);
}
function updateBlock($block)
{
$arr = explode("\r\n", $block);
$lineVar = "";
$firstLine = "";
foreach($arr as $line)
{
if(stripos($line, "@var ") !== false)
{
$lineVar = $line;
}
$line2 = $line;
if($firstLine == "" && trim(str_replace(array('/', '*'), '', $line2)) != "")
{
$firstLine = trim(str_replace(array('/', '*'), '', $line2));
}
}
if($lineVar != "" && $firstLine != "" && stripos($block, "@Label(content=") === false)
{
$trailer = substr($lineVar, 0, strpos($lineVar, "@"));
$replacer = $trailer."@Label(content=\"$firstLine\")";
$block = str_replace($lineVar, $replacer."\r\n".$lineVar, $block);
}
return $block;
}
foreach($files as $file)
{
$content = file_get_contents($file);
$start = getFirst($content, "{") + 1;
$end = getFirst($content, "}");
$body = substr($content, $start, $end-$start);
$header = substr($content, 0, $start);
$footer = substr($content, $end);
$updatedBody = updateBody($body);
file_put_contents($file, $header.$updatedBody.$footer);
}