Skip to content

Commit

Permalink
finalized interfaces, nulladapter, exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Balogh committed Sep 22, 2014
1 parent 1b6cdb0 commit 814ad55
Show file tree
Hide file tree
Showing 14 changed files with 613 additions and 16 deletions.
5 changes: 5 additions & 0 deletions readme.md
@@ -1,6 +1,11 @@
# Key-Value Store by [@adammbalogh](http://twitter.com/adammbalogh)

[![Build Status](https://img.shields.io/travis/adammbalogh/key-value-store/master.svg?style=flat)](https://travis-ci.org/adammbalogh/key-value-store)
[![Quality Score](https://img.shields.io/scrutinizer/g/adammbalogh/key-value-store.svg?style=flat)](https://scrutinizer-ci.com/g/adammbalogh/key-value-store)
[![Software License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)

[![SensioLabsInsight](https://insight.sensiolabs.com/projects/f1ddb443-d2a1-499a-926a-060cdecd4100/small.png)](https://insight.sensiolabs.com/projects/f1ddb443-d2a1-499a-926a-060cdecd4100)

# Support

[![Support with Gittip](http://img.shields.io/gittip/adammbalogh.svg?style=flat)](https://www.gittip.com/adammbalogh/)
14 changes: 14 additions & 0 deletions src/Adapter/AbstractAdapter.php
@@ -0,0 +1,14 @@
<?php namespace AdammBalogh\KeyValueStore\Adapter;

use AdammBalogh\KeyValueStore\Contract\AdapterInterface;

abstract class AbstractAdapter implements AdapterInterface
{
/**
* @return $this
*/
public function getAdapter()
{
return $this;
}
}
6 changes: 6 additions & 0 deletions src/Adapter/NullAdapter.php
@@ -0,0 +1,6 @@
<?php namespace AdammBalogh\KeyValueStore\Adapter;

class NullAdapter extends AbstractAdapter
{
use NullAdapter\ClientTrait, NullAdapter\KeyTrait, NullAdapter\StringTrait;
}
17 changes: 17 additions & 0 deletions src/Adapter/NullAdapter/ClientTrait.php
@@ -0,0 +1,17 @@
<?php namespace AdammBalogh\KeyValueStore\Adapter\NullAdapter;

trait ClientTrait
{
/**
* @var null
*/
protected $client;

/**
* @return null
*/
public function getClient()
{
return $this->client;
}
}
104 changes: 104 additions & 0 deletions src/Adapter/NullAdapter/KeyTrait.php
@@ -0,0 +1,104 @@
<?php namespace AdammBalogh\KeyValueStore\Adapter\NullAdapter;

use AdammBalogh\KeyValueStore\Exception\KeyNotFoundException;

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
trait KeyTrait
{
use ClientTrait;

/**
* @param string $key
*
* @return bool True if the deletion was successful, false if it was unsuccessful.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
*/
public function delete($key)
{
throw new KeyNotFoundException();
}

/**
* @param string $key
* @param int $seconds
*
* @return bool True if the timeout was set, false if the timeout could not be set.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
*/
public function expire($key, $seconds)
{
throw new KeyNotFoundException();
}

/**
* @param string $key
* @param int $timestamp
*
* @return bool True if the timeout was set, false if the timeout could not be set.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
*/
public function expireAt($key, $timestamp)
{
throw new KeyNotFoundException();
}

/**
* @return array
*/
public function getKeys()
{
return [];
}

/**
* Returns the remaining time to live of a key that has a timeout.
*
* @param string $key
*
* @return int Ttl in seconds
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException If the key exists but has no associated expire.
*/
public function getTtl($key)
{
throw new KeyNotFoundException();
}

/**
* @param string $key
*
* @return bool True if the key does exist, false if the key does not exist.
*
* @throws \InvalidArgumentException
*/
public function has($key)
{
return false;
}

/**
* Remove the existing timeout on key, turning the key from volatile (a key with an expire set)
* to persistent (a key that will never expire as no timeout is associated).
*
* @param string $key
*
* @return bool True if the persist was success, false if the persis was unsuccessful.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
*/
public function persist($key)
{
throw new KeyNotFoundException();
}
}
141 changes: 141 additions & 0 deletions src/Adapter/NullAdapter/StringTrait.php
@@ -0,0 +1,141 @@
<?php namespace AdammBalogh\KeyValueStore\Adapter\NullAdapter;

use AdammBalogh\KeyValueStore\Exception\InternalException;
use AdammBalogh\KeyValueStore\Exception\KeyAlreadyExistsException;
use AdammBalogh\KeyValueStore\Exception\KeyNotFoundException;

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
trait StringTrait
{
use ClientTrait;

/**
* @param string $key
* @param string $value
*
* @return int The length of the string after the append operation.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function append($key, $value)
{
throw new KeyNotFoundException();
}

/**
* @param string $key
*
* @return int The value of key after the decrement
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function decrement($key)
{
throw new KeyNotFoundException();
}

/**
* @param string $key
* @param int $decrement
*
* @return int The value of key after the decrement
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function decrementBy($key, $decrement)
{
throw new KeyNotFoundException();
}

/**
* @param string $key
*
* @return string The value of the key
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function get($key)
{
throw new KeyNotFoundException();
}

/**
* @param string $key
*
* @return int
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function getValueLength($key)
{
throw new KeyNotFoundException();
}

/**
* @param string $key
*
* @return int The value of key after the increment
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function increment($key)
{
throw new KeyNotFoundException();
}

/**
* @param string $key
* @param int $increment
*
* @return int The value of key after the increment
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function incrementBy($key, $increment)
{
throw new KeyNotFoundException();
}

/**
* @param string $key
* @param string $value
*
* @return bool True if the set was successful, false if it was unsuccessful
*
* @throws \InvalidArgumentException
*/
public function set($key, $value)
{
return false;
}

/**
* @param string $key
* @param string $value
*
* @return bool True if the set was successful, false if it was unsuccessful
*
* @throws \InvalidArgumentException
* @throws KeyAlreadyExistsException
*/
public function setIfNotExists($key, $value)
{
return false;
}
}
61 changes: 61 additions & 0 deletions src/Contract/KeyInterface.php
@@ -1,18 +1,79 @@
<?php namespace AdammBalogh\KeyValueStore\Contract;

use AdammBalogh\KeyValueStore\Exception\InternalException;
use AdammBalogh\KeyValueStore\Exception\KeyNotFoundException;

interface KeyInterface
{
/**
* @param string $key
*
* @return bool True if the deletion was successful, false if it was unsuccessful.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
*/
public function delete($key);

/**
* @param string $key
* @param int $seconds
*
* @return bool True if the timeout was set, false if the timeout could not be set.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
*/
public function expire($key, $seconds);

/**
* @param string $key
* @param int $timestamp
*
* @return bool True if the timeout was set, false if the timeout could not be set.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
*/
public function expireAt($key, $timestamp);

/**
* @return array
*/
public function getKeys();

/**
* Returns the remaining time to live of a key that has a timeout.
*
* @param string $key
*
* @return int Ttl in seconds
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException If the key exists but has no associated expire.
*/
public function getTtl($key);

/**
* @param string $key
*
* @return bool True if the key does exist, false if the key does not exist.
*
* @throws \InvalidArgumentException
*/
public function has($key);

/**
* Remove the existing timeout on key, turning the key from volatile (a key with an expire set)
* to persistent (a key that will never expire as no timeout is associated).
*
* @param string $key
*
* @return bool True if the persist was success, false if the persis was unsuccessful.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
*/
public function persist($key);
}

0 comments on commit 814ad55

Please sign in to comment.