box-project / box

📦🚀 Fast, zero config application bundler with PHARs.
https://box-project.github.io/box
MIT License
1.12k stars 101 forks source link

Box autoloader not behaving correctly #1405

Closed sebastianfeldmann closed 3 weeks ago

sebastianfeldmann commented 3 weeks ago

Bug report

Question Answer
Box version 3.16.0
PHP version 8.3.8
Platform with version MacOS 14.6.1/Github Actions
Github Repo repo/current issue

Symfony provides multiple polyfills. One of them is the ext-intl one. Symfony configures the autoloader as follows

"autoload": {
        "psr-4": { "Symfony\\Polyfill\\Intl\\Normalizer\\": "" },
        "files": [ "bootstrap.php" ],
        "classmap": [ "Resources/stubs" ]
    },

The classmap directory seems to indicate that if the Normalizer class does not exist it is loaded from Resources/stubs/Normalizer.php. This does not happen during PHAR execution. If the ext-intl is not available the execution fails with ...class Normalizer not found.... So I would think that the "Box autoloader" does not load the Resources/stubs/Normalizer.php file to make the Normalizer class available.

The original classmap can be checked in the resulting vendor/composer/autoload_classmap.php after running composer install.

return array(
    'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
    'CURLStringFile' => $vendorDir . '/symfony/polyfill-php81/Resources/stubs/CURLStringFile.php',
    'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
    'JsonException' => $vendorDir . '/symfony/polyfill-php73/Resources/stubs/JsonException.php',
    'Normalizer' => $vendorDir . '/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php',
    'PhpToken' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
    'ReturnTypeWillChange' => $vendorDir . '/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php',
    'Stringable' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
    'UnhandledMatchError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
    'ValueError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/ValueError.php',
);

Current box.json

{
  "alias": "captainhook",
  "banner": [
    "This file is part of CaptainHook",
    "",
    "(c) Sebastian Feldmann <sf@sebastian-feldmann.info>",
    "",
    "For the full copyright and license information, please view the LICENSE",
    "file that was distributed with this source code."
  ],
  "files":[
    "LICENSE"
  ],
  "base-path": null,
  "output": "build/phar/captainhook.phar",
  "compactors": [
    "KevinGH\\Box\\Compactor\\PhpScoper"
  ],
  "replacements": {
    "runtime": "PHAR"
  },
  "php-scoper": "build/scoper.inc.php"
}

To reproduce do the following ⚠️ use a php without ext-intl

git clone git@github.com:captainhookphp/captainhook.git
cd captainhook
composer install
phive install
composer compile (or tools/box compile)
build/phar/captainhook.phar

without the int extension this should fail as described in the linked issue on top, with the extension it should work.

Or am I missing something else?

theofidry commented 3 weeks ago

I have no idea to be honest. It does sound strange, but I don't see why Normalizer. It would more likely be related to PHP-Scoper which didn't always work nicely with polyfills. That said I doubt I can fix that, this is for Box 3.16.0 which is from Feb 14, 2022, the latest is 4.6.2...

sebastianfeldmann commented 3 weeks ago

oh my bad, missed the major version thingy :/

🤦‍♂️

I will update an try again and just close this in shame if it works

sebastianfeldmann commented 3 weeks ago

I show myself out .... sorry 🤦‍♂️