@@ -33,6 +33,46 @@ public function __construct($resource, $pattern = null)
33
33
$ this ->pattern = $ pattern ;
34
34
}
35
35
36
+ /**
37
+ * Returns the list of filtered file and directory childs of directory resource.
38
+ *
39
+ * @param Boolean $recursive search for files recursive
40
+ *
41
+ * @return array An array of files
42
+ */
43
+ public function getFilteredChilds ($ recursive = true )
44
+ {
45
+ $ iterator = $ recursive
46
+ ? new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ this ->resource ), \RecursiveIteratorIterator::SELF_FIRST )
47
+ : new \DirectoryIterator ($ this ->resource );
48
+
49
+ $ childs = array ();
50
+ foreach ($ iterator as $ file ) {
51
+ // if regex filtering is enabled only return matching files
52
+ if (isset ($ this ->filterRegexList ) && $ file ->isFile ()) {
53
+ $ regexMatched = false ;
54
+ foreach ($ this ->filterRegexList as $ regex ) {
55
+ if (preg_match ($ regex , (string ) $ file )) {
56
+ $ regexMatched = true ;
57
+ }
58
+ }
59
+ if (!$ regexMatched ) {
60
+ continue ;
61
+ }
62
+ }
63
+
64
+ // always monitor directories for changes, except the .. entries
65
+ // (otherwise deleted files wouldn't get detected)
66
+ if ($ file ->isDir () && '/.. ' === substr ($ file , -3 )) {
67
+ continue ;
68
+ }
69
+
70
+ $ childs [] = $ file ;
71
+ }
72
+
73
+ return $ childs ;
74
+ }
75
+
36
76
/**
37
77
* Returns a string representation of the Resource.
38
78
*
@@ -66,24 +106,9 @@ public function getPattern()
66
106
public function getModificationTime ()
67
107
{
68
108
clearstatcache (true , $ this ->resource );
69
-
70
- if (!is_dir ($ this ->resource )) {
71
- return false ;
72
- }
73
-
74
109
$ newestMTime = filemtime ($ this ->resource );
75
- foreach (new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ this ->resource ), \RecursiveIteratorIterator::SELF_FIRST ) as $ file ) {
76
- // if regex filtering is enabled only check matching files
77
- if ($ this ->pattern && $ file ->isFile () && !preg_match ($ this ->pattern , $ file ->getBasename ())) {
78
- continue ;
79
- }
80
-
81
- // always monitor directories for changes, except the .. entries
82
- // (otherwise deleted files wouldn't get detected)
83
- if ($ file ->isDir () && '/.. ' === substr ($ file , -3 )) {
84
- continue ;
85
- }
86
110
111
+ foreach ($ this ->getFilteredChilds () as $ file ) {
87
112
clearstatcache (true , (string ) $ file );
88
113
$ newestMTime = max ($ file ->getMTime (), $ newestMTime );
89
114
}
0 commit comments