X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fsymfony%2Fhttp-kernel%2FTests%2FProfiler%2FMock%2FRedisMock.php;fp=vendor%2Fsymfony%2Fhttp-kernel%2FTests%2FProfiler%2FMock%2FRedisMock.php;h=91222c165b86ececf9069390e7021a0f59d43f11;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/symfony/http-kernel/Tests/Profiler/Mock/RedisMock.php b/vendor/symfony/http-kernel/Tests/Profiler/Mock/RedisMock.php new file mode 100644 index 000000000..91222c165 --- /dev/null +++ b/vendor/symfony/http-kernel/Tests/Profiler/Mock/RedisMock.php @@ -0,0 +1,247 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Tests\Profiler\Mock; + +/** + * RedisMock for simulating Redis extension in tests. + * + * @author Andrej Hudec + */ +class RedisMock +{ + private $connected = false; + private $storage = array(); + + /** + * Add a server to connection pool. + * + * @param string $host + * @param int $port + * @param float $timeout + * + * @return bool + */ + public function connect($host, $port = 6379, $timeout = 0) + { + if ('127.0.0.1' == $host && 6379 == $port) { + $this->connected = true; + + return true; + } + + return false; + } + + /** + * Set client option. + * + * @param int $name + * @param int $value + * + * @return bool + */ + public function setOption($name, $value) + { + if (!$this->connected) { + return false; + } + + return true; + } + + /** + * Verify if the specified key exists. + * + * @param string $key + * + * @return bool + */ + public function exists($key) + { + if (!$this->connected) { + return false; + } + + return isset($this->storage[$key]); + } + + /** + * Store data at the server with expiration time. + * + * @param string $key + * @param int $ttl + * @param mixed $value + * + * @return bool + */ + public function setex($key, $ttl, $value) + { + if (!$this->connected) { + return false; + } + + $this->storeData($key, $value); + + return true; + } + + /** + * Sets an expiration time on an item. + * + * @param string $key + * @param int $ttl + * + * @return bool + */ + public function setTimeout($key, $ttl) + { + if (!$this->connected) { + return false; + } + + if (isset($this->storage[$key])) { + return true; + } + + return false; + } + + /** + * Retrieve item from the server. + * + * @param string $key + * + * @return bool + */ + public function get($key) + { + if (!$this->connected) { + return false; + } + + return $this->getData($key); + } + + /** + * Append data to an existing item. + * + * @param string $key + * @param string $value + * + * @return int Size of the value after the append + */ + public function append($key, $value) + { + if (!$this->connected) { + return false; + } + + if (isset($this->storage[$key])) { + $this->storeData($key, $this->getData($key).$value); + + return strlen($this->storage[$key]); + } + + return false; + } + + /** + * Remove specified keys. + * + * @param string|array $key + * + * @return int + */ + public function delete($key) + { + if (!$this->connected) { + return false; + } + + if (is_array($key)) { + $result = 0; + foreach ($key as $k) { + if (isset($this->storage[$k])) { + unset($this->storage[$k]); + ++$result; + } + } + + return $result; + } + + if (isset($this->storage[$key])) { + unset($this->storage[$key]); + + return 1; + } + + return 0; + } + + /** + * Flush all existing items from all databases at the server. + * + * @return bool + */ + public function flushAll() + { + if (!$this->connected) { + return false; + } + + $this->storage = array(); + + return true; + } + + /** + * Close Redis server connection. + * + * @return bool + */ + public function close() + { + $this->connected = false; + + return true; + } + + private function getData($key) + { + if (isset($this->storage[$key])) { + return unserialize($this->storage[$key]); + } + + return false; + } + + private function storeData($key, $value) + { + $this->storage[$key] = serialize($value); + + return true; + } + + public function select($dbnum) + { + if (!$this->connected) { + return false; + } + + if (0 > $dbnum) { + return false; + } + + return true; + } +}