]> source.dussan.org Git - nextcloud-server.git/commitdiff
mamcache: implement the ArrayAccess interface
authorRobin Appelman <icewind@owncloud.com>
Tue, 16 Jul 2013 14:06:00 +0000 (16:06 +0200)
committerRobin Appelman <icewind@owncloud.com>
Tue, 16 Jul 2013 14:06:00 +0000 (16:06 +0200)
lib/memcache/cache.php
tests/lib/memcache/cache.php

index 9db69ae410453c84297c379f43b4500bf01933c8..0ad1cc7ec0391025ef11be3296b9aa992375d0fa 100644 (file)
@@ -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);
+       }
 }
index 2c1dbc9d2f7b6fc24a5208434920eb65858f8f34..e2643b9fcd94bb0880f61cb15701f1b4459fa5e9 100644 (file)
@@ -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();