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

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