类不符合psr-4自动加载标准。跳绳
我尝试使用作曲家自动加载,但出现此错误
作曲家.json
{
"autoload":{
"psr-4":{
"App":"app/"
},
"files": ["app/functions/helper.php"]
},
"require": {
"vlucas/phpdotenv": "^2.4",
"altorouter/altorouter": "^1.2",
"philo/laravel-blade": "^3.1"
},
"config":{
"optimize-autoloader":true
}
}
我的终端输出
Generating optimized autoload files
Class AppControllersBaseController located in D:/php/Xamp/htdocs/MVC_PHP/appcontrollersBaseController.php does not comply with psr-4 autoloading standard. Skipping.
Class AppControllersIndexControllers located in D:/php/Xamp/htdocs/MVC_PHP/appcontrollersIndexControllers.php does not comply with psr-4 autoloading standard. Skipping.
Class AppRoutingDispatcher located in D:/php/Xamp/htdocs/MVC_PHP/approutingRoutingDispatcher.php does not comply with psr-4 autoloading standard. Skipping.
Generated optimized autoload files containing 508 classes
回答
在PSR-4标准要求的文件和目录区分大小写和相应的类和命名空间是在PascalCase。
对于AppControllersBaseController类,该文件应位于:
app/Controllers/BaseController.php
注意大写
C
第二个错误:对于顶级命名空间之后的任何命名空间,必须有一个同名的目录。
您有一个AppRoutingDispatcher应该放置为的类,app/RoutingDispatcher.php但该app/routing/RoutingDispatcher.php文件将对应于一个AppRoutingRoutingDispatcher类。
您必须更改该类的命名空间或移动文件。
如果更改其命名空间,请务必
app/routing使用前导大写字母重命名目录。
- @FrankChen the standard requires you to have a *top level namespace* corresponding to a *root directory*, this is what you configure in your **composer.json** in `autoload.psr4`: `"SomeTopLevelNamespace": "some/root-directory"`, both of those parts don't need to be named the same as you can see in the [section 3 of the document](https://www.php-fig.org/psr/psr-4/). However, it is very common (I'd even say *standard*) to put all of your PHP classes in a `src` directory.