summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/context/FiberBoundContextStorageScope.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/open-telemetry/context/FiberBoundContextStorageScope.php')
-rw-r--r--vendor/open-telemetry/context/FiberBoundContextStorageScope.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/open-telemetry/context/FiberBoundContextStorageScope.php b/vendor/open-telemetry/context/FiberBoundContextStorageScope.php
new file mode 100644
index 000000000..647552244
--- /dev/null
+++ b/vendor/open-telemetry/context/FiberBoundContextStorageScope.php
@@ -0,0 +1,67 @@
+<?php
+
+/** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */
+
+declare(strict_types=1);
+
+namespace OpenTelemetry\Context;
+
+use function assert;
+use function class_exists;
+use Fiber;
+
+/**
+ * @internal
+ *
+ * @phan-file-suppress PhanUndeclaredClassReference
+ * @phan-file-suppress PhanUndeclaredClassMethod
+ */
+final class FiberBoundContextStorageScope implements ScopeInterface, ContextStorageScopeInterface
+{
+ private ContextStorageScopeInterface $scope;
+
+ public function __construct(ContextStorageScopeInterface $scope)
+ {
+ $this->scope = $scope;
+ }
+
+ public function offsetExists($offset): bool
+ {
+ return $this->scope->offsetExists($offset);
+ }
+
+ /**
+ * @phan-suppress PhanUndeclaredClassAttribute
+ */
+ #[\ReturnTypeWillChange]
+ public function offsetGet($offset)
+ {
+ return $this->scope->offsetGet($offset);
+ }
+
+ public function offsetSet($offset, $value): void
+ {
+ $this->scope->offsetSet($offset, $value);
+ }
+
+ public function offsetUnset($offset): void
+ {
+ $this->scope->offsetUnset($offset);
+ }
+
+ public function context(): ContextInterface
+ {
+ return $this->scope->context();
+ }
+
+ public function detach(): int
+ {
+ $flags = $this->scope->detach();
+ assert(class_exists(Fiber::class, false));
+ if ($this->scope[Fiber::class] !== Fiber::getCurrent()) {
+ $flags |= ScopeInterface::INACTIVE;
+ }
+
+ return $flags;
+ }
+}