nette / robot-loader

🍀 RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.
https://doc.nette.org/robotloader
Other
871 stars 32 forks source link

Exlude dir does not work with relative (../..) parent dir #13

Closed milo closed 6 years ago

milo commented 6 years ago

Description

In Nette application bootstrap, I call:

$configurator->createRobotLoader()
    ->addDirectory(__DIR__)
    ->addDirectory(__DIR__ . '/../lib')
    ->excludeDirectory(__DIR__ . '/../lib/tcpdf')
    ->register();

but exclusion does not work because on line https://github.com/nette/robot-loader/blob/c3b0c97c04ed82f4d1037a0fd0881f94f9588009/src/RobotLoader/RobotLoader.php#L231 leads to

$disallow === [
    "D:/Web/project/lib/tcpdf" => true,
];

$path === "D:/Web/project/app/../lib/tcpdf";

I have two solutions in my mind: 1) Convert path to realpath in addDirectory() and: a) ignore missing paths b) throw an exception on missing paths (BC break probability) 2) Modify mentioned line from $dir->getPathname() to $dir->getRealPath().

Which fix would you prefer? Another one?

dg commented 6 years ago

getRealPath() seems best, because is called only when refreshing cache, right?

milo commented 6 years ago

I think so, good point. I'll open PR.