thinkphp 5 方法注入

方法注入
application\\common.php


use think\\Request;
function getUserInfo(Request $request, $userId){
    
    return $userId.' good luck to you ';// 根据$userId获取用户信息
}
 

控制器中调用
use think\\Request;
public function read($userId='ffzr'){
        Request::hook('user','getUserInfo'); //绑定user指向getUserInfo函数
        $info = request()->user($userId);
        return $info;  
}      
 

结果:110  good luck to you