vendor/sentry/sentry-symfony/src/Tracing/Cache/TraceableCacheAdapterForV3.php line 48

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sentry\SentryBundle\Tracing\Cache;
  4. use Sentry\State\HubInterface;
  5. use Symfony\Component\Cache\Adapter\AdapterInterface;
  6. use Symfony\Component\Cache\PruneableInterface;
  7. use Symfony\Component\Cache\ResettableInterface;
  8. use Symfony\Contracts\Cache\CacheInterface;
  9. /**
  10.  * This implementation of a cache adapter supports the distributed tracing
  11.  * feature of Sentry.
  12.  *
  13.  * @internal
  14.  */
  15. final class TraceableCacheAdapterForV3 implements AdapterInterfaceCacheInterfacePruneableInterfaceResettableInterface
  16. {
  17.     /**
  18.      * @phpstan-use TraceableCacheAdapterTrait<AdapterInterface>
  19.      */
  20.     use TraceableCacheAdapterTrait;
  21.     /**
  22.      * @param HubInterface     $hub              The current hub
  23.      * @param AdapterInterface $decoratedAdapter The decorated cache adapter
  24.      */
  25.     public function __construct(HubInterface $hubAdapterInterface $decoratedAdapter)
  26.     {
  27.         $this->hub $hub;
  28.         $this->decoratedAdapter $decoratedAdapter;
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      *
  33.      * @param mixed[] $metadata
  34.      */
  35.     public function get(string $key, callable $callbackfloat $beta null, array &$metadata null): mixed
  36.     {
  37.         return $this->traceFunction('cache.get_item', function () use ($key$callback$beta, &$metadata) {
  38.             if (!$this->decoratedAdapter instanceof CacheInterface) {
  39.                 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));
  40.             }
  41.             return $this->decoratedAdapter->get($key$callback$beta$metadata);
  42.         }, $key);
  43.     }
  44. }