14

I have create a custom composer package but I am having troubles to set the correct autoload options for it.

All my classes are under MyNamespace/Common namespace. So for example for including my ArrayHelper class I do use Mynamespace/Common/Helper/ArrayHelper.

This is the relevant part of my composer.json:

"autoload": {
    "psr-0": { "MyNamespace\\": "" }
} 

I have read this: composer.json / autoload

Any help?

Paul T. Rawkeen
  • 3,994
  • 3
  • 35
  • 51
brpaz
  • 3,618
  • 9
  • 48
  • 75

1 Answers1

20

You have to navigate the file location of your namespace.

"autoload": {
    "psr-0": { "MyNameSpace": "./<path to your parent directory>" }
}

For example, this is my directory structure:

composer.json
source
  \-Data
    |-Controller
    \-Repository

Then, in the composer.json file:

"autoload": {
    "psr-0": { "MyNameSpace": "source/Data" }
}

Then, I can define classes in these namespaces:

/* namespace for classes in controller directory */
namespace MyNameSpace\Controller;

/* namespace for classes in repository directory */
namespace MyNameSpace\Repository;
Jan Richter
  • 1,976
  • 4
  • 29
  • 49
KarelG
  • 5,176
  • 4
  • 33
  • 49
  • My package structure was similar to symfony2 compoenents so I had to configure a target dir like this: http://getcomposer.org/doc/04-schema.md#target-dir – brpaz Aug 09 '13 at 13:56
  • 1
    namespace definitions delimiter should use "\" not "/" – thenetimp Aug 30 '14 at 09:31