$app->when()->needs('$variableName') '$variableName'是什么?
$app->when(‘App\Http\Controllers\UserController’)->needs(‘$variableName’)->give($value);
$value 这是什么?
‘$variableName’ 这是什么?文档没写
这样写不可以啊
$this->app->when(TestService::class)->needs(‘string’)->give(function(){return [‘1111’];});
文档这样介绍的:
$app->when(‘App\Http\Controllers\UserController’)->needs(‘$variableName’)->give($value);
原始值绑定
逻辑是某个类需要某个变量时解析某个值
这样写就可以
$this->app->when(TestService::class)->needs(CouponRepositoryInterface::class)->give(function($app){
return $app->make(CouponRepository::class);
});
TestService的构造函数必须制定接口 CouponRepositoryInterface。
give(必须是一个实例)
那文档说 “逻辑是某个类需要某个变量时解析某个值”
那TestService的构造函数只需要一个变量$a,怎么绑定呢?
这样的吧
@deatil 是的,可以了。可以变量和接口实现一起吗。 例如UserController 构造函数__construct(interface $f,$a,$b,$c) 这样的容器要如何板顶