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

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

关于Composer自动加载问题。

我的开发环境:
PHP : 7.3.4
Apache : 2.4.39
Composer : 1.8.5

用Composer1.8.5来开发PHP框架,用PSR-4自动加载规则。具体目录:

App
 |-Controller
       |- HomeController.php
 |- Models
 |- View
vendor
 |- autoload.php
 |- .....
index.php
composer.json

composer.json代码是:

{
 "require":?{
 "noahbuscher/macaw": "dev-master",
 },
 "autoload":{
     "psr-4":?{
         "App\": "App"
     }
 }
}

以上在composer 1.8.5运行没什么问题,直接生成命令

composer dump-autoload -o

但是,升级1.10.13 或 2.0版本,用生成命令提示警告:

Class AppControllerHomeController located in C:/web/AppControllerHomeController.php does not comply with psr-4 autoloading standard. Skipping.

理解是 1.10以上版本对psr-4废弃警告

HomeController.php 这个文件的命名空间是:

namespace AppController;

class HomeController{
    public function index(){
    echo 'hi';
    }
}

那这个如何解决?


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

1 Answer

0 votes
by (71.8m points)

解决问题,命名大小写有关系。
namespace Appxxxxxx; 命名第一个大写,后面xxx所有命名必须小写。

然后升级2.0.0-RC1 输入命令:

composer self-update --preview

再生成:

composer dump-autoload -o

无报错!

感谢@bug开发!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...