1<?php 2/** 3 * 4 * This file is part of phpFastCache. 5 * 6 * @license MIT License (MIT) 7 * 8 * For full copyright and license information, please see the docs/CREDITS.txt file. 9 * 10 * @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com 11 * @author Georges.L (Geolim4) <contact@geolim4.com> 12 * 13 */ 14 15namespace phpFastCache\Drivers\Memcache; 16 17use phpFastCache\Cache\ExtendedCacheItemInterface; 18use phpFastCache\Cache\ExtendedCacheItemPoolInterface; 19use phpFastCache\Cache\ItemBaseTrait; 20use phpFastCache\Drivers\Memcache\Driver as MemcacheDriver; 21 22/** 23 * Class Item 24 * @package phpFastCache\Drivers\Apc 25 */ 26class Item implements ExtendedCacheItemInterface 27{ 28 use ItemBaseTrait; 29 30 /** 31 * Item constructor. 32 * @param \phpFastCache\Drivers\Memcache\Driver $driver 33 * @param $key 34 * @throws \InvalidArgumentException 35 */ 36 public function __construct(MemcacheDriver $driver, $key) 37 { 38 if (is_string($key)) { 39 $this->key = $key; 40 $this->driver = $driver; 41 $this->driver->setItem($this); 42 $this->expirationDate = new \DateTime(); 43 } else { 44 throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key))); 45 } 46 } 47 48 /** 49 * @param ExtendedCacheItemPoolInterface $driver 50 * @throws \InvalidArgumentException 51 * @return static 52 */ 53 public function setDriver(ExtendedCacheItemPoolInterface $driver) 54 { 55 if ($driver instanceof MemcacheDriver) { 56 $this->driver = $driver; 57 58 return $this; 59 } else { 60 throw new \InvalidArgumentException('Invalid driver instance'); 61 } 62 } 63}