In my project, I’m including a package I’m developing, which has a composer.json, which includes the following autoload entry:
(censored to not get in trouble with my company of course)
{
"autoload": {
"psr-4": {
"Vendor\Package\": "src/Package"
}
}
}
The main project and the package both have a composer.json, this is from the package’s composer.json
I have also seen some examples that only used "Vendor\", but this resulted in the exact same issue.
I am requiring the package on version tag (from a git repository), so it should get and install the package correctly.
Any time composer runs autoload, it complains the namespaces don’t conform to PSR-4. I have checked the capitalisation, which all checks out. It complains about pretty much every php file in my project. Here’s an example of the file structure:
vendor
|- package
|- src
|- Package
|- PackageServiceProvider.php
The namespace of PackageServiceProvider.php is VendorPackage
, and the class is PackageServiceProvider
.
As far as I know, this is how it’s supposed to be. Yet composer still gives the deprecation notice.
I should probably mention that I have also tried running composer clearcache
between all of the things I’ve tried (which are mainly changing capitalisation), which didn’t help.
I am completely out of ideas on how to fix this.
I’m on composer version 1.10.13, and Laravel version 5.8.38.
One of the many deprecation notices I’m getting:
Deprecation Notice: Class VendorPackagePackageServiceProvider located in D:/wwwroot/project/vendor/{package-vendor}/package/src/PackagePackageServiceProvider.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar://C:/Users/me/AppData/Local/ComposerSetup/bin/composer.phar/src/Composer/Autoload/ClassMapGenerator.php:201
2
Answers
As it turns out, the version of the package that's on our git repository, had a mistake in its composer.json which I'd long fixed locally. But since it wasn't fixed on the repo, composer had never finished updating the dependencies, and hadn't updated its links to the packages.
All I had to do was change
to
and push it to the repository.
That’s wrong approach. That package, which apparently you manually planted in your
vendor/
folder (which is, let’s say, moderately OK) should be valid composer package with owncomposer.json
file. Then ordinarycomposer dumpautoload
would perfectly suffice to build class map for autoloading. No oddities like yours needed.