-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateAPIDocs.php
More file actions
117 lines (96 loc) · 2.85 KB
/
generateAPIDocs.php
File metadata and controls
117 lines (96 loc) · 2.85 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/*
* This file is part of the Valdi package.
*
* (c) Philip Lehmann-Böhm <philip@philiplb.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$doxphpPath = getenv('DOXPHPPATH');
$classHierarchyToctree = [
'Valdi\\\\Validator\\\\AbstractArray' => '.. toctree::
Collection
Nested',
'Valdi\\\\Validator\\\\AbstractComparator' => '.. toctree::
Between
LengthBetween
Max
MaxLength
Min
MinLength
Regexp
Value',
'Valdi\\\\Validator\\\\AbstractDateTimeComparator' => '.. toctree::
AfterDateTime
BeforeDateTime
DateTimeBetween
InTheFuture
InThePast
OlderThan
YoungerThan',
'Valdi\\\\Validator\\\\AbstractFilter' => '.. toctree::
Email
Floating
Integer
IP
IPv4
IPv6
Url',
'Valdi\\\\Validator\\\\AbstractParametrizedValidator' => '.. toctree::
AbstractComparator
AbstractDateTimeComparator',
'Valdi\\\\Validator\\\\Regexp' => '.. toctree::
Alphabetical
AlphaNumerical
Slug'
];
function scanFiles($dir) : array
{
echo "Scanning $dir\n";
$result = [];
$files = scandir($dir);
$omit = ['.', '..', '.DS_Store'];
foreach ($files as $file) {
$completeFile = $dir.DIRECTORY_SEPARATOR.$file;
if (in_array($file, $omit)) {
continue;
}
if (is_file($completeFile)) {
$result[] = $completeFile;
}
if (is_dir($completeFile)) {
$result = array_merge($result, scanFiles($completeFile));
}
}
return $result;
}
function genAPIDoc($doxphpPath, $baseDir, $targetDir, $baseNamespace, $classHierarchyToctree, $file)
{
$cmd = $doxphpPath.'/doxphp < "'.$file.'" | '.$doxphpPath.'/doxphp2sphinx';
$doc = shell_exec($cmd);
$fileWithoutExtension = substr($file, strlen($baseDir) + 1, strlen($file) - strlen($baseDir) - 5);
$fullClassname = $baseNamespace.'\\\\'.str_replace('/', '\\\\', $fileWithoutExtension);
$headlineSeparator = '';
$fullClassnameLength = strlen($fullClassname);
for ($i = 0; $i < $fullClassnameLength; ++$i) {
$headlineSeparator .= '-';
}
$headline = "$headlineSeparator\n$fullClassname\n$headlineSeparator\n";
if (array_key_exists($fullClassname, $classHierarchyToctree)) {
$headline .= "\n".$classHierarchyToctree[$fullClassname]."\n";
}
$targetFile = $targetDir.'/'.$fileWithoutExtension.'.rst';
$targetClassDir = dirname($targetFile);
if (!is_dir($targetClassDir)) {
mkdir($targetClassDir, 0755, true);
}
file_put_contents($targetFile, $headline."\n".$doc."\n");
}
$baseDir = 'src/Valdi';
$files = scanFiles($baseDir);
$targetDir = 'docs/api';
shell_exec('rm -r '.$targetDir);
foreach ($files as $file) {
genAPIDoc($doxphpPath, $baseDir, $targetDir, 'Valdi', $classHierarchyToctree, $file);
}