This repository was archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathscanner.php
More file actions
104 lines (95 loc) · 1.96 KB
/
scanner.php
File metadata and controls
104 lines (95 loc) · 1.96 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
<?php
/**
* PHP 7 MAR
* Scanner Class
*
* @author Alexia E. Smith <washuu@gmail.com>
* @copyright 2015 Alexia E. Smith
* @link https://github.com/Alexia/php7mar
*/
namespace Alexia\Mar\Scanner;
class scanner {
/**
* Project File or Path
*
* @var string
*/
private $projectPath = null;
/**
* List of files.
*
* @var array
*/
private $files = [];
/**
* Main Constructor
*
* @access public
* @param string Project file or folder
* @return void
*/
public function __construct($projectPath) {
if (empty($projectPath)) {
throw new \Exception(__METHOD__.": Project path given was empty.");
}
$this->projectPath = $projectPath;
$this->recursiveScan($this->projectPath);
reset($this->files);
}
/**
* Perform a recursive scan of the given path to return files only.
*
* @access private
* @param string Starting Folder
* @return void
*/
private function recursiveScan($startFolder) {
if (is_file($startFolder)) {
$this->files[] = $startFolder;
return;
}
$contents = scandir($startFolder);
foreach ($contents as $content) {
if (strpos($content, '.') === 0) {
continue;
}
$path = $startFolder.DIRECTORY_SEPARATOR.$content;
if (is_dir($path)) {
$this->recursiveScan($path);
} else {
if (substr($content, -4) != '.php') {
continue;
}
$this->files[] = $path;
}
}
}
/**
* Scan the next file in the array and provide back an array of lines.
*
* @access public
* @return mixed Array of lines from the file or false for no more files.
*/
public function scanNextFile() {
$_file = each($this->files);
if ($_file === false) {
return false;
}
$file = $_file['value'];
$lines = file($file);
if ($lines === false) {
return false;
}
return $lines;
}
/**
* Return the file path of the current array pointer.
*
* @access public
* @return string File Path
*/
public function getCurrentFilePath() {
return current($this->files);
}
}
?>