src/EventSubscriber/LocaleSubscriber.php line 39

  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Common\Functions\DbFunction;
  4. use App\Common\Functions\Helpers;
  5. use App\Common\Globals\MainGlobals;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. use Symfony\Component\HttpKernel\Event\RequestEvent;
  10. use Doctrine\ODM\MongoDB\DocumentManager;
  11. use Symfony\Component\Yaml\Yaml;
  12. class LocaleSubscriber implements EventSubscriberInterface
  13. {
  14.   private $public_urls = [];
  15.   public function __construct(
  16.     public DocumentManager $dm
  17.   )
  18.   {
  19.     $this->public_urls = ['\\/login''\\/auth''\\/forget\\-password''\\/check\\-reset\\-code''\\/reset\\-password'];
  20.   }
  21.   public static function getSubscribedEvents()
  22.   {
  23.     return array(
  24.         KernelEvents::REQUEST => array(array('onKernelRequest'200)),
  25.     );
  26.   }
  27.   private function checkApp($request){
  28.     if($request->getMethod() == "GET"){
  29.       return true;
  30.     }
  31.     $currentPath $request->getPathInfo();
  32.     if(!MainGlobals::$app){
  33.       return preg_match('/'.implode('|'$this->public_urls).'/i'$currentPath);
  34.     }
  35.     return false;
  36.   }
  37.   public function onKernelRequest(RequestEvent $event)
  38.   {
  39.     $request $event->getRequest();
  40.     if($request->headers->has('stripe-signature')){
  41.       return null;
  42.     }
  43.     if ($request->headers->has("Accept-Language")) {
  44.       $locale $request->headers->get('Accept-Language');
  45.       $request->setLocale($locale);
  46.     }
  47.     if($request->headers->has('secure-key')) {
  48.       if($request->headers->get("secure-key") == 'ukkera-admins'){
  49.         MainGlobals::$secure 'ukkera-admins';
  50.       }
  51.     }
  52.     $funs = [];
  53.     $headers $request->headers->all();
  54.     foreach ($headers as $k => $v) {
  55.       $funs[Helpers::capital($k)] = $v[0] ?? $v;
  56.     }
  57.     $vals Helpers::MergeCallingFunction($funsHeaderFetch::class, $this->dm);
  58.     MainGlobals::$extra array_merge(...$vals);
  59.     if(!$this->checkApp($request)){
  60.       if(!(MainGlobals::$app->id ?? false )){
  61.         return $event->setResponse(new JsonResponse(['error'=> 'Invalid server key'], 401));
  62.       }
  63.       $date = new \DateTime();
  64.       if (MainGlobals::$app->de_date && MainGlobals::$app->de_date $date) {
  65.           return $event->setResponse(new JsonResponse(['error' => 'deactivated app'], 401));
  66.       }
  67.     }
  68.     if(MainGlobals::$app && MainGlobals::$app->fetch){
  69.       MainGlobals::$extra DbFunction::FetchExtra($this->dmMainGlobals::$app->fetch);
  70.     }
  71.     MainGlobals::$extra = [...MainGlobals::$extra, ...$vals];
  72.     if(MainGlobals::$app->main_app ?? false){
  73.       MainGlobals::$apps DbFunction::getList($this->dm'apps__app', ['main_app'=>MainGlobals::$app->main_app]);
  74.     }
  75.     if(MainGlobals::$app ?? false){
  76.       $config_path dirname(__DIR__) . '/configs/models';
  77.       $files scandir($config_path);
  78.       foreach ($files as $file) {
  79.           if ($file !== '.' && $file !== '..') {
  80.               $data Yaml::parseFile($config_path '/' $file);
  81.               MainGlobals::$modules array_merge(MainGlobals::$modules$data);
  82.           }
  83.       }
  84.     }
  85.   }
  86. }