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

Composer\InstalledVersions not found #532

Closed
martinssipenko opened this issue Aug 5, 2021 · 13 comments
Closed

Composer\InstalledVersions not found #532

martinssipenko opened this issue Aug 5, 2021 · 13 comments

Comments

@martinssipenko
Copy link

I'm trying to use scoper on my project where I use Composer\InstalledVersions class. After running scoper the class gets prefixed with _PhpScoper2d7049acc8b0 and becomes _PhpScoper2d7049acc8b0\Composer\InstalledVersions. After running scoper I run composer dump --classmap-authoritative from within build/ directory.

Now when I try to run my application I get an error:
Uncaught Error: Class '_PhpScoperb8eeadf8a1cd\Composer\InstalledVersions'

I've found that reference to this class is in vendor/composer/autoload_classmap.php file, but it's referencing a non-prefixed version:

'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',

Is there anything I'm doing wrong?

@theofidry
Copy link
Member

Hi, I'm not certain:

  • which version of PHP-Scoper is it?
  • what OS is it?
  • what PHP version is it?
  • are you loading the vendor/scoper-autoload.php file instead of the composer one?

@martinssipenko
Copy link
Author

@theofidry

  • PHP Scoper version 0.14.1@023b231
  • MacOS
  • PHP 7.4.16
  • I'm loading vendor/autoload.php in my application
  • I'm using Composer version 2.1.5

@theofidry
Copy link
Member

I'm loading vendor/autoload.php in my application

This is the issue: for the scoped code you need to autoload the PHPScoper autoloader. It doesnt look clear from the doc in the "build without Box" section so it might be worth adding a note about it

@martinssipenko
Copy link
Author

Just to be clear, I've actually tried using Box and encountered the same issue. I tried to pinpoint the issue by using Scoper without Box, which produced the same results.

@theofidry
Copy link
Member

that is weird, but to keep in mind Box does more stuff so instead of trying to replicate what it does i would suggest to break down the issue as follows:

  • see if it's a box issue or a PHP-Scoper issue: is the built PHAR working when building with box without PHP-Scoper?
  • is the scoped app working fine outside the PHAR? (you can try --debug when building with Box it will dump the PHAR content in a temporary directory so you can execute the app outside the PHAR)

@martinssipenko
Copy link
Author

I've narrowed it down a bit, turns out that when I run the application that was produced using --debug option, one that's located in .box_dump/ directory, the composer uses class map from autoload_static.php file, but similar to what I said before the value there is without the prefix:

'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',

If I use Box without scoper it works as expected.

@theofidry
Copy link
Member

do you have a reproducer? I think there is more to it because both Box and PHP-Scoper build themselves in a similar fashion

@martinssipenko
Copy link
Author

Wdym? A repo where this can be observed?

@theofidry
Copy link
Member

Yes, something I could easily check out locally ideally

@martinssipenko
Copy link
Author

martinssipenko commented Aug 5, 2021

here is a reproducer https://github.com/martinssipenko/php-scoper-issue
clone it, composer install and try running box
both phar and .box_dump/ have same issue

@theofidry
Copy link
Member

thanks! will try to check it out during the week

@weirdan
Copy link

weirdan commented Jan 8, 2022

This now affects Psalm as well: vimeo/psalm#7329. @theofidry, did you have any luck looking into this? Even though we're using an outdated box version in Psalm, upgrading didn't change a thing as far as this issue is concerned.

@theofidry
Copy link
Member

This should be fixed with 0.16. If that's not the case please open a new issue

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

3 participants