Composer自2.0起已移除include-path功能,旧项目需改用PSR-4、classmap或files实现自动加载,推荐遵循PSR-4规范组织代码。

在旧版本中,你可以在 composer.json 中这样配置:
{
"require": {
"monolog/monolog": "^1.0"
},
"include-path": ["src/", "lib/"]
}
例如,使用 classmap 扫描特定目录:
{
"autoload": {
"classmap": ["src/", "legacy/"]
}
}
或者使用 files 加载工具函数:
{
"autoload": {
"files": ["src/helpers.php"]
}
}
配置完成后运行:
composer dump-autoload
以上就是Composer如何使用include-path添加搜索路径的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号