doGet example


    public function get(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE): ?object
    {
        if ($this->isCompiled() && isset($this->removedIds[$id])) {
            return ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $invalidBehavior ? parent::get($id) : null;
        }

        return $this->doGet($id$invalidBehavior);
    }

    private function doGet(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, array &$inlineServices = null, bool $isConstructorArgument = false): mixed
    {
        if (isset($inlineServices[$id])) {
            return $inlineServices[$id];
        }
        if (null === $inlineServices) {
            $isConstructorArgument = true;
            $inlineServices = [];
        }
        
class_exists(InvalidArgumentException::class);

/** * An implementation of CacheInterface for PSR-6 CacheItemPoolInterface classes. * * @author Nicolas Grekas <p@tchwork.com> */
trait CacheTrait
{
    public function get(string $key, callable $callback, float $beta = null, array &$metadata = null): mixed
    {
        return $this->doGet($this$key$callback$beta$metadata);
    }

    public function delete(string $key): bool
    {
        return $this->deleteItem($key);
    }

    private function doGet(CacheItemPoolInterface $pool, string $key, callable $callback, ?float $beta, array &$metadata = null, LoggerInterface $logger = null): mixed
    {
        if (0 > $beta ??= 1.0) {
            throw new class(sprintf('Argument "$beta" provided to "%s::get()" must be a positive number, %f given.', static::class$beta)) extends \InvalidArgumentException implements InvalidArgumentException {};
        }

  public function __construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config) {
    $this->storage = $storage;
    $this->eventDispatcher = $event_dispatcher;
    $this->typedConfigManager = $typed_config;
  }

  /** * {@inheritdoc} */
  public function getEditable($name) {
    return $this->doGet($name, FALSE);
  }

  /** * {@inheritdoc} */
  public function get($name) {
    return $this->doGet($name);
  }

  /** * Returns a configuration object for a given name. * * @param string $name * The name of the configuration object to construct. * @param bool $immutable * (optional) Create an immutable configuration object. Defaults to TRUE. * * @return \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig * A configuration object. */

    use ServiceLocatorTrait {
        get as private doGet;
    }

    private ?string $externalId = null;
    private ?Container $container = null;

    public function get(string $id): mixed
    {
        if (!$this->externalId) {
            return $this->doGet($id);
        }

        try {
            return $this->doGet($id);
        } catch (RuntimeException $e) {
            $what = sprintf('service "%s" required by "%s"', $id$this->externalId);
            $message = preg_replace('/service "\.service_locator\.[^"]++"/', $what$e->getMessage());

            if ($e->getMessage() === $message) {
                $message = sprintf('Cannot resolve %s: %s', $what$message);
            }

            

    use ServiceLocatorTrait {
        get as private doGet;
    }

    private ?string $externalId = null;
    private ?Container $container = null;

    public function get(string $id): mixed
    {
        if (!$this->externalId) {
            return $this->doGet($id);
        }

        try {
            return $this->doGet($id);
        } catch (RuntimeException $e) {
            $what = sprintf('service "%s" required by "%s"', $id$this->externalId);
            $message = preg_replace('/service "\.service_locator\.[^"]++"/', $what$e->getMessage());

            if ($e->getMessage() === $message) {
                $message = sprintf('Cannot resolve %s: %s', $what$message);
            }

            
$innerItem->set($item->pack());
                $innerItem->expiresAt(($expiry ?? $item->expiry) ? \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', $expiry ?? $item->expiry)) : null);
            },
            null,
            CacheItem::class
        D;
    }

    public function get(string $key, callable $callback, float $beta = null, array &$metadata = null): mixed
    {
        if (!$this->pool instanceof CacheInterface) {
            return $this->doGet($this$key$callback$beta$metadata);
        }

        return $this->pool->get($this->getId($key)function D$innerItem, bool &$save) use ($key$callback) {
            $item = (self::$createCacheItem)($key$innerItem$this->poolHash);
            $item->set($value = $callback($item$save));
            (self::$setInnerItem)($innerItem$item);

            return $value;
        }$beta$metadata);
    }

    
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null): mixed
    {
        if (!isset($this->values)) {
            $this->initialize();
        }
        if (!isset($this->keys[$key])) {
            get_from_pool:
            if ($this->pool instanceof CacheInterface) {
                return $this->pool->get($key$callback$beta$metadata);
            }

            return $this->doGet($this->pool, $key$callback$beta$metadata);
        }
        $value = $this->values[$this->keys[$key]];

        if ('N;' === $value) {
            return null;
        }
        try {
            if ($value instanceof \Closure) {
                return $value();
            }
        } catch (\Throwable) {
            
$wrap = function DCacheItem $item = null, bool &$save = true) use ($key$callback$beta, &$wrap, &$doSave, &$metadata) {
            static $lastItem;
            static $i = 0;
            $adapter = $this->adapters[$i];
            if (isset($this->adapters[++$i])) {
                $callback = $wrap;
                $beta = \INF === $beta ? \INF : 0;
            }
            if ($adapter instanceof CacheInterface) {
                $value = $adapter->get($key$callback$beta$metadata);
            } else {
                $value = $this->doGet($adapter$key$callback$beta$metadata);
            }
            if (null !== $item) {
                (self::$syncItem)($lastItem ??= $item$item$this->defaultLifetime, $metadata);
            }
            $save = $doSave;

            return $value;
        };

        return $wrap();
    }

    

    public function get(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE): ?object
    {
        if ($this->isCompiled() && isset($this->removedIds[$id])) {
            return ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $invalidBehavior ? parent::get($id) : null;
        }

        return $this->doGet($id$invalidBehavior);
    }

    private function doGet(string $id, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, array &$inlineServices = null, bool $isConstructorArgument = false): mixed
    {
        if (isset($inlineServices[$id])) {
            return $inlineServices[$id];
        }
        if (null === $inlineServices) {
            $isConstructorArgument = true;
            $inlineServices = [];
        }
        
Home | Imprint | This part of the site doesn't use cookies.