Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Context.php

class Context

Same name in this branch
  1. 11.1.x vendor/open-telemetry/api/Instrumentation/AutoInstrumentation/Context.php \OpenTelemetry\API\Instrumentation\AutoInstrumentation\Context
  2. 11.1.x vendor/sebastian/recursion-context/src/Context.php \SebastianBergmann\RecursionContext\Context
  3. 11.1.x vendor/symfony/serializer/Attribute/Context.php \Symfony\Component\Serializer\Attribute\Context
  4. 11.1.x vendor/phpdocumentor/type-resolver/src/Types/Context.php \phpDocumentor\Reflection\Types\Context
  5. 11.1.x core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context
  6. 11.1.x core/lib/Drupal/Component/Plugin/Context/Context.php \Drupal\Component\Plugin\Context\Context

Hierarchy

  • class \OpenTelemetry\Context\Context implements \OpenTelemetry\Context\ContextInterface

Expanded class hierarchy of Context

See also

https://github.com/open-telemetry/opentelemetry-specification/blob/main…

26 files declare their use of Context
AutoRootSpan.php in vendor/open-telemetry/sdk/Trace/AutoRootSpan.php
Baggage.php in vendor/open-telemetry/api/Baggage/Baggage.php
BaggagePropagator.php in vendor/open-telemetry/api/Baggage/Propagation/BaggagePropagator.php
BatchLogRecordProcessor.php in vendor/open-telemetry/sdk/Logs/Processor/BatchLogRecordProcessor.php
BatchSpanProcessor.php in vendor/open-telemetry/sdk/Trace/SpanProcessor/BatchSpanProcessor.php

... See full list

18 string references to 'Context'
CompiledUrlMatcherDumper::compileRoute in vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherDumper.php
Compiles a single Route to PHP code used to match it against the path info.
ConditionManagerCreateInstanceContextConfigurationRule::processNode in vendor/mglaman/phpstan-drupal/src/Rules/Deprecations/ConditionManagerCreateInstanceContextConfigurationRule.php
LocaleConfigManager::processTranslatableData in core/modules/locale/src/LocaleConfigManager.php
Process the translatable data array with a given language.
LocaleConfigSubscriber::processTranslatableData in core/modules/locale/src/LocaleConfigSubscriber.php
Process the translatable data array with a given language.
LocaleConfigSubscriber::resetExistingTranslations in core/modules/locale/src/LocaleConfigSubscriber.php
Reset existing locale translations to their source values.

... See full list

File

vendor/open-telemetry/context/Context.php, line 15

Namespace

OpenTelemetry\Context
View source
final class Context implements ContextInterface {
    private const OTEL_PHP_DEBUG_SCOPES_DISABLED = 'OTEL_PHP_DEBUG_SCOPES_DISABLED';
    private static ContextStorageInterface&ExecutionContextAwareInterface $storage;
    // Optimization for spans to avoid copying the context array.
    private static ContextKeyInterface $spanContextKey;
    private ?object $span = null;
    
    /** @var array<int, mixed> */
    private array $context = [];
    
    /** @var array<int, ContextKeyInterface> */
    private array $contextKeys = [];
    private function __construct() {
        self::$spanContextKey = ContextKeys::span();
    }
    public static function createKey(string $key) : ContextKeyInterface {
        return new ContextKey($key);
    }
    public static function setStorage(ContextStorageInterface&ExecutionContextAwareInterface $storage) : void {
        self::$storage = $storage;
    }
    public static function storage() : ContextStorageInterface&ExecutionContextAwareInterface {
        
        /** @psalm-suppress RedundantPropertyInitializationCheck */
        return self::$storage ??= new FiberBoundContextStorageExecutionAwareBC();
    }
    
    /**
     * @internal OpenTelemetry
     */
    public static function resolve(ContextInterface|false|null $context, ?ContextStorageInterface $contextStorage = null) : ContextInterface {
        return $context ?? ($contextStorage ?? self::storage())->current() ?: self::getRoot();
    }
    
    /**
     * @internal
     */
    public static function getRoot() : ContextInterface {
        static $empty;
        return $empty ??= new self();
    }
    public static function getCurrent() : ContextInterface {
        return self::storage()->current();
    }
    public function activate() : ScopeInterface {
        $scope = self::storage()->attach($this);
        
        /** @psalm-suppress RedundantCondition @phpstan-ignore-next-line */
        assert(self::debugScopesDisabled() || ($scope = new DebugScope($scope)));
        return $scope;
    }
    private static function debugScopesDisabled() : bool {
        return filter_var($_SERVER[self::OTEL_PHP_DEBUG_SCOPES_DISABLED] ?? \getenv(self::OTEL_PHP_DEBUG_SCOPES_DISABLED) ?: \ini_get(self::OTEL_PHP_DEBUG_SCOPES_DISABLED), FILTER_VALIDATE_BOOLEAN);
    }
    public function withContextValue(ImplicitContextKeyedInterface $value) : ContextInterface {
        return $value->storeInContext($this);
    }
    public function with(ContextKeyInterface $key, $value) : self {
        if ($this->get($key) === $value) {
            return $this;
        }
        $self = clone $this;
        if ($key === self::$spanContextKey) {
            $self->span = $value;
            // @phan-suppress-current-line PhanTypeMismatchPropertyReal
            return $self;
        }
        $id = spl_object_id($key);
        if ($value !== null) {
            $self->context[$id] = $value;
            $self->contextKeys[$id] ??= $key;
        }
        else {
            unset($self->context[$id], $self->contextKeys[$id]);
        }
        return $self;
    }
    public function get(ContextKeyInterface $key) {
        if ($key === self::$spanContextKey) {
            
            /** @psalm-suppress InvalidReturnStatement */
            return $this->span;
        }
        return $this->context[spl_object_id($key)] ?? null;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Context::$context private property @var array&lt;int, mixed&gt;
Context::$contextKeys private property @var array&lt;int, ContextKeyInterface&gt;
Context::$span private property
Context::$spanContextKey private static property
Context::$storage private static property
Context::activate public function Attaches this context as active context. Overrides ContextInterface::activate
Context::createKey public static function Creates a new context key. Overrides ContextInterface::createKey
Context::debugScopesDisabled private static function
Context::get public function Returns the value assigned to the given key. Overrides ContextInterface::get
Context::getCurrent public static function Returns the current context. Overrides ContextInterface::getCurrent
Context::getRoot public static function @internal
Context::OTEL_PHP_DEBUG_SCOPES_DISABLED private constant
Context::resolve public static function @internal OpenTelemetry
Context::setStorage public static function
Context::storage public static function
Context::with public function Returns a context with the given key set to the given value. Overrides ContextInterface::with
Context::withContextValue public function Returns a context with the given value set. Overrides ContextInterface::withContextValue
Context::__construct private function
RSS feed
Powered by Drupal