Skip to content

Commit

Permalink
Use facades instead of magic helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mwikberg-virta committed Jun 21, 2023
1 parent f2737d7 commit 6d5e194
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/PrometheusServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace Mcoirault\LaravelPrometheusExporter;

use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
use Prometheus\CollectorRegistry;
use Prometheus\Storage\Adapter;
Expand All @@ -12,14 +15,15 @@ class PrometheusServiceProvider extends ServiceProvider implements DeferrablePro
{
/**
* Perform post-registration booting of services.
* @throws BindingResolutionException
*/
public function boot(PrometheusExporter $exporter): void
{
$this->publishes([
__DIR__ . '/../config/prometheus.php' => config_path('prometheus.php'),
__DIR__ . '/../config/prometheus.php' => App::configPath('prometheus.php'),
]);

foreach (config('prometheus.collectors') as $class) {
foreach (Config::get('prometheus.collectors') as $class) {
$collector = $this->app->make($class);
$exporter->registerCollector($collector);
}
Expand All @@ -35,7 +39,7 @@ public function register(): void
$this->app->singleton(PrometheusExporter::class, function ($app) {
$adapter = $app['prometheus.storage_adapter'];
$prometheus = new CollectorRegistry($adapter);
return new PrometheusExporter(config('prometheus.namespace'), $prometheus);
return new PrometheusExporter(Config::get('prometheus.namespace'), $prometheus);
});
$this->app->alias(PrometheusExporter::class, 'prometheus');

Expand All @@ -44,10 +48,10 @@ public function register(): void
});

$this->app->bind(Adapter::class, function ($app) {
$factory = $app['prometheus.storage_adapter_factory'];
/** @var StorageAdapterFactory $factory */
$driver = config('prometheus.storage_adapter');
$configs = config('prometheus.storage_adapters');
$factory = $app['prometheus.storage_adapter_factory'];
$driver = Config::get('prometheus.storage_adapter');
$configs = Config::get('prometheus.storage_adapters');
$config = Arr::get($configs, $driver, []);
return $factory->make($driver, $config);
});
Expand Down

0 comments on commit 6d5e194

Please sign in to comment.