Skip to content
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

Issues with composer autoloader in Symfony project #542

Closed
celdaran opened this issue Oct 25, 2023 · 2 comments
Closed

Issues with composer autoloader in Symfony project #542

celdaran opened this issue Oct 25, 2023 · 2 comments
Assignees

Comments

@celdaran
Copy link

celdaran commented Oct 25, 2023

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?

@yash30201
Copy link
Collaborator

Hi @celdaran , sorry for the delay in coming to this issue.

Do you still face this issue?

@yash30201 yash30201 self-assigned this Apr 30, 2024
@yash30201
Copy link
Collaborator

Closing due to inactivity, please feel free to reopen this is issue still exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants