Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions core/state-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down