core
core copied to clipboard
Core composer.json should replace all sub packages to avoid ambiguous class resolution
How to reproduce
- Require
api-platform/corein 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.
Hi, would you be able to check the v3.3.0-alpha.2? We removed these dependencies from the main composer.json.
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 :
api-platform/corecomposer.json declares areplacesection, avoiding autoload any api-platform sub-packages- or
api-platform/api-packdoes not loadapi-platform/corebut all single api-platform packages. Thus,api-platform/corewould become a dev-only package. The same way my project does not rely onsymfony/symfonypackage, but allsymfony/**sub-packages.
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
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.