|
19 | 19 | class SingletonAspect extends AbstractAspect |
20 | 20 | { |
21 | 21 | public array $classes = [ |
22 | | - \Sentry\CheckInStatus::class . '::getInstance', |
23 | | - \Sentry\EventType::class . '::getInstance', |
24 | | - \Sentry\MonitorScheduleUnit::class . '::getInstance', |
| 22 | + // Singleton Classes |
| 23 | + \Sentry\State\HubAdapter::class . '::getInstance', |
25 | 24 | \Sentry\Integration\IntegrationRegistry::class . '::getInstance', |
26 | | - \Sentry\Logs\LogLevel::class . '::getInstance', |
27 | 25 | \Sentry\Metrics\TraceMetrics::class . '::getInstance', |
28 | | - \Sentry\State\HubAdapter::class . '::getInstance', |
29 | | - \Sentry\Tracing\SpanStatus::class . '::getInstance', |
30 | | - \Sentry\Tracing\TransactionSource::class . '::getInstance', |
31 | | - \Sentry\Transport\ResultStatus::class . '::getInstance', |
32 | | - \Sentry\Unit::class . '::getInstance', |
| 26 | + // Enums |
| 27 | + // \Sentry\CheckInStatus::class . '::getInstance', |
| 28 | + // \Sentry\EventType::class . '::getInstance', |
| 29 | + // \Sentry\MonitorScheduleUnit::class . '::getInstance', |
| 30 | + // \Sentry\Logs\LogLevel::class . '::getInstance', |
| 31 | + // \Sentry\Tracing\SpanStatus::class . '::getInstance', |
| 32 | + // \Sentry\Tracing\TransactionSource::class . '::getInstance', |
| 33 | + // \Sentry\Transport\ResultStatus::class . '::getInstance', |
| 34 | + // \Sentry\Unit::class . '::getInstance', |
33 | 35 | ]; |
34 | 36 |
|
35 | 37 | public function process(ProceedingJoinPoint $proceedingJoinPoint) |
36 | 38 | { |
37 | 39 | $key = $className = $proceedingJoinPoint->className; |
38 | 40 | $arguments = $proceedingJoinPoint->getArguments(); |
39 | 41 |
|
40 | | - if (isset($arguments[0])) { |
| 42 | + if (! array_key_exists(0, $arguments)) { |
41 | 43 | $key .= '#' . $arguments[0]; |
42 | 44 | } |
43 | 45 |
|
44 | | - return Context::getOrSet($key, function () use ($proceedingJoinPoint, $className, $arguments) { |
45 | | - // Reset singleton instance before proceeding |
46 | | - Closure::bind(function () use ($className, $arguments) { |
47 | | - if (property_exists($className, 'instance')) { |
48 | | - $className::$instance = null; |
49 | | - } elseif ( |
50 | | - property_exists($className, 'instances') |
51 | | - && isset($arguments[0]) |
52 | | - && array_key_exists($arguments[0], $className::$instances) |
53 | | - ) { |
54 | | - $className::$instances[$arguments[0]] = null; |
55 | | - } |
56 | | - }, null, $className)(); |
57 | | - |
58 | | - // Proceed to get the singleton instance |
59 | | - return $proceedingJoinPoint->process(); |
60 | | - }); |
| 46 | + return match ($className) { |
| 47 | + // Singleton Classes |
| 48 | + \Sentry\State\HubAdapter::class, |
| 49 | + \Sentry\Integration\IntegrationRegistry::class => Context::getOrSet($key, function () use ($className) { |
| 50 | + return Closure::bind(fn () => new $className(), null, $className)(); |
| 51 | + }), |
| 52 | + \Sentry\Metrics\TraceMetrics::class => Context::getOrSet($key, function () use ($className) { |
| 53 | + return new $className(); |
| 54 | + }), |
| 55 | + |
| 56 | + // Enums |
| 57 | + // \Sentry\CheckInStatus::class, |
| 58 | + // \Sentry\EventType::class, |
| 59 | + // \Sentry\MonitorScheduleUnit::class, |
| 60 | + // \Sentry\Logs\LogLevel::class, |
| 61 | + // \Sentry\Tracing\SpanStatus::class, |
| 62 | + // \Sentry\Tracing\TransactionSource::class, |
| 63 | + // \Sentry\Transport\ResultStatus::class, |
| 64 | + // \Sentry\Unit::class => $proceedingJoinPoint->process(), |
| 65 | + default => $proceedingJoinPoint->process(), |
| 66 | + }; |
61 | 67 | } |
62 | 68 | } |
0 commit comments