1
|
|
|
<?php |
2
|
|
|
function clearFolder($folder) |
3
|
|
|
{ |
4
|
|
|
$files = glob(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . '*'); |
5
|
|
|
foreach ($files as $file) { |
6
|
|
|
if (is_file($file)) { |
7
|
|
|
@unlink($file); |
|
|
|
|
8
|
|
|
} |
9
|
|
|
} |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
function stripAndWordWrap($str) |
13
|
|
|
{ |
14
|
|
|
return wordwrap(stripSpaces($str), 180) . "\n"; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
function formParamLine($param) |
18
|
|
|
{ |
19
|
|
|
return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
function stripSpaces($str) |
23
|
|
|
{ |
24
|
|
|
$str = preg_replace('/[\s]{2,}/', " ", $str); |
25
|
|
|
return $str; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function stripLines($str) |
29
|
|
|
{ |
30
|
|
|
$str = str_replace("\n", " ", $str); |
31
|
|
|
$str = stripSpaces($str); |
32
|
|
|
return $str; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function formMethodName($str) |
36
|
|
|
{ |
37
|
|
|
$arr = array_filter(explode('_', $str)); |
38
|
|
|
$arr = array_map('ucfirst', $arr); |
39
|
|
|
$arr[0] = lcfirst($arr[0]); |
40
|
|
|
return join('', $arr); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function formClassName($str, $clear = ['get_', '_array']) |
44
|
|
|
{ |
45
|
|
|
foreach ($clear as $item) { |
46
|
|
|
$str = str_ireplace($item, '', $str); |
47
|
|
|
} |
48
|
|
|
$arr = array_filter(explode('_', $str)); |
49
|
|
|
$arr = array_map('ucfirst', $arr); |
50
|
|
|
return join('', $arr); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function formParamType($str) |
54
|
|
|
{ |
55
|
|
|
switch ($str) { |
56
|
|
|
case 'text': |
57
|
|
|
return 'string'; |
58
|
|
|
break; |
|
|
|
|
59
|
|
|
case 'date': |
60
|
|
|
return 'string Y-m-d'; |
61
|
|
|
break; |
62
|
|
|
case 'datetime': |
63
|
|
|
return 'string Y-m-d H:i:s'; |
64
|
|
|
break; |
65
|
|
|
} |
66
|
|
|
return $str; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
function parseParams($str) |
70
|
|
|
{ |
71
|
|
|
if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) { |
72
|
|
|
return [ |
73
|
|
|
'name' => $m[1], |
74
|
|
|
'type' => $m[2], |
75
|
|
|
'description' => $m[3], |
76
|
|
|
'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false |
77
|
|
|
]; |
78
|
|
|
} else { |
79
|
|
|
return []; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
function parseReturns($tdHtml) |
84
|
|
|
{ |
85
|
|
|
$uls = pq($tdHtml)->find('ul'); |
86
|
|
|
if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) { |
87
|
|
|
if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) { |
88
|
|
|
$ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>"; |
89
|
|
|
$uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul'); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
$count = $uls->count(); |
93
|
|
|
$parsing = []; |
94
|
|
View Code Duplication |
foreach ($uls->eq($count == 2 ? 1 : 0)->find('li') as $param) { |
|
|
|
|
95
|
|
|
if ($parsedParam = parseParams(pq($param)->text())) { |
96
|
|
|
$parsing[] = $parsedParam; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
if ($count == 2) { |
100
|
|
|
$returnParam = parseParams($uls->eq(0)->text()); |
101
|
|
|
$returnParam['result'] = $parsing; |
102
|
|
|
return [$returnParam]; |
103
|
|
|
} else { |
104
|
|
|
return $parsing; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
function asTable($array) |
109
|
|
|
{ |
110
|
|
|
$header = array_shift($array); |
111
|
|
|
$content = "\n\n|" . join("|", $header) . "\n"; |
112
|
|
|
$content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n"; |
113
|
|
|
foreach ($array as $key => $columns) { |
114
|
|
|
$content .= "|" . join("|", $columns) . "\n"; |
115
|
|
|
} |
116
|
|
|
return $content; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
function asHeader($string) |
120
|
|
|
{ |
121
|
|
|
return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n"; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
function asCode($code) |
125
|
|
|
{ |
126
|
|
|
return "`$code`"; |
127
|
|
|
} |
If you suppress an error, we recommend checking for the error condition explicitly: