-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-problems-in-directory.php
More file actions
46 lines (33 loc) · 1.11 KB
/
parse-problems-in-directory.php
File metadata and controls
46 lines (33 loc) · 1.11 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
<?php
require_once __DIR__ . '/../src/bootstrap.php';
$args = array_slice($argv, 1);
list($baseDir, $baseUrl) = $args;
assert(!!$baseDir);
assert(!!$baseUrl);
chdir($baseDir);
$childArgs = [];
$dirIter = new RecursiveDirectoryIterator(
'.',
\FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS
);
$fileIter = new RecursiveIteratorIterator($dirIter);
foreach ($fileIter as $file) {
if (!preg_match("/\.html?$/", $file->getBaseName())) {
continue;
}
$localPath = preg_replace("~^\./~", '/', $file->getPathname());
$localPath = ltrim($localPath, '/');
$baseProto = parse_url($baseUrl, PHP_URL_SCHEME);
$baseHost = parse_url($baseUrl, PHP_URL_HOST);
assert(!!$baseProto);
assert(!!$baseHost);
$pageUrl = "{$baseProto}://{$baseHost}/{$localPath}";
$childArgs[] = "{$file->getPathname()}:$pageUrl";
}
assert(count($childArgs) > 0);
$escapedArgs = array_map('escapeshellarg', $childArgs);
$scriptPath = __DIR__ . '/parse-problems.php';
$command = "php \"$scriptPath\" " . implode(' ', $escapedArgs);
$exitCode = 0;
passthru($command, $exitCode);
exit($exitCode);