src/Logger/BgRequestProcessor.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Logger;
  3. use App\Utils\Constantes;
  4. use App\Utils\JWTEncoder;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. class BgRequestProcessor
  9. {
  10.     // private $session;
  11.     // private $sessionId;
  12.     private $jwtFactory;
  13.     private $request;
  14.     private $requestStack;
  15.     public function __construct(RequestStack $requestStack)
  16.     {
  17.         // $this->session = $session;
  18.         $this->requestStack $requestStack;
  19.         $this->jwtFactory JWTEncoder::getInstance();
  20.         $this->request Request::createFromGlobals();
  21.     }
  22.     // this method is called for each log record; optimize it to not hurt performance
  23.     public function __invoke(array $record)
  24.     {
  25.         $apiKey $this->request->headers->get(Constantes::AUTH_TOKEN);
  26.         $dataToken $this->jwtFactory->decode($apiKey);
  27.         if ($this->requestStack->getMasterRequest())
  28.             $clientIp = @$this->requestStack->getMasterRequest()->getClientIp();
  29.         else
  30.             $clientIp '';
  31.         // if (!$this->session->isStarted()) {
  32.         //     return $record;
  33.         // }
  34.         // if (!$this->sessionId) {
  35.         //     $this->sessionId = substr($this->session->getId(), 0, 8) ?: '????????';
  36.         // }
  37.         // $record['extra']['token'] = $this->sessionId.'-'.substr(uniqid('', true), -8);
  38.         // var_dump('OK');die;
  39.         // dump($dataToken);die;
  40.         $record['extra']['user']['id'] = @$dataToken['id'] ?: '';
  41.         $record['extra']['user']['username'] = @$dataToken['username'] ?: '';
  42.         $record['extra']['user']['roles'] = @$dataToken['roles'] ?: '';
  43.         $record['extra']['entity'] = @$dataToken['codeClient'] ?: '';
  44.         // $record['extra']['entity'] = 'bgpartners';
  45.         $record['extra']['service'] = 'Station Service';
  46.         $record['extra']['ip_address'] = @$clientIp?:'';
  47.         // var_dump($dataToken);
  48.         // var_dump($record);
  49.         // die;
  50.         return $record;
  51.     }
  52. }