dp518158 2018-10-24 23:48
浏览 99

Laravel包开发服务提供商注册功能单例不工作

I'm trying to create a package and need to validate that the credentials are loaded from the config file each time an instance is created. This is because I'm going to pass the $config variable in the package constructor.

So, in my package service provide class I have the register function and in that I'm using the following code:

// Register the service the package provides.
$this->app->singleton('mypackage', function($app) {
  die(' 49');

  $config = $app['config']->get('mypackage');
  if(!$config){
    throw new \RuntimeException('missing mypackage configuration section');
  }
  if(!isset($config['TARGETBRANCH'])){
    throw new \RuntimeException('missing mypackage configuration: `API`');
  }
  return new Mypackage($config);
});

As you can see that I have a "die" as the first action in the singleton, so I'm expecting to see "49" in the browser where I am calling the instance but the singleton isn't called and I get straight to the package class.

In the class I have the constructor as:

public function __construct($config){
  dd($config);
}

What could be possibly be going wrong here? Any help would be really appreciated.

Thank you

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 shape_predictor_68_face_landmarks.dat
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制