1*d5ef99ddSAndreas Gohr<?php 2*d5ef99ddSAndreas Gohr 3*d5ef99ddSAndreas Gohr/** 4*d5ef99ddSAndreas Gohr * Device Detector - The Universal Device Detection library for parsing User Agents 5*d5ef99ddSAndreas Gohr * 6*d5ef99ddSAndreas Gohr * @link https://matomo.org 7*d5ef99ddSAndreas Gohr * 8*d5ef99ddSAndreas Gohr * @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later 9*d5ef99ddSAndreas Gohr */ 10*d5ef99ddSAndreas Gohr 11*d5ef99ddSAndreas Gohrdeclare(strict_types=1); 12*d5ef99ddSAndreas Gohr 13*d5ef99ddSAndreas Gohrnamespace DeviceDetector\Cache; 14*d5ef99ddSAndreas Gohr 15*d5ef99ddSAndreas Gohruse Psr\Cache\CacheItemPoolInterface; 16*d5ef99ddSAndreas Gohr 17*d5ef99ddSAndreas Gohrclass PSR6Bridge implements CacheInterface 18*d5ef99ddSAndreas Gohr{ 19*d5ef99ddSAndreas Gohr /** 20*d5ef99ddSAndreas Gohr * @var CacheItemPoolInterface 21*d5ef99ddSAndreas Gohr */ 22*d5ef99ddSAndreas Gohr private $pool; 23*d5ef99ddSAndreas Gohr 24*d5ef99ddSAndreas Gohr /** 25*d5ef99ddSAndreas Gohr * PSR6Bridge constructor. 26*d5ef99ddSAndreas Gohr * @param CacheItemPoolInterface $pool 27*d5ef99ddSAndreas Gohr */ 28*d5ef99ddSAndreas Gohr public function __construct(CacheItemPoolInterface $pool) 29*d5ef99ddSAndreas Gohr { 30*d5ef99ddSAndreas Gohr $this->pool = $pool; 31*d5ef99ddSAndreas Gohr } 32*d5ef99ddSAndreas Gohr 33*d5ef99ddSAndreas Gohr /** 34*d5ef99ddSAndreas Gohr * @inheritDoc 35*d5ef99ddSAndreas Gohr */ 36*d5ef99ddSAndreas Gohr public function fetch(string $id) 37*d5ef99ddSAndreas Gohr { 38*d5ef99ddSAndreas Gohr $item = $this->pool->getItem($id); 39*d5ef99ddSAndreas Gohr 40*d5ef99ddSAndreas Gohr return $item->isHit() ? $item->get() : false; 41*d5ef99ddSAndreas Gohr } 42*d5ef99ddSAndreas Gohr 43*d5ef99ddSAndreas Gohr /** 44*d5ef99ddSAndreas Gohr * @inheritDoc 45*d5ef99ddSAndreas Gohr */ 46*d5ef99ddSAndreas Gohr public function contains(string $id): bool 47*d5ef99ddSAndreas Gohr { 48*d5ef99ddSAndreas Gohr return $this->pool->hasItem($id); 49*d5ef99ddSAndreas Gohr } 50*d5ef99ddSAndreas Gohr 51*d5ef99ddSAndreas Gohr /** 52*d5ef99ddSAndreas Gohr * @inheritDoc 53*d5ef99ddSAndreas Gohr */ 54*d5ef99ddSAndreas Gohr public function save(string $id, $data, int $lifeTime = 0): bool 55*d5ef99ddSAndreas Gohr { 56*d5ef99ddSAndreas Gohr $item = $this->pool->getItem($id); 57*d5ef99ddSAndreas Gohr $item->set($data); 58*d5ef99ddSAndreas Gohr 59*d5ef99ddSAndreas Gohr if (\func_num_args() > 2) { 60*d5ef99ddSAndreas Gohr $item->expiresAfter($lifeTime); 61*d5ef99ddSAndreas Gohr } 62*d5ef99ddSAndreas Gohr 63*d5ef99ddSAndreas Gohr return $this->pool->save($item); 64*d5ef99ddSAndreas Gohr } 65*d5ef99ddSAndreas Gohr 66*d5ef99ddSAndreas Gohr /** 67*d5ef99ddSAndreas Gohr * @inheritDoc 68*d5ef99ddSAndreas Gohr */ 69*d5ef99ddSAndreas Gohr public function delete(string $id): bool 70*d5ef99ddSAndreas Gohr { 71*d5ef99ddSAndreas Gohr return $this->pool->deleteItem($id); 72*d5ef99ddSAndreas Gohr } 73*d5ef99ddSAndreas Gohr 74*d5ef99ddSAndreas Gohr /** 75*d5ef99ddSAndreas Gohr * @inheritDoc 76*d5ef99ddSAndreas Gohr */ 77*d5ef99ddSAndreas Gohr public function flushAll(): bool 78*d5ef99ddSAndreas Gohr { 79*d5ef99ddSAndreas Gohr return $this->pool->clear(); 80*d5ef99ddSAndreas Gohr } 81*d5ef99ddSAndreas Gohr} 82