Skip to content

Commit 04bdd63

Browse files
alexislefebvresoyuka
authored andcommitted
doc: refactor BlogPostProvider examples (#2239)
1 parent 2d2a5dd commit 04bdd63

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

core/state-providers.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ use ApiPlatform\Metadata\CollectionOperationInterface;
125125
*/
126126
final class BlogPostProvider implements ProviderInterface
127127
{
128-
private array $data;
128+
// …
129129

130130
public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable|BlogPost|null
131131
{
@@ -185,6 +185,13 @@ final class BlogPostProvider implements ProviderInterface
185185
{
186186
private array $data;
187187

188+
public function __construct() {
189+
$this->data = [
190+
'ab' => new BlogPost('ab'),
191+
'cd' => new BlogPost('cd'),
192+
];
193+
}
194+
188195
public function provide(Operation $operation, array $uriVariables = [], array $context = []): BlogPost|null
189196
{
190197
return $this->data[$uriVariables['id']] ?? null;
@@ -236,7 +243,7 @@ use ApiPlatform\Metadata\CollectionOperationInterface;
236243
*/
237244
final class BlogPostProvider implements ProviderInterface
238245
{
239-
private array $data;
246+
// …
240247

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

0 commit comments

Comments
 (0)