|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Sentry\SentryBundle\Tracing\Cache; |
| 6 | + |
| 7 | +use Sentry\State\HubInterface; |
| 8 | +use Symfony\Component\Cache\Adapter\AdapterInterface; |
| 9 | +use Symfony\Component\Cache\PruneableInterface; |
| 10 | +use Symfony\Component\Cache\ResettableInterface; |
| 11 | +use Symfony\Contracts\Cache\CacheInterface; |
| 12 | +use Symfony\Contracts\Cache\NamespacedPoolInterface; |
| 13 | + |
| 14 | +/** |
| 15 | + * This implementation of a cache adapter supports the distributed tracing |
| 16 | + * feature of Sentry. |
| 17 | + * |
| 18 | + * @internal |
| 19 | + */ |
| 20 | +final class TraceableCacheAdapterForV3WithNamespace implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @phpstan-use TraceableCacheAdapterTrait<AdapterInterface> |
| 24 | + */ |
| 25 | + use TraceableCacheAdapterTrait; |
| 26 | + |
| 27 | + /** |
| 28 | + * @param HubInterface $hub The current hub |
| 29 | + * @param AdapterInterface $decoratedAdapter The decorated cache adapter |
| 30 | + */ |
| 31 | + public function __construct(HubInterface $hub, AdapterInterface $decoratedAdapter) |
| 32 | + { |
| 33 | + $this->hub = $hub; |
| 34 | + $this->decoratedAdapter = $decoratedAdapter; |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * {@inheritdoc} |
| 39 | + * |
| 40 | + * @param mixed[] $metadata |
| 41 | + */ |
| 42 | + public function get(string $key, callable $callback, ?float $beta = null, ?array &$metadata = null): mixed |
| 43 | + { |
| 44 | + return $this->traceFunction('cache.get_item', function () use ($key, $callback, $beta, &$metadata) { |
| 45 | + if (!$this->decoratedAdapter instanceof CacheInterface) { |
| 46 | + throw new \BadMethodCallException(\sprintf('The %s::get() method is not supported because the decorated adapter does not implement the "%s" interface.', self::class, CacheInterface::class)); |
| 47 | + } |
| 48 | + |
| 49 | + return $this->decoratedAdapter->get($key, $callback, $beta, $metadata); |
| 50 | + }, $key); |
| 51 | + } |
| 52 | +} |
0 commit comments