diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index ae1306e..72392ee 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -118,11 +118,13 @@ public function tryLoad($type) public function addDirectory($path) { foreach ((array) $path as $val) { - $real = realpath($val); - if ($real === FALSE) { + if (strncasecmp($val, 'phar://', 7) === 0 && file_exists($val)) { + $this->scanDirs[] = $val; + } elseif (($real = realpath($val)) === FALSE) { throw new Nette\DirectoryNotFoundException("Directory '$val' not found."); + } else { + $this->scanDirs[] = $real; } - $this->scanDirs[] = $real; } return $this; } diff --git a/tests/Loaders/RobotLoader.phar.phpt b/tests/Loaders/RobotLoader.phar.phpt new file mode 100644 index 0000000..172b918 --- /dev/null +++ b/tests/Loaders/RobotLoader.phar.phpt @@ -0,0 +1,49 @@ +setStub('setCacheStorage(new DevNullStorage); +$loader->addDirectory("phar://$pharFile/sub"); +$loader->addDirectory("PHAR://$pharFile/class.B.php"); +Phar::loadPhar($pharFile, 'test.phar'); +$loader->addDirectory("phar://test.phar/class.C.php"); +$loader->register(); + +Assert::false( class_exists('A') ); +Assert::true( class_exists('B') ); +Assert::true( class_exists('C') ); +Assert::true( class_exists('D') ); + + +Assert::exception(function() use ($loader, $pharFile) { + $loader->addDirectory("phar://$pharFile/non-dir"); +}, 'Nette\DirectoryNotFoundException', "Directory 'phar://$pharFile/non-dir' not found."); + +Assert::exception(function() use ($loader, $pharFile) { + $loader->addDirectory("phar://$pharFile/non-file.php"); +}, 'Nette\DirectoryNotFoundException', "Directory 'phar://$pharFile/non-file.php' not found.");