| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- declare(strict_types=1);
- namespace App\State\Provider\Utils;
- use ApiPlatform\Metadata\GetCollection;
- use ApiPlatform\Metadata\Operation;
- use ApiPlatform\State\ProviderInterface;
- use App\ApiResources\Utils\Siret;
- use App\Enum\Utils\HttpCodeEnum;
- use App\Service\Utils\Siret as SiretUtils;
- use RuntimeException;
- use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
- use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
- use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
- use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
- /**
- * Class SiretProvider : custom provider pour assurer l'alimentation des utils Siret
- * @package App\DataProvider\Utils
- */
- final class SiretProvider implements ProviderInterface
- {
- public function __construct(
- private SiretUtils $siretUtils
- )
- { }
- /**
- * @param Operation $operation
- * @param mixed[] $uriVariables
- * @param mixed[] $context
- * @return Siret|null
- * @throws ClientExceptionInterface
- * @throws RedirectionExceptionInterface
- * @throws ServerExceptionInterface
- * @throws TransportExceptionInterface
- */
- public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Siret
- {
- if($operation instanceof GetCollection) {
- throw new RuntimeException('not supported', HttpCodeEnum::METHOD_NOT_ALLOWED()->getValue());
- }
- $id = $uriVariables['id'];
- $siretResponse = new Siret();
- $siretResponse->setNumber($id);
- $siretResponse->setIsCorrect($this->siretUtils->isSiretCorrect($id));
- return $siretResponse;
- }
- }
|