vendor/sentry/sentry/src/State/HubAdapter.php line 127

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sentry\State;
  4. use Sentry\Breadcrumb;
  5. use Sentry\CheckInStatus;
  6. use Sentry\ClientInterface;
  7. use Sentry\Event;
  8. use Sentry\EventHint;
  9. use Sentry\EventId;
  10. use Sentry\Integration\IntegrationInterface;
  11. use Sentry\MonitorConfig;
  12. use Sentry\SentrySdk;
  13. use Sentry\Severity;
  14. use Sentry\Tracing\Span;
  15. use Sentry\Tracing\Transaction;
  16. use Sentry\Tracing\TransactionContext;
  17. /**
  18.  * An implementation of {@see HubInterface} that uses {@see SentrySdk} internally
  19.  * to manage the current hub.
  20.  */
  21. final class HubAdapter implements HubInterface
  22. {
  23.     /**
  24.      * @var self|null The single instance which forwards all calls to {@see SentrySdk}
  25.      */
  26.     private static $instance;
  27.     /**
  28.      * Constructor.
  29.      */
  30.     private function __construct()
  31.     {
  32.     }
  33.     /**
  34.      * Gets the instance of this class. This is a singleton, so once initialized
  35.      * you will always get the same instance.
  36.      */
  37.     public static function getInstance(): self
  38.     {
  39.         if (null === self::$instance) {
  40.             self::$instance = new self();
  41.         }
  42.         return self::$instance;
  43.     }
  44.     /**
  45.      * {@inheritdoc}
  46.      */
  47.     public function getClient(): ?ClientInterface
  48.     {
  49.         return SentrySdk::getCurrentHub()->getClient();
  50.     }
  51.     /**
  52.      * {@inheritdoc}
  53.      */
  54.     public function getLastEventId(): ?EventId
  55.     {
  56.         return SentrySdk::getCurrentHub()->getLastEventId();
  57.     }
  58.     /**
  59.      * {@inheritdoc}
  60.      */
  61.     public function pushScope(): Scope
  62.     {
  63.         return SentrySdk::getCurrentHub()->pushScope();
  64.     }
  65.     /**
  66.      * {@inheritdoc}
  67.      */
  68.     public function popScope(): bool
  69.     {
  70.         return SentrySdk::getCurrentHub()->popScope();
  71.     }
  72.     /**
  73.      * {@inheritdoc}
  74.      */
  75.     public function withScope(callable $callback)
  76.     {
  77.         return SentrySdk::getCurrentHub()->withScope($callback);
  78.     }
  79.     /**
  80.      * {@inheritdoc}
  81.      */
  82.     public function configureScope(callable $callback): void
  83.     {
  84.         SentrySdk::getCurrentHub()->configureScope($callback);
  85.     }
  86.     /**
  87.      * {@inheritdoc}
  88.      */
  89.     public function bindClient(ClientInterface $client): void
  90.     {
  91.         SentrySdk::getCurrentHub()->bindClient($client);
  92.     }
  93.     /**
  94.      * {@inheritdoc}
  95.      */
  96.     public function captureMessage(string $message, ?Severity $level null, ?EventHint $hint null): ?EventId
  97.     {
  98.         return SentrySdk::getCurrentHub()->captureMessage($message$level$hint);
  99.     }
  100.     /**
  101.      * {@inheritdoc}
  102.      */
  103.     public function captureException(\Throwable $exception, ?EventHint $hint null): ?EventId
  104.     {
  105.         return SentrySdk::getCurrentHub()->captureException($exception$hint);
  106.     }
  107.     /**
  108.      * {@inheritdoc}
  109.      */
  110.     public function captureEvent(Event $event, ?EventHint $hint null): ?EventId
  111.     {
  112.         return SentrySdk::getCurrentHub()->captureEvent($event$hint);
  113.     }
  114.     /**
  115.      * {@inheritdoc}
  116.      */
  117.     public function captureLastError(?EventHint $hint null): ?EventId
  118.     {
  119.         return SentrySdk::getCurrentHub()->captureLastError($hint);
  120.     }
  121.     /**
  122.      * {@inheritdoc}
  123.      *
  124.      * @param int|float|null $duration
  125.      */
  126.     public function captureCheckIn(string $slugCheckInStatus $status$duration null, ?MonitorConfig $monitorConfig null, ?string $checkInId null): ?string
  127.     {
  128.         return SentrySdk::getCurrentHub()->captureCheckIn($slug$status$duration$monitorConfig$checkInId);
  129.     }
  130.     /**
  131.      * {@inheritdoc}
  132.      */
  133.     public function addBreadcrumb(Breadcrumb $breadcrumb): bool
  134.     {
  135.         return SentrySdk::getCurrentHub()->addBreadcrumb($breadcrumb);
  136.     }
  137.     /**
  138.      * {@inheritdoc}
  139.      */
  140.     public function getIntegration(string $className): ?IntegrationInterface
  141.     {
  142.         return SentrySdk::getCurrentHub()->getIntegration($className);
  143.     }
  144.     /**
  145.      * {@inheritdoc}
  146.      *
  147.      * @param array<string, mixed> $customSamplingContext Additional context that will be passed to the {@see SamplingContext}
  148.      */
  149.     public function startTransaction(TransactionContext $context, array $customSamplingContext = []): Transaction
  150.     {
  151.         return SentrySdk::getCurrentHub()->startTransaction($context$customSamplingContext);
  152.     }
  153.     /**
  154.      * {@inheritdoc}
  155.      */
  156.     public function getTransaction(): ?Transaction
  157.     {
  158.         return SentrySdk::getCurrentHub()->getTransaction();
  159.     }
  160.     /**
  161.      * {@inheritdoc}
  162.      */
  163.     public function getSpan(): ?Span
  164.     {
  165.         return SentrySdk::getCurrentHub()->getSpan();
  166.     }
  167.     /**
  168.      * {@inheritdoc}
  169.      */
  170.     public function setSpan(?Span $span): HubInterface
  171.     {
  172.         return SentrySdk::getCurrentHub()->setSpan($span);
  173.     }
  174.     /**
  175.      * @see https://www.php.net/manual/en/language.oop5.cloning.php#object.clone
  176.      */
  177.     public function __clone()
  178.     {
  179.         throw new \BadMethodCallException('Cloning is forbidden.');
  180.     }
  181.     /**
  182.      * @see https://www.php.net/manual/en/language.oop5.magic.php#object.wakeup
  183.      */
  184.     public function __wakeup()
  185.     {
  186.         throw new \BadMethodCallException('Unserializing instances of this class is forbidden.');
  187.     }
  188. }