Hyperf自动加载公共函数库

打开composer.json文件,找到autoload配置项,在其子项files加入公共函数库文件路径,最终效果如下:

"autoload": {
    "psr-4": {
        "App\\": "app/"
    },
    "files": [
        "app/Utils/function.lib.php"
    ]
}

执行命令重新生成自动加载文件
[root@localhost hyperf]# /program/php/bin/php /usr/local/bin/composer dump-autoload -o # 该命令耗时约30秒
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]?
Generating optimized autoload files
> rm -rf runtime/container
Generated optimized autoload files containing ***** classes
[root@localhost hyperf]#
 
重新启动项目就会自动加载公共函数库,如果有别的要自动加载也可以加入files里面,启动项目时会按照顺序自动加载。

Copyright © 2024 码农人生. All Rights Reserved