Jump to content

Composer - Autoload and PSR-0 vs PSR-4


Recommended Posts

I'm beginning to study Composer and am developing a system where I separate the files core application files, as follows:

|-- /src
|-- /App
|-- /DBConfig
|-- /Controller
|-- /Model
|-- /Core
|-- /Helper
|-- /Controller
|-- /Model

So, to set this setting in composer.json file and get access to all classes both /App much /Core would be this way?

"autoload" : {
"psr-X" : {
"App\\" : "/src",
"Core\\" : "/src"

Or is there a more correct way?

I have also read about PSR-0 vs PSR-4 and I am still somewhat in doubt which one to use. In my case what should I implement, PSR-0 or PSR-4?

Link to comment
Share on other sites

With the layout you have you should tell composer that you are using psr-0.


Then, as long as you are using namespaces that coincide with your directory structure your classes will be autoloaded.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.