<?php
|
|
namespace App\Controller;
|
|
use App\Entity\Secret;
|
use Doctrine\ORM\EntityManagerInterface;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
/**
|
* We use this custom controller to decrement Secret after a GET operation
|
*/
|
class RetrieveSecretController extends AbstractController
|
{
|
/**
|
* @var EntityManagerInterface
|
*/
|
private $em;
|
|
public function __construct(EntityManagerInterface $entityManager) {
|
$this->em = $entityManager;
|
}
|
|
public function __invoke(Secret $data): Secret
|
{
|
$data->setRemainingViews($data->getRemainingViews() - 1);
|
$this->em->persist($data);
|
$this->em->flush();
|
return $data;
|
}
|
}
|