From 7682335b146dc0b24a2d060c8c10c881a3c24d7e Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Thu, 22 Jan 2026 11:47:56 +0100 Subject: [PATCH] doc: refactor BlogPostProvider examples --- core/state-providers.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/state-providers.md b/core/state-providers.md index 49f6b603d0b..37c9964a13e 100644 --- a/core/state-providers.md +++ b/core/state-providers.md @@ -114,7 +114,7 @@ use ApiPlatform\Metadata\CollectionOperationInterface; */ final class BlogPostProvider implements ProviderInterface { - private array $data; + // … public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable|BlogPost|null { @@ -172,6 +172,13 @@ final class BlogPostProvider implements ProviderInterface { private array $data; + public function __construct() { + $this->data = [ + 'ab' => new BlogPost('ab'), + 'cd' => new BlogPost('cd'), + ]; + } + public function provide(Operation $operation, array $uriVariables = [], array $context = []): BlogPost|null { return $this->data[$uriVariables['id']] ?? null; @@ -219,7 +226,7 @@ use ApiPlatform\Metadata\CollectionOperationInterface; */ final class BlogPostProvider implements ProviderInterface { - private array $data; + // … public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable|BlogPost|null {