Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lucassimines's avatar

Thanks a lot sir, didn't now that thing about composer. ;)!

1 like
rawfan's avatar

Not sure if you solved it, yet, but there's one problem I can see. Your folder structure doesn't seem to conform to namespacing needed for PSR-4.

Inside your actual package folder you have a /src folder. Inside that folder you want to have folders corresponding with your actual namespace. So in your case your package folder should have files like these:

src
src/Fmcdigital
src/Fmcdigital/MyPackage
src/Fmcdigital/MyPackage/MyActualCode.php
composer.json
readme.md

Your namespace in the code would be Fmcdigital/MyPackage and the composer.json autoload-section should look like this:

"autoload": {
    "psr-4": {
      "Fmcdigital\\MyPackage\\": "src/Fmcdigital/MyPackage/"
    }
  },

Hope this clears it up. Just look at other packages.

lucassimines's avatar

@rawfan thanks for the answer, but my package won't run composer because it is not in packagist, it's private. I changed it's folder from vendor to packages, is there any way I can run it's packages folder composer.json ?

rawfan's avatar

Packagist really doesn't seem to have anything to do with your problem. You can always just PSR4 autoload any folder in your file system you wish. The classes in there just need to follow PSR4 (which they don't in your case).

The way I see it your package wouldn't work even if it were on packagist (or any other public or non-public vcs-repository).

Previous

Please or to participate in this conversation.