Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
- MeProvider : guard null user avec AccessDeniedHttpException - MaintenanceToggleProcessor : vérification des opérations filesystem - User : restreindre Get/GetCollection aux ROLE_ADMIN - useAppVersion : corriger le path relatif '/version' Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
33 lines
766 B
PHP
33 lines
766 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\State;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\State\ProviderInterface;
|
|
use App\Entity\User;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
|
|
|
/**
|
|
* @implements ProviderInterface<User>
|
|
*/
|
|
final readonly class MeProvider implements ProviderInterface
|
|
{
|
|
public function __construct(
|
|
private Security $security,
|
|
) {}
|
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): User
|
|
{
|
|
$user = $this->security->getUser();
|
|
|
|
if (!$user instanceof User) {
|
|
throw new AccessDeniedHttpException('User not authenticated.');
|
|
}
|
|
|
|
return $user;
|
|
}
|
|
}
|