| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- declare(strict_types=1);
- namespace App\State\Provider\Cotisation;
- use ApiPlatform\Metadata\GetCollection;
- use ApiPlatform\Metadata\Operation;
- use ApiPlatform\State\ProviderInterface;
- use App\ApiResources\Cotisation\Cotisation;
- use App\Enum\Utils\HttpCodeEnum;
- use App\Service\Cotisation\CotisationCreator;
- use RuntimeException;
- /**
- * Class CotisationProvider : custom provider pour assurer l'alimentation de la réponse du GET cotisation
- * @package App\DataProvider\Cotisation
- */
- final class CotisationProvider implements ProviderInterface
- {
- public function __construct(private CotisationCreator $cotisationCreator)
- { }
- /**
- * @param Operation $operation
- * @param mixed[] $uriVariables
- * @param mixed[] $context
- * @return Cotisation|null
- */
- public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Cotisation
- {
- if ($operation instanceof GetCollection) {
- throw new RuntimeException('not supported', HttpCodeEnum::METHOD_NOT_ALLOWED()->getValue());
- }
- return $this->cotisationCreator->getCotisation($uriVariables['organizationId']);
- }
- }
|