Skip to content

Commit

Permalink
fix(agent): load setup from forest config to allow configuration caching
Browse files Browse the repository at this point in the history
  • Loading branch information
matthv committed Jan 12, 2024
1 parent d6a01bb commit 4e75ff6
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/Providers/AgentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AgentProvider extends ServiceProvider
public function boot()
{
if ($this->forestIsPlanted()) {
$this->app->instance(AgentFactory::class, new AgentFactory($this->loadOptions()));
$this->app->instance(AgentFactory::class, new AgentFactory(config('forest')));
$this->loadConfiguration();
}
}
Expand All @@ -34,7 +34,7 @@ public function loadRoutes()

private function forestIsPlanted(): bool
{
return env('FOREST_AUTH_SECRET') && env('FOREST_ENV_SECRET');
return config('forest.authSecret') && config('forest.envSecret');
}

private function transformMethodsValuesToUpper(array|string $methods): array
Expand All @@ -48,28 +48,17 @@ private function transformMethodsValuesToUpper(array|string $methods): array

private function loadConfiguration(): void
{
if (file_exists($this->app['path.config'] . DIRECTORY_SEPARATOR . 'forest_admin.php')) {
$callback = require $this->app['path.config'] . DIRECTORY_SEPARATOR . 'forest_admin.php';
if (file_exists($this->appForestConfig())) {
$callback = require $this->appForestConfig();
$callback($this);

$this->app->make(AgentFactory::class)->build();
$this->loadRoutes();
}
}

private function loadOptions(): array
private function appForestConfig(): string
{
return [
'debug' => env('FOREST_DEBUG', true),
'authSecret' => env('FOREST_AUTH_SECRET'),
'envSecret' => env('FOREST_ENV_SECRET'),
'forestServerUrl' => env('FOREST_SERVER_URL', 'https://api.forestadmin.com'),
'isProduction' => env('FOREST_ENVIRONMENT', 'dev') === 'prod',
'prefix' => env('FOREST_PREFIX', 'forest'),
'permissionExpiration' => env('FOREST_PERMISSIONS_EXPIRATION_IN_SECONDS', 300),
'cacheDir' => storage_path('framework/cache/data/forest'),
'schemaPath' => base_path() . '/.forestadmin-schema.json',
'projectDir' => base_path(),
];
return base_path() . DIRECTORY_SEPARATOR . 'forest' . DIRECTORY_SEPARATOR . 'forest_admin.php';
}
}

0 comments on commit 4e75ff6

Please sign in to comment.