Skip to content
Closed
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
8 changes: 5 additions & 3 deletions src/RobotLoader/RobotLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
49 changes: 49 additions & 0 deletions tests/Loaders/RobotLoader.phar.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* Test: Nette\Loaders\RobotLoader loading from PHAR.
*
* @phpIni phar.readonly=0
*/

use Nette\Loaders\RobotLoader,
Nette\Caching\Storages\DevNullStorage,
Tester\Assert;


require __DIR__ . '/../bootstrap.php';

$pharFile = TEMP_DIR . '/test.phar';

$phar = new Phar($pharFile);
$phar['class.A.php'] = '<?php class A {}';
$phar['class.B.php'] = '<?php class B {}';
$phar['class.C.php'] = '<?php class C {}';
$phar['sub/class.D.php'] = '<?php class D {}';
$phar->setStub('<?php __HALT_COMPILER();');
unset($phar);

Assert::true( is_file($pharFile) );


$loader = new RobotLoader;
$loader->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.");