mailpoet
/
vendor-prefixed
/
doctrine
/
cache
/
lib
/
Doctrine
/
Common
/
Cache
/
Psr6
/
CacheItem.php
mailpoet
/
vendor-prefixed
/
doctrine
/
cache
/
lib
/
Doctrine
/
Common
/
Cache
/
Psr6
Last commit date
CacheAdapter.php
4 years ago
CacheItem.php
4 years ago
DoctrineProvider.php
2 years ago
InvalidArgument.php
4 years ago
TypedCacheItem.php
2 years ago
index.php
3 years ago
CacheItem.php
73 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Doctrine\Common\Cache\Psr6; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use DateInterval; |
| 5 | use DateTime; |
| 6 | use DateTimeInterface; |
| 7 | use MailPoetVendor\Psr\Cache\CacheItemInterface; |
| 8 | use TypeError; |
| 9 | use function get_class; |
| 10 | use function gettype; |
| 11 | use function is_int; |
| 12 | use function is_object; |
| 13 | use function microtime; |
| 14 | use function sprintf; |
| 15 | final class CacheItem implements CacheItemInterface |
| 16 | { |
| 17 | private $key; |
| 18 | private $value; |
| 19 | private $isHit; |
| 20 | private $expiry; |
| 21 | public function __construct(string $key, $data, bool $isHit) |
| 22 | { |
| 23 | $this->key = $key; |
| 24 | $this->value = $data; |
| 25 | $this->isHit = $isHit; |
| 26 | } |
| 27 | public function getKey() : string |
| 28 | { |
| 29 | return $this->key; |
| 30 | } |
| 31 | public function get() |
| 32 | { |
| 33 | return $this->value; |
| 34 | } |
| 35 | public function isHit() : bool |
| 36 | { |
| 37 | return $this->isHit; |
| 38 | } |
| 39 | public function set($value) : self |
| 40 | { |
| 41 | $this->value = $value; |
| 42 | return $this; |
| 43 | } |
| 44 | public function expiresAt($expiration) : self |
| 45 | { |
| 46 | if ($expiration === null) { |
| 47 | $this->expiry = null; |
| 48 | } elseif ($expiration instanceof DateTimeInterface) { |
| 49 | $this->expiry = (float) $expiration->format('U.u'); |
| 50 | } else { |
| 51 | throw new TypeError(sprintf('Expected $expiration to be an instance of DateTimeInterface or null, got %s', is_object($expiration) ? get_class($expiration) : gettype($expiration))); |
| 52 | } |
| 53 | return $this; |
| 54 | } |
| 55 | public function expiresAfter($time) : self |
| 56 | { |
| 57 | if ($time === null) { |
| 58 | $this->expiry = null; |
| 59 | } elseif ($time instanceof DateInterval) { |
| 60 | $this->expiry = microtime(\true) + DateTime::createFromFormat('U', 0)->add($time)->format('U.u'); |
| 61 | } elseif (is_int($time)) { |
| 62 | $this->expiry = $time + microtime(\true); |
| 63 | } else { |
| 64 | 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))); |
| 65 | } |
| 66 | return $this; |
| 67 | } |
| 68 | public function getExpiry() : ?float |
| 69 | { |
| 70 | return $this->expiry; |
| 71 | } |
| 72 | } |
| 73 |