【发布时间】:2017-05-12 11:42:31
【问题描述】:
这是我的代码:
class WechatServiceProvider extends ServiceProvider
{
// Bootstrap the application services.
// @return void
public function boot()
{
//
}
// Register the application services.
// @return void
public function register()
{
$this->app->bind('App\Http\Wechat',function()
{
$arr = array('token'=>'foo') ;
return new Wechat($arr) ;
});
}
}
尝试在此处自动注入依赖项
class WechatController extends Controller
{
protected $wechatObj;
public function __construct(Wechat $wechatObj)
{
$this->wechatObj = $wechatObj;
}
...
}
在 App\Http\Wechat.php 中
public function __construct($options)
{
$this->token = isset($options['token'])?$options['token']:'';
$this->encodingAesKey = isset($options['encodingaeskey'])?$options['encodingaeskey']:'';
$this->appid = isset($options['appid'])?$options['appid']:'';
$this->appsecret = isset($options['appsecret'])?$options['appsecret']:'';
$this->agentid = isset($options['agentid'])?$options['agentid']:'';
$this->debug = isset($options['debug'])?$options['debug']:false;
$this->logcallback = isset($options['logcallback'])?$options['logcallback']:false;
}
错误堆栈
- Container.php 第 850 行中的 BindingResolutionException: App\Http\Wechat 类中无法解析的依赖解析 [Parameter #0 [ $options ]]
- 在 Container.php 第 850 行
- 在 Container->resolveNonClass(object(ReflectionParameter)) 在 Container.php 第 817 行
- 在 Container->getDependencies(array(object(ReflectionParameter)), array()) in Container.php line 790
【问题讨论】:
-
我认为你需要在这里运行
composer dump-autoload
标签: php laravel dependency-injection laravel-5.3