AuthUrlProvider.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\State\Provider\HelloAsso;
  4. use ApiPlatform\Metadata\GetCollection;
  5. use ApiPlatform\Metadata\Operation;
  6. use ApiPlatform\State\ProviderInterface;
  7. use App\ApiResources\HelloAsso\AuthUrl;
  8. use App\Entity\Access\Access;
  9. use App\Service\HelloAsso\HelloAssoService;
  10. use Symfony\Bundle\SecurityBundle\Security;
  11. use Symfony\Component\HttpFoundation\Response;
  12. /**
  13. * Provider pour la ressource AuthUrl HelloAsso.
  14. */
  15. final class AuthUrlProvider implements ProviderInterface
  16. {
  17. public function __construct(
  18. private HelloAssoService $helloAssoService,
  19. private Security $security,
  20. ) {
  21. }
  22. /**
  23. * @param mixed[] $uriVariables
  24. * @param mixed[] $context
  25. *
  26. * @throws \Exception
  27. */
  28. public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?AuthUrl
  29. {
  30. if ($operation instanceof GetCollection) {
  31. throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);
  32. }
  33. /** @var Access $access */
  34. $access = $this->security->getUser();
  35. $organizationId = $access->getOrganization()->getId();
  36. return $this->helloAssoService->getAuthUrl($organizationId);
  37. }
  38. }