Issues with composer autoloader in Symfony project
celdaran opened this issue · comments
I have a sample script working just fine in a plain test.php
file, because I wanted to make sure it worked before I integrated it into my Symfony project. But transplanting the code is giving me this error:
Attempted to load class "CachedKeySet" from namespace "Firebase\JWT".
Did you forget a "use" statement for another namespace?
Long story short, I've resorted to step-debugging through composer's autoloader to try and find out why CachedKeySet is invisible.
These lines appear in autoload_static.php
:
'Firebase\\JWT\\BeforeValidException' => __DIR__ . '/..' . '/firebase/php-jwt/src/BeforeValidException.php',
'Firebase\\JWT\\CachedKeySet' => __DIR__ . '/..' . '/firebase/php-jwt/src/CachedKeySet.php',
'Firebase\\JWT\\ExpiredException' => __DIR__ . '/..' . '/firebase/php-jwt/src/ExpiredException.php',
etc.
Similar lines in autoload_classmap.php
:
'Firebase\\JWT\\BeforeValidException' => $vendorDir . '/firebase/php-jwt/src/BeforeValidException.php',
'Firebase\\JWT\\CachedKeySet' => $vendorDir . '/firebase/php-jwt/src/CachedKeySet.php',
'Firebase\\JWT\\ExpiredException' => $vendorDir . '/firebase/php-jwt/src/ExpiredException.php',
etc.
And primarily where I would expect to find it, in autoload_psr4.php
:
'Firebase\\JWT\\' => array($vendorDir . '/firebase/php-jwt/src', $vendorDir . '/firebase/php-jwt/src'),
But at the point where it attempts to actually load the file, it comes up missing. In composer's ClassLoader, there's this code:
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
There's no element in prefixLengthsPsr4['F']
and so it bails immediately and never loads.
Any clues?