配置项 `register_providers` 不生效
summerKK opened this issue · 2 comments
summerKK commented
-
Your software version (Screenshot of your startup)
Software Version PHP 7.4 Swoole 4.8.13 Lumen 8.2.3 -
Detail description about this issue(error/log)
-
配置
register_providers
后,我发现在每次请求的时候根本无法注册这两个ServiceProvider
'register_providers' => [ // Tracing 有内存泄露,在这里注册,每次请求结束后销毁 \Sentry\Laravel\ServiceProvider::class, \Sentry\Laravel\Tracing\ServiceProvider::class ],
-
我查了一下原因在于下面这里,
class_exists
的第二个参数(autoload)为false
.这个如果为false
,就不会触发自动加载,类肯定就会找不到,所以这里的provider
永远都不会注册进去.这是一个bug
吗?还是为什么要这样写呢?
vendor/hhxsv5/laravel-s/src/Illuminate/Laravel.php
public function cleanProviders()
{
$loadedProviders = $this->reflectionApp->loadedProviders();
foreach ($this->providers as $provider) {
if (class_exists($provider, false)) {
if ($this->config['is_lumen']) {
unset($loadedProviders[get_class(new $provider($this->currentApp))]);
}
switch ($this->reflectionApp->registerMethodParameterCount()) {
case 1:
$this->currentApp->register($provider);
break;
case 2:
$this->currentApp->register($provider, true);
break;
case 3:
$this->currentApp->register($provider, [], true);
break;
default:
throw new \RuntimeException('The number of parameters of the register method is unknown.');
}
}
}
if ($this->config['is_lumen']) {
$this->reflectionApp->setLoadedProviders($loadedProviders);
}
}
- Some
reproducible
code blocks andsteps
summerKK commented
我创建了一个PR
😎
hhxsv5 commented
Thanks.