Skip to content

Commit

Permalink
feat(laravel): use laravel cache setting
Browse files Browse the repository at this point in the history
Make use of the default laravel cache setting, makes it possible for developers to configure where data should be cached

Closes: api-platform#6735
Signed-off-by: Tobias Oitzinger <[email protected]>
  • Loading branch information
toitzi committed Oct 25, 2024
1 parent 034fcbc commit 5acfa75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Laravel/ApiPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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')
);
});

Expand All @@ -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');

Expand Down Expand Up @@ -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')
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit 5acfa75

Please sign in to comment.