mirakl / sdk-php-shop

Mirakl PHP SDK for sellers
30 stars 16 forks source link

Class "Mirakl\Core\Domain\MiraklObject" not found on PHP 8.3 when installed with --classmap-authoritative #70

Open JanMikes opened 4 months ago

JanMikes commented 4 months ago

Once the composer is installed with composer install --classmap-authoritative, there is error Class "Mirakl\Core\Domain\MiraklObject" not found (there are errors for each class that is in composer.json in exclude).

Code to reproduce:

$request = new UpdateOffersRequest();
Error: Class "Mirakl\Core\Domain\MiraklObject" not found in /app/vendor/mirakl/sdk-php-shop/src/Mirakl/Core/Request/AbstractRequest.php:24
Stack trace:
#0 /app/vendor/composer/ClassLoader.php(576): include()
#1 /app/vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/app/vendor/com...')
#2 /app/vendor/mirakl/sdk-php-shop/src/Mirakl/MMP/OperatorShop/Request/Offer/AbstractUpdateOffersRequest.php(14): Composer\Autoload\ClassLoader->loadClass('Mirakl\\Core\\Req...')
#3 /app/vendor/composer/ClassLoader.php(576): include('/app/vendor/mir...')
#4 /app/vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/app/vendor/com...')
#5 /app/vendor/mirakl/sdk-php-shop/src/Mirakl/MMP/Shop/Request/Offer/UpdateOffersRequest.php(26): Composer\Autoload\ClassLoader->loadClass('Mirakl\\MMP\\Oper...')
#6 /app/vendor/composer/ClassLoader.php(576): include('/app/vendor/mir...')
#7 /app/vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/app/vendor/com...')

Package version 1.20.2 installed via composer.

Working workaround is to add the excluded files to composer.json to autoload:

"autoload": {
      "files": [
              "vendor/mirakl/sdk-php-shop/src/Mirakl/Core/Domain/Collection/AbstractMiraklArray.php",
              "vendor/mirakl/sdk-php-shop/src/Mirakl/Core/Domain/Collection/MiraklCollection.php",
              "vendor/mirakl/sdk-php-shop/src/Mirakl/Core/Domain/Collection/MiraklMap.php",
              "vendor/mirakl/sdk-php-shop/src/Mirakl/Core/Domain/MiraklObject.php"
          ]
}
JanMikes commented 4 months ago

I believe the correct fix would be modify src/Mirakl/autoload.php to add else branch to the if (isPHP7()) { to autoload files which are excluded from autoloading.

jreinke commented 3 months ago

Thanks for your feedback. @JanMikes

Actually, the compatibility with PHP 7 is going to be removed in coming v1.20.5 and therefore it will fix the issue using the --classmap-authoritative option of Composer.