Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/RobotLoader/RobotLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,12 @@ public function tryLoad($type)

/**
* Add directory (or directories) to list.
* @param string|array
* @param string|array absolute path
* @return self
* @throws Nette\DirectoryNotFoundException if path is not found
*/
public function addDirectory($path)
{
foreach ((array) $path as $val) {
$real = realpath($val);
if ($real === FALSE) {
throw new Nette\DirectoryNotFoundException("Directory '$val' not found.");
}
$this->scanDirs[] = $real;
}
$this->scanDirs = array_merge($this->scanDirs, (array) $path);
return $this;
}

Expand Down Expand Up @@ -170,14 +163,15 @@ public function rebuildCallback()
}

$this->classes = array();
foreach (array_unique($this->scanDirs) as $dir) {
foreach ($this->createFileIterator($dir) as $file) {
foreach ($this->scanDirs as $path) {
foreach (is_file($path) ? array(new SplFileInfo($path)) : $this->createFileIterator($path) as $file) {
$file = $file->getPathname();
if (isset($files[$file]) && $files[$file]['time'] == filemtime($file)) {
$classes = $files[$file]['classes'];
} else {
$classes = $this->scanPhp(file_get_contents($file));
}
$files[$file] = array('classes' => array(), 'time' => filemtime($file));

foreach ($classes as $class) {
$info = & $this->classes[strtolower($class)];
Expand All @@ -196,11 +190,12 @@ public function rebuildCallback()
/**
* Creates an iterator scaning directory for PHP files, subdirectories and 'netterobots.txt' files.
* @return \Iterator
* @throws Nette\IOException if path is not found
*/
private function createFileIterator($dir)
{
if (!is_dir($dir)) {
return new \ArrayIterator(array(new \SplFileInfo($dir)));
throw new Nette\IOException("File or directory '$dir' not found.");
}

$ignoreDirs = is_array($this->ignoreDirs) ? $this->ignoreDirs : preg_split('#[,\s]+#', $this->ignoreDirs);
Expand Down
2 changes: 1 addition & 1 deletion tests/Loaders/RobotLoader.renamed.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $loader = new RobotLoader;
$loader->setCacheStorage(new DevNullStorage);
$loader->addDirectory(TEMP_DIR);

$dir = realpath(TEMP_DIR) . DIRECTORY_SEPARATOR;
$dir = TEMP_DIR . DIRECTORY_SEPARATOR;
file_put_contents($dir . 'file1.php', '<?php class A {}');
file_put_contents($dir . 'file2.php', '<?php class B {}');

Expand Down