mamcache: implement the ArrayAccess interface
This commit is contained in:
parent
8ad148feaf
commit
504089940d
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace OC\Memcache;
|
||||
|
||||
abstract class Cache {
|
||||
abstract class Cache implements \ArrayAccess {
|
||||
/**
|
||||
* @var string $prefix
|
||||
*/
|
||||
|
@ -56,4 +56,22 @@ abstract class Cache {
|
|||
* @return mixed
|
||||
*/
|
||||
abstract public function clear($prefix = '');
|
||||
|
||||
//implement the ArrayAccess interface
|
||||
|
||||
public function offsetExists($offset) {
|
||||
return $this->hasKey($offset);
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value) {
|
||||
$this->set($offset, $value);
|
||||
}
|
||||
|
||||
public function offsetGet($offset) {
|
||||
return $this->get($offset);
|
||||
}
|
||||
|
||||
public function offsetUnset($offset) {
|
||||
$this->remove($offset);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,28 @@ class Cache extends \Test_Cache {
|
|||
$this->assertFalse($this->instance->hasKey('foo'));
|
||||
}
|
||||
|
||||
public function testArrayAccessSet() {
|
||||
$this->instance['foo'] = 'bar';
|
||||
$this->assertEquals('bar', $this->instance->get('foo'));
|
||||
}
|
||||
|
||||
public function testArrayAccessGet() {
|
||||
$this->instance->set('foo', 'bar');
|
||||
$this->assertEquals('bar', $this->instance['foo']);
|
||||
}
|
||||
|
||||
public function testArrayAccessExists() {
|
||||
$this->assertFalse(isset($this->instance['foo']));
|
||||
$this->instance->set('foo', 'bar');
|
||||
$this->assertTrue(isset($this->instance['foo']));
|
||||
}
|
||||
|
||||
public function testArrayAccessUnset() {
|
||||
$this->instance->set('foo', 'bar');
|
||||
unset($this->instance['foo']);
|
||||
$this->assertFalse($this->instance->hasKey('foo'));
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
if ($this->instance) {
|
||||
$this->instance->clear();
|
||||
|
|
Loading…
Reference in New Issue