-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] FilteredComposerIterator doesn't find classes in PSR4 fallback dirs #22
Comments
Hi @josefsabl, Can you please test the |
Wow, you are fast 😅❤️. I will check on monday. |
Unfortunately it is still not working. The problem is that Another problem is that when I comment out the aforementioned check your library includes all php files, that are in that directory, even those that do not contain classes but are php scripts that do something which leads to very wild results. In all humbleness, this is pretty important side effect that should be at least highly stressed out in the documentation. I consider it to be very dangerous. But I am sure you are aware of this 😄. I did see this #12 and this composer/composer#6987. |
I see, but maybe I did not understand your problem correctly. Could you please open a PR with a minimal reproducer? |
I am now looking into your tests in the fixing commit. Indeed it is a misunderstanding of the problem or maybe even the fallback directory feature (?). The fallback doesn't work like that those classes don't have a namespace. It practically means that looking for namespaces start in a particular directory (src) and the next level of directories determines the first level of namespaces. Imagine this directory structure:
And this entry in composer.json:
This means that the classes will be autoloaded as:
Attached class-finder-poc.zip is a minimalistic proof of concept with the demonstration of a bug. The <?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
$finder = new \Kcs\ClassFinder\Finder\ComposerFinder();
$finder->inNamespace('ExplicitNamespace'); // <= This works as expected
$finder->inNamespace('FallbackNamespace'); // <= This causes nothing to be found in fallback directory
// When not filtered by namespaces (i.e. remove the two lines above)
// It works as \Kcs\ClassFinder\Iterator\FilteredComposerIterator::validNamespace
// always returns true
foreach ($finder as $className => $reflector) {
echo $className . PHP_EOL;
}
It tests '' against valid namespaces, i.e. looks if it starts with any whitelisted namespace. It is empty, so it can never start with any real namespace. I.e. fallback directory can contain ANY namespace. In fact this check is redundant and merely removing it works for me at the moment. I also noticed another negative consequence of the side effect I mentioned earlier. Because you include the files to check if the class is there, you also include files with classes in path that doesn't correspond with their namespace. Imagine you have a class in |
Yes, you're right. The |
A fix for this has been released in At the moment, if a file is causing fatal error, it can be ignored via I'll leave this issue open, while thinking about a way to not include all the files in the fallback dirs, but at least the fix is released. |
Hello, I am (as it seems) end user of this library as a dependency of The Coding Machines GraphQLite library and encountered this bug: thecodingmachine/graphqlite#696.
I narrowed the problem down to this class-finder. As it seems the
\Kcs\ClassFinder\Iterator\FilteredComposerIterator::searchInPsrMap
method doesn't look for classes in\Composer\Autoload\ClassLoader::getFallbackDirsPsr4
.And that turned to be my case exactly.
I, indeed, have something like this in my composer.json:
And the classes the GraphQLite looks for are, indeed, in the
src
directory :-)Thank you for your library, have a nice day.
PS: If you consider this to be a feature and not a bug, I apologize about the [BUG] in a title.
The text was updated successfully, but these errors were encountered: