| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- declare(strict_types=1);
- namespace App\State\Provider\HelloAsso;
- use ApiPlatform\Metadata\GetCollection;
- use ApiPlatform\Metadata\Operation;
- use ApiPlatform\State\ProviderInterface;
- use App\ApiResources\HelloAsso\AuthUrl;
- use App\Entity\Access\Access;
- use App\Service\HelloAsso\HelloAssoService;
- use Symfony\Bundle\SecurityBundle\Security;
- use Symfony\Component\HttpFoundation\Response;
- /**
- * Provider pour la ressource AuthUrl HelloAsso.
- */
- final class AuthUrlProvider implements ProviderInterface
- {
- public function __construct(
- private HelloAssoService $helloAssoService,
- private Security $security,
- ) {
- }
- /**
- * @param mixed[] $uriVariables
- * @param mixed[] $context
- *
- * @throws \Exception
- */
- public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?AuthUrl
- {
- if ($operation instanceof GetCollection) {
- throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);
- }
- /** @var Access $access */
- $access = $this->security->getUser();
- $organizationId = $access->getOrganization()->getId();
- return $this->helloAssoService->getAuthUrl($organizationId);
- }
- }
|