Skip to content

Commit

Permalink
fix: split the "boot" method better
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Batistella Bellas committed Jul 8, 2023
1 parent cae46c1 commit ddd792a
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/DuskApiConfServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,62 @@
class DuskApiConfServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
* @inheritDoc
*
* @author Alexandre Batistella
* @version 1.0.0
* @since 1.0.0
*
* @return void
*/
public function boot()
{
$this->loadRoutesFrom(__DIR__ . '/Routes/Route.php');
$this->loadViewsFrom(__DIR__ . '/Resources/Views', 'duskapiconf');

$this->mergeConfigFrom(
__DIR__ . '/../config/config.php',
'alebatistella.duskapiconf'
);

$contents = Storage::disk(config('alebatistella.duskapiconf.disk'))->get(config('alebatistella.duskapiconf.file'));
$contents = Storage::disk(config('alebatistella.duskapiconf.disk'))
->get(config('alebatistella.duskapiconf.file'));

$decoded = json_decode($contents, true);

foreach (array_keys($decoded) as $k) {
config([$k => $decoded[$k]]);
}

$this->publishes([
__DIR__ . '/../config/config.php' => config_path('duskapiconf.php'),
]);
}

/**
* @inheritDoc
*
* @author Alexandre Batistella
* @version 1.0.0
* @since 1.0.0
*
* @return void
*/
public function booted()
{
$router = $this->app['router'];
$this->app->booted(function () use ($router) {
$router->pushMiddlewareToGroup('web', \AleBatistella\DuskApiConf\Middleware\ConfigStoreMiddleware::class);
});
$router->pushMiddlewareToGroup('web', \AleBatistella\DuskApiConf\Middleware\ConfigStoreMiddleware::class);
}

/**
* Register the application services.
* @inheritDoc
*
* @author Alexandre Batistella
* @version 1.0.0
* @since 1.0.0
*
* @return void
*/
public function register()
{
}
}
}

0 comments on commit ddd792a

Please sign in to comment.