From 5acfa754aef472a566c247fcddafab5e19c97e5e Mon Sep 17 00:00:00 2001 From: Tobias Oitzinger Date: Fri, 25 Oct 2024 08:47:43 +0200 Subject: [PATCH] feat(laravel): use laravel cache setting Make use of the default laravel cache setting, makes it possible for developers to configure where data should be cached Closes: #6735 Signed-off-by: Tobias Oitzinger --- src/Laravel/ApiPlatformProvider.php | 12 ++++++------ .../app/Providers/WorkbenchServiceProvider.php | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Laravel/ApiPlatformProvider.php b/src/Laravel/ApiPlatformProvider.php index d11885ab54..815bb3fd80 100644 --- a/src/Laravel/ApiPlatformProvider.php +++ b/src/Laravel/ApiPlatformProvider.php @@ -279,7 +279,7 @@ public function register(): void }); $this->app->extend(PropertyMetadataFactoryInterface::class, function (PropertyInfoPropertyMetadataFactory $inner, Application $app) { - /** @var ConfigRepository */ + /** @var ConfigRepository $config */ $config = $app['config']; return new CachePropertyMetadataFactory( @@ -295,12 +295,12 @@ public function register(): void $app->make(ResourceClassResolverInterface::class) ), ), - true === $config->get('app.debug') ? 'array' : 'file' + true === $config->get('app.debug') ? 'array' : $config->get('cache.default', 'file') ); }); $this->app->singleton(PropertyNameCollectionFactoryInterface::class, function (Application $app) { - /** @var ConfigRepository */ + /** @var ConfigRepository $config */ $config = $app['config']; return new CachePropertyNameCollectionMetadataFactory( @@ -313,7 +313,7 @@ public function register(): void ) ) ), - true === $config->get('app.debug') ? 'array' : 'file' + true === $config->get('app.debug') ? 'array' : $config->get('cache.default', 'file') ); }); @@ -327,7 +327,7 @@ public function register(): void // TODO: add cached metadata factories $this->app->singleton(ResourceMetadataCollectionFactoryInterface::class, function (Application $app) { - /** @var ConfigRepository */ + /** @var ConfigRepository $config */ $config = $app['config']; $formats = $config->get('api-platform.formats'); @@ -382,7 +382,7 @@ public function register(): void $app->make('filters') ) ), - true === $config->get('app.debug') ? 'array' : 'file' + true === $config->get('app.debug') ? 'array' : $config->get('cache.default', 'file') ); }); diff --git a/src/Laravel/workbench/app/Providers/WorkbenchServiceProvider.php b/src/Laravel/workbench/app/Providers/WorkbenchServiceProvider.php index a6237450d1..eb0d9f4d5c 100644 --- a/src/Laravel/workbench/app/Providers/WorkbenchServiceProvider.php +++ b/src/Laravel/workbench/app/Providers/WorkbenchServiceProvider.php @@ -32,6 +32,7 @@ public function register(): void { $config = $this->app['config']; $config->set('api-platform.resources', [app_path('Models'), app_path('ApiResource')]); + $config->set('cache.default', 'null'); } /**