File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616
1717final class Context
1818{
19+ /** @psalm-var class-string-map<T, T> */
20+ private array $ extensions = [];
21+
1922 public function __construct (
2023 public readonly TracerProviderInterface $ tracerProvider = new NoopTracerProvider (),
2124 public readonly MeterProviderInterface $ meterProvider = new NoopMeterProvider (),
2225 public readonly LoggerProviderInterface $ loggerProvider = new NoopLoggerProvider (),
2326 public readonly LoggerInterface $ logger = new NullLogger (),
2427 ) {
2528 }
29+
30+ /**
31+ * @psalm-template T of object
32+ * @psalm-param T $extension
33+ * @psalm-param class-string<T>|null $type
34+ */
35+ public function withExtension (object $ extension , ?string $ type = null ): self
36+ {
37+ $ type ??= $ extension ::class;
38+
39+ $ clone = clone $ this ;
40+ $ clone ->extensions [$ type ] = $ extension ;
41+
42+ return $ clone ;
43+ }
44+
45+ /**
46+ * @psalm-template T of object
47+ * @psalm-param class-string<T> $type
48+ * @psalm-return T|null
49+ */
50+ public function getExtension (string $ type ): ?object
51+ {
52+ return $ this ->extensions [$ type ] ?? null ;
53+ }
2654}
2755
2856/** @phpstan-ignore-next-line @phan-suppress-next-line PhanUndeclaredClassReference */
Original file line number Diff line number Diff line change 3535 },
3636 "extra" : {
3737 "branch-alias" : {
38- "dev-main" : " 1.7 .x-dev"
38+ "dev-main" : " 1.8 .x-dev"
3939 },
4040 "spi" : {
4141 "OpenTelemetry\\ API\\ Instrumentation\\ AutoInstrumentation\\ HookManagerInterface" : [
You can’t perform that action at this time.
0 commit comments