From a904dd5f01d9abb658f753cf880aa0cf1cfe6cd6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 3 Jan 2015 23:14:38 +0100 Subject: [PATCH] removed usage of realpath() --- src/RobotLoader/RobotLoader.php | 19 +++++++------------ tests/Loaders/RobotLoader.renamed.phpt | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index ae1306e..c7842de 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -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; } @@ -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)]; @@ -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); diff --git a/tests/Loaders/RobotLoader.renamed.phpt b/tests/Loaders/RobotLoader.renamed.phpt index dac9cbb..80a0cac 100644 --- a/tests/Loaders/RobotLoader.renamed.phpt +++ b/tests/Loaders/RobotLoader.renamed.phpt @@ -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', '