You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.1 KiB

<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
namespace phpFastCache\Drivers\Devfalse;
use phpFastCache\Core\DriverAbstract;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
use phpFastCache\Exceptions\phpFastCacheDriverException;
use Psr\Cache\CacheItemInterface;
/**
* Class Driver
* @package phpFastCache\Drivers
*/
class Driver extends DriverAbstract
{
/**
* Driver constructor.
* @param array $config
* @throws phpFastCacheDriverException
*/
public function __construct(array $config = [])
{
$this->setup($config);
if (!$this->driverCheck()) {
throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
}
}
/**
* @return bool
*/
public function driverCheck()
{
return true;
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return mixed
* @throws \InvalidArgumentException
*/
protected function driverWrite(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return true;
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return array [
* 'd' => 'THE ITEM DATA'
* 't' => 'THE ITEM DATE EXPIRATION'
* 'g' => 'THE ITEM TAGS'
* ]
*/
protected function driverRead(CacheItemInterface $item)
{
return [
self::DRIVER_DATA_WRAPPER_INDEX => false,
self::DRIVER_TAGS_WRAPPER_INDEX => [],
self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(),
];
}
/**
* @param \Psr\Cache\CacheItemInterface $item
* @return bool
* @throws \InvalidArgumentException
*/
protected function driverDelete(CacheItemInterface $item)
{
/**
* Check for Cross-Driver type confusion
*/
if ($item instanceof Item) {
return true;
} else {
throw new \InvalidArgumentException('Cross-Driver type confusion detected');
}
}
/**
* @return bool
*/
protected function driverClear()
{
return true;
}
/**
* @return bool
*/
protected function driverConnect()
{
return true;
}
/********************
*
* PSR-6 Extended Methods
*
*******************/
/**
* @return driverStatistic
*/
public function getStats()
{
$stat = new driverStatistic();
$stat->setInfo('[Devfalse] A void info string')
->setSize(0)
->setData(implode(', ', array_keys($this->itemInstances)))
->setRawData(false);
return $stat;
}
}