4

After running composer update , I keep having the error below:

Warning: Ambiguous class resolution, "Doctrine\ORM\Persisters\Entity\BasicEntityPersister" was found in both "$baseDir . '/engine/Library/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php" and "/var/www/html/shop5/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php", the first will be used. Warning: Ambiguous class resolution, "Doctrine\Common\Proxy\AbstractProxyFactory" was found in both "$baseDir . '/engine/Library/Doctrine/Common/Proxy/AbstractProxyFactory.php" and "/var/www/html/shop5/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php", the first will be used.

I have tried to run the following commands but none of them works:

composer dump-autoload -o
composer clearcache

Any idea how to fix this issue ? Thank you

[shopware5 - php7.0]

Sirius
  • 653
  • 1
  • 14
  • 37
  • 1
    Looks like you have the Doctrine library installed in multiple places, which one are you using? Try to delete the location that you're not using. – Nando Jan 09 '18 at 21:56

2 Answers2

3

This is the normal behavior of Shopware.

The Doctrine library uses the final class statement quite often and in order to get it to work with the Shopware attribute system the classes were replaced through the composer autoloading. You can find the changed files in shopware/engine/Library/Doctrine/Common

FYI: This is the reason why Shopware only works when the composer autoloading is optimized.

composer dump-autoload --optimize

Otherwiese you will encounter random errors from invalid or wrong entities.

FloydThreepwood
  • 1,587
  • 14
  • 24
  • 6
    That's really bad. The final keyword has its purpose, you know? – mblaettermann Apr 17 '18 at 18:15
  • @mblaettermann It means you can't extend it, so we replaced it. In Java it has performance implications, but in PHP it's just the communication of a Contract. I don't see how this can be good or bad either way... It's just clearly necessary. – FloydThreepwood Apr 20 '18 at 08:41
  • @FloydThreepwood The point is: This file is that crucial that it is FORBIDDEN to extend it or even worse: replace it. Please dont argue over these facts. What you did IS wrong and there is no real solution in sight. Your answer insults me. – mblaettermann Apr 24 '18 at 20:36
  • 1
    :D This is more fun then I expected. Of course I will argue over those "facts". An application is not the slave of the frameworks it incorporates, but uses frameworks in it's own interest. This of course does not mean that we should get a free pass here, but also not that the option is strictly forbidden. – FloydThreepwood Apr 25 '18 at 10:07
2

To get rid of these warning you should add files with ambiguous classes to exclude-from-classmap in your composer.json:

"autoload": {
    ...
    "exclude-from-classmap": [
        ...
        "vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php",
        "vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php"
    ]
},

Then dump-autoload will ignore these files.


This is the reason why Shopware only works when the composer autoloading is optimized.

I didn't investigate how this is done in Shopware, but this also could be fixed/improved. For composer more precise definitions for namespaces have a precedence. So if you have this in your autoload:

"autoload": {
    "psr-0": { 
        "somevendor\\somepackage\\": "vendor/somevendor/somepackage/",
        "somevendor\\somepackage\\db\\": "overrides/somevendor/somepackage/db/"
    }
},

And if you request for somevendor\somepackage\db\Entity class, the composer will first search in overrides/somevendor/somepackage/db/Entity.php and only if it can't find it, it will try vendor/somevendor/somepackage/db/Entity.php. This is because definition for somevendor\somepackage\db namespace is more precise than for somevendor\somepackage.

So if you want to override 3rd-party classes in this way, you should define more precise namespaces than 3rd-party library do.

rob006
  • 21,383
  • 5
  • 53
  • 74
  • Interesting. Thanks for sharing this knowledge. I will play with the shopware composer.json and see if this can be solved, at least get rid of the warning. Proper fix would be fixing the shopware attribute system. Much more work and legacy BC breaks involved there. – mblaettermann Apr 25 '18 at 19:30