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 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题