vendor/sentry/sentry-symfony/src/EventListener/SubRequestListener.php line 37

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sentry\SentryBundle\EventListener;
  4. use Sentry\State\HubInterface;
  5. use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
  6. /**
  7.  * This listener ensures that a new {@see \Sentry\State\Scope} is created for
  8.  * each subrequest.
  9.  */
  10. final class SubRequestListener
  11. {
  12.     /**
  13.      * @var HubInterface The current hub
  14.      */
  15.     private $hub;
  16.     /**
  17.      * Constructor.
  18.      *
  19.      * @param HubInterface $hub The current hub
  20.      */
  21.     public function __construct(HubInterface $hub)
  22.     {
  23.         $this->hub $hub;
  24.     }
  25.     /**
  26.      * This method is called for each subrequest handled by the framework and
  27.      * pushes a new {@see \Sentry\State\Scope} onto the stack.
  28.      *
  29.      * @param SubRequestListenerRequestEvent $event The event
  30.      */
  31.     public function handleKernelRequestEvent(SubRequestListenerRequestEvent $event): void
  32.     {
  33.         if ($event->isMasterRequest()) {
  34.             return;
  35.         }
  36.         $this->hub->pushScope();
  37.     }
  38.     /**
  39.      * This method is called for each subrequest handled by the framework and
  40.      * pops a {@see \Sentry\State\Scope} from the stack.
  41.      *
  42.      * @param FinishRequestEvent $event The event
  43.      */
  44.     public function handleKernelFinishRequestEvent(FinishRequestEvent $event): void
  45.     {
  46.         if ($event->isMasterRequest()) {
  47.             return;
  48.         }
  49.         $this->hub->popScope();
  50.     }
  51. }