@@ -38,7 +38,15 @@ public function load($path, $type = null)
38
38
39
39
$ collection = new RouteCollection ();
40
40
$ collection ->addResource (new DirectoryResource ($ dir , '/\.php$/ ' ));
41
- $ files = iterator_to_array (new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ dir ), \RecursiveIteratorIterator::LEAVES_ONLY ));
41
+ $ files = iterator_to_array (new \RecursiveIteratorIterator (
42
+ new RecursiveCallbackFilterIterator (
43
+ new \RecursiveDirectoryIterator ($ dir ),
44
+ function (\SplFileInfo $ current ) {
45
+ return '. ' !== substr ($ current ->getBasename (), 0 , 1 );
46
+ }
47
+ ),
48
+ \RecursiveIteratorIterator::LEAVES_ONLY
49
+ ));
42
50
usort ($ files , function (\SplFileInfo $ a , \SplFileInfo $ b ) {
43
51
return (string ) $ a > (string ) $ b ? 1 : -1 ;
44
52
});
@@ -79,3 +87,34 @@ public function supports($resource, $type = null)
79
87
return is_dir ($ path ) && (!$ type || 'annotation ' === $ type );
80
88
}
81
89
}
90
+
91
+ /**
92
+ * @internal To be removed in 3.1 as RecursiveCallbackFilterIterator is available since PHP 5.4
93
+ */
94
+ class RecursiveCallbackFilterIterator extends \FilterIterator implements \RecursiveIterator
95
+ {
96
+ private $ iterator ;
97
+ private $ callback ;
98
+
99
+ public function __construct (\Iterator $ iterator , $ callback )
100
+ {
101
+ $ this ->iterator = $ iterator ;
102
+ $ this ->callback = $ callback ;
103
+ parent ::__construct ($ iterator );
104
+ }
105
+
106
+ public function accept ()
107
+ {
108
+ return call_user_func ($ this ->callback , $ this ->current (), $ this ->key (), $ this ->iterator );
109
+ }
110
+
111
+ public function hasChildren ()
112
+ {
113
+ return $ this ->iterator ->hasChildren ();
114
+ }
115
+
116
+ public function getChildren ()
117
+ {
118
+ return new static ($ this ->iterator ->getChildren (), $ this ->callback );
119
+ }
120
+ }
0 commit comments