64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?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\Couchbase;
|
|
|
|
use phpFastCache\Core\Item\ExtendedCacheItemInterface;
|
|
use phpFastCache\Core\Item\ItemBaseTrait;
|
|
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
|
|
use phpFastCache\Drivers\Couchbase\Driver as CouchbaseDriver;
|
|
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;
|
|
|
|
/**
|
|
* Class Item
|
|
* @package phpFastCache\Drivers\Couchbase
|
|
*/
|
|
class Item implements ExtendedCacheItemInterface
|
|
{
|
|
use ItemBaseTrait;
|
|
|
|
/**
|
|
* Item constructor.
|
|
* @param \phpFastCache\Drivers\Couchbase\Driver $driver
|
|
* @param $key
|
|
* @throws phpFastCacheInvalidArgumentException
|
|
*/
|
|
public function __construct(CouchbaseDriver $driver, $key)
|
|
{
|
|
if (is_string($key)) {
|
|
$this->key = $key;
|
|
$this->driver = $driver;
|
|
$this->driver->setItem($this);
|
|
$this->expirationDate = new \DateTime();
|
|
} else {
|
|
throw new phpFastCacheInvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param ExtendedCacheItemPoolInterface $driver
|
|
* @throws phpFastCacheInvalidArgumentException
|
|
* @return static
|
|
*/
|
|
public function setDriver(ExtendedCacheItemPoolInterface $driver)
|
|
{
|
|
if ($driver instanceof CouchbaseDriver) {
|
|
$this->driver = $driver;
|
|
|
|
return $this;
|
|
} else {
|
|
throw new phpFastCacheInvalidArgumentException('Invalid driver instance');
|
|
}
|
|
}
|
|
} |