feat : first commit
This commit is contained in:
22
src/State/CurrentUserProvider.php
Normal file
22
src/State/CurrentUserProvider.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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;
|
||||
|
||||
final class CurrentUserProvider implements ProviderInterface
|
||||
{
|
||||
public function __construct(private readonly Security $security) {}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?User
|
||||
{
|
||||
$user = $this->security->getUser();
|
||||
|
||||
return $user instanceof User ? $user : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user