-1

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 Vendor\Package, 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 Vendor\Package\PackageServiceProvider located in D:/wwwroot/project/vendor/{package-vendor}/package/src/Package\PackageServiceProvider.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
Julian
  • 105
  • 1
  • 5
  • 1
    Please share the full and exact error message. Also, the structure does not look good: a package name usually consists of the vendor name, and the name of the package itself. This is used in the file structure, such that the usual folder to hold your files is not like `vendor/package`, but `vendor/user/package` – Nico Haase Oct 26 '20 at 12:52
  • @NicoHaase I have added one of the notices I'm getting. I'm not sure what you mean by vendor/user/package, could you elaborate a bit more? – Julian Oct 26 '20 at 14:58

2 Answers2

0

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

{
    "autoload": {
       "psr-4": {
              "Vendor\\": "src/Package"
          },
    }
}

to

{
    "autoload": {
       "psr-4": {
              "Vendor\\Package\\": "src/Package"
          },
    }
}

and push it to the repository.

Julian
  • 105
  • 1
  • 5
-2

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 own composer.json file. Then ordinary composer dumpautoload would perfectly suffice to build class map for autoloading. No oddities like yours needed.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • Sorry, I guess I was a little unclear. I have a project, that has a package insidse of it, both of which I'm developing. They both have a composer.json, the snippet I shared is from the composer.json in the package root. I'm running compser dump-autoload from the mian project. – Julian Oct 26 '20 at 14:40