使用“jasny/sso”包,我收到以下错误:
IlluminateContractsContainerBindingResolutionException Unresolvable dependency resolving [Parameter #0 [ <required> callable $getBrokerInfo ]] in class JasnySSOServerServer
JasnySSOServerServer.php 内部:
/**
* Class constructor.
*
* @phpstan-param callable(string):?array{secret:string,domains:string[]} $getBrokerInfo
* @phpstan-param CacheInterface $cache
*/
public function __construct(callable $getBrokerInfo, CacheInterface $cache)
{
$this->getBrokerInfo = Closure::fromCallable($getBrokerInfo);
$this->cache = $cache;
$this->logger = new NullLogger();
$this->session = new GlobalSession();
}
我也尝试过:
php artisan route:clear composer dump-autoload php artisan optimize:clear
有人能指出这里的问题吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
由于 jasny/sso 不是 Laravel 包,因此如果没有基于其构造函数的一组关于如何实例化它的特定说明,则不应将其注册到容器中。
在
AppServiceProvider的register()方法中添加以下代码:$this->app->bind(\Jasny\SSO\Server\Server::class, function($app) { $myCallable = function() { // do what you gotta do.. }; return new \Jasny\SSO\Server\Server($myCallable, $app->make(CacheInterface::class)); });从那里您可以在应用程序中的任何位置执行以下操作:
它会自动使用我们在绑定中设置的可调用对象和 CacheInterface 填充构造函数(如果您只需要一个实例,也可以使用
$app->singleton()而不是绑定)此类在整个脚本执行过程中都存在)。通常,您注册到容器中的任何内容都会受到 Laravel 的依赖注入的影响,因此您不能在构造函数中使用未知类型,因为 Laravel 无法知道
callable是什么,并且会发生这种情况时会产生此错误。通常,如果您可以控制这一点,您可以从构造函数中删除可调用函数,并在类上使用 setter。
private $callableFunc = null; public function setCallable(callable $func) : void { $this->callableFunc = $func; }