CotisationProvider.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\State\Provider\Cotisation;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use ApiPlatform\Metadata\Operation;
  6. use ApiPlatform\State\ProviderInterface;
  7. use App\ApiResources\Cotisation\Cotisation;
  8. use App\Service\Cotisation\CotisationCreator;
  9. use RuntimeException;
  10. /**
  11. * Class CotisationProvider : custom provider pour assurer l'alimentation de la réponse du GET cotisation
  12. * @package App\DataProvider\Cotisation
  13. */
  14. final class CotisationProvider implements ProviderInterface
  15. {
  16. public function __construct(private CotisationCreator $cotisationCreator)
  17. { }
  18. /**
  19. * @param Operation $operation
  20. * @param mixed[] $uriVariables
  21. * @param mixed[] $context
  22. * @return Cotisation|null
  23. */
  24. public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Cotisation
  25. {
  26. if($operation instanceof GetCollection) {
  27. throw new RuntimeException('not supported', 500);
  28. }
  29. return $this->cotisationCreator->getCotisation($uriVariables['id']);
  30. }
  31. }