@@ -25,18 +25,30 @@ class scanner {
25
25
*/
26
26
private $ files = [];
27
27
28
+ /**
29
+ * List of file extension to process.
30
+ *
31
+ * @var array
32
+ */
33
+ private $ extensions = ['php ' ];
34
+
28
35
/**
29
36
* Main Constructor
30
37
*
31
38
* @access public
32
39
* @param string Project file or folder
33
40
* @return void
34
41
*/
35
- public function __construct ($ projectPath ) {
42
+ public function __construct ($ projectPath, Array $ extensions = null ) {
36
43
if (empty ($ projectPath )) {
37
44
throw new \Exception (__METHOD__ .": Project path given was empty. " );
38
45
}
39
46
$ this ->projectPath = $ projectPath ;
47
+
48
+ if (!is_null ($ extensions )) {
49
+ $ this ->extensions = $ extensions ;
50
+ }
51
+
40
52
$ this ->recursiveScan ($ this ->projectPath );
41
53
reset ($ this ->files );
42
54
}
@@ -63,7 +75,8 @@ private function recursiveScan($startFolder) {
63
75
if (is_dir ($ path )) {
64
76
$ this ->recursiveScan ($ path );
65
77
} else {
66
- if (substr ($ content , -4 ) != '.php ' ) {
78
+ $ fileExtension = pathinfo ($ content , PATHINFO_EXTENSION );
79
+ if (strlen ($ fileExtension ) == 0 || !in_array ($ fileExtension , $ this ->extensions )) {
67
80
continue ;
68
81
}
69
82
$ this ->files [] = $ path ;
@@ -100,5 +113,28 @@ public function scanNextFile() {
100
113
public function getCurrentFilePath () {
101
114
return current ($ this ->files );
102
115
}
116
+
117
+ /**
118
+ * Sets the file extensions to be considered as PHP file. Ex:
119
+ *
120
+ * array('php', 'inc')
121
+ *
122
+ * Do NOT include the dot before the extension
123
+ *
124
+ * @access public
125
+ * @param array $extensions
126
+ */
127
+ public function setFileExtensions (Array $ extensions ) {
128
+ $ this ->extensions = $ extensions ;
129
+ }
130
+
131
+ /**
132
+ * Gets the list of extensions to be considered PHP files when scanning
133
+ *
134
+ * @return array File extensions to be considered as PHP files
135
+ */
136
+ public function getFileExtensions () {
137
+ return $ this ->extensions ;
138
+ }
103
139
}
104
140
?>
0 commit comments