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

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.     use KernelEventForwardCompatibilityTrait;
  13.     /**
  14.      * @var HubInterface The current hub
  15.      */
  16.     private $hub;
  17.     /**
  18.      * Constructor.
  19.      *
  20.      * @param HubInterface $hub The current hub
  21.      */
  22.     public function __construct(HubInterface $hub)
  23.     {
  24.         $this->hub $hub;
  25.     }
  26.     /**
  27.      * This method is called for each subrequest handled by the framework and
  28.      * pushes a new {@see \Sentry\State\Scope} onto the stack.
  29.      *
  30.      * @param SubRequestListenerRequestEvent $event The event
  31.      */
  32.     public function handleKernelRequestEvent(SubRequestListenerRequestEvent $event): void
  33.     {
  34.         if ($this->isMainRequest($event)) {
  35.             return;
  36.         }
  37.         $this->hub->pushScope();
  38.     }
  39.     /**
  40.      * This method is called for each subrequest handled by the framework and
  41.      * pops a {@see \Sentry\State\Scope} from the stack.
  42.      *
  43.      * @param FinishRequestEvent $event The event
  44.      */
  45.     public function handleKernelFinishRequestEvent(FinishRequestEvent $event): void
  46.     {
  47.         if ($this->isMainRequest($event)) {
  48.             return;
  49.         }
  50.         $this->hub->popScope();
  51.     }
  52. }