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

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