src/EventSubscriber/ExtendUserByApp.php line 41

  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Common\Functions\Helpers;
  4. use App\Common\Globals\MainGlobals;
  5. use App\Functions\Common\GetUser;
  6. use Doctrine\ODM\MongoDB\DocumentManager;
  7. use Symfony\Bundle\SecurityBundle\Security;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  12. use Symfony\Component\HttpKernel\Event\RequestEvent;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. class ExtendUserByApp implements EventSubscriberInterface
  15. {
  16.     public function __construct(
  17.         private Security $security,
  18.         public DocumentManager $dm
  19.     )
  20.     {
  21.     }
  22.     public static function getSubscribedEvents()
  23.     {
  24.         return array(
  25.             KernelEvents::CONTROLLER => array(array('onKernelController'200)),
  26.         );
  27.     }
  28.     public function onKernelController(ControllerEvent $event)
  29.     {
  30.       if(MainGlobals::$app){
  31.           $header_app MainGlobals::$app->id;
  32.         $account_fun Helpers::getMethod(GetUser::class, $header_app);
  33.         if(!$account_fun){
  34.           $account_fun Helpers::getMethod(GetUser::class, 'MainAccount');
  35.         }
  36.         $user $this->security->getUser();
  37.         MainGlobals::$user $user;
  38.         if($account_fun && $user){
  39.             $account $account_fun->invoke((object)[], $this->dm$user$header_app);
  40.             if($account){
  41.               MainGlobals::$account $account;
  42.             }else{
  43.               MainGlobals::$account = (object) [];
  44.             }
  45.         }
  46.         if(MainGlobals::$extra){
  47.           foreach(MainGlobals::$extra as $key => $val){
  48.             MainGlobals::$account->{$key} = $val;
  49.           }
  50.         }
  51.       }
  52.     }
  53. }