composer.json文件php用
composer.json文件怎么使用?laravel 如何使用composer自动加载自己定义的文件夹?
一. 问题
当我们 clone下来一个laravel框架,接着就开始我们表演,但是我们根据业务需求需要创建一些自定义的文件夹,那么我们该如何加载他们呢,如何避免这类错误[Symfony\\Component\\Debug\\Exception\\FatalThrowableError] Class 'tools\\alyduanxin\\api\_demo\\SmsDemo' not found
二:分三步来解决这个问题
在laravel 中项目根目录下创建自己的文件夹,例如我在项目根目录下创建了一个tools文件夹。
在项目文件夹的根目录下找到composer.json
文件,在autoload里添加psr-4节点
"psr-4": {
"tools\\": "tools/"
}
接着执行
composer dump-autoload -o
至此我们就加载成功啦
三. 解释一下 composer dump-autoload 这条命令
下面是composer官方文档中关于dump-autoload命令的解释:
dump-autoload
If you need to update the autoloader(类加载器) because of new classes in a classmap package for example, you can use "dump-autoload" to do that without having to go through an install or update.
Additionally, it can dump an optimized(优化) autoloader that converts(转化) PSR-0/4 packages into classmap ones for performance(性能) reasons. In large applications with many classes, the autoloader can take up a substantial portion of every request's time. Using classmaps for everything is less convenient in development, but using this option you can still use PSR-0/4 for convenience and classmaps for performance.
Options:
--no-scripts: Skips the execution of all scripts defined in composer.json file.
--optimize (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
--classmap-authoritative (-a): Autoload classes from the classmap only. Implicitly enables --optimize.
--apcu: Use APCu to cache found/not-found classes.
--no-dev: Disables autoload-dev rules.
其中官方推荐的参数是 -o,即 composer dump-autoload -o
这个命令可以将PSR-0/4自动加载成classmap来获取一个更快速的类加载器,推荐生产环境使用,但是,可能需要一点时间来运行,因此目前不是默认。
本文出至:学新通
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通
- 本文地址: https://www.swvq.com/boutique/detail/15891
- 联系方式: luke.wu@swvq.com
- 来源链接: www.php.cn/tool/composer/429240.html
系列文章
更多
同类精品
更多
精彩评论
-
docker hub 进不去怎么办
PHP中文网 03-15 -
2023年最新的28道PHP面试题附答案
PHP中文网 03-27 -
windows上查看nginx是否启动
PHP中文网 04-19 -
推荐五款xml编辑工具
PHP中文网 03-04 -
navicat怎样清除注册表
PHP中文网 04-05 -
ChatGPT应用通过Axios+EventSource使用GPT3.5 API
uWydnA 03-13 -
强力推荐10款好看使用的Bootstrap后台管理系统模板
PHP中文网 03-09 -
vscode怎么调整代码大小两种方法
PHP中文网 03-11 -
navicat连接sqlserver数据库
PHP中文网 04-03 -
navicat导入csv文件
PHP中文网 03-30