You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
40 lines
1.0 KiB
<?php |
|
|
|
namespace App\Twig\Components; |
|
|
|
use App\Credits\Service\CreditsManager; |
|
use Psr\Cache\InvalidArgumentException; |
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; |
|
use Symfony\UX\LiveComponent\Attribute\LiveAction; |
|
use Symfony\UX\LiveComponent\ComponentToolsTrait; |
|
use Symfony\UX\LiveComponent\DefaultActionTrait; |
|
|
|
#[AsLiveComponent] |
|
final class GetCreditsComponent |
|
{ |
|
use DefaultActionTrait; |
|
use ComponentToolsTrait; |
|
|
|
public function __construct( |
|
private readonly CreditsManager $creditsManager, |
|
private readonly TokenStorageInterface $tokenStorage) |
|
{ |
|
} |
|
|
|
/** |
|
* @throws InvalidArgumentException |
|
*/ |
|
#[LiveAction] |
|
public function grantVoucher(): void |
|
{ |
|
$npub = $this->tokenStorage->getToken()?->getUserIdentifier(); |
|
if ($npub) { |
|
$this->creditsManager->addCredits($npub, 5, 'voucher'); |
|
} |
|
|
|
// Dispatch event to notify parent |
|
$this->emit('creditsAdded'); |
|
} |
|
} |
|
|
|
|