My PSR4 structure isn't registering when I composer dump-autoload
. This my composer, the entry is src/Booksmart :
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/controllers/Api",
]
},
"psr-4": {
"Booksmart\\": "src/Booksmart"
},
and this is my directory structure:
src/
Booksmart/
Advance/
Advance.php
The Advance.php looks like this:
<?php
namespace Booksmart\Advance
class Advance
{
}
My vendor/composer/autoload_psr4.php
doesn't show the new entry for my Booksmart namespace though, and is definitely not loading the Advance.php class. This seems so simple to screw up, what am I missing?
PSR-4 must be inside autoload:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/controllers/Api",
],
"psr-4": {
"Booksmart\\": "src/Booksmart"
},
},
I thing you don't need compose. In my case I am paying namespace like this in "Advance" class.For Example namespace App\\src\\Bookmart\\Advance
. And then in the dependency class use App\\src\\Bookmart\\Advance;
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.