A gateway/firewall task to be able to talk someone about the real job
Fibinger Ádám
2021-10-22 fd7692eae00cbb0db3e6b732f68357e3c64a8a8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?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;
    }
}