src/Controller/HomeController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Entity\Action;
  5. use App\Entity\Reunion;
  6. use App\Entity\BookMark;
  7. use App\Enum\StatusEnum;
  8. use App\Entity\ReunionAvis;
  9. use Lcobucci\JWT\Signer\Key;
  10. use Lcobucci\JWT\Configuration;
  11. use Symfony\Component\Mime\Message;
  12. use Symfony\Component\WebLink\Link;
  13. use Lcobucci\JWT\Signer\Hmac\Sha256;
  14. use Symfony\Component\Mercure\Update;
  15. use Symfony\Component\Mercure\Publisher;
  16. use Symfony\Component\Messenger\MessageBus;
  17. use Symfony\Component\HttpFoundation\Cookie;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use Symfony\Component\Mercure\PublisherInterface;
  22. use Symfony\Component\Messenger\MessageBusInterface;
  23. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  24. class HomeController extends AbstractController
  25. {
  26.     /**
  27.      * @Route("/", name="home")
  28.      */
  29.     public function index(Request $request): Response
  30.     {
  31.         
  32.         $entityManager $this->getDoctrine()->getManager();
  33.         $user $this->getUser();
  34.         //bookmarks
  35.         $bookMarks $entityManager->getRepository(BookMark::class)->findBy(['user'=>$user]);
  36.         //actions
  37.         $actions $entityManager->getRepository(Action::class)->findBy(
  38.             ['responsible'=>$user,'status'=>StatusEnum::STATUS_IN_PROGRESS],
  39.             ['createdAt'=> 'DESC']
  40.         );
  41.         //reunions
  42.         $reunion $entityManager->getRepository(Reunion::class)->findAll();
  43.         //reunionAvis
  44.         $reunionAvis $entityManager->getRepository(ReunionAvis::class)->findAll();
  45.         //dd(ini_get("upload_max_filesize"));
  46.         $users $entityManager->getRepository(User::class)->findAll();
  47.         $response$this->render('home/index.html.twig',[
  48.             'bookMarks'=> $bookMarks,
  49.             'actions' => $actions,
  50.             'reunion' => $reunion,
  51.             'reunionAvis' => $reunionAvis,
  52.             'users' => $users
  53.             
  54.         ]);
  55.            // This parameter is automatically created by the MercureBundle
  56.            $hubUrl $this->getParameter('mercure.default_hub');
  57.            // Link: <http://localhost:3000/.well-known/mercure>; rel="mercure"
  58.            $this->addLink($request, new Link('mercure'$hubUrl));
  59.    
  60.           
  61.            $key Key\InMemory::plainText('aVerySecretKeyPersol'); // don't forget to set this parameter! Test value: !ChangeMe!
  62.            $configuration Configuration::forSymmetricSigner(new Sha256(), $key);
  63.    
  64.            $token $configuration->builder()
  65.                ->withClaim('mercure',['subscribe'=> ["http://".$request->server->get('HTTP_HOST')."/notification/{$user->getId()}"]])
  66.                ->getToken($configuration->signer(), $configuration->signingKey())
  67.                ->toString();
  68.               $response->headers->set(
  69.                    'set-cookie',
  70.                    sprintf('mercureAuthorization=%s; path=/.well-known/mercure; secure; httponly; SameSite=strict'$token)
  71.                );
  72.         return $response;
  73.     }
  74.     
  75.     
  76.     
  77.     
  78. }