28 lines
976 B
PHP
28 lines
976 B
PHP
<?php
|
|
|
|
namespace App\Provider;
|
|
|
|
use ApiPlatform\Metadata\CollectionOperationInterface;
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\State\ProviderInterface;
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
|
|
final class BookReader implements ProviderInterface
|
|
{
|
|
public function __construct(
|
|
#[Autowire(service: 'api_platform.doctrine.orm.state.collection_provider')]
|
|
private ProviderInterface $collectionProvider,
|
|
#[Autowire(service: 'api_platform.doctrine.orm.state.item_provider')]
|
|
private ProviderInterface $itemProvider,
|
|
) {
|
|
}
|
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
|
{
|
|
if ($operation instanceof CollectionOperationInterface) {
|
|
return $this->collectionProvider->provide($operation, $uriVariables, $context);
|
|
}
|
|
|
|
return $this->itemProvider->provide($operation, $uriVariables, $context);
|
|
}
|
|
}
|