Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
471 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 MyNameSpaceController;

/* namespace for classes in repository directory */
namespace MyNameSpaceRepository;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...