| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sentry\State; |
| 5 |
|
| 6 |
use WCPOS\Vendor\Sentry\Breadcrumb; |
| 7 |
use WCPOS\Vendor\Sentry\CheckInStatus; |
| 8 |
use WCPOS\Vendor\Sentry\ClientInterface; |
| 9 |
use WCPOS\Vendor\Sentry\Event; |
| 10 |
use WCPOS\Vendor\Sentry\EventHint; |
| 11 |
use WCPOS\Vendor\Sentry\EventId; |
| 12 |
use WCPOS\Vendor\Sentry\Integration\IntegrationInterface; |
| 13 |
use WCPOS\Vendor\Sentry\MonitorConfig; |
| 14 |
use WCPOS\Vendor\Sentry\SentrySdk; |
| 15 |
use WCPOS\Vendor\Sentry\Severity; |
| 16 |
use WCPOS\Vendor\Sentry\Tracing\Span; |
| 17 |
use WCPOS\Vendor\Sentry\Tracing\Transaction; |
| 18 |
use WCPOS\Vendor\Sentry\Tracing\TransactionContext; |
| 19 |
/** |
| 20 |
* An implementation of {@see HubInterface} that uses {@see SentrySdk} internally |
| 21 |
* to manage the current hub. |
| 22 |
*/ |
| 23 |
final class HubAdapter implements HubInterface |
| 24 |
{ |
| 25 |
/** |
| 26 |
* @var self|null The single instance which forwards all calls to {@see SentrySdk} |
| 27 |
*/ |
| 28 |
private static $instance; |
| 29 |
/** |
| 30 |
* Constructor. |
| 31 |
*/ |
| 32 |
private function __construct() |
| 33 |
{ |
| 34 |
} |
| 35 |
/** |
| 36 |
* Gets the instance of this class. This is a singleton, so once initialized |
| 37 |
* you will always get the same instance. |
| 38 |
*/ |
| 39 |
public static function getInstance() : self |
| 40 |
{ |
| 41 |
if (self::$instance === null) { |
| 42 |
self::$instance = new self(); |
| 43 |
} |
| 44 |
return self::$instance; |
| 45 |
} |
| 46 |
/** |
| 47 |
* {@inheritdoc} |
| 48 |
*/ |
| 49 |
public function getClient() : ?ClientInterface |
| 50 |
{ |
| 51 |
return SentrySdk::getCurrentHub()->getClient(); |
| 52 |
} |
| 53 |
/** |
| 54 |
* {@inheritdoc} |
| 55 |
*/ |
| 56 |
public function getLastEventId() : ?EventId |
| 57 |
{ |
| 58 |
return SentrySdk::getCurrentHub()->getLastEventId(); |
| 59 |
} |
| 60 |
/** |
| 61 |
* {@inheritdoc} |
| 62 |
*/ |
| 63 |
public function pushScope() : Scope |
| 64 |
{ |
| 65 |
return SentrySdk::getCurrentHub()->pushScope(); |
| 66 |
} |
| 67 |
/** |
| 68 |
* {@inheritdoc} |
| 69 |
*/ |
| 70 |
public function popScope() : bool |
| 71 |
{ |
| 72 |
return SentrySdk::getCurrentHub()->popScope(); |
| 73 |
} |
| 74 |
/** |
| 75 |
* {@inheritdoc} |
| 76 |
*/ |
| 77 |
public function withScope(callable $callback) |
| 78 |
{ |
| 79 |
return SentrySdk::getCurrentHub()->withScope($callback); |
| 80 |
} |
| 81 |
/** |
| 82 |
* {@inheritdoc} |
| 83 |
*/ |
| 84 |
public function configureScope(callable $callback) : void |
| 85 |
{ |
| 86 |
SentrySdk::getCurrentHub()->configureScope($callback); |
| 87 |
} |
| 88 |
/** |
| 89 |
* {@inheritdoc} |
| 90 |
*/ |
| 91 |
public function bindClient(ClientInterface $client) : void |
| 92 |
{ |
| 93 |
SentrySdk::getCurrentHub()->bindClient($client); |
| 94 |
} |
| 95 |
/** |
| 96 |
* {@inheritdoc} |
| 97 |
*/ |
| 98 |
public function captureMessage(string $message, ?Severity $level = null, ?EventHint $hint = null) : ?EventId |
| 99 |
{ |
| 100 |
return SentrySdk::getCurrentHub()->captureMessage($message, $level, $hint); |
| 101 |
} |
| 102 |
/** |
| 103 |
* {@inheritdoc} |
| 104 |
*/ |
| 105 |
public function captureException(\Throwable $exception, ?EventHint $hint = null) : ?EventId |
| 106 |
{ |
| 107 |
return SentrySdk::getCurrentHub()->captureException($exception, $hint); |
| 108 |
} |
| 109 |
/** |
| 110 |
* {@inheritdoc} |
| 111 |
*/ |
| 112 |
public function captureEvent(Event $event, ?EventHint $hint = null) : ?EventId |
| 113 |
{ |
| 114 |
return SentrySdk::getCurrentHub()->captureEvent($event, $hint); |
| 115 |
} |
| 116 |
/** |
| 117 |
* {@inheritdoc} |
| 118 |
*/ |
| 119 |
public function captureLastError(?EventHint $hint = null) : ?EventId |
| 120 |
{ |
| 121 |
return SentrySdk::getCurrentHub()->captureLastError($hint); |
| 122 |
} |
| 123 |
/** |
| 124 |
* {@inheritdoc} |
| 125 |
* |
| 126 |
* @param int|float|null $duration |
| 127 |
*/ |
| 128 |
public function captureCheckIn(string $slug, CheckInStatus $status, $duration = null, ?MonitorConfig $monitorConfig = null, ?string $checkInId = null) : ?string |
| 129 |
{ |
| 130 |
return SentrySdk::getCurrentHub()->captureCheckIn($slug, $status, $duration, $monitorConfig, $checkInId); |
| 131 |
} |
| 132 |
/** |
| 133 |
* {@inheritdoc} |
| 134 |
*/ |
| 135 |
public function addBreadcrumb(Breadcrumb $breadcrumb) : bool |
| 136 |
{ |
| 137 |
return SentrySdk::getCurrentHub()->addBreadcrumb($breadcrumb); |
| 138 |
} |
| 139 |
/** |
| 140 |
* {@inheritdoc} |
| 141 |
*/ |
| 142 |
public function getIntegration(string $className) : ?IntegrationInterface |
| 143 |
{ |
| 144 |
return SentrySdk::getCurrentHub()->getIntegration($className); |
| 145 |
} |
| 146 |
/** |
| 147 |
* {@inheritdoc} |
| 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() : void |
| 185 |
{ |
| 186 |
throw new \BadMethodCallException('Unserializing instances of this class is forbidden.'); |
| 187 |
} |
| 188 |
/** |
| 189 |
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.sleep |
| 190 |
*/ |
| 191 |
public function __sleep() |
| 192 |
{ |
| 193 |
throw new \BadMethodCallException('Serializing instances of this class is forbidden.'); |
| 194 |
} |
| 195 |
} |
| 196 |
|