Files
librenms-librenms/app/Providers/ConfigServiceProvider.php
Tony Murray f1e7a218f0 Convert Config to a singleton (#16349)
* Convert Config to a singleton
Continuation of #14364 by @Jellyfrog
This time, make the old class a shim for the facade.  Will update references in a separate PR.

* Remove logging config call

* Apply fixes from StyleCI

* Fix bad Git constructor call

* Fail on config table does not exist instead of throw exception

* Inline LibrenmsConfig::isRegistered()

* Debug call in case there are more issues,
remove before merge.

* Fix up config tests

* Allow config cache controlled by CONFIG_CACHE_TTL (disabled by default for now)

* Enable config cache for tests

* Remove debug statement and deprecation phpdoc

* Apply fixes from StyleCI

---------

Co-authored-by: Tony Murray <murrant@users.noreply.github.com>
2024-09-09 18:48:07 +02:00

32 lines
826 B
PHP

<?php
namespace App\Providers;
use App\ConfigRepository;
use App\Facades\LibrenmsConfig;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
class ConfigServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register(): void
{
$this->app->singleton('librenms-config', function () {
return new ConfigRepository;
});
// if we skipped loading the DB the first time config was called, load it when it is available
$this->callAfterResolving('db', function () {
if ($this->app->resolved('librenms-config')) {
Log::error('Loaded config twice due to bad initialization order');
LibrenmsConfig::reload();
}
});
}
}