-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScan.php
More file actions
57 lines (49 loc) · 1.59 KB
/
Copy pathScan.php
File metadata and controls
57 lines (49 loc) · 1.59 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
<?php
declare(strict_types=1);
namespace Paths;
final class Scan
{
/**
*
*/
static function filesAndDirectories(array $files_and_directories, array $exclude_files_and_directories, callable $callable): void
{
foreach ($files_and_directories as $file_or_directory) {
foreach ($exclude_files_and_directories as $exclude_file_or_directory) {
if (strpos($file_or_directory, $exclude_file_or_directory) !== false) {
continue 2;
}
}
self::fileOrDirectory($file_or_directory, $callable);
}
}
/**
*
*/
static function fileOrDirectory(string $file_or_directory, callable $callable): void
{
if (is_dir($file_or_directory)) {
self::directory($file_or_directory, $callable);
} else {
self::file($file_or_directory, $callable);
}
}
static function directory(string $directory_name, callable $callable): void
{
$handle = opendir($directory_name);
if (!$handle) {
throw new \ErrorException("Could not open directory {$directory_name}");
}
while (false !== ($file_or_directory = readdir($handle))) {
if ($file_or_directory == "." || $file_or_directory == "..") {
continue;
}
self::fileOrDirectory($directory_name . DIRECTORY_SEPARATOR . $file_or_directory, $callable);
}
closedir($handle);
}
static function file(string $file_name, callable $callable): void
{
$callable($file_name);
}
}