php - 在 Composer 中配置类自动加载
问题描述
Github上有一个运行稳定的项目。下面是一个作曲家文件:
{
"name": "wnull/userbars-warface-generator",
"description": "Simple and free library to generate userbars game Warface",
"keywords": [
"wf",
"warface",
"generator",
"userbars"
],
"type": "library",
"license": "MIT",
"require": {
"php": ">=7.1"
},
"autoload": {
"psr-4": {
"WF\\": "src/WF"
}
}
}
问题是每次通过composer成功安装项目后,都要执行如下命令:
>>> composer dump-autoload -o
之后,所有类都将正常工作。从控制台登录:
C:\hangry>composer require wnull/userbars-warface-generator
Using version ^1.0 for wnull/userbars-warface-generator
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing wnull/userbars-warface-generator (v1.0): Loading from cache
Writing lock file
Generating autoload files
C:\hangry>
C:\hangry>composer dump-autoload -o
Generated optimized autoload files containing 6 classes
问题:如何避免每次都输入此命令,并且在正常安装期间一切正常?
解决方案
通过更换PSR-4
to解决了这个问题classmap
。谢谢@MagnusEriksson。
作曲家文件:
{
"name": "wnull/userbars-warface-generator",
"description": "Simple and free library to generate userbars game Warface",
"keywords": [
"wf",
"warface",
"generator",
"userbars"
],
"type": "library",
"license": "MIT",
"require": {
"php": ">=7.1"
},
"autoload": {
"classmap": ["src/WF"]
}
}
推荐阅读
- react-native - 具有稳定版本的 ReactNative init 项目
- serverless - 如何从 AWS SAM 获取堆栈输出?
- c# - Edit bootstrap modal 可以工作,或者 Jquery .validate 函数可以工作
- git - 如何从 GitHub 中彻底删除敏感提交?
- arrays - BigQuery:如何计算 REPEATED 字段中的特定值?
- c++ - 在某些系统上 std::vector 操作较慢
- php - 在 jQuery 上使用多个远程 ajax
- android - 在 Android 项目 build.gradle 文件中更新 Google Firebase 依赖项
- c++ - C++ 数组大于 0 打印代码
- c - 在for循环中运行scanf时出现逻辑错误,我该如何解决?