src/EventSubscriber/Redirect.php line 76

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Env;
  4. use App\Func;
  5. use App\DTO\AppDTO;
  6. use App\DTO\PageDTO;
  7. use App\Entity\Cart;
  8. use App\Entity\Sett;
  9. use App\Entity\User;
  10. use App\Entity\Block;
  11. use App\Entity\Order;
  12. use App\Entity\Timer;
  13. use Twig\Environment;
  14. use App\Entity\Banner;
  15. use App\Entity\Labels;
  16. use App\Model\Wishlist;
  17. use App\Entity\Template;
  18. use App\GlobalVars\Blocks;
  19. use App\Service\Auth\Auth;
  20. use App\Entity\Transaction;
  21. use App\GlobalVars\Templates;
  22. use App\Entity\Page as EntityPage;
  23. use App\Repository\PageRepository;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use App\GlobalVars\Sett as GlobalVarsSett;
  26. use Symfony\Contracts\Cache\ItemInterface;
  27. use App\Entity\Translation\PageTranslation;
  28. use App\Entity\Translation\SettTranslation;
  29. use Symfony\Contracts\Cache\CacheInterface;
  30. use App\Entity\Translation\TimerTranslation;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use Symfony\Component\Security\Core\Security;
  33. use App\GlobalVars\Labels as GlobalVarsLabels;
  34. use Symfony\Component\HttpFoundation\Response;
  35. use App\Entity\Translation\TemplateTranslation;
  36. use Symfony\Contracts\Cache\TagAwareCacheInterface;
  37. use Symfony\Component\HttpKernel\Event\RequestEvent;
  38. use Symfony\Component\HttpFoundation\RedirectResponse;
  39. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  40. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  41. class Redirect implements EventSubscriberInterface
  42. {
  43.     private $no_cache false;
  44.     
  45.     private Environment $twig;
  46.     private EntityManagerInterface $em;
  47.     private CacheInterface $Cache;
  48.     private Auth $Auth;
  49.     private Env $Env;
  50.     private Func $Func;
  51.     private Wishlist $Wishlist;
  52.     private ?AppDTO $app;
  53.     // Temp
  54.     private $_pagename;
  55.     public function __construct(AppDTO $appEnvironment $twigEntityManagerInterface $emTagAwareCacheInterface $appCacheAuth $AuthEnv $EnvFunc $FuncWishlist $WishlistSecurity $security)
  56.     {
  57.         $this->twig $twig;
  58.         $this->em $em;
  59.         $this->app $app;
  60.         $this->Cache $appCache;
  61.         $this->Auth $Auth;
  62.         $this->Auth->setUser($security->getUser());
  63.         $this->Env $Env;
  64.         $this->Func $Func;
  65.         $this->Wishlist $Wishlist;
  66.     }
  67.     public function onRequest(RequestEvent $event): void
  68.     {
  69.         if (Env::site() == Env::OPT_MIX && $event->getRequest()->getHost() == 'opt.mixform.pl') {
  70.             $event->setResponse(new RedirectResponse("https://mixformwhole.pl".$event->getRequest()->getRequestUri(), 301));
  71.         }        
  72.     }
  73.     private function redirectMixFormOpt(Request $request)
  74.     {        
  75.         if (!$request->getLocale()) {
  76.             $request->setLocale($request->getDefaultLocale());
  77.         }
  78.     }
  79.     public static function getSubscribedEvents(): array
  80.     {
  81.         return [
  82.             'kernel.request' => 'onRequest',
  83.         ];
  84.     }
  85. }