@@ -111,19 +111,12 @@ public function tryLoad($type)
111111
112112 /**
113113 * Add directory (or directories) to list.
114- * @param string|array
114+ * @param string|array absolute path
115115 * @return self
116- * @throws Nette\DirectoryNotFoundException if path is not found
117116 */
118117 public function addDirectory ($ path )
119118 {
120- foreach ((array ) $ path as $ val ) {
121- $ real = realpath ($ val );
122- if ($ real === FALSE ) {
123- throw new Nette \DirectoryNotFoundException ("Directory ' $ val' not found. " );
124- }
125- $ this ->scanDirs [] = $ real ;
126- }
119+ $ this ->scanDirs = array_merge ($ this ->scanDirs , (array ) $ path );
127120 return $ this ;
128121 }
129122
@@ -170,14 +163,15 @@ public function rebuildCallback()
170163 }
171164
172165 $ this ->classes = array ();
173- foreach (array_unique ( $ this ->scanDirs ) as $ dir ) {
174- foreach ($ this ->createFileIterator ($ dir ) as $ file ) {
166+ foreach ($ this ->scanDirs as $ path ) {
167+ foreach (is_file ( $ path ) ? array ( new SplFileInfo ( $ path )) : $ this ->createFileIterator ($ path ) as $ file ) {
175168 $ file = $ file ->getPathname ();
176169 if (isset ($ files [$ file ]) && $ files [$ file ]['time ' ] == filemtime ($ file )) {
177170 $ classes = $ files [$ file ]['classes ' ];
178171 } else {
179172 $ classes = $ this ->scanPhp (file_get_contents ($ file ));
180173 }
174+ $ files [$ file ] = array ('classes ' => array (), 'time ' => filemtime ($ file ));
181175
182176 foreach ($ classes as $ class ) {
183177 $ info = & $ this ->classes [strtolower ($ class )];
@@ -196,11 +190,12 @@ public function rebuildCallback()
196190 /**
197191 * Creates an iterator scaning directory for PHP files, subdirectories and 'netterobots.txt' files.
198192 * @return \Iterator
193+ * @throws Nette\IOException if path is not found
199194 */
200195 private function createFileIterator ($ dir )
201196 {
202197 if (!is_dir ($ dir )) {
203- return new \ ArrayIterator ( array ( new \ SplFileInfo ( $ dir)) );
198+ throw new Nette \ IOException ( " File or directory ' $ dir' not found. " );
204199 }
205200
206201 $ ignoreDirs = is_array ($ this ->ignoreDirs ) ? $ this ->ignoreDirs : preg_split ('#[,\s]+# ' , $ this ->ignoreDirs );
0 commit comments