How to set up a composer autoloader for modules?

35 views Asked by At

I have some config for project

{
  "autoload": {
    "psr-4": {
      "Module\\": [
        "app/modules",
        "system/modules"
      ]
    }
  }
}

and classes are available on this path

app/modules/ModuleName/SomeClass.php

How can I make the composer look to

app/modules/ModuleName /src/SomeClass.php,

but with old namespace Module\ModuleName?

1

There are 1 answers

0
localheinz On

Just add a corresponding mapping:

{
  "autoload": {
    "psr-4": {
      "Module\\": [
        "app/modules",
        "system/modules"
      ],
      "Module\\ModuleName\\": [
        "src/"
      ]
    }
  }
}

Mapping Module\ModuleName to app/modules/ModuleName/ is already covered with the existing mapping.