Skip to content

Commit

Permalink
Use singleton for factory
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Jun 27, 2020
1 parent 831ad5a commit 5e69d60
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/BladeIconsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace BladeUI\Icons;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

Expand All @@ -29,17 +30,19 @@ private function registerConfig(): void

private function registerFactory(): void
{
$config = $this->app->make('config')->get('blade-icons');
$this->app->singleton(Factory::class, function (Application $app) {
$config = $app->make('config')->get('blade-icons');

$factory = new Factory(new Filesystem(), $config['class']);
$factory = new Factory(new Filesystem(), $config['class'] ?? '');

foreach ($config['sets'] as $set => $options) {
$options['path'] = $this->app->basePath($options['path']);
foreach ($config['sets'] ?? [] as $set => $options) {
$options['path'] = $app->basePath($options['path']);

$factory->add($set, $options);
}
$factory->add($set, $options);
}

$this->app->instance(Factory::class, $factory);
return $factory;
});
}

private function bootDirectives(): void
Expand Down

0 comments on commit 5e69d60

Please sign in to comment.