forked from phpearth/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
executable file
·62 lines (49 loc) · 1.6 KB
/
test.php
File metadata and controls
executable file
·62 lines (49 loc) · 1.6 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
#!/usr/bin/env php
<?php
/**
* Script for testing and validating Markdown. Features here are temporary and
* will change in the near future.
*/
$docsDir = realpath(__DIR__.'/..');
$exitCode = 0;
$exclude = ['.git', '.github', '.editorconfig', '.gitignore', '.travis.yml', 'LICENSE'];
function getHttpResponseCode($url)
{
$headers = get_headers($url);
return substr($headers[0], 9, 3);
}
$filter = function ($file, $key, $iterator) use ($exclude) {
if ($iterator->hasChildren() && !in_array($file->getFilename(), $exclude)) {
return true;
}
return ($file->isFile() && !in_array($file->getFilename(), $exclude));
};
$innerIterator = new \RecursiveDirectoryIterator(
$docsDir,
\RecursiveDirectoryIterator::SKIP_DOTS
);
$iterator = new \RecursiveIteratorIterator(
new \RecursiveCallbackFilterIterator($innerIterator, $filter)
);
foreach ($iterator as $pathName => $fileInfo) {
$content = file_get_contents($pathName);
// Internal links
preg_match_all('/\[.+\]\(((?!http)\/.+)(\).*)/i', $content, $matches);
foreach ($matches[1] as $file) {
if (!file_exists($docsDir.$file)) {
$exitCode = 2;
echo '[WARNING] Missing link in '.$pathName.': '.$file.PHP_EOL;
}
}
// External links
preg_match_all('/\[.+\]\((https?\:\/\/.+)(\s|\))/iU', $content, $matches);
foreach ($matches[1] as $url) {
/*$code = getHttpResponseCode($url);
if ($code != '200') {
$exitCode = 2;
echo '[WARNING] '.$code.' error in '.$pathName.': '.$url.PHP_EOL;
}
*/
}
}
exit($exitCode);