I have a folder structure like this:
Root-Folder/backend/user/class-user.php
Root-Folder/backend/profile/class-profile.php
Root-Folder/backend/login.php
Sample class-user.php content:
namespace myapp\user;
class User{
....
}
In my composer.json:
...
"autoload": {
"psr-4": {
"myapp\\": "backend/"
}
},
...
But this way the files are not included because they have a class- prefix in the file name. If I change the file names to user.php and profile.php, they work.
How can I configure composer to include class-user.php too?
PSR-4 requires classes names to be the same as file name that contains it. In this case you need to use "classmap" directive instead of PSR-4
https://getcomposer.org/doc/04-schema.md#classmap
{
"autoload": {
"classmap": ["backend"]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With