Skip to content

Commit 2c9870d

Browse files
doc: refactor BlogPostProvider examples (#2239)
1 parent ed00f67 commit 2c9870d

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

core/state-providers.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ use ApiPlatform\Metadata\CollectionOperationInterface;
114114
*/
115115
final class BlogPostProvider implements ProviderInterface
116116
{
117-
private array $data;
117+
// …
118118

119119
public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable|BlogPost|null
120120
{
@@ -172,6 +172,13 @@ final class BlogPostProvider implements ProviderInterface
172172
{
173173
private array $data;
174174

175+
public function __construct() {
176+
$this->data = [
177+
'ab' => new BlogPost('ab'),
178+
'cd' => new BlogPost('cd'),
179+
];
180+
}
181+
175182
public function provide(Operation $operation, array $uriVariables = [], array $context = []): BlogPost|null
176183
{
177184
return $this->data[$uriVariables['id']] ?? null;
@@ -219,7 +226,7 @@ use ApiPlatform\Metadata\CollectionOperationInterface;
219226
*/
220227
final class BlogPostProvider implements ProviderInterface
221228
{
222-
private array $data;
229+
// …
223230

224231
public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable|BlogPost|null
225232
{

0 commit comments

Comments
 (0)