init
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<?php
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
interface Cache
|
||||
{
|
||||
public const STATS_HITS = 'hits';
|
||||
public const STATS_MISSES = 'misses';
|
||||
public const STATS_UPTIME = 'uptime';
|
||||
public const STATS_MEMORY_USAGE = 'memory_usage';
|
||||
public const STATS_MEMORY_AVAILABLE = 'memory_available';
|
||||
public const STATS_MEMORY_AVAILIABLE = 'memory_available';
|
||||
public function fetch($id);
|
||||
public function contains($id);
|
||||
public function save($id, $data, $lifeTime = 0);
|
||||
public function delete($id);
|
||||
public function getStats();
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use function array_combine;
|
||||
use function array_key_exists;
|
||||
use function array_map;
|
||||
use function sprintf;
|
||||
abstract class CacheProvider implements Cache, FlushableCache, ClearableCache, MultiOperationCache
|
||||
{
|
||||
public const DOCTRINE_NAMESPACE_CACHEKEY = 'DoctrineNamespaceCacheKey[%s]';
|
||||
private $namespace = '';
|
||||
private $namespaceVersion;
|
||||
public function setNamespace($namespace)
|
||||
{
|
||||
$this->namespace = (string) $namespace;
|
||||
$this->namespaceVersion = null;
|
||||
}
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->namespace;
|
||||
}
|
||||
public function fetch($id)
|
||||
{
|
||||
return $this->doFetch($this->getNamespacedId($id));
|
||||
}
|
||||
public function fetchMultiple(array $keys)
|
||||
{
|
||||
if (empty($keys)) {
|
||||
return [];
|
||||
}
|
||||
// note: the array_combine() is in place to keep an association between our $keys and the $namespacedKeys
|
||||
$namespacedKeys = array_combine($keys, array_map([$this, 'getNamespacedId'], $keys));
|
||||
$items = $this->doFetchMultiple($namespacedKeys);
|
||||
$foundItems = [];
|
||||
// no internal array function supports this sort of mapping: needs to be iterative
|
||||
// this filters and combines keys in one pass
|
||||
foreach ($namespacedKeys as $requestedKey => $namespacedKey) {
|
||||
if (!isset($items[$namespacedKey]) && !array_key_exists($namespacedKey, $items)) {
|
||||
continue;
|
||||
}
|
||||
$foundItems[$requestedKey] = $items[$namespacedKey];
|
||||
}
|
||||
return $foundItems;
|
||||
}
|
||||
public function saveMultiple(array $keysAndValues, $lifetime = 0)
|
||||
{
|
||||
$namespacedKeysAndValues = [];
|
||||
foreach ($keysAndValues as $key => $value) {
|
||||
$namespacedKeysAndValues[$this->getNamespacedId($key)] = $value;
|
||||
}
|
||||
return $this->doSaveMultiple($namespacedKeysAndValues, $lifetime);
|
||||
}
|
||||
public function contains($id)
|
||||
{
|
||||
return $this->doContains($this->getNamespacedId($id));
|
||||
}
|
||||
public function save($id, $data, $lifeTime = 0)
|
||||
{
|
||||
return $this->doSave($this->getNamespacedId($id), $data, $lifeTime);
|
||||
}
|
||||
public function deleteMultiple(array $keys)
|
||||
{
|
||||
return $this->doDeleteMultiple(array_map([$this, 'getNamespacedId'], $keys));
|
||||
}
|
||||
public function delete($id)
|
||||
{
|
||||
return $this->doDelete($this->getNamespacedId($id));
|
||||
}
|
||||
public function getStats()
|
||||
{
|
||||
return $this->doGetStats();
|
||||
}
|
||||
public function flushAll()
|
||||
{
|
||||
return $this->doFlush();
|
||||
}
|
||||
public function deleteAll()
|
||||
{
|
||||
$namespaceCacheKey = $this->getNamespaceCacheKey();
|
||||
$namespaceVersion = $this->getNamespaceVersion() + 1;
|
||||
if ($this->doSave($namespaceCacheKey, $namespaceVersion)) {
|
||||
$this->namespaceVersion = $namespaceVersion;
|
||||
return \true;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function getNamespacedId(string $id) : string
|
||||
{
|
||||
$namespaceVersion = $this->getNamespaceVersion();
|
||||
return sprintf('%s[%s][%s]', $this->namespace, $id, $namespaceVersion);
|
||||
}
|
||||
private function getNamespaceCacheKey() : string
|
||||
{
|
||||
return sprintf(self::DOCTRINE_NAMESPACE_CACHEKEY, $this->namespace);
|
||||
}
|
||||
private function getNamespaceVersion() : int
|
||||
{
|
||||
if ($this->namespaceVersion !== null) {
|
||||
return $this->namespaceVersion;
|
||||
}
|
||||
$namespaceCacheKey = $this->getNamespaceCacheKey();
|
||||
$this->namespaceVersion = (int) $this->doFetch($namespaceCacheKey) ?: 1;
|
||||
return $this->namespaceVersion;
|
||||
}
|
||||
protected function doFetchMultiple(array $keys)
|
||||
{
|
||||
$returnValues = [];
|
||||
foreach ($keys as $key) {
|
||||
$item = $this->doFetch($key);
|
||||
if ($item === \false && !$this->doContains($key)) {
|
||||
continue;
|
||||
}
|
||||
$returnValues[$key] = $item;
|
||||
}
|
||||
return $returnValues;
|
||||
}
|
||||
protected abstract function doFetch($id);
|
||||
protected abstract function doContains($id);
|
||||
protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
|
||||
{
|
||||
$success = \true;
|
||||
foreach ($keysAndValues as $key => $value) {
|
||||
if ($this->doSave($key, $value, $lifetime)) {
|
||||
continue;
|
||||
}
|
||||
$success = \false;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
protected abstract function doSave($id, $data, $lifeTime = 0);
|
||||
protected function doDeleteMultiple(array $keys)
|
||||
{
|
||||
$success = \true;
|
||||
foreach ($keys as $key) {
|
||||
if ($this->doDelete($key)) {
|
||||
continue;
|
||||
}
|
||||
$success = \false;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
protected abstract function doDelete($id);
|
||||
protected abstract function doFlush();
|
||||
protected abstract function doGetStats();
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
interface ClearableCache
|
||||
{
|
||||
public function deleteAll();
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
interface FlushableCache
|
||||
{
|
||||
public function flushAll();
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
interface MultiDeleteCache
|
||||
{
|
||||
public function deleteMultiple(array $keys);
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
interface MultiGetCache
|
||||
{
|
||||
public function fetchMultiple(array $keys);
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
interface MultiOperationCache extends MultiGetCache, MultiDeleteCache, MultiPutCache
|
||||
{
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
interface MultiPutCache
|
||||
{
|
||||
public function saveMultiple(array $keysAndValues, $lifetime = 0);
|
||||
}
|
||||
+237
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache\Psr6;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\Cache;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\ClearableCache;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\MultiDeleteCache;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\MultiGetCache;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\MultiPutCache;
|
||||
use MailPoetVendor\Psr\Cache\CacheItemInterface;
|
||||
use MailPoetVendor\Psr\Cache\CacheItemPoolInterface;
|
||||
use MailPoetVendor\Symfony\Component\Cache\DoctrineProvider as SymfonyDoctrineProvider;
|
||||
use function array_key_exists;
|
||||
use function assert;
|
||||
use function count;
|
||||
use function current;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
use function is_string;
|
||||
use function microtime;
|
||||
use function sprintf;
|
||||
use function strpbrk;
|
||||
use const PHP_VERSION_ID;
|
||||
final class CacheAdapter implements CacheItemPoolInterface
|
||||
{
|
||||
private const RESERVED_CHARACTERS = '{}()/\\@:';
|
||||
private $cache;
|
||||
private $deferredItems = [];
|
||||
public static function wrap(Cache $cache) : CacheItemPoolInterface
|
||||
{
|
||||
if ($cache instanceof DoctrineProvider && !$cache->getNamespace()) {
|
||||
return $cache->getPool();
|
||||
}
|
||||
if ($cache instanceof SymfonyDoctrineProvider && !$cache->getNamespace()) {
|
||||
$getPool = function () {
|
||||
// phpcs:ignore Squiz.Scope.StaticThisUsage.Found
|
||||
return $this->pool;
|
||||
};
|
||||
return $getPool->bindTo($cache, SymfonyDoctrineProvider::class)();
|
||||
}
|
||||
return new self($cache);
|
||||
}
|
||||
private function __construct(Cache $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
public function getCache() : Cache
|
||||
{
|
||||
return $this->cache;
|
||||
}
|
||||
public function getItem($key) : CacheItemInterface
|
||||
{
|
||||
assert(self::validKey($key));
|
||||
if (isset($this->deferredItems[$key])) {
|
||||
$this->commit();
|
||||
}
|
||||
$value = $this->cache->fetch($key);
|
||||
if (PHP_VERSION_ID >= 80000) {
|
||||
if ($value !== \false) {
|
||||
return new TypedCacheItem($key, $value, \true);
|
||||
}
|
||||
return new TypedCacheItem($key, null, \false);
|
||||
}
|
||||
if ($value !== \false) {
|
||||
return new CacheItem($key, $value, \true);
|
||||
}
|
||||
return new CacheItem($key, null, \false);
|
||||
}
|
||||
public function getItems(array $keys = []) : array
|
||||
{
|
||||
if ($this->deferredItems) {
|
||||
$this->commit();
|
||||
}
|
||||
assert(self::validKeys($keys));
|
||||
$values = $this->doFetchMultiple($keys);
|
||||
$items = [];
|
||||
if (PHP_VERSION_ID >= 80000) {
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $values)) {
|
||||
$items[$key] = new TypedCacheItem($key, $values[$key], \true);
|
||||
} else {
|
||||
$items[$key] = new TypedCacheItem($key, null, \false);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $values)) {
|
||||
$items[$key] = new CacheItem($key, $values[$key], \true);
|
||||
} else {
|
||||
$items[$key] = new CacheItem($key, null, \false);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
public function hasItem($key) : bool
|
||||
{
|
||||
assert(self::validKey($key));
|
||||
if (isset($this->deferredItems[$key])) {
|
||||
$this->commit();
|
||||
}
|
||||
return $this->cache->contains($key);
|
||||
}
|
||||
public function clear() : bool
|
||||
{
|
||||
$this->deferredItems = [];
|
||||
if (!$this->cache instanceof ClearableCache) {
|
||||
return \false;
|
||||
}
|
||||
return $this->cache->deleteAll();
|
||||
}
|
||||
public function deleteItem($key) : bool
|
||||
{
|
||||
assert(self::validKey($key));
|
||||
unset($this->deferredItems[$key]);
|
||||
return $this->cache->delete($key);
|
||||
}
|
||||
public function deleteItems(array $keys) : bool
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
assert(self::validKey($key));
|
||||
unset($this->deferredItems[$key]);
|
||||
}
|
||||
return $this->doDeleteMultiple($keys);
|
||||
}
|
||||
public function save(CacheItemInterface $item) : bool
|
||||
{
|
||||
return $this->saveDeferred($item) && $this->commit();
|
||||
}
|
||||
public function saveDeferred(CacheItemInterface $item) : bool
|
||||
{
|
||||
if (!$item instanceof CacheItem && !$item instanceof TypedCacheItem) {
|
||||
return \false;
|
||||
}
|
||||
$this->deferredItems[$item->getKey()] = $item;
|
||||
return \true;
|
||||
}
|
||||
public function commit() : bool
|
||||
{
|
||||
if (!$this->deferredItems) {
|
||||
return \true;
|
||||
}
|
||||
$now = microtime(\true);
|
||||
$itemsCount = 0;
|
||||
$byLifetime = [];
|
||||
$expiredKeys = [];
|
||||
foreach ($this->deferredItems as $key => $item) {
|
||||
$lifetime = ($item->getExpiry() ?? $now) - $now;
|
||||
if ($lifetime < 0) {
|
||||
$expiredKeys[] = $key;
|
||||
continue;
|
||||
}
|
||||
++$itemsCount;
|
||||
$byLifetime[(int) $lifetime][$key] = $item->get();
|
||||
}
|
||||
$this->deferredItems = [];
|
||||
switch (count($expiredKeys)) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
$this->cache->delete(current($expiredKeys));
|
||||
break;
|
||||
default:
|
||||
$this->doDeleteMultiple($expiredKeys);
|
||||
break;
|
||||
}
|
||||
if ($itemsCount === 1) {
|
||||
return $this->cache->save($key, $item->get(), (int) $lifetime);
|
||||
}
|
||||
$success = \true;
|
||||
foreach ($byLifetime as $lifetime => $values) {
|
||||
$success = $this->doSaveMultiple($values, $lifetime) && $success;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
public function __destruct()
|
||||
{
|
||||
$this->commit();
|
||||
}
|
||||
private static function validKey($key) : bool
|
||||
{
|
||||
if (!is_string($key)) {
|
||||
throw new InvalidArgument(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
|
||||
}
|
||||
if ($key === '') {
|
||||
throw new InvalidArgument('Cache key length must be greater than zero.');
|
||||
}
|
||||
if (strpbrk($key, self::RESERVED_CHARACTERS) !== \false) {
|
||||
throw new InvalidArgument(sprintf('Cache key "%s" contains reserved characters "%s".', $key, self::RESERVED_CHARACTERS));
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
private static function validKeys(array $keys) : bool
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
self::validKey($key);
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
private function doDeleteMultiple(array $keys) : bool
|
||||
{
|
||||
if ($this->cache instanceof MultiDeleteCache) {
|
||||
return $this->cache->deleteMultiple($keys);
|
||||
}
|
||||
$success = \true;
|
||||
foreach ($keys as $key) {
|
||||
$success = $this->cache->delete($key) && $success;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
private function doFetchMultiple(array $keys) : array
|
||||
{
|
||||
if ($this->cache instanceof MultiGetCache) {
|
||||
return $this->cache->fetchMultiple($keys);
|
||||
}
|
||||
$values = [];
|
||||
foreach ($keys as $key) {
|
||||
$value = $this->cache->fetch($key);
|
||||
if (!$value) {
|
||||
continue;
|
||||
}
|
||||
$values[$key] = $value;
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
private function doSaveMultiple(array $keysAndValues, int $lifetime = 0) : bool
|
||||
{
|
||||
if ($this->cache instanceof MultiPutCache) {
|
||||
return $this->cache->saveMultiple($keysAndValues, $lifetime);
|
||||
}
|
||||
$success = \true;
|
||||
foreach ($keysAndValues as $key => $value) {
|
||||
$success = $this->cache->save($key, $value, $lifetime) && $success;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache\Psr6;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use MailPoetVendor\Psr\Cache\CacheItemInterface;
|
||||
use TypeError;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_int;
|
||||
use function is_object;
|
||||
use function microtime;
|
||||
use function sprintf;
|
||||
final class CacheItem implements CacheItemInterface
|
||||
{
|
||||
private $key;
|
||||
private $value;
|
||||
private $isHit;
|
||||
private $expiry;
|
||||
public function __construct(string $key, $data, bool $isHit)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->value = $data;
|
||||
$this->isHit = $isHit;
|
||||
}
|
||||
public function getKey() : string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
public function get()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
public function isHit() : bool
|
||||
{
|
||||
return $this->isHit;
|
||||
}
|
||||
public function set($value) : self
|
||||
{
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
public function expiresAt($expiration) : self
|
||||
{
|
||||
if ($expiration === null) {
|
||||
$this->expiry = null;
|
||||
} elseif ($expiration instanceof DateTimeInterface) {
|
||||
$this->expiry = (float) $expiration->format('U.u');
|
||||
} else {
|
||||
throw new TypeError(sprintf('Expected $expiration to be an instance of DateTimeInterface or null, got %s', is_object($expiration) ? get_class($expiration) : gettype($expiration)));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function expiresAfter($time) : self
|
||||
{
|
||||
if ($time === null) {
|
||||
$this->expiry = null;
|
||||
} elseif ($time instanceof DateInterval) {
|
||||
$this->expiry = microtime(\true) + DateTime::createFromFormat('U', 0)->add($time)->format('U.u');
|
||||
} elseif (is_int($time)) {
|
||||
$this->expiry = $time + microtime(\true);
|
||||
} else {
|
||||
throw new TypeError(sprintf('Expected $time to be either an integer, an instance of DateInterval or null, got %s', is_object($time) ? get_class($time) : gettype($time)));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function getExpiry() : ?float
|
||||
{
|
||||
return $this->expiry;
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache\Psr6;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\Cache;
|
||||
use MailPoetVendor\Doctrine\Common\Cache\CacheProvider;
|
||||
use MailPoetVendor\Psr\Cache\CacheItemPoolInterface;
|
||||
use MailPoetVendor\Symfony\Component\Cache\Adapter\DoctrineAdapter as SymfonyDoctrineAdapter;
|
||||
use MailPoetVendor\Symfony\Contracts\Service\ResetInterface;
|
||||
use function rawurlencode;
|
||||
final class DoctrineProvider extends CacheProvider
|
||||
{
|
||||
private $pool;
|
||||
public static function wrap(CacheItemPoolInterface $pool) : Cache
|
||||
{
|
||||
if ($pool instanceof CacheAdapter) {
|
||||
return $pool->getCache();
|
||||
}
|
||||
if ($pool instanceof SymfonyDoctrineAdapter) {
|
||||
$getCache = function () {
|
||||
// phpcs:ignore Squiz.Scope.StaticThisUsage.Found
|
||||
return $this->provider;
|
||||
};
|
||||
return $getCache->bindTo($pool, SymfonyDoctrineAdapter::class)();
|
||||
}
|
||||
return new self($pool);
|
||||
}
|
||||
private function __construct(CacheItemPoolInterface $pool)
|
||||
{
|
||||
$this->pool = $pool;
|
||||
}
|
||||
public function getPool() : CacheItemPoolInterface
|
||||
{
|
||||
return $this->pool;
|
||||
}
|
||||
public function reset() : void
|
||||
{
|
||||
if ($this->pool instanceof ResetInterface) {
|
||||
$this->pool->reset();
|
||||
}
|
||||
$this->setNamespace($this->getNamespace());
|
||||
}
|
||||
protected function doFetch($id)
|
||||
{
|
||||
$item = $this->pool->getItem(rawurlencode($id));
|
||||
return $item->isHit() ? $item->get() : \false;
|
||||
}
|
||||
protected function doContains($id)
|
||||
{
|
||||
return $this->pool->hasItem(rawurlencode($id));
|
||||
}
|
||||
protected function doSave($id, $data, $lifeTime = 0)
|
||||
{
|
||||
$item = $this->pool->getItem(rawurlencode($id));
|
||||
if (0 < $lifeTime) {
|
||||
$item->expiresAfter($lifeTime);
|
||||
}
|
||||
return $this->pool->save($item->set($data));
|
||||
}
|
||||
protected function doDelete($id)
|
||||
{
|
||||
return $this->pool->deleteItem(rawurlencode($id));
|
||||
}
|
||||
protected function doFlush()
|
||||
{
|
||||
return $this->pool->clear();
|
||||
}
|
||||
protected function doGetStats()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache\Psr6;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use InvalidArgumentException;
|
||||
use MailPoetVendor\Psr\Cache\InvalidArgumentException as PsrInvalidArgumentException;
|
||||
final class InvalidArgument extends InvalidArgumentException implements PsrInvalidArgumentException
|
||||
{
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace MailPoetVendor\Doctrine\Common\Cache\Psr6;
|
||||
if (!defined('ABSPATH')) exit;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use MailPoetVendor\Psr\Cache\CacheItemInterface;
|
||||
use TypeError;
|
||||
use function get_debug_type;
|
||||
use function is_int;
|
||||
use function microtime;
|
||||
use function sprintf;
|
||||
final class TypedCacheItem implements CacheItemInterface
|
||||
{
|
||||
private ?float $expiry = null;
|
||||
public function __construct(private string $key, private mixed $value, private bool $isHit)
|
||||
{
|
||||
}
|
||||
public function getKey() : string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
public function get() : mixed
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
public function isHit() : bool
|
||||
{
|
||||
return $this->isHit;
|
||||
}
|
||||
public function set(mixed $value) : static
|
||||
{
|
||||
$this->value = $value;
|
||||
return $this;
|
||||
}
|
||||
public function expiresAt($expiration) : static
|
||||
{
|
||||
if ($expiration === null) {
|
||||
$this->expiry = null;
|
||||
} elseif ($expiration instanceof DateTimeInterface) {
|
||||
$this->expiry = (float) $expiration->format('U.u');
|
||||
} else {
|
||||
throw new TypeError(sprintf('Expected $expiration to be an instance of DateTimeInterface or null, got %s', get_debug_type($expiration)));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function expiresAfter($time) : static
|
||||
{
|
||||
if ($time === null) {
|
||||
$this->expiry = null;
|
||||
} elseif ($time instanceof DateInterval) {
|
||||
$this->expiry = microtime(\true) + DateTime::createFromFormat('U', 0)->add($time)->format('U.u');
|
||||
} elseif (is_int($time)) {
|
||||
$this->expiry = $time + microtime(\true);
|
||||
} else {
|
||||
throw new TypeError(sprintf('Expected $time to be either an integer, an instance of DateInterval or null, got %s', get_debug_type($time)));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
public function getExpiry() : ?float
|
||||
{
|
||||
return $this->expiry;
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1 @@
|
||||
<?php
|
||||
Reference in New Issue
Block a user