diff options
Diffstat (limited to 'vendor/open-telemetry/context/ContextStorage.php')
-rw-r--r-- | vendor/open-telemetry/context/ContextStorage.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/open-telemetry/context/ContextStorage.php b/vendor/open-telemetry/context/ContextStorage.php new file mode 100644 index 000000000..e82d3d161 --- /dev/null +++ b/vendor/open-telemetry/context/ContextStorage.php @@ -0,0 +1,57 @@ +<?php + +declare(strict_types=1); + +namespace OpenTelemetry\Context; + +/** + * @internal + */ +final class ContextStorage implements ContextStorageInterface, ExecutionContextAwareInterface +{ + public ContextStorageHead $current; + private ContextStorageHead $main; + /** @var array<int|string, ContextStorageHead> */ + private array $forks = []; + + public function __construct() + { + $this->current = $this->main = new ContextStorageHead($this); + } + + public function fork($id): void + { + $this->forks[$id] = clone $this->current; + } + + public function switch($id): void + { + $this->current = $this->forks[$id] ?? $this->main; + } + + public function destroy($id): void + { + unset($this->forks[$id]); + } + + public function scope(): ?ContextStorageScopeInterface + { + return ($this->current->node->head ?? null) === $this->current + ? $this->current->node + : null; + } + + public function current(): ContextInterface + { + return $this->current->node->context ?? Context::getRoot(); + } + + public function attach(ContextInterface $context): ContextStorageScopeInterface + { + return $this->current->node = new ContextStorageNode($context, $this->current, $this->current->node); + } + + private function __clone() + { + } +} |