Laravel 5.4更新 - SHA Hasher在Singleton中未设置的非法偏移类型

问题描述:

I'm migrating from Laravel 5.3 to Laravel 5.4. We have a custom SHA hasher from a previous application.

In the Laravel 5.4 patch notes, it is shown that share() has been removed and singleton() is to replace it.

I've got the application up and running except for the newly updated hasher. When I change my share function to singleton I get the following error:

ErrorException: Illegal offset type in unset in /Applications/XAMPP/xamppfiles/htdocs/App/vendor/laravel/framework/src/Illuminate/Container/Container.php:1090
#3 /Applications/XAMPP/xamppfiles/htdocs/App/app/Libraries/SHAHashServiceProvider.php(13): Illuminate\Container\Container->singleton(Object(Closure))

I have the newly updated hasher is as following:

public function register() {
    $this->app['hash'] = $this->app->singleton(function () {
        return new SHAHasher();
    });

}

What am I doing wrong here with the singleton function?

Thanks!

我正在从Laravel 5.3迁移到Laravel 5.4。 我们有一个来自先前应用程序的自定义SHA hasher。 p>

在Laravel 5.4补丁说明中,显示已删除 share() code>并且 singleton() code>将替换它。 p>

我已启动并运行该应用程序,但新更新的hasher除外。 当我将共享功能更改为单例时,我收到以下错误: p>

  ErrorException:/ Applications / XAMPP / xamppfiles / htdocs / App / vendor / laravel中未设置的非法偏移类型 /framework/src/Illuminate/Container/Container.php:1090
#3 /Applications/XAMPP/xamppfiles/htdocs/App/app/Libraries/SHAHashServiceProvider.php(13):Illuminate \ Container \ Container-> singleton( 对象(闭包))
  code>  pre> 
 
 

我新更新的hasher如下: p>

 公共函数寄存器(  ){
 $ this-> app ['hash'] = $ this-> app-> singleton(function(){
 return new SHAHasher(); 
}); 
 
} \  n  code>  pre> 
 
 

我在这里使用单例函数做错了什么? p>

谢谢! p> div>

This is what the docs have for creating a singleton:

$this->app->singleton('HelpSpot\API', function ($app) {
    return new HelpSpot\API($app->make('HttpClient'));
});

Doesn't match what you have.

Laravel Docs - 5.4 - Service Container - Bindings