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

Core composer.json should replace all sub packages to avoid ambiguous class resolution #6213

Open
ambroisemaupate opened this issue Mar 12, 2024 · 3 comments

Comments

@ambroisemaupate
Copy link
Contributor

How to reproduce

  • Require api-platform/core in main project
  • Main project requires a package which requires api-platform/metadata
Warning: Ambiguous class resolution, 
"ApiPlatform\Metadata\Resource\Factory\CachedResourceMetadataCollectionFactory" was found 2x: 
in "/xxxxx/vendor/api-platform/metadata/Resource/Factory/CachedResourceMetadataCollectionFactory.php" 
and "/xxxxx/vendor/api-platform/core/src/Metadata/Resource/Factory/CachedResourceMetadataCollectionFactory.php", 
the first will be used.

Possible resolution

Core package composer.json should have a replace section with all sub-packages splitted from core:

{
    "replace": {
        "api-platform/metadata": "*",
        "api-platform/state": "*",
        // etc
    }
}

That way, if core is loaded, composer will not autoload any sub-package.

@soyuka
Copy link
Member

soyuka commented Mar 13, 2024

Hi, would you be able to check the v3.3.0-alpha.2? We removed these dependencies from the main composer.json.

@ambroisemaupate
Copy link
Contributor Author

Hi, would you be able to check the v3.3.0-alpha.2? We removed these dependencies from the main composer.json.

I don't understand. Problem would be the same on v3.3.0-alpha.2.

If I create a project using api-pack, api-platform/core will be loaded into my project.
Then, if my project depends on a library that relies only on api-platform/metadata, my project will have core and metadata packages autoloaded.

There are 2 solutions :

  1. api-platform/core composer.json declares a replace section, avoiding autoload any api-platform sub-packages
  2. or api-platform/api-pack does not load api-platform/core but all single api-platform packages. Thus, api-platform/core would become a dev-only package. The same way my project does not rely on symfony/symfony package, but all symfony/** sub-packages.

@soyuka
Copy link
Member

soyuka commented Mar 21, 2024

Then, if my project depends on a library that relies only on api-platform/metadata, my project will have core and metadata packages autoloaded.

It should not have core at all.

or api-platform/api-pack does not load api-platform/core but all single api-platform packages. Thus, api-platform/core would become a dev-only package. The same way my project does not rely on symfony/symfony package, but all symfony/** sub-packages.

yes we need to do this

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